summaryrefslogtreecommitdiff
path: root/05
diff options
context:
space:
mode:
Diffstat (limited to '05')
-rw-r--r--05/main.b6
-rw-r--r--05/main.c4
-rw-r--r--05/parse.b48
-rw-r--r--05/util.b16
4 files changed, 68 insertions, 6 deletions
diff --git a/05/main.b b/05/main.b
index a85818b..4632338 100644
--- a/05/main.b
+++ b/05/main.b
@@ -94,7 +94,7 @@ function compile_warning
global powers_of_10
global types
-global types_end
+global types_bytes_used
#include util.b
#include constants.b
@@ -138,9 +138,9 @@ function main
*1p = TYPE_POINTER
p += 1
*1p = TYPE_CHAR
+ p += 1
-
- types_end = p
+ types_bytes_used = p - types
input_filename = .str_default_input_filename
diff --git a/05/main.c b/05/main.c
index c5f123b..313487e 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1,6 +1,6 @@
/* +*"hello" */
/* *"hello"+3 */
-/* +*"hello" */
/* 3+4+5 */
/* 3+=4+=5*=6>>=7 */
-"hello"+=7
+/* "hello"+=7 */
+5*(4<<8)-2-"hello"[3/4]
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
diff --git a/05/util.b b/05/util.b
index d30efa6..c8c3e97 100644
--- a/05/util.b
+++ b/05/util.b
@@ -572,6 +572,22 @@ function leftmost_1bit
return 0
:return_1
return 1
+:return_2
+ return 2
+:return_3
+ return 3
+:return_4
+ return 4
+:return_5
+ return 5
+:return_6
+ return 6
+:return_7
+ return 7
+:return_8
+ return 8
+:return_9
+ return 9
:return_minus1
return -1
:return_0x10