summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc')
-rwxr-xr-xtnslc/build.sh11
-rw-r--r--tnslc/compile/codegen.tnsl30
-rw-r--r--tnslc/compile/compbuf.tnsl6
-rw-r--r--tnslc/compile/function.tnsl3
-rw-r--r--tnslc/compile/module.tnsl272
-rw-r--r--tnslc/compile/struct.tnsl174
-rw-r--r--tnslc/compile/var.tnsl380
-rw-r--r--tnslc/parse/ast.tnsl2
-rw-r--r--tnslc/test.tnsl15
9 files changed, 602 insertions, 291 deletions
diff --git a/tnslc/build.sh b/tnslc/build.sh
index 537c7cc..d66742f 100755
--- a/tnslc/build.sh
+++ b/tnslc/build.sh
@@ -7,7 +7,18 @@ mkdir -p $BUILD_DIR
mkdir -p $ARTIFACT_DIR
filename=$1
filename="${filename%.*}"
+
./ctc $filename.tnsl $ARTIFACT_DIR/$filename.asm
+
+if [ $? -ne 0 ]; then
+ exit $?
+fi
+
nasm -g -f elf64 -o $ARTIFACT_DIR/$filename.o $ARTIFACT_DIR/$filename.asm
+
+if [ $? -ne 0 ]; then
+ exit $?
+fi
+
gcc -ggdb -o $BUILD_DIR/$filename $ARTIFACT_DIR/$filename.o
diff --git a/tnslc/compile/codegen.tnsl b/tnslc/compile/codegen.tnsl
index caaafb7..ccb6b06 100644
--- a/tnslc/compile/codegen.tnsl
+++ b/tnslc/compile/codegen.tnsl
@@ -1,8 +1,30 @@
/; generate (~utils.File fin, fout)
- parse.Node ast = parse.generate_ast(fin)
- ast.update_children()
- parse.print_ast(~ast)
- ast.end()
+ # Parse files into AST
+ parse.Node ast = parse.generate_ast(fin)
+ ast.update_children()
+ parse.print_ast(~ast)
+
+ # Create output buffer
+ CompBuf buffer
+ buffer.init()
+
+ # Transform into a module tree
+ # Module mod
+ # mod.init(~ast)
+ # mod.update_children()
+
+ # Compile code
+ # mod.compile(~buffer)
+
+ # Write assembly to output file
+ # fout.create()
+ # buffer.write_to(fout)
+ # fout.close()
+
+ # Free all structs
+ # mod.end()
+ buffer.end()
+ ast.end()
;/
diff --git a/tnslc/compile/compbuf.tnsl b/tnslc/compile/compbuf.tnsl
index b4ce261..d4bc640 100644
--- a/tnslc/compile/compbuf.tnsl
+++ b/tnslc/compile/compbuf.tnsl
@@ -26,13 +26,13 @@ struct CompBuf {
;/
/; write_to(~utils.File fout)
- fout`.write_cstr("BITS 64\0\n")
+ fout`.write_cstr("BITS 64\n\0")
fout`.write_cstr(self.sec_head.as_cstr())
- fout`.write_cstr("\nsection .data\0\n\n")
+ fout`.write_cstr("\nsection .data\n\n\0")
fout`.write_cstr(self.sec_data.as_cstr())
- fout`.write_cstr("\nsection .text\0\n\n")
+ fout`.write_cstr("\nsection .text\n\n\0")
fout`.write_cstr(self.sec_code.as_cstr())
;/
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl
index cf42db1..937e668 100644
--- a/tnslc/compile/function.tnsl
+++ b/tnslc/compile/function.tnsl
@@ -15,6 +15,9 @@ struct Function {
self.outputs.init(len v)
;/
+ /; _compile (~Module parent, ~CompBuf cb)
+ ;/
+
/; end
_delete(self.name)
self.body`.end()
diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl
index 6d1d24a..fd44b07 100644
--- a/tnslc/compile/module.tnsl
+++ b/tnslc/compile/module.tnsl
@@ -1,71 +1,239 @@
+int SEARCH_VAR = 0
+int SEARCH_STRUCT = 1
+int SEARCH_FUNC = 2
+int SEARCH_SUB = 3
+
struct Module {
- # Text name of module
- ~uint8 name,
+ # Text name of module
+ ~uint8 name,
+
+ # Various contained elements
+ utils.Vector
+ vars,
+ structs,
+ funcs,
+ subs,
- # Various contained elements
- utils.Vector
- vars,
- structs,
- funcs,
- subs,
+ # Whether we export or not
+ bool e,
- # Whether we export or not
- bool e
+ # Parent module
+ ~Module parent
}
/; method Module
-
- /; init (~uint8 name, bool exp)
- Var v
- Struct s
- Function f
- Module m
- self.vars.init(len v)
- self.structs.init(len s)
- self.funcs.init(len f)
- self.subs.init(len m)
+ /; init (~parse.Node mod)
+ Var v
+ Struct s
+ Function f
+ Module m
+
+ self.vars.init(len v)
+ self.structs.init(len s)
+ self.funcs.init(len f)
+ self.subs.init(len m)
+
+ self.name = utils.strcpy(mod`.data)
+ self.e = mod`._type == parse.NTYPE_EXPORT
+
+ self._from_tree(mod)
+
+ ~Module sub
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ sub = self.subs.get(i)
+ sub`.update_children()
+ ;/
+ ;/
+
+ /; update_children
+ ~Module sub
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ sub = self.subs.get(i)
+ sub`.parent = ~self
+ ;/
+ ;/
+
+ /; _from_tree (~parse.Node mod)
+ ~parse.Node sub
+ /; loop (int i = 0; i < mod`.sub.count) [i++]
+ sub = mod`.sub.get(i)
+
+ # TODO: Vars, Enums, Method blocks
+
+ /; if (sub`._type == parse.NTYPE_MOD || sub`._type == parse.NTYPE_EXPORT)
+ Module m
+ m.init(sub)
+ self.subs.push(~m)
+ ;; else if (sub`._type == parse.NTYPE_STRUCT)
+ Struct s
+ s.init(sub)
+ self.structs.push(~s)
+ ;; else if (sub`._type == parse.NTYPE_FUNCTION)
+ Function f
+ f.init(sub)
+ self.funcs.push(~f)
+ ;/
+ ;/
+ ;/
+
+ /; compile (~CompBuf cb)
+ # First, since all the types are in place, we need to size all of them.
+ self._size_structs()
+
+ # Finally, write all functions to the code section
+ self._compile(cb)
+ ;/
+
+ /; _size_structs
+ ~Struct s
+ /; loop (int i = 0; i < self.structs.count) [i++]
+ s = self.structs.get(i)
+ /; if (s`.size == 0)
+ s`._compute_size(~self)
+ ;/
+ ;/
+
+ ~Module m
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ m = self.subs.get(i)
+ m`._size_structs()
+ ;/
+ ;/
+
+ /; _compile (~CompBuf cb)
+ ~Function f
+ /; loop (int i = 0; i < self.funcs.count) [i++]
+ f = self.funcs.get(i)
+ f`._compile(~self, cb)
+ ;/
+
+ ~Module m
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ m = self.subs.get(i)
+ m`._compile(cb)
+ ;/
+ ;/
+
+ #
+ # Functions to search sub-modules
+ #
+
+ /; find (int stype, ~utils.Vector key) [~void]
+ return self._find(stype, key, 0)
+ ;/
+
+ /; _find (int stype, ~utils.Vector key, int lvl) [~void]
+
+ /; if ((lvl + 1) < key`.count)
+ ~Module m
+ ~uint8 str = key`.get(lvl)
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ m = self.subs.get(i)
+ /; if (utils.strcmp(str, m`.name) == true)
+ ~void v = m._find(stype, key, lvl + 1)
+ /; if (v != NULL)
+ return v
+ ;/
+ return NULL
+ ;/
+ ;/
+ ;; else
+ ~uint8 str = key`.get(key`.count - 1)
+ /; if (stype == SEARCH_VAR)
+ return _find_var(str)
+ ;; else if (stype == SEARCH_STRUCT)
+ return _find_struct(str)
+ ;; else if (stype == SEARCH_FUNC)
+ return _find_func(str)
+ ;; else if (stype == SEARCH_SUB)
+ return _find_sub(str)
+ ;/
+ ;/
+
+ /; if (lvl == 0 && self.parent !== NULL)
+ return self.parent._find(stype, key, 0)
+ ;/
- self.name = name
- self.e = exp
- ;/
+ return NULL
+ ;/
- /; from_tree (~parse.Node root)
- ;/
+ /; _find_var (~uint8 name) [~void]
+ ~Var v
+ /; loop (int i = 0; i < self.vars.count) [i++]
+ v = self.vars.get(i)
+ /; if (utils.strcmp(name, v`.name) == true)
+ return v
+ ;/
+ ;/
+ return NULL
+ ;/
- /; end
- _delete(self.name)
+ /; _find_struct (~uint8 name) [~void]
+ ~Struct s
+ /; loop (int i = 0; i < self.structs.count) [i++]
+ s = self.structs.get(i)
+ /; if (utils.strcmp(name, s`.name) == true)
+ return s
+ ;/
+ ;/
+ return NULL
+ ;/
+
+ /; _find_func (~uint8 name) [~void]
+ ~Function f
+ /; loop (int i = 0; i < self.funcs.count) [i++]
+ f = self.funcs.get(i)
+ /; if (utils.strcmp(name, f`.name) == true)
+ return f
+ ;/
+ ;/
+ return NULL
+ ;/
+
+ /; _find_sub (~uint8 name) [~void]
+ ~Module m
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ m = self.subs.get(i)
+ /; if (utils.strcmp(name, m`.name) == true)
+ return m
+ ;/
+ ;/
+ return NULL
+ ;/
- ~Var v
- /; loop (int i = 0; i < self.vars.count) [i++]
- v = self.vars.get(i)
- v`.end()
- ;/
- self.vars.end()
+ /; end
+ _delete(self.name)
- ~Struct s
- /; loop (int i = 0; i < self.structs.count) [i++]
- s = self.structs.get(i)
- s`.end()
- ;/
- self.structs.end()
+ ~Var v
+ /; loop (int i = 0; i < self.vars.count) [i++]
+ v = self.vars.get(i)
+ v`.end()
+ ;/
+ self.vars.end()
- ~Function f
- /; loop (int i = 0; i < self.funcs.count) [i++]
- f = self.funcs.get(i)
- f`.end()
- ;/
- self.funcs.end()
+ ~Struct s
+ /; loop (int i = 0; i < self.structs.count) [i++]
+ s = self.structs.get(i)
+ s`.end()
+ ;/
+ self.structs.end()
- ~Module m
- /; loop (int i = 0; i < self.subs.count) [i++]
- m = self.subs.get(i)
- m`.end()
- ;/
- self.subs.end()
+ ~Function f
+ /; loop (int i = 0; i < self.funcs.count) [i++]
+ f = self.funcs.get(i)
+ f`.end()
+ ;/
+ self.funcs.end()
- ;/
+ ~Module m
+ /; loop (int i = 0; i < self.subs.count) [i++]
+ m = self.subs.get(i)
+ m`.end()
+ ;/
+ self.subs.end()
+ ;/
;/
diff --git a/tnslc/compile/struct.tnsl b/tnslc/compile/struct.tnsl
index d175aef..79d3267 100644
--- a/tnslc/compile/struct.tnsl
+++ b/tnslc/compile/struct.tnsl
@@ -3,44 +3,160 @@ struct Struct {
~uint8 name,
~Module methods,
utils.Vector members,
- int size
+ int size,
+
+ ~parse.Node _up
}
+~uint8 PRIMITIVE_1 = "bool,uint8,int8"
+~uint8 PRIMITIVE_2 = "uint16,int16"
+~uint8 PRIMITIVE_4 = "uint32,int32,float32"
+~uint8 PRIMITIVE_8 = "uint64,int64,float64,int,uint,float,void"
+
+/; is_primitive (~parse.Node tn) [int]
+ /; if (tn`.sub.count < 1)
+ return 0
+ ;/
+
+ ~parse.Node n = tn`.sub.get(0)
+
+ # Check for pointer, array
+ /; if (n`._type == parse.NTYPE_PRE_OP)
+ return 8
+ ;/
+
+ # Check for prim type
+ /; if (parse._in_csv(PRIMITIVE_1, n`.data) == true)
+ return 1
+ ;; else if (parse._in_csv(PRIMITIVE_2, n`.data) == true)
+ return 2
+ ;; else if (parse._in_csv(PRIMITIVE_4, n`.data) == true)
+ return 4
+ ;; else if (parse._in_csv(PRIMITIVE_8, n`.data) == true)
+ return 8
+ ;/
+
+ # Check for ref
+ n = tn`.sub.get(tn`.sub.count - 1)
+ /; if (n`._type == parse.NTYPE_POST_OP)
+ return 8
+ ;/
+
+ return 0
+;/
+
/; method Struct
- /; init (~uint8 name)
- self.name = name
- Var v
- self.members.init(len v)
- ;/
+ /; init (~parse.Node node)
+ self._up = node
+ self.size = 0
+ self.methods = NULL
+ self.name = utils.strcpy(node`.data)
+ Var v
+ self.members.init(len v)
+ ;/
+
+ /; add_member(~Var v)
+ self.members.push(v)
+ ;/
+
+ /; get_member(~uint8 name) [~Var]
+ ~Var out = NULL
+
+ ~Var v
+ /; loop (int i = 0; i < self.members.count) [i++]
+ v = self.members.get(i)
+ /; if (utils.strcmp(v`.name, name) == true)
+ return v
+ ;/
+ ;/
+
+ return out
+ ;/
+
+ /; _dlist [~parse.Node]
+ ~parse.Node up = self._up
+ ~parse.Node n
+ /; loop (int i = 0; i < up`.sub.count) [i++]
+ n = up`.sub.get(i)
+ /; if (n`._type == parse.NTYPE_DLIST)
+ return n
+ ;/
+ ;/
+ return NULL
+ ;/
+
+ /; _compute_size (~Module parent)
+ /; if (self.size !== 0)
+ return
+ ;/
+
+ self.size = self.size - 1
- /; add_member(~Var v)
- self.members.push(v)
- ;/
+ int total = 0
+ ~parse.Node up = self._dlist()
+ ~parse.Node n
+ int add_size = 0
+ /; loop (int i = 0; i < up`.sub.count) [i++]
+ n = up`.sub.get(i)
+
+ /; if (n`._type == parse.NTYPE_TYPE)
+ # Check for primitive type
+ add_size = is_primitive(n)
+ /; if (add_size == 0)
+ # Find type, compute size, set add_size to type size
+ ~Struct ft = self._find_type(parent, n)
+ /; if (ft`.size < 0)
+ # Cyclical dependency
+ return
+ ;/
+ add_size = ft`.size
+ ;/
+ ;; else if (n`._type == parse.NTYPE_ID)
+ total = total + add_size
+ ;/
+ ;/
- /; get_member(~uint8 name) [~Var]
- ~Var out = NULL
+ self.size = total
+ ;/
- ~Var v
- /; loop (int i = 0; i < self.members.count) [i++]
- v = self.members.get(i)
- /; if (utils.strcmp(v`.name, name) == true)
- return v
- ;/
- ;/
+ /; _find_type (~Module parent, ~parse.Node tn) [~Struct]
+ # First loop through all the names and create a vector of strings
+ utils.Vector sv
+ sv.init(8)
+ ~void str
+ ~parse.Node n
+ /; loop (int i = 0; i < tn`.sub.count) [i++]
+ n = tn`.sub.get(i)
+ /; if (n`._type == parse.NTYPE_ID)
+ str = n`.data
+ sv.push(~str)
+ ;; else
+ i = tn`.sub.count
+ ;/
+ ;/
- return out
- ;/
+ # Find struct and compute its size
+ ~Struct out = parent.find(SEARCH_STRUCT, ~sv)
+ sv.pop()
+ ~Module outp = parent
+ /; if (sv.count !== 0)
+ outp = parent.find(SEARCH_SUB, ~sv)
+ ;/
+ sv.end()
+ out._compute_size(outp)
+ return out
+ ;/
- /; end
- _delete(self.name)
- ~Var v
- /; loop (int i = 0; i < self.members.count) [i++]
- v = self.members.get(i)
- v`.end()
- ;/
- self.members.end()
- ;/
+ /; end
+ _delete(self.name)
+ ~Var v
+ /; loop (int i = 0; i < self.members.count) [i++]
+ v = self.members.get(i)
+ v`.end()
+ ;/
+ self.members.end()
+ ;/
;/
diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl
index 23da42b..320c3a1 100644
--- a/tnslc/compile/var.tnsl
+++ b/tnslc/compile/var.tnsl
@@ -23,232 +23,232 @@ int PRIM_FLT = 3
# 9-16 are r8, r9, r10, r11, r12, r13, r14, r15
# 17-32 are xmm0, xmm1, xmm2, ..., xmm15
/; reg_string (int r, int size) [~uint8]
- utils.Vector out
- out.init(1)
- uint8 add
-
- /; if (r < 9)
- /; if (size == 4)
- add = 'e'
- out.push(~add)
- ;; else if (size == 8)
- add = 'r'
- out.push(~add)
- ;/
+ utils.Vector out
+ out.init(1)
+ uint8 add
- add = 'a'
- /; if (r < 5)
- add = add + r - 1
- ;; else if (r == 5 || r == 7)
- add = 's'
- ;; else if (r == 6)
- add = 'd'
- ;; else if (r == 8)
- add = 'b'
- ;/
- out.push(~add)
-
- /; if (r == 5 || r == 6)
- add = 'i'
- out.push(~add)
- ;; else if (r == 7 || r == 8)
- add = 'p'
- out.push(~add)
- ;; else if (size !== 1)
- add = 'x'
- out.push(~add)
- ;/
+ /; if (r < 9)
+ /; if (size == 4)
+ add = 'e'
+ out.push(~add)
+ ;; else if (size == 8)
+ add = 'r'
+ out.push(~add)
+ ;/
- /; if (size == 1)
- add = 'l'
- out.push(~add)
- ;/
- ;; else if (r < 17)
- add = 'r'
- out.push(~add)
-
- ~uint8 num = utils.int_to_str(r - 1)
- out.push_cstr(num)
- _delete(num)
- /; if (size == 1)
- add = 'b'
- out.push(~add)
- ;; else if (size == 2)
- add = 'w'
- out.push(~add)
- ;; else if (size == 4)
- add = 'd'
- out.push(~add)
- ;/
- ;; else if (r < 33)
- out.push_cstr("xmm\0")
- ~uint8 num = utils.int_to_str(r - 17)
- out.push_cstr(num)
- _delete(num)
- ;/
-
- return out.as_cstr()
+ add = 'a'
+ /; if (r < 5)
+ add = add + r - 1
+ ;; else if (r == 5 || r == 7)
+ add = 's'
+ ;; else if (r == 6)
+ add = 'd'
+ ;; else if (r == 8)
+ add = 'b'
+ ;/
+ out.push(~add)
+
+ /; if (r == 5 || r == 6)
+ add = 'i'
+ out.push(~add)
+ ;; else if (r == 7 || r == 8)
+ add = 'p'
+ out.push(~add)
+ ;; else if (size !== 1)
+ add = 'x'
+ out.push(~add)
+ ;/
+
+ /; if (size == 1)
+ add = 'l'
+ out.push(~add)
+ ;/
+ ;; else if (r < 17)
+ add = 'r'
+ out.push(~add)
+
+ ~uint8 num = utils.int_to_str(r - 1)
+ out.push_cstr(num)
+ _delete(num)
+ /; if (size == 1)
+ add = 'b'
+ out.push(~add)
+ ;; else if (size == 2)
+ add = 'w'
+ out.push(~add)
+ ;; else if (size == 4)
+ add = 'd'
+ out.push(~add)
+ ;/
+ ;; else if (r < 33)
+ out.push_cstr("xmm\0")
+ ~uint8 num = utils.int_to_str(r - 17)
+ out.push_cstr(num)
+ _delete(num)
+ ;/
+
+ return out.as_cstr()
;/
struct Var {
- ~uint8 name,
- ~Struct _type,
- utils.Vector ptrc,
- int loc
+ ~uint8 name,
+ ~Struct _type,
+ utils.Vector ptrc,
+ int loc
}
/; method Var
- /; init (~uint8 name)
- self.name = name
- self.ptrc.init(4)
- ;/
+ /; init (~uint8 name)
+ self.name = name
+ self.ptrc.init(4)
+ ;/
+
+ /; ptr [int32]
+ ~int32 i
+ i = self.ptrc.get(self.ptrc.count - 1)
+ return i`
+ ;/
- /; ptr [int32]
- ~int32 i
- i = self.ptrc.get(self.ptrc.count - 1)
- return i`
- ;/
+ /; ptr_push (int32 p)
+ self.ptrc.push(~p)
+ ;/
- /; ptr_push (int32 p)
- self.ptrc.push(~p)
- ;/
+ /; ptr_pop
+ self.ptrc.pop()
+ ;/
- /; ptr_pop
- self.ptrc.pop()
- ;/
+ /; is_primitive [int]
+ ~uint8 tn = self`._type`.name
- /; is_primitive [int]
- ~uint8 tn = self`._type`.name
+ /; if (parse._in_csv(PRIM_CSV_BOO, tn) == true)
+ return PRIM_BOO
+ ;; else if (parse._in_csv(PRIM_CSV_INT, tn) == true)
+ return PRIM_INT
+ ;; else if (parse._in_csv(PRIM_CSV_FLT, tn) == true)
+ return PRIM_FLT
+ ;/
- /; if (parse._in_csv(PRIM_CSV_BOO, tn) == true)
- return PRIM_BOO
- ;; else if (parse._in_csv(PRIM_CSV_INT, tn) == true)
- return PRIM_INT
- ;; else if (parse._in_csv(PRIM_CSV_FLT, tn) == true)
- return PRIM_FLT
- ;/
+ return PRIM_NON
+ ;/
- return PRIM_NON
- ;/
+ /; end
+ _delete(self.name)
+ self.ptrc.end()
+ ;/
- /; end
- _delete(self.name)
- self.ptrc.end()
- ;/
+ ###################################
+ # Variable manipulation functions #
+ ###################################
- ###################################
- # Variable manipulation functions #
- ###################################
+ # Generate a string which represents where the variable is in memory,
+ # this string may be used to set the value of the variable with operations like "mov"
+ # if "maybe_mem" is true, this might be an address like "[rsi]"
+ /; gen_to (bool maybe_mem) [~uint8]
+ utils.Vector out
+ out.init(1)
+ return out.as_cstr()
+ ;/
- # Generate a string which represents where the variable is in memory,
- # this string may be used to set the value of the variable with operations like "mov"
- # if "maybe_mem" is true, this might be an address like "[rsi]"
- /; gen_to (bool maybe_mem) [~uint8]
- utils.Vector out
- out.init(1)
- return out.as_cstr()
- ;/
+ # Generate a string which represents where the variable is in memory,
+ # this string may be used to read the value of the variable with operations like "mov"
+ # if "maybe_mem" is true, this might be an address like "[rsi]"
+ /; gen_from (bool maybe_mem) [~uint8]
+ utils.Vector out
+ out.init(1)
+ return out.as_cstr()
+ ;/
- # Generate a string which represents where the variable is in memory,
- # this string may be used to read the value of the variable with operations like "mov"
- # if "maybe_mem" is true, this might be an address like "[rsi]"
- /; gen_from (bool maybe_mem) [~uint8]
- utils.Vector out
- out.init(1)
- return out.as_cstr()
- ;/
+ # Returns true if the variable is stored in memory
+ /; in_mem [bool]
+ /; if (self.loc !> 0)
+ return true
+ ;/
+ return false
+ ;/
- # Returns true if the variable is stored in memory
- /; in_mem [bool]
- /; if (self.loc !> 0)
- return true
- ;/
- return false
- ;/
+ # Set this variable to the value of a literal
+ /; set_literal (~CompBuf buf, ~Var other)
+ ;/
- # Set this variable to the value of a literal
- /; set_literal (~CompBuf buf, ~Var other)
- ;/
+ # Set this Variable to the value of other
+ /; set (~CompBuf buf, ~Var other)
+ ;/
- # Set this Variable to the value of other
- /; set (~CompBuf buf, ~Var other)
- ;/
+ /; standard_op (~CompBuf buf, ~Var other, ~uint8 op_str)
+ ~uint8 from_str
+ ~uint8 to_str = self.gen_to(true)
- /; standard_op (~CompBuf buf, ~Var other, ~uint8 op_str)
- ~uint8 from_str
- ~uint8 to_str = self.gen_to(true)
+ /; if (self.in_mem())
+ from_str = other`.gen_from(false)
+ ;; else
+ from_str = other`.gen_from(true)
+ ;/
- /; if (self.in_mem())
- from_str = other`.gen_from(false)
- ;; else
- from_str = other`.gen_from(true)
- ;/
+ buf`.add_c(op_str)
+ buf`.add_c(" \0")
+ buf`.add_c(to_str)
+ buf`.add_c(", \0")
+ buf`.add_c(from_str)
+ buf`.add_c("\n\0")
- buf`.add_c(op_str)
- buf`.add_c(" \0")
- buf`.add_c(to_str)
- buf`.add_c(", \0")
- buf`.add_c(from_str)
- buf`.add_c("\n\0")
+ _delete(from_str)
+ _delete(to_str)
+ ;/
- _delete(from_str)
- _delete(to_str)
- ;/
+ /; product_op (~CompBuf buf, ~Var other, ~uint8 op_str, int read_reg)
- /; product_op (~CompBuf buf, ~Var other, ~uint8 op_str, int read_reg)
-
- ;/
+ ;/
- /; add (~CompBuf buf, ~Var other)
- /; if (self.loc = VLOC_LITL)
- ;/
- self.standard_op("add")
- ;/
+ /; add (~CompBuf buf, ~Var other)
+ /; if (self.loc = VLOC_LITL)
+ ;/
+ self.standard_op(buf, other, "add")
+ ;/
- /; sub (~CompBuf buf, ~Var other)
- self.standard_op("sub")
- ;/
+ /; sub (~CompBuf buf, ~Var other)
+ self.standard_op(buf, other, "sub")
+ ;/
- /; mul (~CompBuf buf, ~Var other)
- self.product_op(buf, other, "imul", 1)
- ;/
+ /; mul (~CompBuf buf, ~Var other)
+ self.product_op(buf, other, "imul", 1)
+ ;/
- /; div (~CompBuf buf, ~Var other)
- /; if ("signed")
- self.product_op(buf, other, "idiv", 1)
- ;; else
- self.product_op(buf, other, "div", 1)
- ;/
- ;/
+ /; div (~CompBuf buf, ~Var other)
+ /; if ("signed")
+ self.product_op(buf, other, "idiv", 1)
+ ;; else
+ self.product_op(buf, other, "div", 1)
+ ;/
+ ;/
- /; mod (~CompBuf buf, ~Var other)
- /; if ("signed")
- self.product_op(buf, other, "idiv", 4)
- ;; else
- self.product_op(buf, other, "div", 4)
- ;/
- ;/
+ /; mod (~CompBuf buf, ~Var other)
+ /; if ("signed")
+ self.product_op(buf, other, "idiv", 4)
+ ;; else
+ self.product_op(buf, other, "div", 4)
+ ;/
+ ;/
- /; and (~CompBuf buf, ~Var other)
- self.standard_op("and")
- ;/
+ /; and (~CompBuf buf, ~Var other)
+ self.standard_op(buf, other, "and")
+ ;/
- /; or (~CompBuf buf, ~Var other)
- self.standard_op("or")
- ;/
+ /; or (~CompBuf buf, ~Var other)
+ self.standard_op(buf, other, "or")
+ ;/
- /; xor (~CompBuf buf, ~Var other)
- self.standard_op("xor")
- ;/
+ /; xor (~CompBuf buf, ~Var other)
+ self.standard_op(buf, other, "xor")
+ ;/
- /; not (~CompBuf buf, ~Var other)
- self.standard_op("xor")
- ;/
+ /; not (~CompBuf buf, ~Var other)
+ self.standard_op(buf, other, "xor")
+ ;/
- /; member (~CompBuf buf, ~uint8 name) [Var]
- Var out
- return out
- ;/
+ /; member (~CompBuf buf, ~uint8 name) [Var]
+ Var out
+ return out
+ ;/
;/
diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl
index b12e75e..e38c413 100644
--- a/tnslc/parse/ast.tnsl
+++ b/tnslc/parse/ast.tnsl
@@ -2115,7 +2115,7 @@ int errors_shown = 0
utils.Vector v
v.init(1)
- out.init(NTYPE_MODULE, v.as_cstr())
+ out.init(NTYPE_EXPORT, v.as_cstr())
_ast_file(fin, ~out)
diff --git a/tnslc/test.tnsl b/tnslc/test.tnsl
index 72836c3..dbfdb31 100644
--- a/tnslc/test.tnsl
+++ b/tnslc/test.tnsl
@@ -1,14 +1,5 @@
-int i = 1 + 2 * 4 - 3 + 4
-int j = -3
-
-~uint8 a = b{0}
-
-/; main ({}{}uint8 args) [int]
-
- tnsl.print("Hello, World!")
-
- ~uint8 as = 12
- as` = 3 + 4
-;/
+struct Box {
+ {}~{}A(B`)` a
+}