diff options
Diffstat (limited to 'tnslc')
| -rw-r--r-- | tnslc/compile/function.tnsl | 4 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 42 |
2 files changed, 37 insertions, 9 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 0ad8e6f..682236b 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -37,8 +37,8 @@ struct Function { p.loc = reg reg++ ;; else - p.loc = 0 - p.loc = p.loc - stack_down + p.loc = 0 - 1 + p.offset = 0 - stack_down stack_down = stack_down - p.actual_size() ;/ self.inputs.push(~p) diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index 5d86406..12d0dab 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -1,8 +1,8 @@ # Location enum -int VLOC_STCK = 2 -int VLOC_LITL = 1 -int VLOC_DATA = 0 +int VLOC_DATA = 2 +int VLOC_STCK = 1 +int VLOC_LITL = 0 # Should be -2 int32 PTYPE_NONE = 2 @@ -104,6 +104,7 @@ struct Var { self.name = utils.strcpy(id`.data) self.ptrc.init(4) self.loc = 0 + self.offset = 0 self._tn = tn self._id = id @@ -309,6 +310,10 @@ struct Var { ################################### /; gen_loc [~uint8] + /; if (self.loc == 0) + return utils.int_to_str(self.offset) + ;/ + utils.Vector out out.init(1) @@ -317,7 +322,10 @@ struct Var { ;/ ~uint8 str - /; if (self.loc < 1) + /; if (self.loc + 1 < 0) + out.push_cstr("rel \0") + str = utils.strcpy(self.name) + ;; else if (self.loc < 0) str = reg_string(7, 8) ;; else str = reg_string(self.loc, self.actual_size()) @@ -327,7 +335,7 @@ struct Var { /; if (self.in_mem() == true) - /; if (self.loc < 0) + /; if (self.loc + 1 == 0) int stk = 0 stk = stk - self.loc out.push_cstr(" + \0") @@ -343,7 +351,7 @@ struct Var { # Returns true if the variable is known to be stored in memory /; in_mem [bool] - /; if (self.loc < 1) + /; if (self.loc < 0) return true ;/ @@ -397,20 +405,35 @@ struct Var { ;/ /; add (~CompBuf buf, ~Var other) - /; if (self.loc = VLOC_LITL) + /; if (self.loc == VLOC_LITL && other`.loc == VLOC_LITL) + self.offset = self.offset + other`.offset + return ;/ self.standard_op(buf, other, "add") ;/ /; sub (~CompBuf buf, ~Var other) + /; if (self.loc == VLOC_LITL && other`.loc == VLOC_LITL) + self.offset = self.offset - other`.offset + return + ;/ self.standard_op(buf, other, "sub") ;/ /; mul (~CompBuf buf, ~Var other) + /; if (self.loc == VLOC_LITL && other`.loc == VLOC_LITL) + self.offset = self.offset * other`.offset + return + ;/ self.product_op(buf, other, "imul", 1) ;/ /; div (~CompBuf buf, ~Var other) + /; if (self.loc == VLOC_LITL && other`.loc == VLOC_LITL) + self.offset = self.offset / other`.offset + return + ;/ + /; if ("signed") self.product_op(buf, other, "idiv", 1) ;; else @@ -419,6 +442,11 @@ struct Var { ;/ /; mod (~CompBuf buf, ~Var other) + /; if (self.loc == VLOC_LITL && other`.loc == VLOC_LITL) + self.offset = self.offset % other`.offset + return + ;/ + /; if ("signed") self.product_op(buf, other, "idiv", 4) ;; else |