summaryrefslogtreecommitdiff
path: root/tnslc/util.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-14 14:05:03 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-14 14:05:03 -0400
commit4e2e269fab3f5facedc6ec0131f132bd66c0aac4 (patch)
treedab2c175c4c81c3665703c800d07bb1d775821e0 /tnslc/util.tnsl
parent37d1e9fa02b27d1a6c56b4c95d31e6d2b9eab9ee (diff)
Focus on ASM generation instead of raw binary
Diffstat (limited to 'tnslc/util.tnsl')
-rw-r--r--tnslc/util.tnsl68
1 files changed, 68 insertions, 0 deletions
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl
index f1644e7..a26b93e 100644
--- a/tnslc/util.tnsl
+++ b/tnslc/util.tnsl
@@ -32,6 +32,20 @@
;return true
;/
+/; add_strings (~{}charp a, b) [{}charp]
+ ;{}charp out = ""
+
+ /; loop (int i = 0; i < len a`) [i++]
+ ;out.append(a`{i})
+ ;/
+
+ /; loop (int i = 0; i < len b`) [i++]
+ ;out.append(b`{i})
+ ;/
+
+ ;return out
+;/
+
/; is_whitespace (charp c) [bool]
;return c == '\t' || c == '\n' || c == ' '
;/
@@ -44,3 +58,57 @@
;bool low = c !< 'A' && c !> 'Z', high = c !< 'a' && c >! 'z'
;return low || high
;/
+
+/; digit_to_char(int i) [charp]
+ ;charp out = '0'
+ ;out = out + (i % 10)
+ ;return out
+;/
+
+/; string_from_int(int i) [{}charp]
+ ;{}charp c = ""
+
+ /; if (i < 0)
+ ;c = "-"
+ ;i = -i
+ ;/
+
+ ;c.append(digit_to_char(i))
+
+ /; loop (i !== 0) [i = i / 10]
+ ;c.append(digit_to_char(i))
+ ;/
+
+ ;return c
+;/
+
+/; get_escape_code (charp c) [charp]
+ /; if (c == '\'')
+ ;return '\''
+ ;; else if (c == 'n')
+ ;return '\n'
+ ;; else if (c == 't')
+ ;return '\t'
+ ;; else if (c == '\r')
+ ;return '\r'
+ ;; else if (c == '\b')
+ ;return '\b'
+ ;/
+
+ ;return 0
+;/
+
+/; unquote_char ({}charp c) [charp]
+ /; if (c{1} == '\\')
+ /; if (c{2} == 'u')
+ ;return 0
+ ;/
+ ;return get_escape_code(c{2})
+ ;/
+
+ ;return c{1}
+;/
+
+/; unquote_string ({}charp str) [{}charp]
+
+;/