diff options
Diffstat (limited to 'tnslc/compile/struct.tnsl')
| -rw-r--r-- | tnslc/compile/struct.tnsl | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/tnslc/compile/struct.tnsl b/tnslc/compile/struct.tnsl index 79d3267..5403553 100644 --- a/tnslc/compile/struct.tnsl +++ b/tnslc/compile/struct.tnsl @@ -8,10 +8,10 @@ struct Struct { ~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" +~uint8 PRIMITIVE_1 = "bool,uint8,int8\0" +~uint8 PRIMITIVE_2 = "uint16,int16\0" +~uint8 PRIMITIVE_4 = "uint32,int32,float32\0" +~uint8 PRIMITIVE_8 = "uint64,int64,float64,int,uint,float,void\0" /; is_primitive (~parse.Node tn) [int] /; if (tn`.sub.count < 1) @@ -25,17 +25,6 @@ struct Struct { 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) @@ -45,6 +34,23 @@ struct Struct { return 0 ;/ +/; _print_type(~parse.Node tn) + ~parse.Node n + /; loop (int i = 0; i < tn`.sub.count) [i++] + /; if (i > 0) + _printf(".\0") + ;/ + + n = tn`.sub.get(i) + + /; if (n`._type == parse.NTYPE_ID) + _printf(n`.data) + ;; else + return + ;/ + ;/ +;/ + /; method Struct /; init (~parse.Node node) @@ -101,17 +107,30 @@ struct Struct { 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 + # Find type, compute size, set add_size to type size + ~Struct ft = self._find_type(parent, n) + + /; if (ft == NULL) + # Type not found + _printf("ERROR: Unable to find type '\0") + _print_type(n) + _printf("' for use in struct '\0") + _printf(self.name) + _printf("'\n\0") + return + ;/ + + /; if (ft`.size == 0) + # Recurse + ft`._compute_size(parent) + ;/ + + /; if (ft`.size < 0) + # Cyclical dependency + return ;/ + + add_size = ft`.size ;; else if (n`._type == parse.NTYPE_ID) total = total + add_size ;/ @@ -121,17 +140,22 @@ struct Struct { ;/ /; _find_type (~Module parent, ~parse.Node tn) [~Struct] - # First loop through all the names and create a vector of strings + + # Init vector of strings utils.Vector sv sv.init(8) + ~void str ~parse.Node n + bool seen_id = false + /; 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 + seen_id = true + ;; else if (seen_id == true) i = tn`.sub.count ;/ ;/ @@ -144,7 +168,6 @@ struct Struct { outp = parent.find(SEARCH_SUB, ~sv) ;/ sv.end() - out._compute_size(outp) return out ;/ |