diff options
Diffstat (limited to 'tnslc')
-rw-r--r-- | tnslc/compile/compile.tnsl | 16 | ||||
-rw-r--r-- | tnslc/dummy.tnsl | 31 | ||||
-rw-r--r-- | tnslc/util.tnsl | 45 |
3 files changed, 56 insertions, 36 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl index d7e9416..3820812 100644 --- a/tnslc/compile/compile.tnsl +++ b/tnslc/compile/compile.tnsl @@ -22,10 +22,8 @@ /; compile_block (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec) - ;hsec`.append('b') - ;cur`++ - + /; loop (cur` < len data`) [cur`++] /; if (string_equate(data`{cur`}.data`, ";/") || string_equate(data`{cur`}.data`, ";;")) ;break @@ -33,6 +31,9 @@ ;bool ch = true /; loop (ch) ;compile_block(cur, data, hsec, csec, dsec) + /; if (cur` !< len data`) + ;break + ;/ ;ch = string_equate(data`{cur`}.data`, ";;") ;/ ;; else if (string_equate(data`{cur`}.data`, ";")) @@ -42,8 +43,13 @@ ;/ /; compile_statement (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec) - ;csec`.append('c') - ;dsec`.append('d') + ;cur`++ + /; if (cur` < len data`) + /; if (string_equate(data`{cur`}.data`, "asm")) + ;{}charp raw_asm = unquote_string(data`{cur` + 1}.data`) + ;add_strings(csec, ~raw_asm) + ;/ + ;/ ;/ /; do_compile ({}charp file, ~{}Token data) diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl index 8fdb165..233d726 100644 --- a/tnslc/dummy.tnsl +++ b/tnslc/dummy.tnsl @@ -1,30 +1,3 @@ -; struct Token { - int - token_type, - line, - col, - - ~{}charp - data -} - -;struct Node { - Token - # associated token to the node - tok, - - ~{}Node - # sub-nodes - sub -} - -;{}charp cnull = "a" - -/; main [int] - ;{}Node s = {} - ;Node n = {{1, 2, 3, ~cnull}, ~s} - ;s.append(n) - ;tnsl.io.println(~s) - ;tnsl.io.println(n.sub) - ;return 0 +/; asm_test + ;asm "_start:\n" ;/
\ No newline at end of file diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl index 5d84dec..27f9f89 100644 --- a/tnslc/util.tnsl +++ b/tnslc/util.tnsl @@ -103,6 +103,8 @@ /; get_escape_code (charp c) [charp] /; if (c == '\'') ;return '\'' + ;; else if (c == '"') + ;return '"' ;; else if (c == 'a') ;return '\a' ;; else if (c == 'b') @@ -125,15 +127,32 @@ ;/ /; parse_hex_code ({}charp c) [charp] - /; + ;charp out = 0 + + /; loop (int i = 0; i < len c) [i++] + ;out = out * 16 + ;charp tmp = c{i} + /; if (tmp !< 'a') + ;tmp = tmp - 'a' + 'A' + ;/ + /; if (tmp !< '0' && tmp !> '9') + ;out = out + tmp - '0' + ;; else if (tmp !< 'A' && tmp !> 'F') + ;out = out + 10 + (tmp - 'A') + ;; else + ;break + ;/ ;/ + + ;return out ;/ /; unquote_char ({}charp c) [charp] /; if (c{1} == '\\') /; if (c{2} == 'x') - ;return 0 + ;{}charp d = {c{3}, c{4}} + ;return parse_hex_code(d) ;/ ;return get_escape_code(c{2}) ;/ @@ -142,5 +161,27 @@ ;/ /; unquote_string ({}charp str) [{}charp] + ;{}charp out = "" + ;{}charp unc = "'" + + /; loop (int i = 1; i < len str - 1) [i++] + /; if (str{i} == '\\') + ;unc.append('\\') + ;unc.append(str{i + 1}) + ;i++ + + /; if (str{i} == 'x') + ;unc.append(str{i + 1}) + ;unc.append(str{i + 2}) + ;i = i + 2 + ;/ + + ;out.append(unquote_char(unc)) + ;unc = "'" + ;; else + ;out.append(str{i}) + ;/ + ;/ + ;return out ;/ |