emit OP_NOT

This commit is contained in:
Yuichi Nishiwaki 2014-02-02 14:55:46 +09:00
parent 0fec56362d
commit 4a01b8296f
4 changed files with 17 additions and 3 deletions

View File

@ -90,7 +90,7 @@ typedef struct {
pic_sym sDEFINE_LIBRARY, sIMPORT, sEXPORT; pic_sym sDEFINE_LIBRARY, sIMPORT, sEXPORT;
pic_sym sCONS, sCAR, sCDR, sNILP; pic_sym sCONS, sCAR, sCDR, sNILP;
pic_sym sADD, sSUB, sMUL, sDIV, sMINUS; pic_sym sADD, sSUB, sMUL, sDIV, sMINUS;
pic_sym sEQ, sLT, sLE, sGT, sGE; pic_sym sEQ, sLT, sLE, sGT, sGE, sNOT;
struct xhash *sym_tbl; struct xhash *sym_tbl;
const char **sym_pool; const char **sym_pool;

View File

@ -57,7 +57,6 @@ pic_bool_equal_p(pic_state *pic)
return pic_bool_value(pic_equal_p(pic, x, y)); return pic_bool_value(pic_equal_p(pic, x, y));
} }
/* TODO: replace it with native opcode */
static pic_value static pic_value
pic_bool_not(pic_state *pic) pic_bool_not(pic_state *pic)
{ {

View File

@ -91,7 +91,7 @@ typedef struct analyze_state {
analyze_scope *scope; analyze_scope *scope;
pic_sym rCONS, rCAR, rCDR, rNILP; pic_sym rCONS, rCAR, rCDR, rNILP;
pic_sym rADD, rSUB, rMUL, rDIV; pic_sym rADD, rSUB, rMUL, rDIV;
pic_sym rEQ, rLT, rLE, rGT, rGE; pic_sym rEQ, rLT, rLE, rGT, rGE, rNOT;
pic_sym sCALL, sTAILCALL, sREF; pic_sym sCALL, sTAILCALL, sREF;
} analyze_state; } analyze_state;
@ -137,6 +137,7 @@ new_analyze_state(pic_state *pic)
register_renamed_symbol(pic, state, rLE, stdlib, "<="); register_renamed_symbol(pic, state, rLE, stdlib, "<=");
register_renamed_symbol(pic, state, rGT, stdlib, ">"); register_renamed_symbol(pic, state, rGT, stdlib, ">");
register_renamed_symbol(pic, state, rGE, stdlib, ">="); register_renamed_symbol(pic, state, rGE, stdlib, ">=");
register_renamed_symbol(pic, state, rNOT, stdlib, "not");
register_symbol(pic, state, sCALL, "call"); register_symbol(pic, state, sCALL, "call");
register_symbol(pic, state, sTAILCALL, "tail-call"); register_symbol(pic, state, sTAILCALL, "tail-call");
@ -521,6 +522,10 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos)
ARGC_ASSERT(2); ARGC_ASSERT(2);
return CONSTRUCT_OP2(pic->sGE); return CONSTRUCT_OP2(pic->sGE);
} }
else if (sym == state->rNOT) {
ARGC_ASSERT(1);
return CONSTRUCT_OP1(pic->sNOT);
}
} }
return analyze_call(state, obj, tailpos); return analyze_call(state, obj, tailpos);
} }
@ -1273,6 +1278,12 @@ codegen(codegen_state *state, pic_value obj)
cxt->clen++; cxt->clen++;
return; return;
} }
else if (sym == pic->sNOT) {
codegen(state, pic_list_ref(pic, obj, 1));
cxt->code[cxt->clen].insn = OP_NOT;
cxt->clen++;
return;
}
else if (sym == state->sCALL || sym == state->sTAILCALL) { else if (sym == state->sCALL || sym == state->sTAILCALL) {
int len = pic_length(pic, obj); int len = pic_length(pic, obj);
pic_value elt; pic_value elt;
@ -1526,6 +1537,9 @@ print_code(pic_state *pic, struct pic_code c)
case OP_JMPIF: case OP_JMPIF:
printf("OP_JMPIF\t%d\n", c.u.i); printf("OP_JMPIF\t%d\n", c.u.i);
break; break;
case OP_NOT:
puts("OP_NOT");
break;
case OP_CALL: case OP_CALL:
printf("OP_CALL\t%d\n", c.u.i); printf("OP_CALL\t%d\n", c.u.i);
break; break;

View File

@ -112,6 +112,7 @@ pic_open(int argc, char *argv[], char **envp)
register_core_symbol(pic, sLE, "<="); register_core_symbol(pic, sLE, "<=");
register_core_symbol(pic, sGT, ">"); register_core_symbol(pic, sGT, ">");
register_core_symbol(pic, sGE, ">="); register_core_symbol(pic, sGE, ">=");
register_core_symbol(pic, sNOT, "not");
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
pic_init_core(pic); pic_init_core(pic);