Cast fixes
This commit is contained in:
parent
14ab1f432d
commit
1708faf14d
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
24
src/types.c
24
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/x86/cg.c
10
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());
|
||||
|
Loading…
Reference in New Issue
Block a user