parsing/typing fixes

This commit is contained in:
pommicket 2022-01-15 10:35:36 -05:00
parent 2ec0cd4ae3
commit 857d5552fc
4 changed files with 68 additions and 6 deletions

View file

@ -94,7 +94,7 @@ function compile_warning
global powers_of_10 global powers_of_10
global types global types
global types_end global types_bytes_used
#include util.b #include util.b
#include constants.b #include constants.b
@ -138,9 +138,9 @@ function main
*1p = TYPE_POINTER *1p = TYPE_POINTER
p += 1 p += 1
*1p = TYPE_CHAR *1p = TYPE_CHAR
p += 1
types_bytes_used = p - types
types_end = p
input_filename = .str_default_input_filename input_filename = .str_default_input_filename

View file

@ -1,6 +1,6 @@
/* +*"hello" */ /* +*"hello" */
/* *"hello"+3 */ /* *"hello"+3 */
/* +*"hello" */
/* 3+4+5 */ /* 3+4+5 */
/* 3+=4+=5*=6>>=7 */ /* 3+=4+=5*=6>>=7 */
"hello"+=7 /* "hello"+=7 */
5*(4<<8)-2-"hello"[3/4]

View file

@ -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 function type_create_pointer
argument type 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 function parse_expression
argument tokens argument tokens

View file

@ -572,6 +572,22 @@ function leftmost_1bit
return 0 return 0
:return_1 :return_1
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_minus1
return -1 return -1
:return_0x10 :return_0x10