summaryrefslogtreecommitdiff
path: root/05/parse.b
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-15 10:35:36 -0500
committerpommicket <pommicket@gmail.com>2022-01-15 10:35:36 -0500
commit857d5552fc04bbaf8437df2edc957c6d9d7c582a (patch)
tree81ae896af414d8a1a351038393c6af46f5d0c926 /05/parse.b
parent2ec0cd4ae35c3a238e0dcc75bbafcf7ba0938356 (diff)
parsing/typing fixes
Diffstat (limited to '05/parse.b')
-rw-r--r--05/parse.b48
1 files changed, 47 insertions, 1 deletions
diff --git a/05/parse.b b/05/parse.b
index f451466..dc61d0c 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -1,6 +1,52 @@
+; how many bytes does it take to encode this type?
+function type_length
+ argument type
+ local p
+ local n
+ p = types + type
+ if *1p <= TYPE_DOUBLE goto return_1
+ if *1p != TYPE_POINTER goto type_length_not_pointer
+ type += 1
+ n = type_length(type)
+ return n + 1
+ :type_length_not_pointer
+ if *1p != TYPE_ARRAY goto type_length_not_array
+ type += 9
+ n = type_length(type)
+ return n + 9
+ :type_length_not_array
+ if *1p == TYPE_STRUCT goto return_5
+ if *1p == TYPE_UNION goto return_5
+ fputs(2, .str_type_length_bad_type)
+ exit(1)
+ :str_type_length_bad_type
+ string Bad type passed to type_length. This shouldn't happen.
+ byte 10
+ byte 0
+
+
+; returns length of type
+function type_copy
+ argument dest
+ argument src
+ local n
+ n = type_length(src)
+ dest += types
+ src += types
+ memcpy(dest, src, n)
+ return n
+
function type_create_pointer
argument type
- byte 0xcc ; @TODO
+ local id
+ local p
+ id = types_bytes_used
+ p = types + id
+ *1p = TYPE_POINTER
+ types_bytes_used += 1
+ p = id + 1
+ types_bytes_used += type_copy(p, type)
+ return id
function parse_expression
argument tokens