diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2023-02-21 12:35:19 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2023-02-21 12:35:19 -0500 |
commit | 06dfde98d64c04303b78d026e575b088895d5367 (patch) | |
tree | f15acad1ceb5c90b98408dd9c6731483692b4c57 | |
parent | 1309264425fa72fc7703711cbebabd839c3883cb (diff) |
Fix up add, sub, and set on variables
-rw-r--r-- | tnslc/c_wrap.tnsl | 6 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 73 |
2 files changed, 49 insertions, 30 deletions
diff --git a/tnslc/c_wrap.tnsl b/tnslc/c_wrap.tnsl index b9b96eb..f35b808 100644 --- a/tnslc/c_wrap.tnsl +++ b/tnslc/c_wrap.tnsl @@ -8,7 +8,7 @@ asm "mov r8, 0" asm "mov r9, 0" asm "mov r10, 0" - asm "call malloc" + asm "call malloc wrt ..got" # Set out to the returned value # (The compiler assignes spaces sequentially, and we have a uint in r8) asm "mov r9, rax" @@ -26,7 +26,7 @@ asm "mov r9, 0" asm "mov r10, 0" # Do call - asm "call realloc" + asm "call realloc wrt ..got" # Set out to the returned value # (The compiler assignes spaces sequentially. We have a ptr in r8, and a uint in r9) asm "mov r10, rax" @@ -43,7 +43,7 @@ asm "mov r9, 0" asm "mov r10, 0" # do call - asm "call free" + asm "call free wrt ..got" # there's no more to do 'cause free returns nothing ;/ diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index bfac5d2..d65ddb9 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -502,37 +502,43 @@ ;/ # functions that do work on this variable - /; add (Variable v, int tr) [{}uint8] + /; add (Variable v, ~CompData dat) /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) - ;return v.add(self) + ;v.add(self, dat) + ;; else + ;self.location = self.location + v.location ;/ - ;self.location = self.location + v.location - ;return "" - ;; if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 tmp = get_reg(tr, self.norm_size()) - ;{}uint8 out = self.norm_op("mov", { tmp, v.norm_loc(self.norm_size()) }) - ;return string_add(out, self.norm_op("add", { self.norm_loc(self.norm_size()), tmp })) + ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, self.norm_size()), ", ", v.norm_loc(self.norm_size()), "\n", + "\tadd ", self.norm_loc(self.norm_size()), ", ", get_reg(0, self.norm_size()), "\n" + }, "") + ;; + ;dat`.csec = string_add(dat`.csec, self.norm_op("add", { self.norm_loc(self.norm_size()), get_reg(tr, self.norm_size()) })) ;/ - ;return self.norm_op("add", { self.norm_loc(self.norm_size()), get_reg(tr, self.norm_size()) }) ;/ - /; sub (Variable v) [{}uint8] + /; sub (Variable v, ~CompData dat) /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) - ;return v.add(self) + ;v.add(self, dat) + ;; else + ;self.location = self.location - v.location ;/ - ;self.location = self.location - v.location - ;return "" - ;; if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 tmp = get_reg(tr, self.norm_size()) - ;{}uint8 out = self.norm_op("mov", { tmp, v.norm_loc(self.norm_size()) }) - ;return string_add(out, self.norm_op("sub", { self.norm_loc(self.norm_size()), tmp })) + ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, self.norm_size()), ", ", v.norm_loc(self.norm_size()), "\n", + "\tsub ", self.norm_loc(self.norm_size()), ", ", get_reg(0, self.norm_size()), "\n" + }, "") + ;; else + ;dat`.csec = string_add(dat`.csec, self.norm_op("sub", { self.norm_loc(self.norm_size()), get_reg(tr, self.norm_size()) })) ;/ - ;return self.norm_op("sub", { self.norm_loc(self.norm_size()), get_reg(tr, self.norm_size()) }) ;/ - /; div (Variable v) [{}uint8] + /; div (Variable v, ~CompData dat) /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) ;return v.div(self) @@ -547,7 +553,7 @@ ;return self.norm_op("div", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size) }) ;/ - /; mul (Variable v) [{}uint8] + /; mul (Variable v, ~CompData dat) /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) ;return v.mul(self) @@ -559,7 +565,7 @@ # TODO ;return out ;/ - ;return self.norm_op("mul", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size) }) + ;return self.norm_op("mul", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size()) }) ;/ /; set (Variable v, ~CompData dat) @@ -568,13 +574,17 @@ ;return v.set(self) ;/ ;self.location = v.location - ;return "" - ;; if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 out = "" - # TODO - ;return out + ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) + ;dat`.csec = string_join( { + dat`.csec, + "\tlea rdi, ", self.norm_loc(0), "\n", + "\tlea rsi, ", v.norm_loc(0), "\n", + "\tmov rcx, ", int_to_string(self.norm_size()), "\n", + "\trep movsb\n" + }, "") + ;; else + ;dat`.csec = string_add(dat`.csec, self.norm_op("mov", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size) })) ;/ - ;return self.norm_op("mov", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size) }) ;/ # functions that do work on another variable @@ -1460,6 +1470,14 @@ # Need to impliment in place solving # Need to impliment auto typing /; _eval_value(~{}Token tok, int start, max, ~CompData out, ~Module current, ~Scope scope, Type t) [Variable] + /; if (start == max - 1) + /; if (tok`{start}.type_is(TOKEN.LITERAL)) + /; if (tok`{start}.data{0} == '"') + + ;; else if (tok`{start}.data{0} == '"') + ;/ + ;/ + ;int first = -1, pr = -1, pa = -1 /; loop (int i = start; i < max) [i++] /; if (tok`{i}.type_is(TOKEN.AUGMENT) && priority(tok`{i}) !< pr) @@ -1505,6 +1523,7 @@ ;/ ;/ ;_eval_value(tok, cur`, end, out, current, scope, t) + ;Variable set = {"#tmp", } ;cur` = end ;/ |