summaryrefslogtreecommitdiff
path: root/scope.h
diff options
context:
space:
mode:
authorTom Harley2019-10-09 14:26:04 +0100
committerTom Harley2019-10-09 14:26:04 +0100
commit6d4925e61687c2221ab20a4dd2371d1a3e7acb2d (patch)
tree28ae9225d518b4effb72aae421b28f412f47cae1 /scope.h
parentSupport + and * operations (diff)
downloadsinter-6d4925e61687c2221ab20a4dd2371d1a3e7acb2d.tar.gz
sinter-6d4925e61687c2221ab20a4dd2371d1a3e7acb2d.zip

Implement function definitions

Functions can now be defined using the “def” construct. A “main” function has to be defined for LLVM to compile the program.

Recursive function definitions are not supported, since all values are eagerly evaluated, causing infinite recursion of the non-base case. Recursive definitions can be supported either by including an if primitive that does not evaluate both sides, or by implementing support for lazy evalution. I’m interested in exploring the latter, but will probably implement the former for now.

Similar to the if primitive above, the def primitive is currently an implementation which could potentially be altered into a function that manipulates meta-variables at compile time. This would require compile-time evaluation of functions, which would be really cool, but is also superfluous to the current goal. I might return to this idea after I’m happy with the base implementation of the language.

Diffstat (limited to 'scope.h')
-rw-r--r--scope.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/scope.h b/scope.h
new file mode 100644
index 0000000..196f88a
--- /dev/null
+++ b/scope.h
@@ -0,0 +1,26 @@
+#ifndef _SCOPE_H
+#define _SCOPE_H
+
+#include <llvm-c/Core.h>
+
+typedef struct scope_entry {
+ char *id;
+ LLVMValueRef value;
+ LLVMTypeRef type;
+ struct scope_entry *prev;
+} scope_entry;
+
+typedef struct scope_layer {
+ struct scope_entry *head;
+ struct scope_layer *prev;
+} scope_layer;
+
+typedef scope_layer *scope;
+
+void scope_push_layer(scope *sc);
+void scope_pop_layer(scope *sc);
+
+void scope_add_entry(scope sc, char *id, LLVMValueRef val, LLVMTypeRef type);
+scope_entry *scope_find(scope sc, char *id);
+
+#endif /* _SCOPE_H */