Commit 49fd10de authored by Chris Müller's avatar Chris Müller
Browse files

Add Define Macro to bootstrap-cherry

parent 406c9e49
......@@ -268,7 +268,6 @@ core_environment(void)
#define proc_to_env(ENV, STR, FUN) \
env_let(ENV, symbol(STR), primitive(FUN))
proc_to_env(env, "write", core_write);
proc_to_env(env, "println", core_println);
return env;
......@@ -318,13 +317,6 @@ core_println(struct value* env, struct value* args)
return True;
}
struct value*
core_write(struct value* env, struct value* args)
{
cherry_write(stdout, args);
return True;
}
// ----------------------------------------------------------------------------
// Reading
......@@ -946,10 +938,33 @@ env_let(struct value* env, struct value* var, struct value* val)
return True;
}
// ----------------------------------------------------------------------------
// transform
// ----------------------------------------------------------------------------
static struct value*
transform_define(struct value* define)
{
struct value* name = HEAD(HEAD(define));
struct value* args = TAIL(HEAD(define));
struct value* body = TAIL(define);
return list3(Let, name, cons(Lambda, cons(args, body)));
}
struct value*
cherry_transform(struct value* value)
{
if(IS_TAGGED(value, Define))
return transform_define(TAIL(value));
else
return value;
}
// ----------------------------------------------------------------------------
// compile
// eval
// ----------------------------------------------------------------------------
static struct value*
......@@ -1229,7 +1244,7 @@ void cherry_main(const char* filename, const byte_t* method, struct value* args)
struct value* env = core_environment();
while(exp != 0) {
cherry_eval(env, exp);
cherry_eval(env, cherry_transform(exp));
exp = cherry_read(&p, buffer, SCANNER_BUFFERSIZE);
}
......
......@@ -122,9 +122,9 @@ struct value* cons(struct value* head, struct value* tail);
#define list2(A, B) cons(A cons(B, emptylist))
#define list3(A, B, C) cons(A, cons(B, cons(C, emptylist)))
#define list4(A, B, C, D) cons(A, cons(B, cons(C, cons(D, emptylist))))
#define list2(A, B) cons(A, cons(B, Emptylist))
#define list3(A, B, C) cons(A, cons(B, cons(C, Emptylist)))
#define list4(A, B, C, D) cons(A, cons(B, cons(C, cons(D, Emptylist))))
#define SYMBOL_ENTRY(sym, left, right) cons(sym, cons(left, right))
#define SYMBOL_LEFT(node) HEAD(TAIL(node))
......@@ -147,13 +147,16 @@ struct value* env_let(struct value* env, struct value* var, struct value* val);
#define IS_SELF_EVALUATING(val) \
(IS_BOOLEAN(val) || IS_FIXNUM(val) || IS_CHARACTER(val) || IS_STRING(val) || IS_FLOAT(val))
#define IS_TAGGED(value, symbol) \
(IS_PAIR(value) && IS_SYMBOL(HEAD(value)) && HEAD(value) == symbol)
#define IS_VARIABLE(val) IS_SYMBOL(val)
void cherry_initialize(void);
struct value* cherry_read(byte_t** begin, byte_t* buffer, size_t buffer_size);
struct value* cherry_transform(struct value* code);
struct value* cherry_eval(struct value* env, struct value* code);
void cherry_write(FILE* out, struct value* v);
void cherry_writeln(FILE* out, struct value* v);
struct value* core_println(struct value* env, struct value* args);
struct value* core_write(struct value* env, struct value* args);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment