add VM
This commit is contained in:
1 parent
5dd15ce9f1
commit
d7860fdac0
7 files changed
+136
-15
No files matched your search
@@ -45,6 +45,32 @@ Value eval_arith(IRInstr instr, const Value *lhs, const Value *rhs) {
|
||||
return (Value){0};
|
||||
}
|
||||
|
||||
Value eval_unary(IRInstr instr, const Value *v) {
|
||||
switch (instr) {
|
||||
case IRSet:
|
||||
return *v;
|
||||
case IRNeg:
|
||||
if (v->type.kind == TypeInt)
|
||||
return (Value){ .type.kind = TypeInt, .Int = -v->Int };
|
||||
else if (v->type.kind == TypeFloat)
|
||||
return (Value){ .type.kind = TypeFloat, .Float = -v->Float };
|
||||
else {
|
||||
set_err("Unsupported types for operation '%s'", irinstr_str[instr]);
|
||||
return (Value){0};
|
||||
}
|
||||
default:
|
||||
ASSERT_UNREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
bool is_nonzero(const Value *v) {
|
||||
switch (v->type.kind) {
|
||||
case TypeInt: return v->Int != 0;
|
||||
case TypeFloat: return v->Float != 0.0;
|
||||
default: ASSERT_UNREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
Value zero_val(Type ty) {
|
||||
Value ret;
|
||||
ret.type = ty;
|
||||
|
||||
Reference in new issue
Block a user