-
-
Save ngopher/331b19499b64bd4de88b1bd60c4663ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INLINE | |
u32 index(Ref r) { | |
return r >> 4; | |
} | |
INLINE | |
u32 tag(Ref r) { | |
return r & 15; | |
} | |
extern u32 (*eval_table[16])(u32, u32); | |
INLINE | |
u32 eval(Ref r) { | |
u32 x = nodes[index(r)].x; | |
u32 y = nodes[index(r)].y; | |
return eval_table[tag(r)](x, y); | |
} | |
u32 eval_lit(u32 x, u32 y) { | |
return x; | |
} | |
u32 eval_neg(u32 x, u32 y) { | |
return -eval(x); | |
} | |
u32 eval_not(u32 x, u32 y) { | |
return ~eval(x); | |
} | |
u32 eval_add(u32 x, u32 y) { | |
return eval(x) + eval(y); | |
} | |
u32 eval_sub(u32 x, u32 y) { | |
return eval(x) - eval(y); | |
} | |
u32 eval_and(u32 x, u32 y) { | |
return eval(x) & eval(y); | |
} | |
u32 eval_or(u32 x, u32 y) { | |
return eval(x) | eval(y); | |
} | |
u32 eval_xor(u32 x, u32 y) { | |
return eval(x) ^ eval(y); | |
} | |
u32 eval_lsl(u32 x, u32 y) { | |
return eval(x) << (eval(y) & 31); | |
} | |
u32 eval_lsr(u32 x, u32 y) { | |
return eval(x) >> (eval(y) & 31); | |
} | |
u32 eval_asr(u32 x, u32 y) { | |
return (i32)eval(x) >> (eval(y) & 31); | |
} | |
u32 (*eval_table[16])(u32, u32) = { | |
[LIT] = eval_lit, | |
[NEG] = eval_neg, | |
[NOT] = eval_not, | |
[ADD] = eval_add, | |
[SUB] = eval_sub, | |
[AND] = eval_and, | |
[OR] = eval_or, | |
[XOR] = eval_xor, | |
[LSL] = eval_lsl, | |
[LSR] = eval_lsr, | |
[ASR] = eval_asr, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment