diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2023-02-22 16:22:21 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2023-02-22 16:22:21 -0500 |
commit | e53a018ffe378af678fa0e7b3c0bc7d098d83ac9 (patch) | |
tree | 32fa1c3b417d47ab5797f9276ff1d00074f5f51a /tnslc | |
parent | 07b0a675d733c54ad395b085e2a10048c13b13c0 (diff) |
Apprehensive multiplication and division
Diffstat (limited to 'tnslc')
-rw-r--r-- | tnslc/simple.tnsl | 6 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 138 |
2 files changed, 122 insertions, 22 deletions
diff --git a/tnslc/simple.tnsl b/tnslc/simple.tnsl index 795b626..bbe8ba3 100644 --- a/tnslc/simple.tnsl +++ b/tnslc/simple.tnsl @@ -1,6 +1,6 @@ uint a = 2, b = 4 +{}uint8 str = "Hello" -/; raw main [int] - int c = a + b - raw return c + a - b +/; main [int] + return 273 ;/
\ No newline at end of file diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 408ebb9..760f4cd 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -562,51 +562,148 @@ ;/ ;/ + /; ax_compute + ;{}uint8 s_ext = "", op = "idiv" + /; if (v.loc_type == LOCATION.LITERAL || v.loc_type == LOCATION.REGISTER) + ;s_ext = mov_by_size(sz) + ;; if (self.data_type.name{0} == 'u') + ;op{0} = ' ' + ;/ + + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, sz), ", ", self.norm_loc(sz), "\n" + }, "") + + /; if (v.loc_type == LOCATION.LITERAL) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(3, sz), ", ", v.norm_loc(sz), "\n", + "\t", op, " ", s_ext, get_reg(3, sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(3, sz), "\n" + }, "") + ;; else + ;dat`.csec = string_join( { + dat`.csec, + "\t", op, " ", s_ext, v.norm_loc(sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(3, sz), "\n" + }, "") + ;/ + + ;/ + /; div (Variable v, ~CompData dat) + ;int sz = self.norm_size() /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) - ;v.div(self) + ;v.mul(self) ;; else - ;self.location = self.location / v.location + ;self.location = self.location * v.location ;/ - ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 out = "" - # TODO - ;return out ;; else - ;return self.norm_op("div", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size()) }) + ;{}uint8 s_ext = "", op = "idiv" + /; if (v.loc_type == LOCATION.LITERAL || v.loc_type == LOCATION.REGISTER) + ;s_ext = mov_by_size(sz) + ;; if (self.data_type.name{0} == 'u') + ;op{0} = ' ' + ;/ + + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, sz), ", ", self.norm_loc(sz), "\n" + }, "") + + /; if (v.loc_type == LOCATION.LITERAL) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(3, sz), ", ", v.norm_loc(sz), "\n", + "\t", op, " ", s_ext, get_reg(3, sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(0, sz), "\n" + }, "") + ;; else + ;dat`.csec = string_join( { + dat`.csec, + "\t", op, " ", s_ext, v.norm_loc(sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(0, sz), "\n" + }, "") + ;/ ;/ ;/ /; mod (Variable v, ~CompData dat) + ;int sz = self.norm_size() /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) - ;v.div(self) + ;v.mul(self) ;; else - ;self.location = self.location % v.location + ;self.location = self.location * v.location ;/ - ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 out = "" - # TODO - ;return out ;; else - ;return self.norm_op("div", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size()) }) + ;{}uint8 s_ext = "", op = "idiv" + /; if (v.loc_type == LOCATION.LITERAL || v.loc_type == LOCATION.REGISTER) + ;s_ext = mov_by_size(sz) + ;; if (self.data_type.name{0} == 'u') + ;op{0} = ' ' + ;/ + + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, sz), ", ", self.norm_loc(sz), "\n" + }, "") + + /; if (v.loc_type == LOCATION.LITERAL) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(3, sz), ", ", v.norm_loc(sz), "\n", + "\t", op, " ", s_ext, get_reg(3, sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(3, sz), "\n" + }, "") + ;; else + ;dat`.csec = string_join( { + dat`.csec, + "\t", op, " ", s_ext, v.norm_loc(sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(3, sz), "\n" + }, "") + ;/ ;/ ;/ /; mul (Variable v, ~CompData dat) + ;int sz = self.norm_size() /; if (self.loc_type == LOCATION.LITERAL) /; if (v.loc_type !== LOCATION.LITERAL) ;v.mul(self) ;; else ;self.location = self.location * v.location ;/ - ;; else if (self.loc_type == LOCATION.STACK && v.loc_type == LOCATION.STACK) - ;{}uint8 out = "" - # TODO - ;return out + ;; else + ;{}uint8 s_ext = "", op = "imul" + /; if (v.loc_type == LOCATION.LITERAL || v.loc_type == LOCATION.REGISTER) + ;s_ext = mov_by_size(sz) + ;; if (self.data_type.name{0} == 'u') + ;op{0} = ' ' + ;/ + + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(0, sz), ", ", self.norm_loc(sz), "\n" + }, "") + + /; if (v.loc_type == LOCATION.LITERAL) + ;dat`.csec = string_join( { + dat`.csec, + "\tmov ", get_reg(3, sz), ", ", v.norm_loc(sz), "\n", + "\t", op, " ", s_ext, get_reg(3, sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(0, sz), "\n" + }, "") + ;; else + ;dat`.csec = string_join( { + dat`.csec, + "\t", op, " ", s_ext, v.norm_loc(sz), "\n", + "\tmov ", self.norm_loc(sz), ", ", get_reg(0, sz), "\n" + }, "") + ;/ ;/ - ;return self.norm_op("mul", { self.norm_loc(self.norm_size()), v.norm_loc(self.norm_size()) }) ;/ /; set (Variable v, ~CompData dat) @@ -1608,6 +1705,9 @@ ;s1 = _eval_value(tok, start, first, out, current, scope, t, alt) ;; else ;s1 = _eval_value(tok, start, first, out, current, scope, t, alt) + /; if (tok`{first}.cmp("=")) + ;t = s1.data_type + ;/ ;s2 = _eval_value(tok, first + 1, max, out, current, scope, t, !alt) ;tnsl.io.print("Calculated s2 as ") ;tnsl.io.println(s2.name) |