summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-05-15 19:26:57 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-05-15 19:26:57 -0400
commitaab648543af3d874667041349b1a22ae19dde30b (patch)
tree28fc1ff968c8dbe589a2adb74207a795cd08f3d9 /tnslc
parentca5b305ab25c42fba3d022fd0e4c4288159c451b (diff)
Fix initial struct calling
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/README.md2
-rw-r--r--tnslc/hello.tnsl8
-rw-r--r--tnslc/simple.tnsl18
-rw-r--r--tnslc/tnslc.tnsl24
4 files changed, 31 insertions, 21 deletions
diff --git a/tnslc/README.md b/tnslc/README.md
index da461e2..e0f9a61 100644
--- a/tnslc/README.md
+++ b/tnslc/README.md
@@ -11,7 +11,7 @@ Examples:
- `./run.sh dummy.tnsl` - Run the compiler on the dummy file
- `./run.sh "dummy.tnsl ../libtnsl/libtnsl.tnsl"` - Run the compiler on the dummy file but also link libtnsl
-- `.\run.ps1 tnslc_wrapped.tnsl`: Run the compiler on the sample "Hello World" program
+- `.\run.ps1 hello.tnsl`: Run the compiler on the sample "Hello World" program
### Credits
diff --git a/tnslc/hello.tnsl b/tnslc/hello.tnsl
new file mode 100644
index 0000000..8fb98a3
--- /dev/null
+++ b/tnslc/hello.tnsl
@@ -0,0 +1,8 @@
+:include "c_wrap.tnsl"
+
+{}uint8 hello = "Hello World!\n\0"
+
+/; main [int]
+ _printf(~hello{0})
+ return 0
+;/ \ No newline at end of file
diff --git a/tnslc/simple.tnsl b/tnslc/simple.tnsl
index 5ef7946..1c54577 100644
--- a/tnslc/simple.tnsl
+++ b/tnslc/simple.tnsl
@@ -2,17 +2,17 @@
{}uint8 str1 = "abcd"
struct Stress {
- int i
+ int i, j, k
}
struct Test {
- Stress s
+ ~Stress s
}
-/; s_call () [Stress]
- Stress a
- a.i = 1
- return a
+/; s_call (Test t)
+ t.s`.i = 1
+ t.s`.j = 1 + t.s`.i
+ t.s`.k = t.s`.j + 1
;/
/; main (int argc, ~~uint argv) [int]
@@ -24,11 +24,11 @@ struct Test {
Stress test
Test stress
- test.i = 1
+ stress.s = ~test
- stress.s = s_call()
+ s_call(stress)
# return 3
- return stress.s.i
+ return stress.s`.k
;/
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index e5b8d94..f75284d 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -1408,12 +1408,12 @@
;out.data_type = out.data_type.members{i}.data_type
;out.data_type.ptr_chain.append(PTYPE.REFERENCE)
- /; if (accum > 0)
+ /; if (accum > 0)
;data`.csec = string_join( {
data`.csec,
"\tadd rsi, ", int_to_string(accum), "\n"
}, "")
- ;/
+ ;/
;return out
;/
@@ -2696,18 +2696,18 @@
;f = base.data_type.mod`.find_function( {name} )
;/
;Variable ctmp = {"#ctmp", NO_TYPE, 0-1, LOCATION.REGISTER}
-
+ ;int old_start = start
/; loop (int i = 0; i < len (f.inputs)) [i++]
;Type t = f.mod`.find_type(string_split(f.inputs{i}.name, '.'))`
;t.ptr_chain = f.inputs{i}.ptr_chain
;ctmp.data_type = t
/; if (ctmp.is_ref())
- ;ctmp.data_type.ptr_chain{len (ctmp.data_type.ptr_chain)} = PTYPE.POINTER
+ ;ctmp.data_type.ptr_chain{len (ctmp.data_type.ptr_chain) - 1} = PTYPE.POINTER
;/
;ctmp.data_type.ptr_chain.append(PTYPE.REFERENCE)
- /; if (!(ctmp.is_prim()) || regs > 5)
+ /; if (!(ctmp.is_prim()) || regs !< 6)
;int layer = 0
;Variable val = _eval_value(tok, start, _param_end(tok, start), out, mov, current, scope, t, ~layer)
;out`.csec = string_join( {
@@ -2716,17 +2716,17 @@
}, "")
;scope`.tmp = scope`.tmp + ctmp.norm_size()
;ctmp.set(val, out)
- ;start = _param_end(tok, start) + 1
;; else
;regs++
;/
+ ;start = _param_end(tok, start) + 1
;/
;int regs = 1
/; if (string_equate(base.name, ""))
;regs = 0
;/
-
+ ;start = old_start
/; loop (int i = 0; i < len (f.inputs)) [i++]
;Type t = f.mod`.find_type(string_split(f.inputs{i}.name, '.'))`
;t.ptr_chain = f.inputs{i}.ptr_chain
@@ -2751,10 +2751,10 @@
;ctmp.set(val, out)
;regs++
- ;start = _param_end(tok, start) + 1
;; else if (regs == 6)
;break
;/
+ ;start = _param_end(tok, start) + 1
;/
/; if (f.is_method())
@@ -2843,7 +2843,7 @@
;wk = wk.member(tok`{start` + 1}.data, out)
;start` = start` + 2
;/
- ;; if (tok`{start`}.cmp("("))
+ ;; else if (tok`{start`}.cmp("("))
;start` = start` - 1
;; else if (tok`{start`}.cmp("`"))
;log_debug("Pre loop deref")
@@ -2898,8 +2898,10 @@
;scope`.tmp = scope`.tmp + 8
;/
- ;Function to_call = _setup_call(tok, start`, wk, out, mov, current, scope)
- ;wk = _perform_call(to_call, scope, out)
+ ;Scope call_sc = scope`.new_sub_cf("call")
+ ;Function to_call = _setup_call(tok, start`, wk, out, mov, current, ~call_sc)
+ ;wk = _perform_call(to_call, ~call_sc, out)
+ ;call_sc.clear_tmp(out)
/; if (layer` > 2)
;out`.csec = string_join({