summaryrefslogtreecommitdiff
path: root/tnslc/compile
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/compile')
-rw-r--r--tnslc/compile/function.tnsl33
-rw-r--r--tnslc/compile/scope.tnsl31
2 files changed, 52 insertions, 12 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl
index c47040f..c9ab985 100644
--- a/tnslc/compile/function.tnsl
+++ b/tnslc/compile/function.tnsl
@@ -231,6 +231,8 @@ struct Function {
s`.cb`.add_c(" \0")
s`.cb`.add_c(n`.data)
s`.cb`.add_c(" ; User defined asm\n\0")
+ ;; else if (n`._type == parse.NTYPE_DECL)
+ self._compile_decl(s, n)
;/
;/
;/
@@ -272,9 +274,36 @@ struct Function {
;/
;/
+ # Should handle variable declarations
+ /; _compile_decl(~Scope s, ~parse.Node n)
+ ~parse.Node sub
+ /; loop (int i = 0; i < n`.sub.count) [i++]
+ sub = n`.sub.get(i)
+ /; if (sub`._type == parse.NTYPE_ID)
+ ~Var v = s`._find_var(sub`.data)
+
+ /; if (v == NULL)
+ _printf("Failed to find variable '\0")
+ _printf(sub`.data)
+ _printf("'\n\0")
+ return
+ ;/
+
+ /; if (sub`.sub.count > 0)
+ sub = sub`.sub.get(0)
+ Var val = self._compile_value(s, sub, v)
+ s`.mk_set_var(~val)
+ val.end()
+ ;; else
+ s`.mk_var(v)
+ ;/
+ ;/
+ ;/
+ ;/
+
# Should handle computing a value, delegate to other funcs when needed
- /; _compile_value (~Scope s, ~parse.Node n) [Var]
- Var out
+ /; _compile_value (~Scope s, ~parse.Node n, ~Var type_hint) [Var]
+ Var out = type_hint`.copy()
return out
;/
diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl
index 191d433..62bbf68 100644
--- a/tnslc/compile/scope.tnsl
+++ b/tnslc/compile/scope.tnsl
@@ -121,14 +121,13 @@ struct Scope {
;/
/; mk_aware_node (~parse.Node n)
-
~parse.Node sub
~parse.Node tp = NULL
/; loop (int i = 0; i < n`.sub.count) [i++]
sub = n`.sub.get(i)
- /; if (n`._type == parse.NTYPE_TYPE)
- tp = n
- ;; else if (n`._type == parse.NTYPE_ID)
+ /; if (sub`._type == parse.NTYPE_TYPE)
+ tp = sub
+ ;; else if (sub`._type == parse.NTYPE_ID)
/; if (tp == NULL)
_printf("COMPILER ERROR: Should have type node before first id in decl node\n\0")
return
@@ -136,7 +135,7 @@ struct Scope {
# Part 1: Add var
Var v
- v.init(tp, n`.data)
+ v.init(tp, sub)
v._resolve_type(self.mod)
# TODO: Make sure this works properly
@@ -150,9 +149,9 @@ struct Scope {
self.vars.push(~v)
# Part 2: Compute via value (if exists)
- /; if (n`.sub.count > 0)
- n = n`.sub.get(0)
- /; if (n`._type == parse.NTYPE_VALUE)
+ /; if (sub`.sub.count > 0)
+ sub = sub`.sub.get(0)
+ /; if (sub`._type == parse.NTYPE_VALUE)
self.precheck_stmt(n)
;/
;/
@@ -193,11 +192,11 @@ struct Scope {
return NULL
;/
- /; mk_set_var (~Var src)
+ /; mk_var (~Var src) [~Var]
~Var v = self._find_var(src`.name)
/; if (v == NULL)
- return
+ return NULL
;/
int tmp = 0
@@ -215,6 +214,16 @@ struct Scope {
;/
;/
+ return v
+ ;/
+
+ /; mk_set_var (~Var src) [~Var]
+ ~Var v = self.mk_var(src)
+
+ /; if (v == NULL)
+ return NULL
+ ;/
+
~int32 p = v`.top_ptrc()
/; if (p == NULL)
v`.set(self.cb, src)
@@ -223,6 +232,8 @@ struct Scope {
;; else
v`.set(self.cb, src)
;/
+
+ return v
;/
#