[FORM_STRING] = "char*"
};
-static char* BinaryOps[] = {
- ['+'] = "+",
- ['-'] = "-",
- ['*'] = "*",
- ['/'] = "/",
- ['%'] = "%",
+static char* Operators[] = {
+ ['+'] = "+",
+ ['-'] = "-",
+ ['*'] = "*",
+ ['/'] = "/",
+ ['%'] = "%",
+ [AND] = "&&",
+ [OR] = "||",
+ [NOT] = "!",
+ [EQ] = "==",
+ [NEQ] = "!=",
+ ['<'] = "<",
+ [LTEQ] = "<=",
+ ['>'] = ">",
+ [GTEQ] = ">=",
+// [IS] = ???
};
static void load_var(Parser* p, Item* item)
}
}
-/* Operators
+/* Operator Handling
*****************************************************************************/
-void binary_op(Parser* p, int op, Item* a, Item* b)
+static void binary_op(Parser* p, int op, Item* a, Item* b)
{
char* type = TypeNames[a->type->form];
- char* oper = BinaryOps[op];
+ char* oper = Operators[op];
+ assert(type && oper);
printf(" const %s _T%d = _T%d %s _T%d;\n",
type, p->curr_reg, a->reg, oper, b->reg);
a->reg = p->curr_reg;
p->curr_reg++;
}
+static void unary_op(Parser* p, int op, Item* a)
+{
+ char* type = TypeNames[a->type->form];
+ char* oper = Operators[op];
+ assert(type && oper);
+ printf(" const %s _T%d = %s _T%d;\n",
+ type, p->curr_reg, oper, a->reg);
+ a->reg = p->curr_reg;
+ p->curr_reg++;
+}
+
/* Public Interface
*****************************************************************************/
void codegen_setint(Item* item, Type* type, long long val)
}
else
{
- assert(!"not supported");
+ load_var(p, a);
+ unary_op(p, op, a);
}
}
}
}
-/* Code generation for
-find(obj);
-OSS.Get(sym);
-IF obj.class = OSG.SProc THEN
- StandProc(obj.val)
-ELSE
- OSG.MakeItem(x, obj, level);
- selector(x);
-
- IF sym = OSS.becomes THEN (*assignment*)
-
- OSS.Get(sym);
- expression(y);
- IF (x.type.form IN {OSG.Boolean, OSG.Integer}) & (x.type.form = y.type.form) THEN
- OSG.Store(x, y)
- ELSE
- OSS.Mark("incompatible assignment")
- END
-
-// ELSIF sym = OSS.eql THEN
-// OSS.Mark("should be :=");
-// OSS.Get(sym);
-// expression(y)
-// ELSIF sym = OSS.lparen THEN (*procedure call*)
-// OSS.Get(sym);
-// IF (obj.class = OSG.Proc) & (obj.type = NIL) THEN
-// ParamList(obj);
-// OSG.Call(obj);
-// ELSE
-// OSS.Mark("not a procedure")
-// END
-// ELSIF obj.class = OSG.Proc THEN (*procedure call without parameters*)
-// IF obj.nofpar > 0 THEN
-// OSS.Mark("missing parameters")
-// END ;
-// IF obj.type = NIL THEN
-// OSG.Call(obj) ELSE
-// OSS.Mark("not a procedure")
-// END
-// ELSIF (obj.class = OSG.SProc) & (obj.val = 3) THEN
-// OSG.WriteLn
-// ELSIF obj.class = OSG.Typ THEN
-// OSS.Mark("illegal assignment")
-// ELSE
-// OSS.Mark("not a procedure")
-// END
-END
-
-*/
-
RULE(statement_seq)
{
while (1)