Skip to content

Commit

Permalink
Merge pull request #122 from billhails/tidy
Browse files Browse the repository at this point in the history
Tidy
  • Loading branch information
billhails authored Oct 20, 2024
2 parents 8ace092 + 7c9d3d6 commit 8404755
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 69,748 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ EXTRA_TARGETS= \
$(EXTRA_H_TARGETS) \
$(EXTRA_OBJTYPES_H_TARGETS) \
$(EXTRA_DEBUG_H_TARGETS) \
$(EXTRA_DEBUG_C_TARGETS)
$(EXTRA_DEBUG_C_TARGETS) \
generated/UnicodeData.inc

MAIN=src/main.c
PREAMBLE=generated/preamble.c
Expand Down Expand Up @@ -178,8 +179,10 @@ unicode/UnicodeData.csv: unicode/UnicodeData.txt ./tools/convertCsv.py
$(PYTHON) ./tools/convertCsv.py

unicode/UnicodeData.txt: | unicode
wget https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
mv UnicodeData.txt $@
wget -P unicode https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt

generated/UnicodeData.inc: unicode/UnicodeData.txt tools/analyzeCsv.py | generated
$(PYTHON) ./tools/analyzeCsv.py > $@

realclean: clean
rm -rf tags unicode
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ the $step$ function: one to deal with `amb` and one to deal with `back`.
flowchart TD
classDef process fill:#aef;
source(Source) -->
parser([Parser]):::process -->
ast(AST) -->
parser([Parser]):::process
parser <--> oi([Operator Inlining]):::process
parser --> ast(AST) -->
lc([Lambda Conversion]):::process --> tpmc([Pattern Matching Compiler]):::process
lc <---> pg([Print Function Generator]):::process
lc <---> me([Macro Expansion]):::process
tpmc --> vs([Variable Substitution]):::process
vs --> lc
lc <--> des([Desugaring]):::process
Expand Down
22 changes: 1 addition & 21 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ More of a wish-list than a hard and fast plan.

