fixed bug when evaluating division
This commit is contained in:
parent
c19bed7454
commit
e8378ddac0
1 changed files with 8 additions and 14 deletions
18
05/parse.b
18
05/parse.b
|
@ -624,15 +624,11 @@ function token_reverse_to_matching_lparen
|
||||||
*8p_token = token
|
*8p_token = token
|
||||||
return
|
return
|
||||||
|
|
||||||
; parse things like `int x` or `int f(void, int, char *)`
|
|
||||||
; advances *p_token
|
; we split types into base (B), prefix (P) and suffix (S)
|
||||||
; returns type ID, or 0, in which case you should look at parse_type_result
|
; struct Thing (*things[5])(void), *something_else[3];
|
||||||
function parse_type
|
; BBBBBBBBBBBB PP SSSSSSSSSS P SSS
|
||||||
; split types into base (B), prefix (P) and suffix (S)
|
; the following functions deal with figuring out where these parts are.
|
||||||
; struct Thing (*things[5])(void), *something_else[3];
|
|
||||||
; BBBBBBBBBBBB PP SSSSSSSSSS P SSS
|
|
||||||
; Here, we call `struct Thing` the "base type".
|
|
||||||
byte 0xcc
|
|
||||||
|
|
||||||
; return the end of the base for this type.
|
; return the end of the base for this type.
|
||||||
function type_get_base_end
|
function type_get_base_end
|
||||||
|
@ -795,10 +791,7 @@ function parse_type_declarators
|
||||||
types_bytes_used += 4000
|
types_bytes_used += 4000
|
||||||
|
|
||||||
expr = malloc(4000)
|
expr = malloc(4000)
|
||||||
|
|
||||||
parse_expression(suffix, p, expr)
|
parse_expression(suffix, p, expr)
|
||||||
;print_expression(expr)
|
|
||||||
;putc(10)
|
|
||||||
evaluate_constant_expression(prefix, expr, &n)
|
evaluate_constant_expression(prefix, expr, &n)
|
||||||
if n < 0 goto bad_array_size
|
if n < 0 goto bad_array_size
|
||||||
free(expr)
|
free(expr)
|
||||||
|
@ -2165,6 +2158,7 @@ function evaluate_constant_expression
|
||||||
expr += 8
|
expr += 8
|
||||||
expr = evaluate_constant_expression(token, expr, &a)
|
expr = evaluate_constant_expression(token, expr, &a)
|
||||||
expr = evaluate_constant_expression(token, expr, &b)
|
expr = evaluate_constant_expression(token, expr, &b)
|
||||||
|
p = types + type
|
||||||
if *1p == TYPE_UNSIGNED_LONG goto eval_div_unsigned
|
if *1p == TYPE_UNSIGNED_LONG goto eval_div_unsigned
|
||||||
; division is signed or uses a small type, so we can use 64-bit signed division
|
; division is signed or uses a small type, so we can use 64-bit signed division
|
||||||
*8p_value = a / b
|
*8p_value = a / b
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue