bugfix, planning static variables
This commit is contained in:
parent
d75b4154d3
commit
267b52814e
3 changed files with 32 additions and 13 deletions
|
@ -10,6 +10,9 @@
|
||||||
#define RWDATA_END 0x1000000
|
#define RWDATA_END 0x1000000
|
||||||
#define EXECUTABLE_SIZE 0x1000000
|
#define EXECUTABLE_SIZE 0x1000000
|
||||||
|
|
||||||
|
; "* 15 nesting levels of compound statements, iteration control structures, and selection control structures" C89 § 2.2.4.1
|
||||||
|
#define BLOCK_DEPTH_LIMIT 16
|
||||||
|
|
||||||
; C OPERATOR PRECEDENCE
|
; C OPERATOR PRECEDENCE
|
||||||
; lowest
|
; lowest
|
||||||
; 1 ,
|
; 1 ,
|
||||||
|
|
28
05/main.b
28
05/main.b
|
@ -54,11 +54,16 @@ global function_statements
|
||||||
; statement_datas[0] = pointer to statement data for block-nesting depth 0 (i.e. function bodies)
|
; statement_datas[0] = pointer to statement data for block-nesting depth 0 (i.e. function bodies)
|
||||||
; statement_datas[1] = pointer to statement data for block-nesting depth 1 (blocks inside functions)
|
; statement_datas[1] = pointer to statement data for block-nesting depth 1 (blocks inside functions)
|
||||||
; statement_datas[2] = pointer to statement data for block-nesting depth 2 (blocks inside blocks inside functions)
|
; statement_datas[2] = pointer to statement data for block-nesting depth 2 (blocks inside blocks inside functions)
|
||||||
; etc. up to statement_datas[15] "* 15 nesting levels of compound statements, iteration control structures, and selection control structures" C89 § 2.2.4.1
|
; etc. up to statement_datas[BLOCK_DEPTH_LIMIT-1]
|
||||||
; these have to be separated for reasons™
|
; these have to be separated for reasons™
|
||||||
global statement_datas
|
global statement_datas
|
||||||
global statement_datas_ends
|
global statement_datas_ends
|
||||||
global parse_stmt_depth
|
; ident lists of addresses
|
||||||
|
; block_static_variables[0] = static variables inside this function
|
||||||
|
; block_static_variables[1] = static variables inside this block inside this function
|
||||||
|
; etc.
|
||||||
|
global block_static_variables
|
||||||
|
global block_depth
|
||||||
global expressions
|
global expressions
|
||||||
global expressions_end
|
global expressions_end
|
||||||
|
|
||||||
|
@ -176,20 +181,29 @@ function main
|
||||||
local q
|
local q
|
||||||
local i
|
local i
|
||||||
local output_fd
|
local output_fd
|
||||||
|
local memory
|
||||||
|
|
||||||
statement_datas = malloc(4000)
|
memory = malloc(4000)
|
||||||
statement_datas_ends = malloc(4000)
|
statement_datas = memory
|
||||||
|
statement_datas_ends = memory + 400
|
||||||
|
block_static_variables = memory + 800
|
||||||
p = statement_datas
|
p = statement_datas
|
||||||
q = statement_datas_ends
|
q = statement_datas_ends
|
||||||
i = 0
|
i = 0
|
||||||
:statement_datas_loop
|
:statement_datas_loop
|
||||||
*8p = malloc(4000000) ; supports 100,000 statements at each level
|
*8p = malloc(4000000) ; supports 100,000 statements at each level
|
||||||
*8q = p
|
*8q = *8p
|
||||||
p += 8
|
p += 8
|
||||||
q += 8
|
q += 8
|
||||||
i += 1
|
i += 1
|
||||||
if i < 16 goto statement_datas_loop
|
if i < BLOCK_DEPTH_LIMIT goto statement_datas_loop
|
||||||
|
p = block_static_variables
|
||||||
|
i = 0
|
||||||
|
:bsv_alloc_loop
|
||||||
|
*8p = malloc(24000) ; more than enough memory to hold static variable names/addresses for a particular block
|
||||||
|
p += 8
|
||||||
|
i += 1
|
||||||
|
if i < BLOCK_DEPTH_LIMIT goto bsv_alloc_loop
|
||||||
fill_in_powers_of_10()
|
fill_in_powers_of_10()
|
||||||
|
|
||||||
typedefs = ident_list_create(100000)
|
typedefs = ident_list_create(100000)
|
||||||
|
|
14
05/parse.b
14
05/parse.b
|
@ -176,7 +176,7 @@ function parse_tokens
|
||||||
p = function_stmt_data + function_stmt_data_bytes_used
|
p = function_stmt_data + function_stmt_data_bytes_used
|
||||||
out = p
|
out = p
|
||||||
parse_statement(&token, &out)
|
parse_statement(&token, &out)
|
||||||
if parse_stmt_depth != 0 goto stmtdepth_internal_err
|
if block_depth != 0 goto stmtdepth_internal_err
|
||||||
function_stmt_data_bytes_used = out - function_stmt_data
|
function_stmt_data_bytes_used = out - function_stmt_data
|
||||||
ident_list_add(function_statements, name, p)
|
ident_list_add(function_statements, name, p)
|
||||||
print_statement(p)
|
print_statement(p)
|
||||||
|
@ -310,6 +310,7 @@ function parse_statement
|
||||||
if c == KEYWORD_RETURN goto stmt_return
|
if c == KEYWORD_RETURN goto stmt_return
|
||||||
if c == KEYWORD_GOTO goto stmt_goto
|
if c == KEYWORD_GOTO goto stmt_goto
|
||||||
if c == KEYWORD_CASE goto stmt_case
|
if c == KEYWORD_CASE goto stmt_case
|
||||||
|
if c == KEYWORD_STATIC goto stmt_static_declaration
|
||||||
|
|
||||||
token_error(token, .str_unrecognized_statement)
|
token_error(token, .str_unrecognized_statement)
|
||||||
:str_unrecognized_statement
|
:str_unrecognized_statement
|
||||||
|
@ -319,6 +320,8 @@ function parse_statement
|
||||||
*8p_token = token
|
*8p_token = token
|
||||||
*8p_out = out
|
*8p_out = out
|
||||||
return
|
return
|
||||||
|
:stmt_static_declaration
|
||||||
|
byte 0xcc ; @TODO
|
||||||
:stmt_break
|
:stmt_break
|
||||||
write_statement_header(out, STATEMENT_BREAK, token)
|
write_statement_header(out, STATEMENT_BREAK, token)
|
||||||
token += 16
|
token += 16
|
||||||
|
@ -414,13 +417,12 @@ function parse_statement
|
||||||
local block_p_out
|
local block_p_out
|
||||||
; find the appropriate statement data to use for this block's body
|
; find the appropriate statement data to use for this block's body
|
||||||
block_p_out = statement_datas_ends
|
block_p_out = statement_datas_ends
|
||||||
block_p_out += parse_stmt_depth < 3
|
block_p_out += block_depth < 3
|
||||||
|
|
||||||
*8out = *8block_p_out
|
*8out = *8block_p_out
|
||||||
out += 32
|
out += 32
|
||||||
|
|
||||||
parse_stmt_depth += 1
|
block_depth += 1
|
||||||
if parse_stmt_depth >= 16 goto too_much_nesting
|
if block_depth >= BLOCK_DEPTH_LIMIT goto too_much_nesting
|
||||||
|
|
||||||
token += 16 ; skip opening {
|
token += 16 ; skip opening {
|
||||||
:parse_block_loop
|
:parse_block_loop
|
||||||
|
@ -433,7 +435,7 @@ function parse_statement
|
||||||
p = *8block_p_out
|
p = *8block_p_out
|
||||||
*1p = 0 ; probably redundant, but whatever
|
*1p = 0 ; probably redundant, but whatever
|
||||||
*8block_p_out += 8 ; add 8 and not 1 because of alignment
|
*8block_p_out += 8 ; add 8 and not 1 because of alignment
|
||||||
parse_stmt_depth -= 1
|
block_depth -= 1
|
||||||
goto parse_statement_ret
|
goto parse_statement_ret
|
||||||
|
|
||||||
:parse_block_eof
|
:parse_block_eof
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue