summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-03-26 18:23:52 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-03-26 18:23:52 -0400
commit6aa8c17b281eb0c8785bb76449bad428b6b3fdd6 (patch)
treefb7f7ce45a1e12abf29d2333727bbee47c017da5
parent4a71d4c02a4613454f3fdb782acd830de0f23641 (diff)
Fixes for method calling
-rw-r--r--tnslc/simple.tnsl11
-rw-r--r--tnslc/tnslc.tnsl45
2 files changed, 32 insertions, 24 deletions
diff --git a/tnslc/simple.tnsl b/tnslc/simple.tnsl
index 8af8a68..0a419c8 100644
--- a/tnslc/simple.tnsl
+++ b/tnslc/simple.tnsl
@@ -3,7 +3,8 @@
{}uint8 str2 = "abcd"
/; method Test
- /; wamba
+ /; wamba [int]
+ return self.i + self.j
;/
;/
@@ -11,10 +12,6 @@ struct Test {
int i, j, k
}
-/; call_me (int i, ~int j) [int]
- return i + j`
-;/
-
/; main (int argc, ~~uint argv) [int]
# On windows, the first two arguments are passed in RCX and RDX, so we need to
# update their positions here or else tnsl will have garbage values in r8 and r9
@@ -35,8 +32,8 @@ struct Test {
argc = 90
;/
- m.j = call_me(m.j, ~argc)
+ m.i = argc
# return 3
- return m.j
+ return m.wamba()
;/
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index bb4d095..afe0adb 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -694,16 +694,17 @@
int s,
{}uint8
name,
- mod_name,
{}int
ptr_chain,
{}Variable
- members
+ members,
+ ~Module
+ mod
}
/; method Type
/; sprint [{}uint8]
- ;{}uint8 out = string_join( {"{ ", int_to_string(self.s), ", ", self.name, ", ", self.mod_name, ", { "}, "")
+ ;{}uint8 out = string_join( {"{ ", int_to_string(self.s), ", ", self.name, ", { "}, "")
;{}{}uint8 pch = {}
/; loop (int i = 0; i < len(self.ptr_chain)) [i++]
;pch.append(int_to_string(self.ptr_chain{i}))
@@ -747,7 +748,7 @@
8
}
-;Type NO_TYPE = {0, "", "", {}, {}}
+;Type NO_TYPE = {0, "", {}, {}, 0}
/; is_primitive ({}uint8 t) [int]
;{}{}uint8 pn = PRIM_NAMES
@@ -763,7 +764,7 @@
/; get_primitive (int i) [Type]
;{}{}uint8 pn = PRIM_NAMES
;{}int ps = PRIM_SIZES
- ;return {ps{i}, pn{i}, string_add("_", pn{i}), {}, {}}
+ ;return {ps{i}, pn{i}, {}, {}, 0}
;/
# Represents the place in memory where a variable is
@@ -1808,13 +1809,13 @@
;/
/; if (string_equate(self.name, ""))
- ;Type nt = {0, artifact{len artifact - 1}, "", {}, {}}
+ ;Type nt = {0, artifact{len artifact - 1}, {}, {}, 0}
;return ~nt
;/
;~Module m = self.parent
/; loop (r > 0) [r = r - 1]
- ;m = m.parent
+ ;m = m`.parent
;/
;return m`._find_type(artifact, 0)
;/
@@ -1823,7 +1824,7 @@
/; find_type ({}{}uint8 artifact) [~Type]
;int p = is_primitive(artifact{0})
/; if (p !< 0)
- ;Type out = {p, artifact{0}, {}, {}, {}}
+ ;Type out = {p, artifact{0}, {}, {}, 0}
;return ~out
;/
@@ -1861,7 +1862,7 @@
;~Module m = self.parent
/; loop (r > 0) [r = r - 1]
- ;m = m.parent
+ ;m = m`.parent
;/
;return m`._find_def(artifact, 0)
;/
@@ -1896,7 +1897,7 @@
;~Module m = self.parent
/; loop (r > 0) [r = r - 1]
- ;m = m.parent
+ ;m = m`.parent
;/
;return m`._find_function(artifact, 0)
;/
@@ -1931,7 +1932,7 @@
;~Module m = self.parent
/; loop (r > 0) [r = r - 1]
- ;m = m.parent
+ ;m = m`.parent
;/
;return m`._find_mod(artifact, 0)
;/
@@ -2014,7 +2015,7 @@
;/
;{}uint8 a = string_join(get_artifact(tok, cur), ".")
- ;Type out = {0, a, "", ptr_chain, {}}
+ ;Type out = {0, a, ptr_chain, {}, 0}
/; if (tok`{cur`}.cmp("`"))
;out.ptr_chain.append(PTYPE.REFERENCE)
@@ -2184,11 +2185,11 @@
}, ""))
;/
- ;Type out = {0, tok`{cur`}.data, "", {}, {}}
+ ;Type out = {0, tok`{cur`}.data, {}, {}, 0}
;{}uint8 mod_name = string_add("_#", out.name)
;~Module new = find_or_create(mod_name, current, current`.exp)
- ;out.mod_name = new`.full_path()
+ ;out.mod = new
/; loop (cur` < len tok`) [cur`++]
/; if (tok`{cur`}.cmp("{"))
@@ -2201,7 +2202,7 @@
;log_debug(string_join({"[", out.members{i}.name, ":", out.members{i}.data_type.name, "]"}, ""))
;/
- ;log_debug(string_add("Generated type ", string_add(out.name, string_add(":", out.mod_name))))
+ ;log_debug(string_add("Generated type ", string_add(out.name, string_add(":", out.mod`.name))))
;current`.types.append(out)
;/
@@ -2593,8 +2594,7 @@
;regs = 0
;f = current`.find_function( {name} )
;; else
- ;~Module tmp = current`.find_mod(string_split(base.mod_name, '.'))
- ;f = current`.find_function(name)
+ ;f = base.data_type.mod`.find_function( {name} )
;/
;Variable ctmp = {"#ctmp", NO_TYPE, 0-1, LOCATION.REGISTER}
@@ -2651,6 +2651,17 @@
;/
;/
+ /; if (f.is_method())
+ /; if (base.is_ref())
+ ;base.move_register(0, out)
+ ;; else
+ ;out`.csec = string_join( {
+ out`.csec,
+ "\tlea rax, ", base.norm_loc(base.norm_size()), "\n"
+ }, "")
+ ;/
+ ;/
+
;return f
;/