summaryrefslogtreecommitdiff
path: root/tnslc/tests
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-05-14 11:43:43 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-05-14 11:43:43 -0400
commit89f2b3b4a40749eba388ea998b99381a37bbeb53 (patch)
tree9e58cc6361202feed369a6ac11b542aa9e21d35a /tnslc/tests
parent3217d450a61d5acb5f268604ce97b7b134697afd (diff)
Indexing and proper string decomp
Diffstat (limited to 'tnslc/tests')
-rw-r--r--tnslc/tests/proper_calling.tnsl21
-rw-r--r--tnslc/tests/syntax-playground.tnsl92
2 files changed, 113 insertions, 0 deletions
diff --git a/tnslc/tests/proper_calling.tnsl b/tnslc/tests/proper_calling.tnsl
new file mode 100644
index 0000000..6fd5e69
--- /dev/null
+++ b/tnslc/tests/proper_calling.tnsl
@@ -0,0 +1,21 @@
+struct CallMe {
+ int a, b
+}
+
+/; method CallMe
+ /; call_two (int a, b) [int]
+ return a + b + self.a + self.b
+ ;/
+
+ /; call_four (int a, b, c, d) [int]
+ return self.call_two(a + b, b * c + d) + self.call_two(a * b + c, c + d)
+ ;/
+
+;/
+
+/; main [int]
+ CallMe cm
+ cm.a = 0
+ cm.b = 0
+ return cm.call_four(0, 2, 2, 0)
+;/ \ No newline at end of file
diff --git a/tnslc/tests/syntax-playground.tnsl b/tnslc/tests/syntax-playground.tnsl
new file mode 100644
index 0000000..651be62
--- /dev/null
+++ b/tnslc/tests/syntax-playground.tnsl
@@ -0,0 +1,92 @@
+# This file is for playing with syntax and seeing what works and what does not.
+
+
+## TEST 1 - newlines seperate statements, not ;
+## newlines can be escaped with \
+
+/; test1
+ int main = 0
+
+ /; loop (int i = 0, i < 5) [i++]
+ tnsl.io.println("Hi!")
+ ;/
+
+ String str = {}
+
+ /; loop (char j = ' ', j != 'k') \
+ [j++]
+
+ str.append(j)
+ ;/
+
+ tnsl.io.println(str)
+
+ return main
+;/
+
+## END TEST 1
+##
+## Thoughts: this is much better.
+
+## TEST 2 - get '.' augment auto de-references pointers
+
+struct a {
+ int i, j
+}
+
+struct b {
+ String str,
+ ~a ints
+}
+
+/; ptr_test1
+ b str_b = {"Hello", {0, 1}}
+
+ ~b ptr_b = ~str_b
+
+ tnsl.io.println(ptr_b.str)
+ # vs
+ tnsl.io.println(ptr_b`.str)
+ # both work
+
+ ptr_b.ints.i = 12
+ ptr_b.ints.j = ptr_b.ints.i / 4
+ # vs
+ ptr_b`.ints`.i = 12
+ ptr_b`.ints`.j = ptr_b`.ints`.i / 4
+ # Again, the second one is more descriptive, but is it better?
+
+ ptr_call(ptr_b)
+ ref_call(ptr_b)
+;/
+
+/; ptr_call (~b ptr)
+ ptr.ints.i = 8
+;/
+
+/; ref_call (b` ref)
+ ref.ints.j = 9
+;/
+
+## END TEST 2
+##
+## Thoughts: not sure, the . operator could become a little too ambiguous if this is added
+
+## Test 3: using [] for array indexing instead of {}
+
+:include "tnsl"
+:using "tnsl"
+
+/; main ({}String args) [int]
+ int i = len args
+ String first = args[0]
+
+ {}int list = {0, 1, 2, 3}
+ i = list[2]
+
+ return i
+;/
+
+## End test 3
+##
+## Thoughts: I'm not sure weather I like it better or not.