parser
Dibyendu Majumdar 4 years ago
parent 8600378cce
commit 5ce1cc3c64

@ -213,11 +213,11 @@ struct ast_node {
struct var_type type;
struct lua_symbol *var;
} symbol_expr;
struct {
struct { /* AST_Y_INDEX_EXPR */
struct var_type type;
struct ast_node *expr; /* '[' expr ']' */
} index_expr;
struct {
struct { /* AST_UNARY_EXPR */
struct var_type type;
UnOpr unary_op;
struct ast_node *expr;
@ -240,10 +240,10 @@ struct ast_node {
struct lua_symbol_list *upvalues; /* List of upvalues */
struct lua_symbol_list *locals; /* List of locals */
} function_expr; /* a literal expression whose result is a value of type function */
struct {
struct { /* AST_INDEXED_ASSIGN_EXPR - used in table constructor */
struct var_type type;
struct ast_node *
index_expr; /* If NULL means this is a list field with next available index, else specfies index expression */
struct ast_node *index_expr; /* If NULL means this is a list field with next available index, else specifies index
expression */
struct ast_node *value_expr;
} indexed_assign_expr; /* Assign values in table constructor */
struct {
@ -251,6 +251,8 @@ struct ast_node {
struct ast_node_list *expr_list;
} table_expr; /* table constructor expression */
struct {
/* suffixedexp -> primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
/* suffix_list may have AST_FIELD_SELECTOR_EXPR, AST_Y_INDEX_EXPR, AST_FUNCTION_CALL_EXPR */
struct var_type type;
struct ast_node *primary_expr;
struct ast_node_list *suffix_list;
@ -368,7 +370,17 @@ enum opcode {
op_bnot,
};
enum pseudo_type { PSEUDO_LOCAL, PSEUDO_TEMP_FLT, PSEUDO_TEMP_INT, PSEUDO_TEMP_ANY, PSEUDO_CONSTANT, PSEUDO_PROC, PSEUDO_NIL, PSEUDO_TRUE, PSEUDO_FALSE };
enum pseudo_type {
PSEUDO_LOCAL,
PSEUDO_TEMP_FLT,
PSEUDO_TEMP_INT,
PSEUDO_TEMP_ANY,
PSEUDO_CONSTANT,
PSEUDO_PROC,
PSEUDO_NIL,
PSEUDO_TRUE,
PSEUDO_FALSE
};
/* pseudo represents a pseudo (virtual) register */
struct pseudo {

@ -349,7 +349,7 @@ static struct pseudo *linearize_unaryop(struct proc *proc, struct ast_node *node
struct instruction *insn = alloc_instruction(proc, targetop);
struct pseudo *target = subexpr;
if (op == OPR_TO_TYPE) {
struct constant *tname_constant = allocate_string_constant(proc, node->unary_expr.type.type_name);
const struct constant *tname_constant = allocate_string_constant(proc, node->unary_expr.type.type_name);
struct pseudo *tname_pseudo = allocate_constant_pseudo(proc, tname_constant);
ptrlist_add((struct ptr_list **)&insn->operands, tname_pseudo, &proc->linearizer->ptrlist_allocator);
}
@ -524,6 +524,31 @@ static struct pseudo *linearize_function_expr(struct proc *proc, struct ast_node
return target;
}
/*
* Suffixed expression examples:
* f()[1]
* x[1][2]
* x.y[1]
*/
static struct pseudo * linearize_suffixedexpr(struct proc* proc, struct ast_node* node) {
/* suffixedexp -> primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
struct pseudo *prev_psedo = linearize_expr(proc, node->suffixed_expr.primary_expr);
struct ast_node* prev_node = node->suffixed_expr.primary_expr;
struct ast_node* this_node;
FOR_EACH_PTR(node->suffixed_expr.suffix_list, this_node) {
if (this_node->type == AST_Y_INDEX_EXPR) {
}
else if (this_node->type == AST_FIELD_SELECTOR_EXPR) {
}
else if (this_node->type == AST_FUNCTION_CALL_EXPR) {
}
prev_node = this_node;
}
END_FOR_EACH_PTR(node);
//copy_type(node->suffixed_expr.type, prev_node->common_expr.type);
}
static struct pseudo *linearize_expr(struct proc *proc, struct ast_node *expr) {
switch (expr->type) {
case AST_LITERAL_EXPR: {

Loading…
Cancel
Save