summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-12-17 10:56:18 -0500
committerKyle Gunger <kgunger12@gmail.com>2022-12-17 10:56:18 -0500
commit2ec32dac56b544bc4851a3efddf75ee5fd9314ed (patch)
treed145c241d7c114b6aaa83d7759d9647b21997b87
parentc5219bb99f5ae0cca484457dfb89d00b0c68011e (diff)
Change charp to uint8
+ Change charp to uint8 + Start value abstraction
-rw-r--r--tnslc/compile/compile.tnsl158
-rw-r--r--tnslc/compile/isa_x86.tnsl48
-rw-r--r--tnslc/compile/value.tnsl148
-rw-r--r--tnslc/copy.tnsl2
-rw-r--r--tnslc/parse/parse.tnsl6
-rw-r--r--tnslc/parse/token.tnsl36
-rw-r--r--tnslc/paths.tnsl32
-rw-r--r--tnslc/tnslc.tnsl5
-rw-r--r--tnslc/util.tnsl42
9 files changed, 291 insertions, 186 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index 14916b5..b8c6cd3 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -15,7 +15,7 @@
#/
-;{}{}charp COMMON_ASM = {
+;{}{}uint8 COMMON_ASM = {
"\tret\n"
}
@@ -26,14 +26,14 @@
int
ptr,
- {}charp name,
+ {}uint8 name,
{}VType sub_types,
- {}{}charp sub_names
+ {}{}uint8 sub_names
}
/; method VType
- /; get_sub_type({}charp name) [VType]
+ /; get_sub_type({}uint8 name) [VType]
/; loop (int i = 0; i < len (self.sub_types)) [i++]
/; if (string_equate(~name, ~(self.sub_names{i})))
;return self.sub_types{i}
@@ -42,7 +42,7 @@
;return NT
;/
- /; get_offset({}charp name) [int]
+ /; get_offset({}uint8 name) [int]
;int out = 0
/; loop (int i = 0; i < len (self.on_stack)) [i++]
/; if (string_equate(~name, ~(self.sub_types{i*2 + 1})))
@@ -67,7 +67,7 @@
# Tracks defined variables in a block
;struct VTrack {
- {}{}charp
+ {}{}uint8
sym_names,
{}bool
@@ -79,7 +79,7 @@
/; method VTrack
# returns true if the value is allocated to the stack
- /; add_track({}charp name, VType _type) [int]
+ /; add_track({}uint8 name, VType _type) [int]
;bool to_stack = is_struct(_type)
;int count = 0
@@ -105,7 +105,7 @@
;/
# Returns true if the variable is being tracked
- /; in_vtrack({}charp name) [bool]
+ /; in_vtrack({}uint8 name) [bool]
/; loop (int i = 0; i < len (self.on_stack)) [i++]
/; if (string_equate(~name, ~(self.sym_names{i})))
;return true
@@ -126,7 +126,7 @@
;/
# returns the type of the named variable
- /; get_vtype ({}charp name) [VType]
+ /; get_vtype ({}uint8 name) [VType]
/; loop (int i = 0; i < len (self.on_stack)) [i++]
/; if (string_equate(name, self.sym_names{i}))
;return (self.sym_types{i})
@@ -158,44 +158,23 @@
;VType NT = {0, 0, "null", {}, {}}
# Returns an index in the vtrack for a given variable name
-/; name_to_index ({}charp name, ~VTrack tab) [int]
+/; name_to_index ({}uint8 name, ~VTrack tab) [int]
/; loop (int i = 0; i < len (tab`.sym_names)) [i++]
/; if (string_equate(tab`.sym_names{i}, name))
;return i
;/
;/
-
+
;tnsl.io.print("Failed to find vairable ")
;tnsl.io.println(name)
;return -1
;/
-# The commonly used registers in order
-/; reg_by_num(int r) [{}charp]
- /; if (r == 0)
- ;return "ax"
- ;; if (r == 1)
- ;return "bx"
- ;; if (r == 2)
- ;return "cx"
- ;; if (r == 3)
- ;return "dx"
- ;; if (r == 4)
- ;return "si"
- ;; if (r == 5)
- ;return "di"
- ;; if (r == 6)
- ;return "bp"
- ;; if (r == 7)
- ;/
- ;return string_from_int(r)
-;/
-
# Given an index in the vtrack, returns a string representation of the
# register or memory where that variable is
-/; index_to_loc (int index, ~VTrack tab) [{}charp]
- ;{}charp out = ""
+/; index_to_loc (int index, ~VTrack tab) [{}uint8]
+ ;{}uint8 out = ""
;int stack_bytes = 0
;int reg = 0
;int i = 0
@@ -232,29 +211,9 @@
;return true
;/
-# Using the type name and member name, create a label of form "_type.member"
-/; construct_offset_label ({}charp t, {}charp n) [{}charp]
- ;{}charp out = "_"
- ;add_strings(~out, ~t)
- ;out.append('.')
- ;add_strings(~out, ~n)
- ;return out
-;/
-
-# For use when constructing module labels
-/; construct_path_label({}{}charp path)
- ;{}charp out = "_."
- /; loop (int i = 0; i < len path) [i++]
- ;add_strings(~out, ~(path{i}))
- ;out.append('.')
- ;/
- ;out{len out - 1} = ':'
- ;return out
-;/
-
# Using the given offset (in bytes), return an asm value of form ".quad <offset>"
-/; construct_value (int size, int offset) [{}charp]
- ;{}charp out = ".byte "
+/; construct_value (int size, int offset) [{}uint8]
+ ;{}uint8 out = ".byte "
/; if (size == 2)
;out = ".word "
;; if (size == 4)
@@ -262,28 +221,25 @@
;; if (size == 8)
;out = ".quad "
;/
- ;{}charp tmp = string_from_int(offset)
+ ;{}uint8 tmp = string_from_int(offset)
;add_strings(~out, ~tmp)
;return out
;/
-/; construct_text_value ({}charp t) [{}charp]
- ;{}charp tmp = unquote_string(t)
- ;{}charp out = construct_value(1, len tmp)
- ;{}charp tmp = "\n\t.ascii "
- ;add_strings(~out, ~tmp)
- ;add_strings(~out, ~t)
- ;return out
+/; construct_text_value ({}uint8 t) [{}uint8]
+ ;{}uint8 tmp = "\n\t.ascii "
+ ;add_strings(~tmp, ~t)
+ ;return tmp
;/
-/; construct_mov_literal({}charp value, reg) [{}charp]
- ;{}charp tmp = "$"
+/; construct_mov_literal({}uint8 value, reg) [{}uint8]
+ ;{}uint8 tmp = "$"
;add_strings(~tmp, ~value)
;return mov_asm(tmp, reg)
;/
# Parse a struct and add it to the table
-/; def_struct (~int cur, ~{}Token data, ~{}charp dsec) [VType]
+/; def_struct (~int cur, ~{}Token data, ~{}uint8 dsec) [VType]
;VType out = {0, 0, "", {}, {}}
;cur`++
@@ -333,7 +289,7 @@
;/
# Checks if the current token's data member is equal to a given string
-/; token_is(~int cur, ~{}Token data, {}charp str) [bool]
+/; token_is(~int cur, ~{}Token data, {}uint8 str) [bool]
;return string_equate(data`{cur`}.data`, str)
;/
@@ -350,7 +306,7 @@
;/
# Searches the type table for a type
-/; vtype_by_name ({}charp name) [VType]
+/; vtype_by_name ({}uint8 name) [VType]
/; loop (int i = 0; i < len type_table) [i++]
;VType tmp = tnslc.type_table{i}
/; if (string_equate(name, tmp.name))
@@ -408,7 +364,7 @@
;/
# Mostly deals with structs and enums
-/; compile_global (~int cur, ~{}Token data, ~VTrack gsc, ~{}charp hsec, csec, dsec)
+/; compile_global (~int cur, ~{}Token data, ~VTrack gsc, ~{}uint8 hsec, csec, dsec)
;cur`++
/; if (token_is(cur, data, "struct"))
;def_struct(cur, data, dsec)
@@ -416,7 +372,7 @@
;/
# Evaluate a value and return it to the register pointed at by reg
-/; eval_value (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}charp hsec, csec, dsec, int reg)
+/; eval_value (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec, int reg)
/; if (token_is(cur, data, ";/"))
;return
;/
@@ -432,7 +388,7 @@
# Char literal
;; else
# int literal
- ;{}charp tmp = construct_mov_literal(data`{cur`}.data`, get_reg(8, reg_by_num(val_layer)))
+ ;{}uint8 tmp = construct_mov_literal(data`{cur`}.data`, get_reg(8, reg_by_num(val_layer)))
;add_strings(csec, ~tmp)
;val_layer++
;cur`++
@@ -446,12 +402,12 @@
;/
;/
-/; get_function_label(~int cur, ~{}Token data) [{}charp]
+/; get_function_label(~int cur, ~{}Token data) [{}uint8]
/; if (string_equate(data`{cur` + 1}.data`, "("))
;return data`{cur`}.data`
;/
- ;{}{}charp func_path = {}
+ ;{}{}uint8 func_path = {}
/; loop (cur` < len data`) [cur`++]
/; if (token_is(cur, data, "("))
@@ -460,17 +416,17 @@
;func_path.append(data`{cur`}.data`)
;/
;/
- ;{}charp out = "_."
- ;{}charp jn_tmp = join(func_path, '.')
+ ;{}uint8 out = "_."
+ ;{}uint8 jn_tmp = join(func_path, '.')
;add_strings(~out, ~jn_tmp)
;return out
;/
# Sets up a call and reports back where the return value is stored
-/; eval_call (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}charp hsec, csec, dsec) [{}charp]
+/; eval_call (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec) [{}uint8]
# Store the name of the function we are calling
- ;{}charp to_call = get_function_label(cur, data)
+ ;{}uint8 to_call = get_function_label(cur, data)
;tnsl.io.println(to_call)
# Set read head to first parameter
;cur`++
@@ -490,29 +446,29 @@
;/
;cur`++
- ;{}charp call_ist = call_asm(to_call)
+ ;{}uint8 call_ist = call_asm(to_call)
;add_strings(csec, ~call_ist)
;return "ax"
;/
-/; set_struct_value (~{}charp csec)
+/; set_struct_value (~{}uint8 csec)
;/
-/; copy_struct ({}charp from, to, VType t) [{}charp]
- ;{}charp out = ""
- ;{}charp init = ""
+/; copy_struct ({}uint8 from, to, VType t) [{}uint8]
+ ;{}uint8 out = ""
+ ;{}uint8 init = ""
;/
-/; set_value ({}charp from, to, int size, ~{}charp csec)
+/; set_value ({}uint8 from, to, int size, ~{}uint8 csec)
/; if (is_common_reg(from))
;from = get_reg(size, from)
;; if (is_common_reg(to))
;to = get_reg(size, to)
;/
- ;{}charp tmp = "\tmov"
+ ;{}uint8 tmp = "\tmov"
/; if (size == 1)
;mov.append('b')
;; else if (size == 2)
@@ -544,13 +500,13 @@
;/
# Compile a statement in a function
-/; compile_statement (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}charp hsec, csec, dsec) [bool]
+/; compile_statement (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec) [bool]
;cur`++
;bool r = false
/; if (cur` < len data`)
/; if (token_is(cur, data, "asm"))
;cur`++
- ;{}charp raw_asm = unquote_string(data`{cur`}.data`)
+ ;{}uint8 raw_asm = unquote_string(data`{cur`}.data`)
;raw_asm.append('\n')
;csec`.append('\t')
;add_strings(csec, ~raw_asm)
@@ -570,7 +526,7 @@
;; else if (name_to_index(data`{cur`}.data`, tab) !< 0)
# set value
;int i = name_to_index(data`{cur`}.data`, tab)
- ;{}charp tmp = index_to_loc(i)
+ ;{}uint8 tmp = index_to_loc(i)
;eval_value(cur, data, tab, gsc, hsec, csec, dsec, 0)
;tmp = mov_asm(get_reg(tab`.sym_types{i}._size, "ax"), tmp)
;add_strings(csec, ~tmp)
@@ -585,7 +541,7 @@
/; if (token_is(cur, data, ","))
;cur`++
;; else if (token_is(cur, data, "="))
- ;{}charp loc = index_to_loc(len tab`.sym_names - 1, tab)
+ ;{}uint8 loc = index_to_loc(len tab`.sym_names - 1, tab)
;eval_value(cur, data, tab, gsc, hsec, csec, dsec, loc)
/; if (token_is(cur, data, ","))
;cur`++
@@ -606,10 +562,10 @@
-/; compile_block (~int cur, ~{}Token data, ~VTrack gsc, ~{}charp hsec, csec, dsec, {}{}charp mod_path, Path rel)
+/; compile_block (~int cur, ~{}Token data, ~VTrack gsc, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path, Path rel)
;VTrack tab = { {}, {}, {} }
;VType out_type = tnslc.type_table{14}
- ;{}charp name = ""
+ ;{}uint8 name = ""
;bool r = false
/; loop (cur`++; cur` < len data`) [cur`++]
@@ -621,8 +577,8 @@
/; if (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD && len name == 0)
;name = data`{cur`}.data`
/; if (len mod_path > 0)
- ;{}charp frs = "_."
- ;{}charp jn = join(mod_path, '.')
+ ;{}uint8 frs = "_."
+ ;{}uint8 jn = join(mod_path, '.')
;add_strings(~frs, ~jn)
;add_strings(csec, ~frs)
;csec`.append('.')
@@ -684,13 +640,13 @@
;csec`.append('\n')
;/
-/; compile_include (Path file_path, ~VTrack global, ~{}charp hsec, csec, dsec, {}{}charp mod_path)
+/; compile_include (Path file_path, ~VTrack global, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path)
# Autocomplete in the case of module syntax
;bool d = file_path.extension_is("tnsl")
/; if (!d)
;file_path.dirs.append(file_path.file)
- ;{}charp ftmp = file_path.file
- ;{}charp tmp = ".tnsl"
+ ;{}uint8 ftmp = file_path.file
+ ;{}uint8 tmp = ".tnsl"
;add_strings(~ftmp, ~tmp)
;file_path.file = ftmp
;/
@@ -708,7 +664,7 @@
;compile_file(file_path, data, global, hsec, csec, dsec, mod_path)
;/
-/; compile_file (Path rel, ~{}Token data, ~VTrack global, ~{}charp hsec, csec, dsec, {}{}charp mod_path)
+/; compile_file (Path rel, ~{}Token data, ~VTrack global, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path)
;int j = len data`
@@ -728,10 +684,10 @@
;/
-/; do_compile ({}charp file_out, Path rel)
- ;{}charp hsec = ".global main\n"
- ;{}charp csec = ".text\n"
- ;{}charp dsec = ".data\n"
+/; do_compile ({}uint8 file_out, Path rel)
+ ;{}uint8 hsec = ".global main\n"
+ ;{}uint8 csec = ".text\n"
+ ;{}uint8 dsec = ".data\n"
;VTrack global_scope = {{}, {}}
diff --git a/tnslc/compile/isa_x86.tnsl b/tnslc/compile/isa_x86.tnsl
index ee5bf27..02ba899 100644
--- a/tnslc/compile/isa_x86.tnsl
+++ b/tnslc/compile/isa_x86.tnsl
@@ -14,7 +14,7 @@
EXPRESS OR IMPLIED
#/
-/; construct_statement({}charp base, {}{}charp args) [{}charp]
+/; construct_statement({}uint8 base, {}{}uint8 args) [{}uint8]
/; loop (int i = 0; i < len args) [i++]
;add_strings(~base, ~(args{i}))
/; if (i < len args - 1)
@@ -26,59 +26,59 @@
;return base
;/
-/; literal_num ({}charp num) [{}charp]
- ;{}charp out = "$"
+/; literal_num ({}uint8 num) [{}uint8]
+ ;{}uint8 out = "$"
;add_strings(~out, ~num)
;return out
;/
-/; add_asm ({}charp from, to) [{}charp]
+/; add_asm ({}uint8 from, to) [{}uint8]
;return construct_statement("\tadd ", {from, to})
;/
-/; sub_asm({}charp from, to) [{}charp]
+/; sub_asm({}uint8 from, to) [{}uint8]
;return construct_statement("\tsub ", {from, to})
;/
-/; push_asm ({}charp reg) [{}charp]
+/; push_asm ({}uint8 reg) [{}uint8]
;return construct_statement("\tpush ", {reg})
;/
-/; pop_asm ({}charp reg) [{}charp]
+/; pop_asm ({}uint8 reg) [{}uint8]
;return construct_statement("\tpop ", {reg})
;/
-/; cmp_asm ({}charp a, b) [{}charp]
+/; cmp_asm ({}uint8 a, b) [{}uint8]
;return construct_statement("\tcmp ", {a, b})
;/
-/; mov_asm ({}charp a, b) [{}charp]
+/; mov_asm ({}uint8 a, b) [{}uint8]
;return construct_statement("\tmov ", {a, b})
;/
-/; jmp_asm ({}charp pos) [{}charp]
+/; jmp_asm ({}uint8 pos) [{}uint8]
;return construct_statement("\tjmp ", {pos})
;/
-/; call_asm ({}charp pos) [{}charp]
+/; call_asm ({}uint8 pos) [{}uint8]
;return construct_statement("\tcall ", {pos})
;/
-/; cjmp_asm ({}charp suffix, pos) [{}charp]
- ;{}charp p = "\tj"
+/; cjmp_asm ({}uint8 suffix, pos) [{}uint8]
+ ;{}uint8 p = "\tj"
;add_strings(~p, ~suffix)
;p.append(' ')
;return construct_statement(p, {pos})
;/
-/; mem_offset ({}charp pos, offset, scale) [{}charp]
- ;{}charp tmp = construct_statement("(", {pos, offset, scale})
+/; mem_offset ({}uint8 pos, offset, scale) [{}uint8]
+ ;{}uint8 tmp = construct_statement("(", {pos, offset, scale})
;tmp{len tmp - 1} = ')'
;return tmp
;/
-/; header_guard (~{}charp csec) [{}charp]
- ;{}charp out = "", tmp = ""
+/; header_guard (~{}uint8 csec) [{}uint8]
+ ;{}uint8 out = "", tmp = ""
;tmp = push_asm("%r8")
;add_strings(~out, ~tmp)
;tmp = push_asm("%r9")
@@ -98,8 +98,8 @@
;add_strings(csec, ~out)
;/
-/; tail_guard (~{}charp csec) [{}charp]
- ;{}charp out = "", tmp = ""
+/; tail_guard (~{}uint8 csec) [{}uint8]
+ ;{}uint8 out = "", tmp = ""
;tmp = pop_asm("%r15")
;add_strings(~out, ~tmp)
;tmp = pop_asm("%r14")
@@ -119,7 +119,7 @@
;add_strings(csec, ~out)
;/
-/; is_common_reg ({}charp n) [bool]
+/; is_common_reg ({}uint8 n) [bool]
;return string_equate(n, "ax") || string_equate(n, "bx") || string_equate(n, "cx") || string_equate(n, "dx")
|| string_equate(n, "sp") || string_equate(n, "bp") || string_equate(n, "si") || string_equate(n, "di")
|| string_equate(n, "8") || string_equate(n, "9") || string_equate(n, "10") || string_equate(n, "11")
@@ -137,8 +137,8 @@
# - di
# - 8-15
#/
-/; get_reg (uint size, {}charp common) [{}charp]
- ;{}charp out = "%"
+/; get_reg (uint size, {}uint8 common) [{}uint8]
+ ;{}uint8 out = "%"
/; if (string_equate(common, "ax") || string_equate(common, "bx") || string_equate(common, "cx") || string_equate(common, "dx"))
@@ -166,7 +166,7 @@
;; else
- ;{}charp out = "r"
+ ;{}uint8 out = "r"
;add_strings(~out, ~common)
/; if (size == 1)
;out.append('b')
@@ -181,7 +181,7 @@
;return out
;/
-/; make_label ({}charp func_name, func_place, ~{}charp csec)
+/; make_label ({}uint8 func_name, func_place, ~{}uint8 csec)
;func_name.append("_")
;add_strings(~func_name, ~func_place)
;func_name.append(':')
diff --git a/tnslc/compile/value.tnsl b/tnslc/compile/value.tnsl
new file mode 100644
index 0000000..701d4b9
--- /dev/null
+++ b/tnslc/compile/value.tnsl
@@ -0,0 +1,148 @@
+;struct Value {
+ bool
+ on_stack,
+ temp,
+ literal,
+
+ int
+ loc,
+ val,
+
+ VType
+ _type
+}
+
+;Value NV = {false, false, false, 0, 0, 0, {0, 0, "null", {}, {}}}
+
+/; setup_stack_offset (int offset) [{}uint8]
+ ;{}uint8 out = "$"
+ ;{}uint8 tmp = string_from_int(offset)
+ ;add_strings(~out, ~tmp)
+ ;return mov_asm(out, "%rax")
+;/
+
+;{}charp general_stack_offset = "(%rsp, %rax, 1)"
+
+
+# The temp registers in order
+/; reg_by_num(int r) [{}uint8]
+ /; if (r == 0)
+ ;return "ax"
+ ;; if (r == 1)
+ ;return "bx"
+ ;; if (r == 2)
+ ;return "cx"
+ ;; if (r == 3)
+ ;return "dx"
+ ;; if (r == 4)
+ ;return "si"
+ ;; if (r == 5)
+ ;return "di"
+ ;; if (r == 6)
+ ;return "bp"
+ ;/
+ ;return string_from_int(r)
+;/
+
+
+/; method Value
+
+ /; get_norm_loc [{}uint8]
+ /; if (self.on_stack)
+ ;return general_stack_offset
+ ;/
+
+ /; if (self.temp)
+ ;return get_reg(self._type._size, reg_by_num(self.loc))
+ ;; else
+ ;return get_reg(self._type._size, reg_by_num(self.loc + 8))
+ ;/
+
+ ;return ""
+ ;/
+
+ /; add_literal (int i) [{}uint8]
+ /; if (self.literal)
+ ;self.val = self.val + i
+ ;return ""
+ ;; else if (!self.on_stack)
+ ;{}uint8 reg = self.get_norm_loc()
+ ;{}uint8 out = "\tadd $"
+ ;{}uint8 tmp = string_from_int(i)
+ ;add_strings(~out, ~tmp)
+ ;out.append(',')
+ ;out.append(' ')
+ ;add_strings(~out, ~reg)
+ ;return out
+ ;/
+
+ ;/
+
+ /; add_value (Value v) [{}uint8]
+ /; if (self.literal)
+ ;self.val = self.val + v.val
+ ;return ""
+ ;; else if (!self.on_stack)
+ ;{}uint8 tmp = self.get_norm_loc()
+ ;{}uint8 out = "\tadd "
+ ;add_strings(~out, ~tmp)
+ ;out.append(',')
+ ;out.append(' ')
+ ;tmp = v.get_norm_loc()
+ ;add_strings(~out, ~tmp)
+ ;return out
+ ;/
+ ;/
+
+ /; sub_value (Value v) [{}uint8]
+ /; if (self.literal)
+ ;self.val = self.val - v.val
+ ;return ""
+ ;/
+ ;/
+
+ /; mul_literal (int i) [{}uint8]
+ /; if (self.literal)
+ ;return ""
+ ;/
+ ;/
+
+ /; div_literal (int i) [{}uint8]
+
+ ;/
+
+ /; mul_value (Value v) [{}uint8]
+
+ ;/
+
+ /; div_value (int i) [{}uint8]
+
+ ;/
+
+ /; deref_value [Value]
+ /; if (self._type.ptr == 0)
+
+ ;/
+ ;/
+
+ /; arr_value (int i) [Value]
+ /; if (self._type.ptr == 0)
+
+ ;/
+ ;/
+
+ /; copy_from_value (Value v)
+
+ ;/
+
+ /; get_member_value ({}uint8 name) [Value]
+ ;Value out = self
+ ;/
+
+ /; update_loc(int offset)
+ /; if (self.on_stack)
+ ;self.loc = self.loc + offset
+ ;/
+ ;/
+
+;/ \ No newline at end of file
diff --git a/tnslc/copy.tnsl b/tnslc/copy.tnsl
index 953a7c8..0cc594e 100644
--- a/tnslc/copy.tnsl
+++ b/tnslc/copy.tnsl
@@ -7,7 +7,7 @@
Seems to work.
#/
-/; main ({}{}charp args) [int]
+/; main ({}{}uint8 args) [int]
/; if (len args < 2)
;tnsl.io.println("Usage: copy [file to copy] [path to copy to]")
;return 1
diff --git a/tnslc/parse/parse.tnsl b/tnslc/parse/parse.tnsl
index 5fb1a18..8919c3a 100644
--- a/tnslc/parse/parse.tnsl
+++ b/tnslc/parse/parse.tnsl
@@ -19,7 +19,7 @@
:include "parse/tokenizer.tnsl"
;/
-/; create_panic ({}charp err)
+/; create_panic ({}uint8 err)
;tnsl.io.println("ABOUT TO INDUCE PANIC... STAND BY")
;tnsl.io.print("Error code given: ")
;tnsl.io.println(err)
@@ -47,7 +47,7 @@
line,
col,
- ~{}charp
+ ~{}uint8
data
}
@@ -69,7 +69,7 @@
;delete self.data
;/
- /; add_char (~{}charp part)
+ /; add_char (~{}uint8 part)
# ;uint l = len self.data`
# ;realloc self.data, l + len part
/; loop (int i = 0; i < len part`) [i++]
diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl
index c2c3d89..fecc7f7 100644
--- a/tnslc/parse/token.tnsl
+++ b/tnslc/parse/token.tnsl
@@ -19,7 +19,7 @@
helper funcs for checking their token types.
#/
-;{}{}charp PREWORDS = {
+;{}{}uint8 PREWORDS = {
"include",
"define",
"extern",
@@ -32,7 +32,7 @@
"abi"
}
-;{}{}charp KEYTYPES = {
+;{}{}uint8 KEYTYPES = {
"int8",
"int16",
"int32",
@@ -54,7 +54,7 @@
"type"
}
-;{}{}charp KEYWORDS = {
+;{}{}uint8 KEYWORDS = {
"struct",
"interface",
"enum",
@@ -96,7 +96,7 @@
"export"
}
-;{}{}charp LITERALS = {
+;{}{}uint8 LITERALS = {
"true",
"false",
@@ -106,14 +106,14 @@
"super"
}
-;{}charp RESERVED = "`~!#%^&*()-=+[]{}|;:,.<>/"
+;{}uint8 RESERVED = "`~!#%^&*()-=+[]{}|;:,.<>/"
-;{}charp DELIMITS = "()[]{}"
-;{}charp LINESEPS = ";:#"
-;{}charp INLNSEPS = ","
-;{}charp AUGMENTS = "~`.&|^><!+-*/%"
+;{}uint8 DELIMITS = "()[]{}"
+;{}uint8 LINESEPS = ";:#"
+;{}uint8 INLNSEPS = ","
+;{}uint8 AUGMENTS = "~`.&|^><!+-*/%"
-;{}{}charp MDELIMITS = {
+;{}{}uint8 MDELIMITS = {
# Code block
"/;",
";/",
@@ -135,7 +135,7 @@
"#:"
}
-;{}{}charp MAUGMENTS = {
+;{}{}uint8 MAUGMENTS = {
# Boolean
"==",
"&&",
@@ -183,7 +183,7 @@
/##
Checks if the character point p is in the string cmp
-#; is_in_string (~{}charp cmp, charp p) [bool]
+#; is_in_string (~{}uint8 cmp, uint8 p) [bool]
/; loop (int i = 0; i < len cmp`) [i++]
/; if (p == cmp`{i})
@@ -197,7 +197,7 @@
/##
Checks if the string s is in the list cmp
-#; is_in_string_list (~{}{}charp cmp, ~{}charp s) [bool]
+#; is_in_string_list (~{}{}uint8 cmp, ~{}uint8 s) [bool]
/; loop (int i = 0; i < len cmp`) [i++]
@@ -218,7 +218,7 @@
;return false
;/
-/; is_numeric_literal(~{}charp dat) [bool]
+/; is_numeric_literal(~{}uint8 dat) [bool]
/; if (len dat` == 0)
;return false
;/
@@ -250,19 +250,19 @@
;return true
;/
-/; is_text_literal(~{}charp dat) [bool]
+/; is_text_literal(~{}uint8 dat) [bool]
/; if (len dat` < 1)
;return false
;/
;return dat`{0} == '"' || dat`{0} == '\''
;/
-/; string_closed ({}charp dat, charp c) [bool]
+/; string_closed ({}uint8 dat, uint8 c) [bool]
/; if (len dat < 2)
;return false
;/
- ;charp closing = dat{0}
+ ;uint8 closing = dat{0}
;bool escaping = false
/; loop (int i = 1; i < len dat) [i++]
@@ -281,7 +281,7 @@
/#
Get the token_type value for a given string of character points
-#; get_token_type (~{}charp s) [int]
+#; get_token_type (~{}uint8 s) [int]
/; if (len s` > 1)
diff --git a/tnslc/paths.tnsl b/tnslc/paths.tnsl
index 1a97f08..17719a0 100644
--- a/tnslc/paths.tnsl
+++ b/tnslc/paths.tnsl
@@ -1,12 +1,12 @@
# Requires util.tnsl
;struct Path {
- {}{}charp dirs,
- {}charp file
+ {}{}uint8 dirs,
+ {}uint8 file
}
/; method Path
- /; rel_file ({}charp rpath) [Path]
- ;{}{}charp spl = split(rpath, '/')
+ /; rel_file ({}uint8 rpath) [Path]
+ ;{}{}uint8 spl = split(rpath, '/')
;Path out = {{}, ""}
/; loop (int i = 0; i < len (self.dirs)) [i++]
@@ -21,8 +21,8 @@
;return out
;/
- /; full_path [{}charp]
- ;{}charp out = join((self.dirs), '/')
+ /; full_path [{}uint8]
+ ;{}uint8 out = join((self.dirs), '/')
/; if (len (self.dirs) > 0)
;out.append('/')
;/
@@ -38,8 +38,8 @@
;return tnsl.io.readFile(self.full_path())
;/
- /; extension_is ({}charp chk) [bool]
- ;{}charp ext = ""
+ /; extension_is ({}uint8 chk) [bool]
+ ;{}uint8 ext = ""
;int dot = -1
/; loop (int i = len (self.file) - 1; i > 0) [i = i - 1]
/; if (self.file{i} == '.')
@@ -60,14 +60,14 @@
;/
-/; split({}charp str, charp c) [{}{}charp]
- ;{}{}charp out = {}
- ;{}charp tmp = ""
+/; split({}uint8 str, uint8 c) [{}{}uint8]
+ ;{}{}uint8 out = {}
+ ;{}uint8 tmp = ""
/; loop (int i = 0; i < len str) [i++]
/; if (str{i} == c)
;out.append(tmp)
- ;{}charp tmp = ""
+ ;{}uint8 tmp = ""
;true # work around for interpreter bug
;; else
;tmp.append(str{i})
@@ -78,8 +78,8 @@
;return out
;/
-/; join ({}{}charp s, charp jc) [{}charp]
- ;{}charp out = ""
+/; join ({}{}uint8 s, uint8 jc) [{}uint8]
+ ;{}uint8 out = ""
/; loop (int i = 0; i < len s) [i++]
/; loop (int j = 0; j < len s{i}) [j++]
;out.append(s{i}{j})
@@ -92,8 +92,8 @@
;return out
;/
-/; path_from_str ({}charp f) [Path]
- ;{}{}charp spl = split(f, '/')
+/; path_from_str ({}uint8 f) [Path]
+ ;{}{}uint8 spl = split(f, '/')
;Path out = {{}, ""}
/; loop (int i = 0; i < len spl - 1) [i++]
;out.dirs.append(spl{i})
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 8c2e18d..7ca1dfb 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -21,15 +21,16 @@
:include "parse/parse.tnsl"
:include "compile/compile.tnsl"
:include "compile/isa_x86.tnsl"
+ :include "compile/value.tnsl"
;/
-/; main ({}{}charp args) [int]
+/; main ({}{}uint8 args) [int]
/; if (len args < 1)
;tnsl.io.println("Usage: tnslc [file in]")
;return 1
;/
- ;{}charp file = args{0}
+ ;{}uint8 file = args{0}
# ;tnslc.Node tree_node = tnslc.ast.make_tree(psrc, args{0})
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl
index 3badb8b..156cbb4 100644
--- a/tnslc/util.tnsl
+++ b/tnslc/util.tnsl
@@ -18,7 +18,7 @@
Utility functions that may be useful in many places.
#/
-/; string_equate({}charp s1, s2) [bool]
+/; string_equate({}uint8 s1, s2) [bool]
/; if (len s1 !== len s2)
;return false
;/
@@ -32,14 +32,14 @@
;return true
;/
-/; add_strings (~{}charp a, b)
+/; add_strings (~{}uint8 a, b)
/; loop (int i = 0; i < len b`) [i++]
;a`.append(b`{i})
;/
;/
-/; reverse_string({}charp str) [{}charp]
- ;{}charp out = ""
+/; reverse_string({}uint8 str) [{}uint8]
+ ;{}uint8 out = ""
/; loop (int i = len str; i > 0) [i = i - 1]
;out.append(str{i - 1})
@@ -48,27 +48,27 @@
;return out
;/
-/; is_whitespace (charp c) [bool]
+/; is_whitespace (uint8 c) [bool]
;return c == '\t' || c == '\n' || c == ' '
;/
-/; is_digit (charp c) [bool]
+/; is_digit (uint8 c) [bool]
;return c !< '0' && c !> '9'
;/
-/; is_alpha (charp c) [bool]
+/; is_alpha (uint8 c) [bool]
;bool low = c !< 'A' && c !> 'Z', high = c !< 'a' && c >! 'z'
;return low || high
;/
-/; digit_to_char(int i) [charp]
- ;charp out = '0'
+/; digit_to_char(int i) [uint8]
+ ;uint8 out = '0'
;out = out + (i % 10)
;return out
;/
-/; string_from_int(int i) [{}charp]
- ;{}charp c = ""
+/; string_from_int(int i) [{}uint8]
+ ;{}uint8 c = ""
/; if (i < 0)
;c = "-"
@@ -85,7 +85,7 @@
;return reverse_string(c)
;/
-/; int_from_string ({}charp str) [int]
+/; int_from_string ({}uint8 str) [int]
;bool inv = str{0} == '-'
;int out = 0
@@ -100,7 +100,7 @@
;return out
;/
-/; get_escape_code (charp c) [charp]
+/; get_escape_code (uint8 c) [uint8]
/; if (c == '\'')
;return '\''
;; else if (c == '"')
@@ -126,12 +126,12 @@
;return 0
;/
-/; parse_hex_code ({}charp c) [charp]
- ;charp out = 0
+/; parse_hex_code ({}uint8 c) [uint8]
+ ;uint8 out = 0
/; loop (int i = 0; i < len c) [i++]
;out = out * 16
- ;charp tmp = c{i}
+ ;uint8 tmp = c{i}
/; if (tmp !< 'a')
;tmp = tmp - 'a' + 'A'
;/
@@ -148,10 +148,10 @@
;return out
;/
-/; unquote_char ({}charp c) [charp]
+/; unquote_char ({}uint8 c) [uint8]
/; if (c{1} == '\\')
/; if (c{2} == 'x')
- ;{}charp d = {c{3}, c{4}}
+ ;{}uint8 d = {c{3}, c{4}}
;return parse_hex_code(d)
;/
;return get_escape_code(c{2})
@@ -160,9 +160,9 @@
;return c{1}
;/
-/; unquote_string ({}charp str) [{}charp]
- ;{}charp out = ""
- ;{}charp unc = "'"
+/; unquote_string ({}uint8 str) [{}uint8]
+ ;{}uint8 out = ""
+ ;{}uint8 unc = "'"
/; loop (int i = 1; i < len str - 1) [i++]
/; if (str{i} == '\\')