* Over-application i.e. `fn (a) { fn (b) { a + b } }(2, 3)`.
* Unpacking function return values (tuples only).
* Error function.
* Macro support (see [MACROS](./MACROS.md) for initial thoughts).
* More numbers:
* NaN.
* Improve arithmetic.
* General overhaul.
* move to [libgmp](https://gmplib.org/)?
* trig functions.
* trig and log functions.
* Pre-compute constant values at compile time.
* allow numeric (not symbolic) arithmetic expressions in patterns.
* allow unpacking of numerator and denominator variables in patterns.
Expand All @@ -25,25 +23,7 @@ More of a wish-list than a hard and fast plan.
* allow unpacking of the real and imaginary parts of a complex number in patterns.
* another special case: `a + b`, `b` would be bound to `0i` if the actual
argument is not complex.
* Much better error reporting.
* `--expression="..."` to execute a snippet from the command line.
* Error recovery.
* User definable operators.
* With precedence and associativity.
* `infix 55 left ">>=" fn(l, r) { ... }`
* `prefix 45 "$" fn(a) { ... }`
* `suffix 60 "!" factorial`
* `infix 40 "and" and` - where `and` would have to be a macro.
* precedence of prefix and postfix operators matters, i.e. `-2**2` is `-(2**2)` not `(-2)**2`.
* looks like this is a biggie and would involve replacing the existing parser (and probably lexer)
with a
[Pratt Parser](https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/).
However this may be the right thing to do as it also opens up a much better approach to
[macros](https://journal.stuffwithstuff.com/2011/02/13/extending-syntax-from-within-a-language/).
* Curried binary operators `(2+)` etc.
* Aliases
* `alias some = maybe.some;`
* `alias string = list(char);`
* (internal) have a NEWZ variant of NEW that bzero's its result.
* Builtins
* `now()` builtin returns current time in milliseconds.
7 changes: 2 additions & 5 deletions src/anf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ structs:
next: CexpIntCondCases

CexpCharCondCases:
option: char
option: character
body: Exp
next: CexpCharCondCases

Expand Down Expand Up @@ -146,15 +146,12 @@ unions:
intCases: CexpIntCondCases

Aexp:
t: void_ptr
f: void_ptr
v: void_ptr
lam: AexpLam
var: HashSymbol
annotatedVar: AexpAnnotatedVar
biginteger: MaybeBigInt
littleinteger: int
character: char
character: character
prim: AexpPrimApp
unary: AexpUnaryApp
makeVec: AexpMakeVec
Expand Down
9 changes: 0 additions & 9 deletions src/anf_pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,6 @@ void ppAexp(Aexp *x) {
case AEXP_TYPE_ANNOTATEDVAR:
ppAexpAnnotatedVar(x->val.annotatedVar);
break;
case AEXP_TYPE_T:
eprintf("#t");
break;
case AEXP_TYPE_F:
eprintf("#f");
break;
case AEXP_TYPE_V:
eprintf("nil");
break;
case AEXP_TYPE_BIGINTEGER:
fprintMaybeBigInt(errout, x->val.biginteger);
break;
Expand Down
3 changes: 0 additions & 3 deletions src/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,9 @@ static CTEnv *annotateAexp(Aexp *x, CTEnv *env) {
case AEXP_TYPE_ANNOTATEDVAR:
cant_happen("annotateAexp called on annotated var %s",
x->val.annotatedVar->var->name);
case AEXP_TYPE_T:
case AEXP_TYPE_F:
case AEXP_TYPE_BIGINTEGER:
case AEXP_TYPE_LITTLEINTEGER:
case AEXP_TYPE_CHARACTER:
case AEXP_TYPE_V:
return env;
case AEXP_TYPE_PRIM:
return annotateAexpPrimApp(x->val.prim, env);
Expand Down
8 changes: 2 additions & 6 deletions src/ast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ unions:
unpack: AstUnpack
unpackStruct: AstUnpackStruct
number: MaybeBigInt
character: char
character: character
tuple: AstArgList

AstExpression:
Expand All @@ -227,7 +227,7 @@ unions:
symbol: HashSymbol
gensym: HashSymbol
number: MaybeBigInt
character: char
character: character
fun: AstCompositeFunction
nest: AstNest
iff: AstIff
Expand All @@ -243,10 +243,6 @@ hashes:
entries: int

arrays:
AstCharArray:
dimension: 1
entries: char

AstNamespaceArray:
dimension: 1
entries: AstNamespaceImpl
Expand Down
12 changes: 0 additions & 12 deletions src/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,6 @@ void writeAexp(Aexp *x, ByteCodeArray *b) {
writeAexpAnnotatedVar(x->val.annotatedVar, b);
}
break;
case AEXP_TYPE_T:{
addByte(b, BYTECODES_TYPE_TRUE);
}
break;
case AEXP_TYPE_F:{
addByte(b, BYTECODES_TYPE_FALSE);
}
break;
case AEXP_TYPE_V:{
addByte(b, BYTECODES_TYPE_VOID);
}
break;
case AEXP_TYPE_LITTLEINTEGER:{
addByte(b, BYTECODES_TYPE_STDINT);
addInteger(b, x->val.littleinteger);
Expand Down
10 changes: 5 additions & 5 deletions src/cekf.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ void restoreFail(Stack *s, Fail *source) {
copyAllStackEntries(s, source->S);
}

CharArray *listToCharArray(Value list) {
CharArray *chars = newCharArray();
CharacterArray *listToCharArray(Value list) {
CharacterArray *chars = newCharacterArray();
int save = PROTECT(chars);
while (list.val.vec) {
#ifdef SAFETY_CHECKS
Expand All @@ -251,18 +251,18 @@ CharArray *listToCharArray(Value list) {
cant_happen("unexpected %s", valueTypeName(character.type));
}
#endif
pushCharArray(chars, character.val.character);
pushCharacterArray(chars, character.val.character);
list = v->entries[2];
} else {
list.val.vec = NULL;
}
}
pushCharArray(chars, (Character) 0); // null terminated
pushCharacterArray(chars, (Character) 0); // null terminated
UNPROTECT(save);
return chars;
}

Value charArrayToList(CharArray *c) {
Value charArrayToList(CharacterArray *c) {
Vec *nullByte = newVec(1);
nullByte->entries[0] = value_Stdint(0); // tag=null
Value v = value_Vec(nullByte);
Expand Down
4 changes: 2 additions & 2 deletions src/cekf.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void markVec(Vec *x);
void dumpStack(Stack *stack);
void dumpFrame(Frame *frame);

CharArray *listToCharArray(Value list);
Value charArrayToList(CharArray *c);
CharacterArray *listToCharArray(Value list);
Value charArrayToList(CharacterArray *c);
Value makeNull(void);
Value makePair(Value car, Value cdr);

Expand Down
9 changes: 3 additions & 6 deletions src/cekfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ inline:
rational_imag: Vec
irrational_imag: double
complex: Vec
character: char
character: character
clo: Clo
pclo: Clo
kont: Kont
Expand All @@ -86,8 +86,8 @@ inline:
entries: byte

arrays:
CharArray:
entries: char
CharacterArray:
entries: character

ByteArray:
entries: byte
Expand Down Expand Up @@ -136,9 +136,6 @@ enums:
- BACK
- LET
- CALLCC
- "TRUE"
- "FALSE"
- VOID
- STDINT
- BIGINT
- IRRATIONAL
Expand Down
12 changes: 0 additions & 12 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,6 @@ void dumpByteCode(ByteCodeArray *bca) {
eprintf("CALLCC\n");
}
break;
case BYTECODES_TYPE_TRUE:{
eprintf("TRUE\n");
}
break;
case BYTECODES_TYPE_FALSE:{
eprintf("FALSE\n");
}
break;
case BYTECODES_TYPE_VOID:{
eprintf("VOID\n");
}
break;
case BYTECODES_TYPE_STDINT_IMAG:{
int val = readInteger(bca, &i);
eprintf("STDINT_IMAG [%d]\n", val);
Expand Down
4 changes: 2 additions & 2 deletions src/lambda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ structs:
next: LamIntCondCases

LamCharCondCases:
constant: char
constant: character
body: LamExp
next: LamCharCondCases

Expand Down Expand Up @@ -264,7 +264,7 @@ unions:
cond: LamCond
amb: LamAmb
print: LamPrint
character: char
character: character
back: void_ptr
error: void_ptr
cond_default: void_ptr
Expand Down
2 changes: 1 addition & 1 deletion src/pratt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ arrays:
entries: uchar

PrattUnicode:
entries: char
entries: character

primitives: !include primitives.yaml

Expand Down
2 changes: 1 addition & 1 deletion src/primitives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool:
printf: "%d"
valued: true

char:
character:
cname: Character
printf: "%lc"
valued: true
Expand Down
21 changes: 0 additions & 21 deletions src/step.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,27 +1037,6 @@ static void step() {
}
break;

case BYTECODES_TYPE_TRUE:{
// push true
DEBUGPRINTF("TRUE\n");
push(vTrue);
}
break;

case BYTECODES_TYPE_FALSE:{
// push false
DEBUGPRINTF("FALSE\n");
push(vFalse);
}
break;

case BYTECODES_TYPE_VOID:{
// push void
DEBUGPRINTF("VOID\n");
push(vVoid);
}
break;

case BYTECODES_TYPE_IRRATIONAL:{
// push literal Double
Double f = readCurrentIrrational();
Expand Down
2 changes: 1 addition & 1 deletion src/tpmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ unions:
comparison: TpmcComparisonPattern
assignment: TpmcAssignmentPattern
wildcard: void_ptr
character: char
character: character
biginteger: MaybeBigInt
constructor: TpmcConstructorPattern
tuple: TpmcPatternArray
Expand Down
Loading

0 comments on commit 8404755

Please sign in to comment.