debbuging failure to read from builtin map
This commit is contained in:
@@ -33,6 +33,7 @@ typedef enum {
|
||||
EXPR_ASS,
|
||||
EXPR_INT,
|
||||
EXPR_CALL,
|
||||
EXPR_LIST,
|
||||
EXPR_NONE,
|
||||
EXPR_TRUE,
|
||||
EXPR_FALSE,
|
||||
@@ -78,6 +79,12 @@ typedef struct {
|
||||
int len;
|
||||
} StringExprNode;
|
||||
|
||||
typedef struct {
|
||||
ExprNode base;
|
||||
Node *items;
|
||||
int itemc;
|
||||
} ListExprNode;
|
||||
|
||||
typedef struct {
|
||||
ExprNode base;
|
||||
char *val;
|
||||
|
||||
@@ -113,6 +113,42 @@ static _Bool emit_instr_for_node(ExeBuilder *exeb, Node *node, Error *error)
|
||||
return ExeBuilder_Append(exeb, error, OPCODE_PUSHVAR, &op, 1, node->offset, node->length);
|
||||
}
|
||||
|
||||
case EXPR_LIST:
|
||||
{
|
||||
// PUSHLST
|
||||
// PUSHINT
|
||||
// <expr>
|
||||
// INSERT
|
||||
|
||||
ListExprNode *l = (ListExprNode*) node;
|
||||
|
||||
Operand op;
|
||||
|
||||
op = (Operand) { .type = OPTP_INT, .as_int = l->itemc };
|
||||
if(!ExeBuilder_Append(exeb, error, OPCODE_PUSHLST, &op, 1, node->offset, node->length))
|
||||
return 0;
|
||||
|
||||
Node *item = l->items;
|
||||
int i = 0;
|
||||
|
||||
while(item)
|
||||
{
|
||||
op = (Operand) { .type = OPTP_INT, .as_int = i };
|
||||
if(!ExeBuilder_Append(exeb, error, OPCODE_PUSHINT, &op, 1, item->offset, item->length))
|
||||
return 0;
|
||||
|
||||
if(!emit_instr_for_node(exeb, item, error))
|
||||
return 0;
|
||||
|
||||
if(!ExeBuilder_Append(exeb, error, OPCODE_INSERT, NULL, 0, item->offset, item->length))
|
||||
return 0;
|
||||
|
||||
i += 1;
|
||||
item = item->next;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
case EXPR_CALL:
|
||||
{
|
||||
CallExprNode *p = (CallExprNode*) expr;
|
||||
|
||||
@@ -651,6 +651,96 @@ static Node *parse_string_primary_expression(Context *ctx)
|
||||
return (Node*) node;
|
||||
}
|
||||
|
||||
static Node *parse_list_primary_expression(Context *ctx)
|
||||
{
|
||||
assert(ctx != NULL);
|
||||
|
||||
if(done(ctx))
|
||||
{
|
||||
Error_Report(ctx->error, 0, "Source ended where a list literal was expected");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(current(ctx) != '[')
|
||||
{
|
||||
Error_Report(ctx->error, 0, "Got token \"%.*s\" where a list literal was expected", ctx->token->length, ctx->src + ctx->token->offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int offset = current_token(ctx)->offset;
|
||||
|
||||
Node *items = NULL;
|
||||
int itemc = 0;
|
||||
|
||||
next(ctx); // Skip the '['.
|
||||
|
||||
if(current(ctx) != ']')
|
||||
{
|
||||
Node *tail = NULL;
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Parse.
|
||||
Node *item = parse_expression(ctx);
|
||||
|
||||
if(item == NULL)
|
||||
return NULL;
|
||||
|
||||
// Append.
|
||||
if(tail)
|
||||
tail->next = item;
|
||||
else
|
||||
items = item;
|
||||
tail = item;
|
||||
itemc += 1;
|
||||
|
||||
// Get ',' or ']'.
|
||||
|
||||
if(current(ctx) == ']')
|
||||
break;
|
||||
|
||||
if(current(ctx) != ',')
|
||||
{
|
||||
if(current(ctx) == TDONE)
|
||||
Error_Report(ctx->error, 0, "Source ended inside a list literal");
|
||||
else
|
||||
Error_Report(ctx->error, 0, "Got unexpected token \"%.*s\" inside list literal, where ',' or ']' were expected", ctx->token->length, ctx->src + ctx->token->offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
next(ctx); // Skip the ','.
|
||||
}
|
||||
}
|
||||
|
||||
int length = current_token(ctx)->offset
|
||||
+ current_token(ctx)->length
|
||||
- offset;
|
||||
|
||||
next(ctx); // Skip the ']'.
|
||||
|
||||
ListExprNode *list;
|
||||
{
|
||||
list = BPAlloc_Malloc(ctx->alloc, sizeof(ListExprNode));
|
||||
|
||||
if(list == NULL)
|
||||
{
|
||||
Error_Report(ctx->error, 1, "No memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->base.base.kind = NODE_EXPR;
|
||||
list->base.base.next = NULL;
|
||||
list->base.base.offset = offset;
|
||||
list->base.base.length = length;
|
||||
list->base.kind = EXPR_LIST;
|
||||
list->items = items;
|
||||
list->itemc = itemc;
|
||||
}
|
||||
|
||||
return (Node*) list;
|
||||
|
||||
}
|
||||
|
||||
static char *copy_token_text(Context *ctx)
|
||||
{
|
||||
char *copy = BPAlloc_Malloc(ctx->alloc, ctx->token->length + 1);
|
||||
@@ -705,6 +795,9 @@ static Node *parse_primary_expresion(Context *ctx)
|
||||
return (Node*) temp;
|
||||
}
|
||||
|
||||
case '[':
|
||||
return parse_list_primary_expression(ctx);
|
||||
|
||||
case '(':
|
||||
{
|
||||
next(ctx); // Consume the '('.
|
||||
|
||||
Reference in New Issue
Block a user