Skip to content

Commit

Permalink
ported to clang
Browse files Browse the repository at this point in the history
  • Loading branch information
billhails committed Oct 30, 2024
1 parent 9dec5e9 commit 02c5336
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 31 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ endif
endif
endif

CC:=cc -Wall -Wextra -Werror $(CCMODE) $(EXTRA_DEFINES)
LAXCC:=cc -Werror $(CCMODE) $(EXTRA_DEFINES)
ifndef CCC
CCC:=clang
endif

CC:=$(CCC) -Wall -Wextra -Werror $(CCMODE) $(EXTRA_DEFINES)
LAXCC:=$(CCC) -Werror $(CCMODE) $(EXTRA_DEFINES)

PYTHON=python3
MAKE_AST=$(PYTHON) ./tools/makeAST.py
Expand Down
2 changes: 2 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

More of a wish-list than a hard and fast plan.

* Target LLVM
* Proper namespace import support including user-defined operators.
* Over-application i.e. `fn (a) { fn (b) { a + b } }(2, 3)`.
* Unpacking function return values (tuples only).
* More numbers:
Expand Down
5 changes: 3 additions & 2 deletions src/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ static CTEnv *annotateCexpCondCases(CexpCondCases *x, CTEnv *env) {

static CTEnv *annotateLetRecLam(Aexp *x, CTEnv *env, int letRecOffset) {
switch (x->type) {
case AEXP_TYPE_LAM:
case AEXP_TYPE_LAM: {
AexpLam *lam = x->val.lam;
annotateAexpLam(lam, env);
lam->letRecOffset = letRecOffset;
break;
}
break;
default:
cant_happen("letrec bindings can only contain lambdas, got %s", aexpTypeName(x->type));
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins_helper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef cekf_builtins_helper_h
# define cekf_builtin_helper_h
# define cekf_builtins_helper_h
/*
* CEKF - VM supporting amb
* Copyright (C) 2022-2023 Bill Hails
Expand Down
2 changes: 0 additions & 2 deletions src/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ void printHashSymbol(HashSymbol *symbol) {
}

void printHashTable(HashTable *table, int depth) {
int count = 0;
eprintf("%*s", depth * PAD_WIDTH, "");
if (table == NULL) {
eprintf("HashTable: (NULL)");
Expand Down Expand Up @@ -289,7 +288,6 @@ void printHashTable(HashTable *table, int depth) {
} else {
eprintf("\n");
}
count++;
}
}
if (first)
Expand Down
32 changes: 24 additions & 8 deletions src/lambda_simplfication.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


#include <stdio.h>
#include <stdlib.h>
#include "common.h"
Expand All @@ -37,8 +36,10 @@ static LamExp *performLamSimplifications(LamLam *lam) {
lam->exp = lamPerformSimplifications(lam->exp);
if ( lam->args == NULL
&& lam->exp->type == LAMEXP_TYPE_APPLY
&& lam->exp->val.apply->args == NULL) {
&& lam->exp->val.apply->args == NULL
&& lam->exp->val.apply->function->type != LAMEXP_TYPE_CONSTRUCTOR) {
LEAVE(performLamSimplifications);
printLamLam(lam, 0);
return lam->exp->val.apply->function;
}
LEAVE(performLamSimplifications);
Expand All @@ -64,19 +65,34 @@ static LamUnaryApp *performUnarySimplifications(LamUnaryApp *unary) {
return unary;
}

static LamSequence *performSequenceSimplifications(LamSequence *sequence) {
ENTER(performSequenceSimplifications);
static LamSequence *_performSequenceSimplifications(LamSequence *sequence) {
ENTER(_performSequenceSimplifications);
if (sequence == NULL) {
LEAVE(performSequenceSimplifications);
LEAVE(_performSequenceSimplifications);
return NULL;
}
sequence->next =
performSequenceSimplifications(sequence->next);
_performSequenceSimplifications(sequence->next);
sequence->exp = lamPerformSimplifications(sequence->exp);
LEAVE(performSequenceSimplifications);
LEAVE(_performSequenceSimplifications);
return sequence;
}

#define SIMPLIFY_SINGLE_SEQUENCE

static LamExp *performSequenceSimplifications(ParserInfo I, LamSequence *sequence) {
sequence = _performSequenceSimplifications(sequence);
#ifdef SIMPLIFY_SINGLE_SEQUENCE
if (countLamSequence(sequence) == 1) {
return sequence->exp;
}
#endif
int save = PROTECT(sequence);
LamExp *res = newLamExp_List(I, sequence);
UNPROTECT(save);
return res;
}

static LamList *performListSimplifications(LamList *list) {
ENTER(performListSimplifications);
if (list == NULL) {
Expand Down Expand Up @@ -294,7 +310,7 @@ LamExp *lamPerformSimplifications(LamExp *exp) {
exp->val.unary = performUnarySimplifications(exp->val.unary);
break;
case LAMEXP_TYPE_LIST:
exp->val.list = performSequenceSimplifications(exp->val.list);
exp = performSequenceSimplifications(CPI(exp), exp->val.list);
break;
case LAMEXP_TYPE_MAKEVEC:
exp->val.makeVec = performMakeVecSimplifications(exp->val.makeVec);
Expand Down
3 changes: 2 additions & 1 deletion src/pratt_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,12 @@ static MaybeBigInt *makeIrrational(char *str, int length) {
case '.':
frac = true;
continue;
default:
default: {
int n = convert_char(*p);
f *= 10.0;
f += n;
if (frac) div *= 10.0;
}
}
}
return irrationalBigInt(f/div, imag);
Expand Down
4 changes: 2 additions & 2 deletions src/print_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ LamLetRecBindings *makePrintFunctions(LamTypeDefList *typeDefs,
LamLetRecBindings *rest,
LamContext *env, bool inPreamble);
LamExp *makeSymbolExpr(ParserInfo I, char *name);
LamExp *makePrintInt();
LamExp *makePrintChar();
LamExp *makePrintInt(ParserInfo);
LamExp *makePrintChar(ParserInfo);
HashSymbol *makePrintName(char *prefix, char *name);
LamExp *stringToLamList(ParserInfo I, char *name);

Expand Down
6 changes: 1 addition & 5 deletions src/step.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ static inline Value peek(int index) {
return peeknStack(state.S, index);
}

static inline Value tos(void) {
return peekStack(state.S);
}

static inline void copyToVec(Vec *vec) {
copyTosToVec(vec, state.S);
}
Expand Down Expand Up @@ -502,7 +498,7 @@ static void applyProc(int naargs) {
}
break;
default:
cant_happen("unexpected type %d in APPLY", callable.type);
cant_happen("unexpected type %s in APPLY", valueTypeName(callable.type));
}
UNPROTECT(save);
}
Expand Down
12 changes: 7 additions & 5 deletions src/tpmc_translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static LamExp *translateArcToCode(TpmcArc *arc, LamExpTable *lambdaCache) {
}
break;
default:
// no-op
break;
}
LEAVE(translateArcToCode);
return res;
Expand Down Expand Up @@ -715,12 +715,13 @@ static LamExp *translateState(TpmcState *dfa, LamExpTable *lambdaCache) {
static void resetStateRefCountsToZero(TpmcState *dfa) {
dfa->refcount = 0;
switch (dfa->state->type) {
case TPMCSTATEVALUE_TYPE_TEST:
case TPMCSTATEVALUE_TYPE_TEST:{
TpmcArcArray *arcs = dfa->state->val.test->arcs;
for (Index i = 0; i < arcs->size; ++i) {
resetStateRefCountsToZero(arcs->entries[i]->state);
}
break;
}
break;
case TPMCSTATEVALUE_TYPE_FINAL:
case TPMCSTATEVALUE_TYPE_ERROR:
break;
Expand All @@ -734,12 +735,13 @@ static void incrementStateRefCounts(TpmcState *dfa) {
dfa->refcount++;
if (dfa->refcount == 1) {
switch (dfa->state->type) {
case TPMCSTATEVALUE_TYPE_TEST:
case TPMCSTATEVALUE_TYPE_TEST:{
TpmcArcArray *arcs = dfa->state->val.test->arcs;
for (Index i = 0; i < arcs->size; ++i) {
incrementStateRefCounts(arcs->entries[i]->state);
}
break;
}
break;
case TPMCSTATEVALUE_TYPE_FINAL:
case TPMCSTATEVALUE_TYPE_ERROR:
break;
Expand Down
2 changes: 2 additions & 0 deletions tests/fn/test_if.fn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let a = if (true) { 3 } else { 4 };
in assert(a == 3);
2 changes: 1 addition & 1 deletion tests/src/test_pratt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void test(char *expr, char *expected, bool expectError) {
PrattUTF8 *dest = newPrattUTF8();
PROTECT(dest);
ppAstNest(dest, result);
if (strcmp(dest->entries, expected) != 0) {
if (strcmp((char *)dest->entries, expected) != 0) {
printf("%s - expected %s got %s\n", expr, expected, dest->entries);
failed = true;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#define TEST(c, s) do { \
character = c; \
assert(byteSize(character) == s); \
char *ptr = writeChar(bytes, character); \
unsigned char *ptr = writeChar(bytes, character); \
*ptr = 0; \
assert(strlen(bytes) == s); \
assert(strlen((char *)bytes) == s); \
assert(decodedLength(bytes) == 1); \
character = 0; \
utf8_to_unicode_char(&character, bytes); \
Expand Down

0 comments on commit 02c5336

Please sign in to comment.