summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-03-27 10:30:10 -1000
committerCarson Fleming <[email protected]>2026-03-27 10:30:10 -1000
commitfca3bf239cfdf03c4479f5d0c14a21c1fd96ea3e (patch)
tree0618ad64a13e949ce9273098df724d8d25bdcb36 /scope.c
parent21f688c1eac5fb09ae68fd9b3cfcff687de36601 (diff)
downloadccc-fca3bf239cfdf03c4479f5d0c14a21c1fd96ea3e.tar.gz
woah we got variables
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/scope.c b/scope.c
index 251aa51..3bd070b 100644
--- a/scope.c
+++ b/scope.c
@@ -79,6 +79,41 @@ void scope_pop(struct scope** p_scope) {
free(discarded_scope);
}
+void scope_install_default_types(struct scope* scope) {
+ scope_define_type(scope, (struct type_def) {
+ .name = "void",
+ .size = 0,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "bool",
+ .size = 1,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "char",
+ .size = 1,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "short",
+ .size = 2,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "int",
+ .size = 4,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "float",
+ .size = 4,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "long",
+ .size = 8,
+ });
+ scope_define_type(scope, (struct type_def) {
+ .name = "double",
+ .size = 8,
+ });
+}
+
bool scope_get_type(
const struct scope* scope,
struct type_def* p_entry,
@@ -87,7 +122,7 @@ bool scope_get_type(
for (; scope != NULL; scope = scope->next_out) {
struct type_def* type_def = *type_cell(scope, name);
if (type_def == NULL) continue;
- *p_entry = *type_def;
+ if (p_entry != NULL) *p_entry = *type_def;
return true;
}
return false;
@@ -115,7 +150,7 @@ bool scope_get_var(
for (; scope != NULL; scope = scope->next_out) {
struct var_def* var_def = *var_cell(scope, name);
if (var_def == NULL) continue;
- *p_entry = *var_def;
+ if (p_entry != NULL) *p_entry = *var_def;
return true;
}
return false;