|
|
|
@ -208,9 +208,33 @@ void init(void) {
@@ -208,9 +208,33 @@ void init(void) {
|
|
|
|
|
environment_init(); |
|
|
|
|
environment_set(NIL, STANDARD_INPUT, stream(stdin)); |
|
|
|
|
environment_set(NIL, STANDARD_OUTPUT, stream(stdout)); |
|
|
|
|
SET_FUNC("eval", eval_fn); |
|
|
|
|
SET_FUNC("cons", cons_fn); |
|
|
|
|
SET_FUNC("car", car_fn); |
|
|
|
|
SET_FUNC("cdr", cdr_fn); |
|
|
|
|
SET_FUNC("reduce", reduce_fn); |
|
|
|
|
SET_FUNC("list", list_fn); |
|
|
|
|
SET_FUNC("+", add_fn); |
|
|
|
|
SET_FUNC("-", sub_fn); |
|
|
|
|
SET_FUNC("*", mul_fn); |
|
|
|
|
SET_FUNC("/", div_fn); |
|
|
|
|
SET_FUNC("pow", pow_fn); |
|
|
|
|
SET_FUNC("sqrt", sqrt_fn); |
|
|
|
|
SET_FUNC("&", logand_fn); |
|
|
|
|
SET_FUNC("|", logor_fn); |
|
|
|
|
SET_FUNC("^", logxor_fn); |
|
|
|
|
SET_FUNC("~", lognot_fn); |
|
|
|
|
SET_FUNC("peek-char", peek_char_fn); |
|
|
|
|
SET_FUNC("read-char", read_char_fn); |
|
|
|
|
|
|
|
|
|
SET_FORM("if", if_fn); |
|
|
|
|
SET_FORM("let", let_fn); |
|
|
|
|
SET_FORM("quote", quote_fn); |
|
|
|
|
SET_FORM("and", and_fn); |
|
|
|
|
SET_FORM("or", or_fn); |
|
|
|
|
SET_FORM("def", def_fn); |
|
|
|
|
SET_FORM("set", set_fn); |
|
|
|
|
SET_FORM("fn", fn_fn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void repl(void) { |
|
|
|
@ -218,103 +242,3 @@ void repl(void) {
@@ -218,103 +242,3 @@ void repl(void) {
|
|
|
|
|
print(eval(readed, NIL), stdout); |
|
|
|
|
printf("\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Pointer op_readChar(Pointer params) { */ |
|
|
|
|
/* return readerPop(params == NIL ? STANDARD_INPUT : GET_CONS(params).car); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* Pointer op_peekChar(Pointer params) { */ |
|
|
|
|
/* return readerPop(params == NIL ? STANDARD_INPUT : GET_CONS(params).car); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* Pointer set_reader_macro(Pointer params) { */ |
|
|
|
|
/* Cons cons = CONS(params); */ |
|
|
|
|
/* return rdr_setReaderMacro(cons.car, GET_CONS(cons.cdr).car); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* Pointer op_read(Pointer params) { */ |
|
|
|
|
/* return rdr_read(CAR(params)); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* Pointer op_map(Pointer params) { */ |
|
|
|
|
/* Cons cons = GET_CONS(params); */ |
|
|
|
|
/* Pointer list = cons.car; */ |
|
|
|
|
/* Pointer fn = GET_CONS(cons.cdr).car; */ |
|
|
|
|
/* while (list != NIL) { */ |
|
|
|
|
/* cons = GET_CONS(list); */ |
|
|
|
|
/* list = cons.cdr; */ |
|
|
|
|
/* } */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* void run() { */ |
|
|
|
|
/* do { */ |
|
|
|
|
/* prn_print(evl_eval(rdr_read(GLOBAL_ENV_GET(STANDARD_INPUT)), */ |
|
|
|
|
/* ALLOC_CONS(GLOBAL_ENV, NIL)), */ |
|
|
|
|
/* stdout); */ |
|
|
|
|
/* fprintf(stdout, "\n"); */ |
|
|
|
|
/* } while(rdr_peekChar(T, GET_STREAM(GLOBAL_ENV_GET(STANDARD_INPUT))) != 0); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* void start() { */ |
|
|
|
|
/* mem_init(1024); */ |
|
|
|
|
/* ascii_init(); */ |
|
|
|
|
/* GLOBAL_ENV = tbl_alloc(2); // GLOBAL ENV */ |
|
|
|
|
|
|
|
|
|
/* ALLOC_STATIC_SYMBOL(NIL, "nil"); */ |
|
|
|
|
/* ALLOC_STATIC_SYMBOL(T, "t"); */ |
|
|
|
|
/* ALLOC_STATIC_SYMBOL(STANDARD_INPUT, "*standard-input*"); */ |
|
|
|
|
/* ALLOC_STATIC_SYMBOL(STANDARD_OUTPUT, "*standard-output*"); */ |
|
|
|
|
/* ALLOC_STATIC_SYMBOL(READTABLE, "*readtable*"); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("+", op_add); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("-", op_sub); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("*", op_mul); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("/", op_div); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("pow", op_pow); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("sqrt", op_sqrt); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("&", op_logand); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("|", op_logior); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("^", op_logxor); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("~", op_lognot); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("list", op_list); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("car", op_car); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("cdr", op_cdr); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("not", op_not); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("set-reader-macro", op_setReaderMacro); */ |
|
|
|
|
/* ALLOC_NATIVE_FUNC("read", op_read); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("if", op_if); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("let", op_let); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("quote", op_quote); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("and", op_and); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("or", op_or); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("def", op_def); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("set", op_set); */ |
|
|
|
|
/* ALLOC_SPECIAL_FORM("fn", op_fn); */ |
|
|
|
|
/* /\* ALLOC_STREAM(STANDARD_INPUT, "*standard-input*", stdin); *\/ */ |
|
|
|
|
/* /\* ALLOC_STREAM(STANDARD_OUTPUT, "*standard-output*", stdout); *\/ */ |
|
|
|
|
|
|
|
|
|
/* rdr_init(); */ |
|
|
|
|
/* /\* op_print(getFromTable(globalEnv, T), stdout); *\/ */ |
|
|
|
|
/* /\* op_print(globalEnv, stdout); *\/ */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* /\* Stream stream = {"(fn (stream char) ())\0"}; *\/ */ |
|
|
|
|
/* /\* tbl_insert(readerMacros, *\/ */ |
|
|
|
|
/* /\* '\\', *\/ */ |
|
|
|
|
/* /\* mem_alloc(CONS, *\/ */ |
|
|
|
|
/* /\* (Data) (Cons) {eval(read(&stream), NIL), NIL})); *\/ */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* /\* inputStream.text = "(def add (fn (a b) (+ a b))) (add 1 2)\0"; *\/ */ |
|
|
|
|
/* /\* inputStream.text = "(if t 1 2)\0"; *\/ */ |
|
|
|
|
/* /\* printf("%s\n", inputStream.text); *\/ */ |
|
|
|
|
|
|
|
|
|
/* FILE* file = fopen("lisp.lisp", "r"); */ |
|
|
|
|
/* GLOBAL_ENV_INSERT(STANDARD_INPUT, ALLOC_STREAM(file)); */ |
|
|
|
|
/* run(); */ |
|
|
|
|
/* fclose(file); */ |
|
|
|
|
|
|
|
|
|
/* GLOBAL_ENV_SET(STANDARD_INPUT, ALLOC_STREAM(stdin)); */ |
|
|
|
|
/* run(); */ |
|
|
|
|
/* printf("\n"); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|