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) {
|
if(num) {
|
||||||
current_stride *= (*num);
|
current_stride *= (*num);
|
||||||
} else {
|
} 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
|
void
|
||||||
define_string(void)
|
define_string(void)
|
||||||
{
|
{
|
||||||
scope_add_symbol(parser->current.start,
|
scope_add_symbol(parser->current.start, parser->current.length, SYMBOL_STR,
|
||||||
parser->current.length,
|
0);
|
||||||
SYMBOL_STR, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -358,14 +358,13 @@ build_symbol_table(char *source)
|
||||||
define_plex();
|
define_plex();
|
||||||
} else if(match(TOKEN_KEYWORD_TRAIT)) {
|
} else if(match(TOKEN_KEYWORD_TRAIT)) {
|
||||||
define_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();
|
define_string();
|
||||||
} else if(parser->current.type >= TOKEN_TYPE_I8 &&
|
} else if(parser->current.type >= TOKEN_TYPE_I8 &&
|
||||||
parser->current.type <= TOKEN_TYPE_PTR) {
|
parser->current.type <= TOKEN_TYPE_PTR) {
|
||||||
advance();
|
advance();
|
||||||
if (check(TOKEN_LBRACKET)) {
|
if(check(TOKEN_LBRACKET)) define_array();
|
||||||
define_array();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* in binary bytecode output mode we need to count the bytes here */
|
/* in binary bytecode output mode we need to count the bytes here */
|
||||||
/* otherwise ignore everything */
|
/* otherwise ignore everything */
|
||||||
|
|
@ -389,10 +388,8 @@ variable_declaration(Symbol *def)
|
||||||
Symbol *variable;
|
Symbol *variable;
|
||||||
List *array_literal;
|
List *array_literal;
|
||||||
|
|
||||||
|
|
||||||
if(tt == TOKEN_TYPE_STR) {
|
if(tt == TOKEN_TYPE_STR) {
|
||||||
variable = scope_get_symbol(parser->current_scope,
|
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
||||||
parser->current.start,
|
|
||||||
parser->current.length);
|
parser->current.length);
|
||||||
if(!variable) {
|
if(!variable) {
|
||||||
emitter->error("cannot find str symbol", 23, parser->current.line);
|
emitter->error("cannot find str symbol", 23, parser->current.line);
|
||||||
|
|
@ -403,7 +400,8 @@ variable_declaration(Symbol *def)
|
||||||
if(match(TOKEN_EQ)) {
|
if(match(TOKEN_EQ)) {
|
||||||
expect(TOKEN_LITERAL_STR);
|
expect(TOKEN_LITERAL_STR);
|
||||||
variable->size = parser->previous.length - 2;
|
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);
|
expect(TOKEN_SEMICOLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,13 +410,10 @@ variable_declaration(Symbol *def)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parser->current.type == TOKEN_LBRACKET) {
|
if(parser->current.type == TOKEN_LBRACKET) {
|
||||||
while(!check(TOKEN_RBRACKET)) {
|
while(!check(TOKEN_RBRACKET)) advance();
|
||||||
advance();
|
|
||||||
}
|
|
||||||
advance();
|
advance();
|
||||||
|
|
||||||
variable = scope_get_symbol(parser->current_scope,
|
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
||||||
parser->current.start,
|
|
||||||
parser->current.length);
|
parser->current.length);
|
||||||
if(!variable) {
|
if(!variable) {
|
||||||
emitter->error("cannot find array symbol", 25, parser->current.line);
|
emitter->error("cannot find array symbol", 25, parser->current.line);
|
||||||
|
|
@ -445,7 +440,9 @@ variable_declaration(Symbol *def)
|
||||||
expect(TOKEN_SEMICOLON);
|
expect(TOKEN_SEMICOLON);
|
||||||
|
|
||||||
emitter->emit_array(arena, memory, variable, nil);
|
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;
|
parser->current_type = st;
|
||||||
|
|
@ -455,7 +452,8 @@ variable_declaration(Symbol *def)
|
||||||
if(st != SYMBOL_UNDEFINED) {
|
if(st != SYMBOL_UNDEFINED) {
|
||||||
size = emitter->get_size(st);
|
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;
|
if(!def && (parser->pass == 0)) return size;
|
||||||
|
|
||||||
|
|
@ -630,7 +628,9 @@ variable(void)
|
||||||
if(sleq("length", parser->current.start, parser->current.length)) {
|
if(sleq("length", parser->current.start, parser->current.length)) {
|
||||||
emitter->emit_deref(arena, code, 2);
|
emitter->emit_deref(arena, code, 2);
|
||||||
} else {
|
} 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;
|
parser->current_type = SYMBOL_NAT;
|
||||||
advance();
|
advance();
|
||||||
|
|
@ -679,7 +679,9 @@ variable(void)
|
||||||
if(sleq("length", parser->current.start, parser->current.length)) {
|
if(sleq("length", parser->current.start, parser->current.length)) {
|
||||||
emitter->emit_deref(arena, code, size);
|
emitter->emit_deref(arena, code, size);
|
||||||
} else {
|
} 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;
|
parser->current_type = SYMBOL_NAT;
|
||||||
advance();
|
advance();
|
||||||
|
|
@ -789,14 +791,16 @@ cast_type(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
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
|
void
|
||||||
declaration(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);
|
variable_declaration(nil);
|
||||||
else
|
else
|
||||||
statement();
|
statement();
|
||||||
|
|
@ -826,7 +830,8 @@ if_statement(void)
|
||||||
statement();
|
statement();
|
||||||
emitter->else_if_depth--;
|
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
|
void
|
||||||
|
|
@ -930,19 +935,33 @@ grouping(void)
|
||||||
void
|
void
|
||||||
number(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
|
void
|
||||||
string(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
|
void
|
||||||
character(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
|
void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue