From b998c903a3c87a9da20a8cb6c149f0dda2e16c5a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 15 Oct 2013 21:52:44 +0900 Subject: [PATCH] remove eval.c --- Makefile | 2 +- src/eval.c | 85 ------------------------------------------------------ 2 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 src/eval.c diff --git a/Makefile b/Makefile index b6651a43..0dbb9eba 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ build: cd src; \ yacc -d parse.y; \ lex scan.l - gcc -o bin/picrin -I./include src/main.c src/state.c src/gc.c src/pair.c src/port.c src/symbol.c src/value.c src/y.tab.c src/lex.yy.c src/eval.c src/bool.c src/vm.c src/init.c + gcc -o bin/picrin -I./include src/main.c src/state.c src/gc.c src/pair.c src/port.c src/symbol.c src/value.c src/y.tab.c src/lex.yy.c src/bool.c src/vm.c src/init.c clean: rm -f src/y.tab.c src/y.tab.h src/lex.yy.c diff --git a/src/eval.c b/src/eval.c deleted file mode 100644 index 2d1926ab..00000000 --- a/src/eval.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "picrin.h" - -static pic_value -pic_assq(pic_state *pic, pic_value key, pic_value assoc) -{ - pic_value cell; - - enter: - - if (pic_nil_p(assoc)) - return assoc; - - cell = pic_car(pic, assoc); - if (pic_eq_p(pic, key, pic_car(pic, cell))) - return cell; - - assoc = pic_cdr(pic, assoc); - goto enter; -} - -static pic_value -pic_env_lookup(pic_state *pic, pic_value sym, struct pic_env *env) -{ - pic_value v; - - enter: - - v = pic_assq(pic, sym, env->assoc); - if (! pic_nil_p(v)) { - return pic_cdr(pic, v); - } - if (env->parent) { - env = env->parent; - goto enter; - } - - return pic_nil_value(); -} - -static void -pic_env_define(pic_state *pic, pic_value sym, pic_value obj, struct pic_env *env) -{ - env->assoc = pic_cons(pic, pic_cons(pic, sym, obj), env->assoc); -} - -pic_value -pic_eval(pic_state *pic, pic_value obj, struct pic_env *env) -{ - pic_value sDEFINE = pic_intern_cstr(pic, "define"); - pic_value sQUOTE = pic_intern_cstr(pic, "quote"); - - while (1) { - switch (pic_type(obj)) { - case PIC_TT_SYMBOL: { - return pic_env_lookup(pic, obj, env); - } - case PIC_TT_PAIR: { - pic_value proc; - - proc = pic_car(pic, obj); - if (pic_eq_p(pic, proc, sQUOTE)) { - return pic_car(pic, pic_cdr(pic, obj)); - } - else if (pic_eq_p(pic, proc, sDEFINE)) { - pic_value sym, data; - - sym = pic_car(pic, pic_cdr(pic, obj)); - data = pic_car(pic, pic_cdr(pic, pic_cdr(pic, obj))); - pic_env_define(pic, sym, pic_eval(pic, data, env), env); - - return pic_nil_value(); - } - else { - /* not implemented */ - } - } - case PIC_TT_FLOAT: - case PIC_TT_NIL: { - return obj; - } - default: - return pic_nil_value(); - } - } -}