summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-15 15:30:53 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-15 15:30:53 -0400
commit5582d6427e2bc09b9975615f87cace64ce2d29ca (patch)
tree2844b7d5f54f7b24ae48086356ad758eb2b503b1
parent4e2e269fab3f5facedc6ec0131f132bd66c0aac4 (diff)
Fix string from int
-rw-r--r--tnslc/tnslc.tnsl2
-rw-r--r--tnslc/util.tnsl56
2 files changed, 49 insertions, 9 deletions
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 10a7bbd..ec6fa04 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -25,7 +25,7 @@
/; main ({}{}charp args) [int]
/; if (len args < 1)
- ;tnsl.io.println("Usage: tnslc [File to compile] <path to libtnsl>")
+ ;tnsl.io.println(string_from_int(97265))
;return 1
;/
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl
index a26b93e..4e2849b 100644
--- a/tnslc/util.tnsl
+++ b/tnslc/util.tnsl
@@ -46,6 +46,16 @@
;return out
;/
+/; reverse_string({}charp str) [{}charp]
+ ;{}charp out = ""
+
+ /; loop (int i = len str; i > 0) [i = i - 1]
+ ;out.append(str{i - 1})
+ ;/
+
+ ;return out
+;/
+
/; is_whitespace (charp c) [bool]
;return c == '\t' || c == '\n' || c == ' '
;/
@@ -74,33 +84,63 @@
;/
;c.append(digit_to_char(i))
+ ;i = i / 10
/; loop (i !== 0) [i = i / 10]
;c.append(digit_to_char(i))
;/
- ;return c
+ ;return reverse_string(c)
+;/
+
+/; int_from_string ({}charp str) [int]
+ ;bool inv = str{0} == '-'
+ ;int out = 0
+
+ /; loop ()
+
+ ;/
+
+ /; if (inv)
+ ;out = -out
+ ;/
+
+ ;return out
;/
/; get_escape_code (charp c) [charp]
/; if (c == '\'')
;return '\''
+ ;; else if (c == 'a')
+ ;return '\a'
+ ;; else if (c == 'b')
+ ;return '\b'
+ ;; else if (c == 'e')
+ ;return '\e'
+ ;; else if (c == 'f')
+ ;return '\f'
;; else if (c == 'n')
;return '\n'
- ;; else if (c == 't')
- ;return '\t'
- ;; else if (c == '\r')
+ ;; else if (c == 'r')
;return '\r'
- ;; else if (c == '\b')
- ;return '\b'
- ;/
+ ;; else if (c == 't')
+ ;return '\t'
+ ;; else if (c == 'v')
+ ;return '\v'
+ ;/
;return 0
;/
+/; parse_hex_code ({}charp c) [charp]
+ /;
+
+ ;/
+;/
+
/; unquote_char ({}charp c) [charp]
/; if (c{1} == '\\')
- /; if (c{2} == 'u')
+ /; if (c{2} == 'x')
;return 0
;/
;return get_escape_code(c{2})