WIP array fixes
This commit is contained in:
parent
0ab7ef872b
commit
9c746ad15b
73
compiler.c
73
compiler.c
|
|
@ -291,7 +291,8 @@ calculate_strides(List *dims, List *strides)
|
|||
if(num) {
|
||||
current_stride *= (*num);
|
||||
} else {
|
||||
emitter->error("Tried to get a dimension that did not exist", 43, parser->previous.line);
|
||||
emitter->error("Tried to get a dimension that did not exist", 43,
|
||||
parser->previous.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -334,9 +335,8 @@ define_array(void)
|
|||
void
|
||||
define_string(void)
|
||||
{
|
||||
scope_add_symbol(parser->current.start,
|
||||
parser->current.length,
|
||||
SYMBOL_STR, 0);
|
||||
scope_add_symbol(parser->current.start, parser->current.length, SYMBOL_STR,
|
||||
0);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -358,14 +358,13 @@ build_symbol_table(char *source)
|
|||
define_plex();
|
||||
} else if(match(TOKEN_KEYWORD_TRAIT)) {
|
||||
define_trait();
|
||||
} else if (parser->previous.type != TOKEN_KEYWORD_AS && match(TOKEN_TYPE_STR)) {
|
||||
} else if(parser->previous.type != TOKEN_KEYWORD_AS &&
|
||||
match(TOKEN_TYPE_STR)) {
|
||||
define_string();
|
||||
} else if(parser->current.type >= TOKEN_TYPE_I8 &&
|
||||
parser->current.type <= TOKEN_TYPE_PTR) {
|
||||
advance();
|
||||
if (check(TOKEN_LBRACKET)) {
|
||||
define_array();
|
||||
}
|
||||
if(check(TOKEN_LBRACKET)) define_array();
|
||||
} else {
|
||||
/* in binary bytecode output mode we need to count the bytes here */
|
||||
/* otherwise ignore everything */
|
||||
|
|
@ -389,10 +388,8 @@ variable_declaration(Symbol *def)
|
|||
Symbol *variable;
|
||||
List *array_literal;
|
||||
|
||||
|
||||
if(tt == TOKEN_TYPE_STR) {
|
||||
variable = scope_get_symbol(parser->current_scope,
|
||||
parser->current.start,
|
||||
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
||||
parser->current.length);
|
||||
if(!variable) {
|
||||
emitter->error("cannot find str symbol", 23, parser->current.line);
|
||||
|
|
@ -403,7 +400,8 @@ variable_declaration(Symbol *def)
|
|||
if(match(TOKEN_EQ)) {
|
||||
expect(TOKEN_LITERAL_STR);
|
||||
variable->size = parser->previous.length - 2;
|
||||
emitter->emit_str(arena, memory, variable, parser->previous.start, parser->previous.length);
|
||||
emitter->emit_str(arena, memory, variable, parser->previous.start,
|
||||
parser->previous.length);
|
||||
expect(TOKEN_SEMICOLON);
|
||||
}
|
||||
|
||||
|
|
@ -412,13 +410,10 @@ variable_declaration(Symbol *def)
|
|||
}
|
||||
|
||||
if(parser->current.type == TOKEN_LBRACKET) {
|
||||
while(!check(TOKEN_RBRACKET)) {
|
||||
advance();
|
||||
}
|
||||
while(!check(TOKEN_RBRACKET)) advance();
|
||||
advance();
|
||||
|
||||
variable = scope_get_symbol(parser->current_scope,
|
||||
parser->current.start,
|
||||
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
||||
parser->current.length);
|
||||
if(!variable) {
|
||||
emitter->error("cannot find array symbol", 25, parser->current.line);
|
||||
|
|
@ -445,7 +440,9 @@ variable_declaration(Symbol *def)
|
|||
expect(TOKEN_SEMICOLON);
|
||||
|
||||
emitter->emit_array(arena, memory, variable, nil);
|
||||
emitter->emit_zero_block(arena, memory, variable->size * emitter->get_size(variable->secondary_type));
|
||||
emitter->emit_zero_block(arena, memory,
|
||||
variable->size *
|
||||
emitter->get_size(variable->secondary_type));
|
||||
}
|
||||
|
||||
parser->current_type = st;
|
||||
|
|
@ -455,7 +452,8 @@ variable_declaration(Symbol *def)
|
|||
if(st != SYMBOL_UNDEFINED) {
|
||||
size = emitter->get_size(st);
|
||||
|
||||
variable = scope_add_symbol(parser->current.start, parser->current.length, st, size);
|
||||
variable = scope_add_symbol(parser->current.start, parser->current.length,
|
||||
st, size);
|
||||
|
||||
if(!def && (parser->pass == 0)) return size;
|
||||
|
||||
|
|
@ -630,7 +628,9 @@ variable(void)
|
|||
if(sleq("length", parser->current.start, parser->current.length)) {
|
||||
emitter->emit_deref(arena, code, 2);
|
||||
} else {
|
||||
emitter->error("arrays currently can only get their length, don't do anything fancy yet...", 75, parser->current.line);
|
||||
emitter->error("arrays currently can only get their length, don't do "
|
||||
"anything fancy yet...",
|
||||
75, parser->current.line);
|
||||
}
|
||||
parser->current_type = SYMBOL_NAT;
|
||||
advance();
|
||||
|
|
@ -679,7 +679,9 @@ variable(void)
|
|||
if(sleq("length", parser->current.start, parser->current.length)) {
|
||||
emitter->emit_deref(arena, code, size);
|
||||
} else {
|
||||
emitter->error("arrays currently can only get their length, don't do anything fancy yet...", 75, parser->current.line);
|
||||
emitter->error("arrays currently can only get their length, don't do "
|
||||
"anything fancy yet...",
|
||||
75, parser->current.line);
|
||||
}
|
||||
parser->current_type = SYMBOL_NAT;
|
||||
advance();
|
||||
|
|
@ -789,14 +791,16 @@ cast_type(void)
|
|||
break;
|
||||
}
|
||||
default:
|
||||
emitter->error("Type cast not implemented for this type (oops)", 46, parser->previous.line);
|
||||
emitter->error("Type cast not implemented for this type (oops)", 46,
|
||||
parser->previous.line);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
declaration(void)
|
||||
{
|
||||
if(is_type() && (parser->current.type == TOKEN_IDENTIFIER || parser->current.type == TOKEN_LBRACKET) )
|
||||
if(is_type() && (parser->current.type == TOKEN_IDENTIFIER ||
|
||||
parser->current.type == TOKEN_LBRACKET))
|
||||
variable_declaration(nil);
|
||||
else
|
||||
statement();
|
||||
|
|
@ -826,7 +830,8 @@ if_statement(void)
|
|||
statement();
|
||||
emitter->else_if_depth--;
|
||||
}
|
||||
if(emitter->else_if_depth == 0) emitter->emit_patch_if_done(arena, code, emitter->ifs++);
|
||||
if(emitter->else_if_depth == 0)
|
||||
emitter->emit_patch_if_done(arena, code, emitter->ifs++);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -930,19 +935,33 @@ grouping(void)
|
|||
void
|
||||
number(void)
|
||||
{
|
||||
emitter->emit_int(arena, code, parser->previous.start, parser->previous.length);
|
||||
switch(parser->current_type) {
|
||||
case SYMBOL_BOOL:
|
||||
case SYMBOL_BYTE:
|
||||
case SYMBOL_U8:
|
||||
case SYMBOL_I8:
|
||||
emitter->emit_char(arena, code, parser->previous.start,
|
||||
parser->previous.length);
|
||||
break;
|
||||
default:
|
||||
emitter->emit_nat(arena, code, parser->previous.start,
|
||||
parser->previous.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
string(void)
|
||||
{
|
||||
emitter->emit_inline_str(arena, code, parser->previous.start, parser->previous.length);
|
||||
emitter->emit_inline_str(arena, code, parser->previous.start,
|
||||
parser->previous.length);
|
||||
}
|
||||
|
||||
void
|
||||
character(void)
|
||||
{
|
||||
emitter->emit_char(arena, code, parser->previous.start, parser->previous.length);
|
||||
emitter->emit_char(arena, code, parser->previous.start,
|
||||
parser->previous.length);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Reference in New Issue