diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2026-07-03 05:01:26 -0400 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2026-07-03 05:01:26 -0400 |
| commit | fc0262447a128ec8047689ddb885cffa8aa6e2dc (patch) | |
| tree | 5ad6744e877cf48c78cd54da368c1c5f405637bc | |
| parent | 5a0e41021e7ef474c206688a32020be5435bcb09 (diff) | |
[tnslc] Fix some parsing issues
| -rw-r--r-- | tnslc/compile/function.tnsl | 3 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 6 | ||||
| -rw-r--r-- | tnslc/parse/ast.tnsl | 139 |
3 files changed, 71 insertions, 77 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 849bae1..2a8363a 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -1461,6 +1461,7 @@ struct Function { s`.free_after(~lhs, true) ;/ + _printf("COMPILE_BOOL_OP\n\0") /; if (lhs.is_struct() == true) _printf("Can not use struct as boolean value\n\0") lhs.end() @@ -1512,6 +1513,7 @@ struct Function { # Compute right hand side Var rhs = self._compile_value(s, rhn) + _printf("COMPILE_BOOL_OP\n\0") /; if (rhs.is_struct() == true) _printf("Can not use struct as boolean value\n\0") lhs.end() @@ -1601,6 +1603,7 @@ struct Function { # Compute right hand side Var rhs = self._compile_value(s, rhn) + _printf("COMPILE_CMP_OP\n\0") # Check not structs /; if (lhs.is_struct() == true || rhs.is_struct() == true) _printf("Can not compare structs in this version of tnsl\n\0") diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index 8babc1b..0154931 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -944,6 +944,7 @@ struct Var { # Typechecking structs /; _tc_struct (~Var other) [bool] + _printf("TC_STRUCT\n\0") /; if (other`.is_struct() == false) return false ;/ @@ -1237,7 +1238,7 @@ struct Var { # - If builtin then move based on size (byte, word, dword, qword) # - If pointer then move qword # - If struct then move via rep movsb - + _printf("SET\n\0") /; if (self.is_struct() == true) # Struct set self._set_struct(buf, other) @@ -1314,6 +1315,7 @@ struct Var { ~int32 p = vcpy.ptrc.get(idx) p` = set ;; else + _printf("TAKE_PTR\n\0") /; if (self.is_struct() == true) self._set_struct_r(buf, reg) ;; else @@ -1859,7 +1861,7 @@ struct Var { ;/ /; member (~CompBuf buf, ~uint8 name) [Var] - + _printf("MEMBER\n\0") /; if (self.is_struct() == false) _printf("ERROR: Attempted to get a member named \"\0") _printf(name) diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl index 8753bf4..fea6421 100644 --- a/tnslc/parse/ast.tnsl +++ b/tnslc/parse/ast.tnsl @@ -1314,40 +1314,56 @@ int errors_shown = 0 ;/ ;/ - /; loop (idx < _type`.sub.count && sub`._type == NTYPE_ID) - /; if (idx < _type`.sub.count - 1) - sub = _type`.sub.get(idx + 1) - /; if (sub`._type == NTYPE_ID) - sub = _type`.sub.get(idx) - Node op, n + /; loop (idx < _type`.sub.count) + /; if (sub`._type == NTYPE_ID) + int cmp = 0 + /; if (cur`.eq(".\0") == true) + cmp++ + ;/ + + /; if (cur`.sub.count > cmp) + # Create bin op + ~Node mid + mid = cur`.sub.get(cur`.sub.count - 1) + + Node op op.init(NTYPE_BIN_OP, utils.strcpy(".\0")) - n.init(NTYPE_ID, utils.strcpy(sub`.data)) - /; if (cur`.sub.count == 0) - cur`.add_child(~n) - ;; else - _printf("ERROR? Unsure why cur has data???\n\0") - sub = cur`.sub.get(cur`.sub.count - 1) - sub`.add_child(~n) - op.add_child(sub) - cur`.sub.pop() - ;/ + op.add_child(mid) + cur`.sub.pop() + cur = cur`.add_child(~op) - ;; else - sub = _type`.sub.get(idx) - Node n - n.init(NTYPE_ID, utils.strcpy(sub`.data)) - /; if (cur`.sub.count !== 0) - cur = cur`.sub.get(cur`.sub.count - 1) - ;/ - cur = cur`.add_child(~n) ;/ - ;; else + Node n n.init(NTYPE_ID, utils.strcpy(sub`.data)) - /; if (cur`.sub.count !== 0) - cur = cur`.sub.get(cur`.sub.count - 1) + cur`.add_child(~n) + + ;; else if (sub`._type == NTYPE_TLIST && sub`.eq("(\0") == true) + ~Node mid + mid = cur`.sub.get(cur`.sub.count - 1) + + Node lst + lst.init(NTYPE_VLIST, utils.strcpy("(\0")) + + /; loop (int i = 0; i < sub`.sub.count) [i++] + ~Node lsub = sub`.sub.get(i) + at = _mhf_transform(lsub, at) + /; if (at == lsub) + at = lst.add_child(lsub) + ;; else + lst.add_child(lsub) + ;/ + ;/ + + /; loop (sub`.sub.count > 0) + sub`.sub.pop() + ;/ + + /; if (at == sub) + at = mid`.add_child(~lst) + ;; else + mid`.add_child(~lst) ;/ - cur = cur`.add_child(~n) ;/ idx++ @@ -1357,34 +1373,6 @@ int errors_shown = 0 ;/ ;/ - ~int pt1 = at - /; if (idx < _type`.sub.count && sub`._type == NTYPE_TLIST && sub`.eq("(\0") == true) - Node lst - lst.init(NTYPE_VLIST, utils.strcpy("(\0")) - - /; loop (int i = 0; i < sub`.sub.count) [i++] - ~Node lsub = sub`.sub.get(i) - at = _mhf_transform(lsub, at) - ~int pt2 = lsub - /; if (at == lsub) - at = lst.add_child(lsub) - ;; else - lst.add_child(lsub) - ;/ - ;/ - - /; loop (sub`.sub.count > 0) - sub`.sub.pop() - ;/ - - ~int pt2 = sub - /; if (pt1 == pt2) - at = cur`.add_child(~lst) - ;; else - cur`.add_child(~lst) - ;/ - ;/ - _type`.end() _type` = out _type`.update_children() @@ -1441,20 +1429,22 @@ int errors_shown = 0 /; _mhf_lower (~Node cur) [~Node] /; loop (bool run = true; run == true) /; if (cur`.sub.count > 0) - cur = cur`.sub.get(cur`.sub.count - 1) + int i = cur`.sub.count + i = i - 1 + cur = cur`.sub.get(i) ;; else return cur ;/ - /; if (cur`.eq(".\0") || cur`._type == NTYPE_ID) - return cur + /; if (cur`._type == NTYPE_ID) + return cur`.parent ;/ ;/ # should never happen return NULL ;/ -/; _mhf_post_value(~utils.File fin, ~Node cur, ~Token first, bool lnok) [~Node] +/; _mhf_post_value (~utils.File fin, ~Node cur, ~Token first, bool lnok) [~Node] int ln = first`.line /; loop (bool run = true; run == true && first`._type !== TTYPE_ERR) /; if (ln !== first`.line && lnok == false) @@ -1467,7 +1457,6 @@ int errors_shown = 0 id.init(NTYPE_ID, first`.data) ln = first`.line - cur = cur`.parent ~Node sub = cur`.sub.get(cur`.sub.count - 1) op.add_child(sub) @@ -1484,27 +1473,27 @@ int errors_shown = 0 ;; else if (_op_postfix(first) == true) Node op op.init(NTYPE_POST_OP, first`.data) - /; if (cur`.eq(".\0") == true) + /; if (cur`._type == NTYPE_ID) + cur`.add_child(~op) + ;; else if (cur`.sub.count > 0) cur = cur`.sub.get(cur`.sub.count - 1) cur`.add_child(~op) cur = cur`.parent - ;; else if (cur`._type == NTYPE_ID) - cur`.add_child(~op) ;; else - _ast_print_err(fin, first, "Unsure where we are at in the tree ('`'). [CMPERR]") + _ast_print_err(fin, first, "Unsure where we are at in the tree ('`'). [CMPERR]\0") op.end() return NULL ;/ first` = produce_next_token(fin, first`) ;; else if (first`.eq("(\0") == true) - /; if (cur`.eq(".\0") == true) + /; if (cur`._type == NTYPE_ID) + ln = _ast_list_value(fin, cur, first) + ;; else if (cur`.sub.count > 0) cur = cur`.sub.get(cur`.sub.count - 1) ln = _ast_list_value(fin, cur, first) cur = cur`.parent - ;; else if (cur`._type == NTYPE_ID) - ln = _ast_list_value(fin, cur, first) ;; else - _ast_print_err(fin, first, "Unsure where we are at in the tree ('('). [CMPERR]") + _ast_print_err(fin, first, "Unsure where we are at in the tree ('('). [CMPERR]\0") return NULL ;/ ;; else if (first`.eq("{\0") == true) @@ -1515,14 +1504,14 @@ int errors_shown = 0 _ast_print_err(fin, first, "Expected value for index operation after '{'\0") ;/ - /; if (cur`.eq(".\0") == true) + /; if (cur`._type == NTYPE_ID) + cur`.add_child(~ind) + ;; else if (cur`.sub.count > 0) cur = cur`.sub.get(cur`.sub.count - 1) cur`.add_child(~ind) cur = cur`.parent - ;; else if (cur`._type == NTYPE_ID) - cur`.add_child(~ind) ;; else - _ast_print_err(fin, first, "Unsure where we are at in the tree ('{'). [CMPERR]") + _ast_print_err(fin, first, "Unsure where we are at in the tree ('{'). [CMPERR]\0") ind.end() return NULL ;/ @@ -1661,10 +1650,10 @@ int errors_shown = 0 ~int p1 = cur ~int p2 = mod int ln = first`.line - bool firstRun = true - + # While we are in subtree /; loop (bool run = true; run == true && p1 !== p2 && first`._type !== TTYPE_ERR) + ~Node tmp = cur # First loop for while we are in value /; if (tmp`._type == NTYPE_VALUE) |