aboutsummaryrefslogtreecommitdiff
path: root/compiler/types.cup
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-05 19:05:40 -0500
committerMustafa Quraish <[email protected]>2022-02-05 19:05:40 -0500
commit8164626888793c0e706a8dd9f65a2bedb4110b55 (patch)
tree235a1381f3cebb5447f9baa807e470945ba04e81 /compiler/types.cup
parentAdd implementation of self-hosted compiler so far (diff)
downloadcup-8164626888793c0e706a8dd9f65a2bedb4110b55.tar.xz
cup-8164626888793c0e706a8dd9f65a2bedb4110b55.zip
[compiler.cup] Add support for lexically scoped local variables
Diffstat (limited to 'compiler/types.cup')
-rw-r--r--compiler/types.cup12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/types.cup b/compiler/types.cup
index f3c7b38..c2afdec 100644
--- a/compiler/types.cup
+++ b/compiler/types.cup
@@ -34,6 +34,18 @@ fn size_for_base_type(type: int): int {
return 0;
}
+fn size_for_type(typ: Type*): int {
+ if (typ.typ == TYPE_INT) return 8;
+ if (typ.typ == TYPE_PTR) return 8;
+ if (typ.typ == TYPE_CHAR) return 1;
+ if (typ.typ == TYPE_ARRAY) return typ.array_size * size_for_type(typ.ptr);
+ if (typ.typ == TYPE_STRUCT) return typ.size;
+ if (typ.typ == TYPE_UNION) return typ.size;
+ if (typ.typ == TYPE_VOID) return 0;
+ if (typ.typ == TYPE_ANY) return 8;
+ die("Unknown type in size_for_type");
+}
+
let _type_int: Type* = null;
let _type_char: Type* = null;
let _type_void: Type* = null;