diff options
-rw-r--r-- | 05/constants.b | 3 | ||||
-rw-r--r-- | 05/main.b | 28 | ||||
-rw-r--r-- | 05/parse.b | 14 |
3 files changed, 32 insertions, 13 deletions
diff --git a/05/constants.b b/05/constants.b index ca3bda9..cc48e3c 100644 --- a/05/constants.b +++ b/05/constants.b @@ -10,6 +10,9 @@ #define RWDATA_END 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 ; lowest ; 1 , @@ -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[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) -; 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™ global statement_datas 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_end @@ -176,20 +181,29 @@ function main local q local i local output_fd + local memory - statement_datas = malloc(4000) - statement_datas_ends = malloc(4000) + memory = malloc(4000) + statement_datas = memory + statement_datas_ends = memory + 400 + block_static_variables = memory + 800 p = statement_datas q = statement_datas_ends i = 0 :statement_datas_loop *8p = malloc(4000000) ; supports 100,000 statements at each level - *8q = p + *8q = *8p p += 8 q += 8 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() typedefs = ident_list_create(100000) @@ -176,7 +176,7 @@ function parse_tokens p = function_stmt_data + function_stmt_data_bytes_used out = p 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 ident_list_add(function_statements, name, p) print_statement(p) @@ -310,6 +310,7 @@ function parse_statement if c == KEYWORD_RETURN goto stmt_return if c == KEYWORD_GOTO goto stmt_goto if c == KEYWORD_CASE goto stmt_case + if c == KEYWORD_STATIC goto stmt_static_declaration token_error(token, .str_unrecognized_statement) :str_unrecognized_statement @@ -319,6 +320,8 @@ function parse_statement *8p_token = token *8p_out = out return + :stmt_static_declaration + byte 0xcc ; @TODO :stmt_break write_statement_header(out, STATEMENT_BREAK, token) token += 16 @@ -414,13 +417,12 @@ function parse_statement local block_p_out ; find the appropriate statement data to use for this block's body block_p_out = statement_datas_ends - block_p_out += parse_stmt_depth < 3 - + block_p_out += block_depth < 3 *8out = *8block_p_out out += 32 - parse_stmt_depth += 1 - if parse_stmt_depth >= 16 goto too_much_nesting + block_depth += 1 + if block_depth >= BLOCK_DEPTH_LIMIT goto too_much_nesting token += 16 ; skip opening { :parse_block_loop @@ -433,7 +435,7 @@ function parse_statement p = *8block_p_out *1p = 0 ; probably redundant, but whatever *8block_p_out += 8 ; add 8 and not 1 because of alignment - parse_stmt_depth -= 1 + block_depth -= 1 goto parse_statement_ret :parse_block_eof |