Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step &co. all use more sensible names now #53

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# TODO

* over-application i.e. `fn (a) { fn (b) { a + b } }(2, 3)`.
* allow user overrides of print functions.
* tuples - can use vec type to implement.
* BUT - the collection of args to a function is not itself a tuple, that might interfere with currying.
* tc has support for pairs and we might leverage those as a start, but flat vecs will be more efficient.
* specific syntax: `#(2, "hi")` might be better than just round braces.
* unpacking function return values (tuples only).
* Over-application i.e. `fn (a) { fn (b) { a + b } }(2, 3)`.
* Allow user overrides of print functions.
* Unpacking function return values (tuples only).
* `now()` expression returns current time in milliseconds.
* macro support (see [MACROS](./MACROS.md) for initial thoughts).
* more numbers:
* rationals: 1/3.
* irrationals: sqrt(2).
* complex numbers.
* Macro support (see [MACROS](./MACROS.md) for initial thoughts).
* More numbers:
* Rationals: 1/3.
* Irrationals: sqrt(2).
* Complex numbers.
* UTF8 and `wchar_t`.
* first class environments.
* libraries.
* probably use file system layout.
* env var to specify the root location(s).
* better preable/postamble handling.
* propagate file and line numbers into all error reporting.
* much better error reporting.
* error recovery.
* command-line arguments for libraries etc.
* fail on non-exhaustive pattern match (optional).
* error function.
* user definable infix operators.
* with precedence and associativity.
* curried binary operators `(2+)` etc.
* Namespaces.
* Libraries.
* Probably use file system layout.
* Env var to specify the root location(s).
* Better preable/postamble handling.
* Propagate file and line numbers into all error reporting.
* Much better error reporting.
* Error recovery.
* Command-line arguments for libraries etc.
* Fail on non-exhaustive pattern match (optional).
* Error function.
* User definable infix operators.
* With precedence and associativity.
* Curried binary operators `(2+)` etc.
34 changes: 17 additions & 17 deletions src/cekf.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ ValueList *newValueList(int count) {
return x;
}

Clo *newClo(int nvar, Control c, Env *rho) {
Clo *newClo(int pending, Control ip, Env *env) {
Clo *x = NEW(Clo, OBJTYPE_CLO);
x->nvar = nvar;
x->c = c;
x->rho = rho;
x->pending = pending;
x->ip = ip;
x->env = env;
return x;
}

Expand All @@ -91,20 +91,20 @@ Env *newEnv(Env *next, int count) {
return x;
}

Kont *newKont(Control body, Env *rho, Kont *next) {
Kont *newKont(Control body, Env *env, Kont *next) {
Kont *x = NEW(Kont, OBJTYPE_KONT);
x->body = body;
x->rho = rho;
x->env = env;
x->next = next;
x->snapshot = noSnapshot;
return x;
}

Fail *newFail(Control exp, Env *rho, Kont *k, Fail *next) {
Fail *newFail(Control exp, Env *env, Kont *kont, Fail *next) {
Fail *x = NEW(Fail, OBJTYPE_FAIL);
x->exp = exp;
x->rho = rho;
x->k = k;
x->env = env;
x->kont = kont;
x->next = next;
x->snapshot = noSnapshot;
return x;
Expand All @@ -130,13 +130,13 @@ void markValue(Value x) {
markClo(x.val.clo);
break;
case VALUE_TYPE_CONT:
markKont(x.val.k);
markKont(x.val.kont);
break;
case VALUE_TYPE_VEC:
markVec(x.val.vec);
break;
case VALUE_TYPE_BIGINT:
markBigInt(x.val.b);
markBigInt(x.val.bigint);
break;
default:
cant_happen("unrecognised type in markValue (%d)", x.type);
Expand All @@ -160,7 +160,7 @@ void markClo(Clo *x) {
if (MARKED(x))
return;
MARK(x);
markEnv(x->rho);
markEnv(x->env);
}

void markEnv(Env *x) {
Expand Down Expand Up @@ -188,7 +188,7 @@ void markKont(Kont *x) {
return;
MARK(x);
markSnapshot(x->snapshot);
markEnv(x->rho);
markEnv(x->env);
markKont(x->next);
}

Expand All @@ -210,8 +210,8 @@ void markFail(Fail *x) {
return;
MARK(x);
markSnapshot(x->snapshot);
markEnv(x->rho);
markKont(x->k);
markEnv(x->env);
markKont(x->kont);
markFail(x->next);
}

Expand Down Expand Up @@ -259,8 +259,8 @@ void freeCekfObj(Header *h) {
}
break;
case OBJTYPE_KONT:{
Kont *k = (Kont *) h;
FREE_ARRAY(Value, k->snapshot.frame, k->snapshot.frameSize);
Kont *kont = (Kont *) h;
FREE_ARRAY(Value, kont->snapshot.frame, kont->snapshot.frameSize);
reallocate((void *) h, sizeof(Kont), 0);
}
break;
Expand Down
21 changes: 11 additions & 10 deletions src/cekf.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ typedef struct Snapshot {
typedef struct Kont {
struct Header header;
Control body;
struct Env *rho;
struct Env *env;
Snapshot snapshot;
struct Kont *next;
} Kont;
Expand All @@ -77,16 +77,16 @@ typedef struct ValueList {

typedef struct Clo {
struct Header header;
int nvar;
Control c;
struct Env *rho;
int pending;
Control ip;
struct Env *env;
} Clo;

typedef struct Fail {
struct Header header;
Control exp;
struct Env *rho;
struct Kont *k;
struct Env *env;
struct Kont *kont;
Snapshot snapshot;
struct Fail *next;
} Fail;
Expand All @@ -103,7 +103,7 @@ void snapshotKont(Stack *stack, struct Kont *target);
void snapshotFail(Stack *stack, struct Fail *target);
void restoreKont(Stack *stack, struct Kont *source);
void restoreFail(Stack *stack, struct Fail *source);
void setFrame(Stack *stack, int nargs);
void setFrame(Stack *stack, int base, int nargs);
void clearFrame(Stack *stack);
void copyTosToEnv(Stack *s, Env *e, int n);
void copyValues(Value *to, Value *from, int size);
Expand All @@ -122,12 +122,13 @@ void initStack(Stack *stack);
int frameSize(Stack *stack);
void pushN(Stack *stack, int n);
void popN(Stack *s, int n);
void ensureCapacity(Stack *s, int n);

ValueList *newValueList(int count);
Clo *newClo(int nvar, Control c, Env *rho);
Clo *newClo(int nvar, Control ip, Env *env);
Env *newEnv(Env *next, int count);
Kont *newKont(Control body, Env *rho, Kont *next);
Fail *newFail(Control exp, Env *rho, Kont *k, Fail *next);
Kont *newKont(Control body, Env *env, Kont *next);
Fail *newFail(Control exp, Env *env, Kont *kont, Fail *next);
Vec *newVec(int size);

void markValue(Value x);
Expand Down
Loading
Loading