WIP more array stuff
This commit is contained in:
parent
974d282d7a
commit
f8008e81d5
|
|
@ -40,7 +40,7 @@ print_help()
|
||||||
"output, currently Uxn tal code and Reality Engine rom.\n\n");
|
"output, currently Uxn tal code and Reality Engine rom.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MEM_SIZE 64000
|
#define MEM_SIZE (1 << 16)
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
|
|
|
||||||
30
compiler.c
30
compiler.c
|
|
@ -361,6 +361,20 @@ ParseRule *get_rule(TokenType type);
|
||||||
void parse_precedence(Precedence precedence);
|
void parse_precedence(Precedence precedence);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
FIXME: we need to move the string to be on the heap instead of the stack
|
||||||
|
so we need special handling in variable_dec
|
||||||
|
|
||||||
|
During the first pass we need to append the string label @variable
|
||||||
|
and then the hexed out literal.
|
||||||
|
|
||||||
|
every time we reference the string we should reference the global ptr.
|
||||||
|
|
||||||
|
If the string gets appended then we should copy and use the local varaiable
|
||||||
|
|
||||||
|
but for string conts or array conts we should use the global ref '@'
|
||||||
|
*/
|
||||||
|
|
||||||
u32
|
u32
|
||||||
variable_declaration(Symbol *def)
|
variable_declaration(Symbol *def)
|
||||||
{
|
{
|
||||||
|
|
@ -368,6 +382,7 @@ variable_declaration(Symbol *def)
|
||||||
TokenType tt = parser.previous.type;
|
TokenType tt = parser.previous.type;
|
||||||
SymbolType st = token_type_to_sym_type(tt);
|
SymbolType st = token_type_to_sym_type(tt);
|
||||||
Symbol *variable;
|
Symbol *variable;
|
||||||
|
List *array_literal;
|
||||||
|
|
||||||
if (parser.current.type == TOKEN_LBRACE) {
|
if (parser.current.type == TOKEN_LBRACE) {
|
||||||
while(!check(TOKEN_RBRACKET)) {
|
while(!check(TOKEN_RBRACKET)) {
|
||||||
|
|
@ -378,13 +393,20 @@ variable_declaration(Symbol *def)
|
||||||
parser.previous.start,
|
parser.previous.start,
|
||||||
parser.previous.length);
|
parser.previous.length);
|
||||||
|
|
||||||
if (check(TOKEN_EQ)) {
|
if (match(TOKEN_EQ)) {
|
||||||
|
expect(TOKEN_LBRACKET);
|
||||||
|
|
||||||
|
while (!match(TOKEN_RBRACKET)) {
|
||||||
|
StrBuf_append_exactly(arena, array_literal,
|
||||||
|
(char*)parser.previous.start,
|
||||||
|
parser.previous.length);
|
||||||
|
if(match(TOKEN_RBRACKET)) break;
|
||||||
|
expect(TOKEN_COMMA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!check(TOKEN_SEMICOLON)) {
|
expect(TOKEN_SEMICOLON);
|
||||||
advance();
|
emitter.emit_array(arena, memory, variable, array_literal);
|
||||||
}
|
|
||||||
|
|
||||||
return variable->size;
|
return variable->size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
emit.h
3
emit.h
|
|
@ -11,6 +11,7 @@ typedef void (*SymbolEmit)(Arena *a, List *out, Symbol *sym);
|
||||||
typedef void (*VoidArgEmit)(Arena *a, List *out);
|
typedef void (*VoidArgEmit)(Arena *a, List *out);
|
||||||
typedef void (*StrArgEmit)(Arena *a, List *out, const char *str, i32 length);
|
typedef void (*StrArgEmit)(Arena *a, List *out, const char *str, i32 length);
|
||||||
typedef void (*VarEmit)(Arena *a, List *out, Symbol *sym, bool local);
|
typedef void (*VarEmit)(Arena *a, List *out, Symbol *sym, bool local);
|
||||||
|
typedef void (*MultipleEmit)(Arena *a, List *out, Symbol *sym, List* in);
|
||||||
typedef void (*I32ArgEmit)(Arena *a, List *out, i32 val);
|
typedef void (*I32ArgEmit)(Arena *a, List *out, i32 val);
|
||||||
|
|
||||||
typedef struct emitter_s Emitter;
|
typedef struct emitter_s Emitter;
|
||||||
|
|
@ -43,7 +44,7 @@ struct emitter_s {
|
||||||
StrArgEmit emit_byte;
|
StrArgEmit emit_byte;
|
||||||
StrArgEmit emit_str;
|
StrArgEmit emit_str;
|
||||||
VarEmit emit_type;
|
VarEmit emit_type;
|
||||||
VoidArgEmit emit_array;
|
MultipleEmit emit_array;
|
||||||
SymbolEmit emit_function;
|
SymbolEmit emit_function;
|
||||||
VoidArgEmit emit_plex;
|
VoidArgEmit emit_plex;
|
||||||
VoidArgEmit emit_method;
|
VoidArgEmit emit_method;
|
||||||
|
|
|
||||||
115
emit/uxn/emit.c
115
emit/uxn/emit.c
|
|
@ -836,10 +836,119 @@ uxn_emit_constant(Arena *a, List *out, Symbol *sym, bool local)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uxn_emit_array(Arena *a, List *out)
|
uxn_emit_array(Arena *a, List *out, Symbol *sym, List *in)
|
||||||
{
|
{
|
||||||
USED(a);
|
Node *curr;
|
||||||
USED(out);
|
SymbolType t = sym->secondary_type;
|
||||||
|
|
||||||
|
sprintf(uxn_temp_strbuf, "@%.*s ", sym->name_length, sym->name);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
|
||||||
|
switch(t) {
|
||||||
|
case SYMBOL_BOOL: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
if (sleq(tmp_str, "true", 4)) {
|
||||||
|
StrBuf_append(a, out, "0001 ");
|
||||||
|
} else {
|
||||||
|
StrBuf_append(a, out, "0000 ");
|
||||||
|
}
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_U8:
|
||||||
|
case SYMBOL_BYTE: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
u8 i = (u8)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_INT: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
i32 i = (i32)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_U32:
|
||||||
|
case SYMBOL_ARRAY:
|
||||||
|
case SYMBOL_PLEX:
|
||||||
|
case SYMBOL_STR:
|
||||||
|
case SYMBOL_NAT: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
u32 i = (u32)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_I8: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
i8 i = (i8)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_I16: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
i16 i = (i16)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_U16: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
u16 i = (u16)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%04x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_I32: {
|
||||||
|
curr = in->head;
|
||||||
|
while (curr) {
|
||||||
|
char* tmp_str = node_value(curr);
|
||||||
|
i32 i = (i32)strtol(tmp_str, nil, 10);
|
||||||
|
sprintf(uxn_temp_strbuf, "%08x ", i);
|
||||||
|
StrBuf_append(a, out, uxn_temp_strbuf);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYMBOL_F32:
|
||||||
|
case SYMBOL_REAL: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StrBuf_append(a, out, "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue