typedefs mostly working
This commit is contained in:
parent
46635e5748
commit
5167a60347
3 changed files with 64 additions and 21 deletions
|
@ -4,4 +4,5 @@
|
|||
} (*x)(void);
|
||||
*/
|
||||
typedef long int unsigned Foo[sizeof"hello"+sizeof(double[sizeof(int) * sizeof 3])];
|
||||
typedef int (*x)(Foo);
|
||||
/* */
|
||||
|
|
24
05/parse.b
24
05/parse.b
|
@ -40,11 +40,27 @@ function parse_tokens
|
|||
:parse_typedef
|
||||
token += 16
|
||||
type = parse_type(&token, &ident)
|
||||
if ident == 0 goto typedef_no_ident
|
||||
if *1token != SYMBOL_SEMICOLON goto typedef_no_semicolon
|
||||
puts(ident)
|
||||
putc(10)
|
||||
putc(':)
|
||||
putc(32)
|
||||
print_type(type)
|
||||
putc(10)
|
||||
exit(0)
|
||||
|
||||
ident_list_add(typedefs, ident, type)
|
||||
token += 16 ; skip semicolon
|
||||
goto parse_tokens_loop
|
||||
:typedef_no_ident
|
||||
token_error(tokens, .str_typedef_no_ident)
|
||||
:str_typedef_no_ident
|
||||
string No identifier in typedef declaration.
|
||||
byte 0
|
||||
:typedef_no_semicolon
|
||||
token_error(tokens, .str_typedef_no_semicolon)
|
||||
:str_typedef_no_semicolon
|
||||
string typedef does not end with a semicolon.
|
||||
byte 0
|
||||
:parse_tokens_eof
|
||||
return
|
||||
|
||||
|
@ -264,7 +280,7 @@ function parse_type_to
|
|||
if *1p == SYMBOL_TIMES goto parse_pointer_type
|
||||
if suffix == suffix_end goto parse_base_type
|
||||
if *1suffix == SYMBOL_RPAREN goto parse_type_remove_parentheses
|
||||
|
||||
goto bad_type
|
||||
|
||||
:parse_pointer_type
|
||||
*1out = TYPE_POINTER
|
||||
|
@ -440,7 +456,9 @@ function parse_type_to
|
|||
:base_type_typedef
|
||||
p = prefix + 8
|
||||
c = ident_list_lookup(typedefs, *8p)
|
||||
if c == 0 goto bad_type
|
||||
n = type_length(c)
|
||||
c += types
|
||||
out = memcpy(out, c, n)
|
||||
goto base_type_done
|
||||
|
||||
|
|
24
05/util.b
24
05/util.b
|
@ -372,6 +372,13 @@ function puts
|
|||
fputs(1, s)
|
||||
return
|
||||
|
||||
function putsln
|
||||
argument s
|
||||
fputs(1, s)
|
||||
fputc(1, 10)
|
||||
return
|
||||
|
||||
|
||||
function print_separator
|
||||
fputs(1, .str_separator)
|
||||
return
|
||||
|
@ -455,6 +462,18 @@ function putn_signed
|
|||
fputn_signed(1, n)
|
||||
return
|
||||
|
||||
function putnln
|
||||
argument n
|
||||
fputn(1, n)
|
||||
fputc(1, 10)
|
||||
return
|
||||
|
||||
function putnln_signed
|
||||
argument n
|
||||
fputn_signed(1, n)
|
||||
fputc(1, 10)
|
||||
return
|
||||
|
||||
|
||||
function fputc
|
||||
argument fd
|
||||
|
@ -466,6 +485,11 @@ function putc
|
|||
argument c
|
||||
fputc(1, c)
|
||||
return
|
||||
function putcln
|
||||
argument c
|
||||
fputc(1, c)
|
||||
fputc(1, 10)
|
||||
return
|
||||
|
||||
; returns 0 at end of file
|
||||
function fgetc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue