summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCircleShift <kgunger12@gmail.com>2025-12-07 02:08:21 -0500
committerCircleShift <kgunger12@gmail.com>2025-12-07 02:08:21 -0500
commit17620a6aae801ff22e8eb6a95b30f6e830742542 (patch)
treeccd95517a42181bff5e462298e4a59925d83233e
parent062aefd6aa7cda6a30ae557f4813a2a967b49596 (diff)
in progress reg gen
-rw-r--r--tnslc/compile/function.tnsl15
-rw-r--r--tnslc/compile/module.tnsl6
-rw-r--r--tnslc/compile/scope.tnsl63
-rw-r--r--tnslc/compile/var.tnsl19
-rw-r--r--tnslc/eee70
5 files changed, 95 insertions, 78 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl
index bf06f80..f0aac81 100644
--- a/tnslc/compile/function.tnsl
+++ b/tnslc/compile/function.tnsl
@@ -19,6 +19,8 @@ struct Function {
/; _resolve_dlist (~Module parent, ~parse.Node dl)
~parse.Node tn = NULL
~parse.Node n
+ int reg = 1
+ int stack_down = 0
/; loop (int i = 0; i < dl`.sub.count) [i++]
n = dl`.sub.get(i)
/; if (n`._type == parse.NTYPE_TYPE)
@@ -31,6 +33,14 @@ struct Function {
Var p
p.init(tn, n)
p._resolve_type(parent)
+ /; if (p.is_reg_passed() == true && reg < 7)
+ p.loc = reg
+ reg++
+ ;; else
+ p.loc = 0
+ p.loc = p.loc - stack_down
+ stack_down = stack_down - p.actual_size()
+ ;/
self.inputs.push(~p)
;/
;/
@@ -96,6 +106,11 @@ struct Function {
cb`.add_c(" push r15 ; scope init\n\n\0")
# TODO: Add all params to the scope
+ ~Var in
+ /; loop (int i = 0; i < self.inputs.count) [i++]
+ in = self.inputs.get(i)
+ out.mk_set_var(in)
+ ;/
return out
;/
diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl
index 99d42f1..c7ceab6 100644
--- a/tnslc/compile/module.tnsl
+++ b/tnslc/compile/module.tnsl
@@ -184,12 +184,6 @@ struct Module {
/; if ((lvl + 1) < key`.count)
~Module m
~~uint8 str = key`.get(lvl)
- _printf("Trying to find sub '\0")
- _printf(str`)
- _printf("' in module '\0")
- _printf(self.name)
- _print_num("' at level %d\n\0", lvl)
-
/; loop (int i = 0; i < self.subs.count) [i++]
m = self.subs.get(i)
diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl
index c152d00..24fbed1 100644
--- a/tnslc/compile/scope.tnsl
+++ b/tnslc/compile/scope.tnsl
@@ -5,8 +5,7 @@ struct Scope {
~Scope parent,
- utils.Vector
- vars,
+ utils.Vector vars,
int unique
}
@@ -62,6 +61,66 @@ struct Scope {
;/
#
+ # Make variables
+ #
+
+ /; _next_reg_slot [uint]
+ uint out = 9
+ /; if (self.parent !== NULL)
+ out = self.parent`._next_reg_slot()
+ ;/
+
+ /; if (out == 0)
+ return out
+ ;/
+
+ ~Var v
+ /; loop (int i = 0; i < self.vars.count) [i++]
+ v = self.vars.get(i)
+ /; if (v`.loc > 0)
+ out++
+ /; if (out > 16)
+ return 0
+ ;/
+ ;/
+ ;/
+
+ return out
+ ;/
+
+ /; _next_stack_slot [uint]
+ uint out = 0
+ /; if (self.parent !== NULL)
+ out = self.parent`._next_stack_slot()
+ ;/
+
+ ~Var v
+ /; loop (int i = 0; i < self.vars.count) [i++]
+ v = self.vars.get(i)
+ /; if (v`.loc < 0)
+ out = out - v`.actual_size()
+ ;/
+ ;/
+
+ return out
+ ;/
+
+ /; mk_set_var (~Var src)
+ Var out
+
+ /; if (src`.is_reg_passed() == true)
+ out.loc = self._next_reg_slot()
+ /; if (out.loc == 0)
+ out.loc = self._next_stack_slot()
+ ;/
+ ;; else
+ out.loc = self._next_stack_slot()
+ ;/
+
+ self.vars.push(~out)
+ ;/
+
+ #
# Sub scope
#
diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl
index df62d66..34c101a 100644
--- a/tnslc/compile/var.tnsl
+++ b/tnslc/compile/var.tnsl
@@ -108,6 +108,8 @@ struct Var {
/; init (~parse.Node tn, id)
self.name = utils.strcpy(id`.data)
self.ptrc.init(4)
+ self.loc = 0
+
self._tn = tn
self._id = id
;/
@@ -148,6 +150,23 @@ struct Var {
self.ptrc.push(~ptr)
;/
+ /; is_reg_passed [bool]
+ /; if (self.ptrc.count > 0)
+ return true
+ ;/
+ return false
+ ;/
+
+ /; actual_size [uint]
+ /; if (self.ptrc.count > 0)
+ return 8
+ ;; else if (self._type == NULL)
+ return 0
+ ;/
+
+ return self._type`.size
+ ;/
+
# Sets up both the ptrc and the _type members, requires
# parent module for resolution of types
/; _resolve_type (~Module parent)
diff --git a/tnslc/eee b/tnslc/eee
deleted file mode 100644
index 150f6e9..0000000
--- a/tnslc/eee
+++ /dev/null
@@ -1,70 +0,0 @@
-==== STARTING FIND WITH KEY ====
-key parts 1
-==== STARTING FIND WITH KEY ====
-key parts 1
-{ Module :
- { Struct : Box
- size: 8
- members:
- }
- { Struct : bool
- size: 1
- members:
- }
- { Struct : uint8
- size: 1
- members:
- }
- { Struct : int8
- size: 1
- members:
- }
- { Struct : uint16
- size: 2
- members:
- }
- { Struct : int16
- size: 2
- members:
- }
- { Struct : uint32
- size: 4
- members:
- }
- { Struct : int32
- size: 4
- members:
- }
- { Struct : float32
- size: 4
- members:
- }
- { Struct : uint64
- size: 8
- members:
- }
- { Struct : int64
- size: 8
- members:
- }
- { Struct : float64
- size: 8
- members:
- }
- { Struct : uint
- size: 8
- members:
- }
- { Struct : int
- size: 8
- members:
- }
- { Struct : float
- size: 8
- members:
- }
- { Struct : void
- size: 8
- members:
- }
-}