add begin syntax

This commit is contained in:
Yuichi Nishiwaki 2013-10-17 17:54:28 +09:00
parent 17f0c928da
commit d9e47bdd05
3 changed files with 14 additions and 2 deletions

View File

@ -23,7 +23,8 @@ typedef struct {
pic_callinfo *ci;
pic_callinfo *cibase, *ciend;
pic_value sDEFINE, sLAMBDA, sIF, sCONS;
pic_value sDEFINE, sLAMBDA, sIF, sBEGIN;
pic_value sCONS;
pic_value sADD, sSUB, sMUL, sDIV;
struct pic_env *global_env;

View File

@ -48,6 +48,7 @@ pic_open()
pic->sDEFINE = pic_intern_cstr(pic, "define");
pic->sLAMBDA = pic_intern_cstr(pic, "lambda");
pic->sIF = pic_intern_cstr(pic, "if");
pic->sBEGIN = pic_intern_cstr(pic, "begin");
pic->sCONS = pic_intern_cstr(pic, "cons");
pic->sADD = pic_intern_cstr(pic, "+");
pic->sSUB = pic_intern_cstr(pic, "-");

View File

@ -227,11 +227,12 @@ static struct pic_irep *pic_gen_lambda(pic_state *, pic_value, struct pic_env *)
static void
pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *env)
{
pic_value sDEFINE, sLAMBDA, sIF, sCONS, sADD, sSUB, sMUL, sDIV;
pic_value sDEFINE, sLAMBDA, sIF, sBEGIN, sCONS, sADD, sSUB, sMUL, sDIV;
sDEFINE = pic->sDEFINE;
sLAMBDA = pic->sLAMBDA;
sIF = pic->sIF;
sBEGIN = pic->sBEGIN;
sCONS = pic->sCONS;
sADD = pic->sADD;
sSUB = pic->sSUB;
@ -309,6 +310,15 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en
irep->code[t].u.i = irep->clen - t;
break;
}
else if (pic_eq_p(pic, proc, sBEGIN)) {
pic_value v, seq;
seq = pic_cdr(pic, obj);
for (v = seq; ! pic_nil_p(v); v = pic_cdr(pic, v)) {
pic_gen(pic, irep, pic_car(pic, v), env);
}
break;
}
else if (pic_eq_p(pic, proc, sCONS)) {
pic_gen(pic, irep, pic_car(pic, pic_cdr(pic, pic_cdr(pic, obj))), env);
pic_gen(pic, irep, pic_car(pic, pic_cdr(pic, obj)), env);