unify printing + add basic strings

This commit is contained in:
r4
2021-12-25 12:16:06 +01:00
parent 92c4c5c991
commit f02dae603d
8 changed files with 162 additions and 52 deletions

23
ir.c
View File

@@ -72,32 +72,11 @@ void irtoks_eat_irtoks(IRToks *v, IRToks *other, size_t jmp_offset) {
free(other->toks);
}
static void print_val(const Value *v);
static void print_irparam(const IRParam *p);
static void print_val(const Value *v) {
switch (v->type.kind) {
case TypeFloat:
printf("%f", v->Float);
break;
case TypeInt:
printf("%zd", v->Int);
break;
case TypeBool:
printf("%s", v->Bool ? "true" : "false");
break;
case TypeChar:
printf("'%c'", v->Char);
break;
default:
printf("(unknown type)");
break;
}
}
static void print_irparam(const IRParam *p) {
if (p->kind == IRParamLiteral) {
print_val(&p->Literal);
print_value(&p->Literal, false);
} else if (p->kind == IRParamAddr) {
printf("%%%zd", p->Addr);
}