diff --git a/src/ast/dump.c b/src/ast/dump.c index 796e993..e9d7922 100644 --- a/src/ast/dump.c +++ b/src/ast/dump.c @@ -56,6 +56,8 @@ static char *ast_dumpe(AST *tlc, AST *e) { return strdup(vte->data.var.name); } else if(vte->kind == SCOPEITEM_SYMBOL) { return strdup(vte->data.symbol.name); + } else if(vte->kind == SCOPEITEM_CEXPR) { + return ast_dumpe(tlc, vte->data.cexpr.concrete); } else abort(); } else if(e->nodeKind == AST_EXPR_UNARY_OP) { const char *op = NULL; diff --git a/src/parse.c b/src/parse.c index c4b4c35..14aae78 100644 --- a/src/parse.c +++ b/src/parse.c @@ -152,9 +152,10 @@ static char *parametrize_function_name(Type *t, const char *original, Scope *sco static void binop_implicit_cast(/*Parser *P, */ASTExprBinaryOp *binop) { if(type_size(binop->operands[0]->expression.type) < type_size(binop->operands[1]->expression.type)) { binop->operands[0] = ast_cast_expr(binop->operands[0], binop->operands[1]->expression.type); - } - - if(type_size(binop->operands[1]->expression.type) < type_size(binop->operands[0]->expression.type)) { + } else if(type_size(binop->operands[1]->expression.type) < type_size(binop->operands[0]->expression.type)) { + binop->operands[1] = ast_cast_expr(binop->operands[1], binop->operands[0]->expression.type); + } else { + binop->operands[0] = ast_cast_expr(binop->operands[0], binop->operands[0]->expression.type); binop->operands[1] = ast_cast_expr(binop->operands[1], binop->operands[0]->expression.type); } diff --git a/src/types.c b/src/types.c index db06d24..333fd32 100644 --- a/src/types.c +++ b/src/types.c @@ -293,17 +293,19 @@ Type *type_parametrize(Type *t, Scope *scope) { AST *n = vte->data.cexpr.concrete; - if(n) { - if(n->nodeKind == AST_EXPR_PRIMITIVE) { - t->array.length = n->exprPrim.val; - t->array.lengthIsGeneric = false; - } else if(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR) { - t->array.lengthGenericParamIdx = n->exprVar.thing->data.cexpr.paramIdx; - t->array.lengthGenericParamName = n->exprVar.thing->data.cexpr.paramName; - t->array.lengthIsGeneric = true; - } else { - stahp_node(n, "Invalid parametrization expression."); - } + while(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR && n->exprVar.thing->data.cexpr.concrete != NULL) { + n = n->exprVar.thing->data.cexpr.concrete; + } + + if(n->nodeKind == AST_EXPR_PRIMITIVE) { + t->array.length = n->exprPrim.val; + t->array.lengthIsGeneric = false; + } else if(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR) { + t->array.lengthGenericParamIdx = n->exprVar.thing->data.cexpr.paramIdx; + t->array.lengthGenericParamName = n->exprVar.thing->data.cexpr.paramName; + t->array.lengthIsGeneric = true; + } else { + stahp_node(n, "Invalid parametrization expression."); } } } diff --git a/src/x86/cg.c b/src/x86/cg.c index 5f24614..303b84d 100644 --- a/src/x86/cg.c +++ b/src/x86/cg.c @@ -497,10 +497,18 @@ void cg_chunk(CGState *cg, AST *a) { } else if(is_xop(s->stmtAssign.what) && s->stmtAssign.to->nodeKind == AST_EXPR_CAST) { - if(type_size(s->stmtAssign.what->expression.type) > type_size(s->stmtAssign.to->expression.type)) { + if(type_size(s->stmtAssign.what->expression.type) > type_size(s->stmtAssign.to->exprCast.what->expression.type)) { printf("movzx %s, %s\n", xop(cg->tlc, s->stmtAssign.what), xop(cg->tlc, s->stmtAssign.to->exprCast.what)); + } else if(type_size(s->stmtAssign.what->expression.type) > type_size(s->stmtAssign.to->exprCast.what->expression.type)) { + + /* + * LEMMA: For every register in x86, its lowest bits are accessible. + */ + + assert(0 && "Not implemented."); + } else { const char *dest = xop_sz(cg->tlc, s->stmtAssign.what, x86_max_gpr_size());