Cast fixes

This commit is contained in:
Mid 2025-09-19 19:03:50 +03:00
parent 14ab1f432d
commit 1708faf14d
4 changed files with 28 additions and 15 deletions

View File

@ -56,6 +56,8 @@ static char *ast_dumpe(AST *tlc, AST *e) {
return strdup(vte->data.var.name); return strdup(vte->data.var.name);
} else if(vte->kind == SCOPEITEM_SYMBOL) { } else if(vte->kind == SCOPEITEM_SYMBOL) {
return strdup(vte->data.symbol.name); return strdup(vte->data.symbol.name);
} else if(vte->kind == SCOPEITEM_CEXPR) {
return ast_dumpe(tlc, vte->data.cexpr.concrete);
} else abort(); } else abort();
} else if(e->nodeKind == AST_EXPR_UNARY_OP) { } else if(e->nodeKind == AST_EXPR_UNARY_OP) {
const char *op = NULL; const char *op = NULL;

View File

@ -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) { static void binop_implicit_cast(/*Parser *P, */ASTExprBinaryOp *binop) {
if(type_size(binop->operands[0]->expression.type) < type_size(binop->operands[1]->expression.type)) { 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); binop->operands[0] = ast_cast_expr(binop->operands[0], binop->operands[1]->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);
if(type_size(binop->operands[1]->expression.type) < type_size(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); binop->operands[1] = ast_cast_expr(binop->operands[1], binop->operands[0]->expression.type);
} }

View File

@ -293,17 +293,19 @@ Type *type_parametrize(Type *t, Scope *scope) {
AST *n = vte->data.cexpr.concrete; AST *n = vte->data.cexpr.concrete;
if(n) { while(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR && n->exprVar.thing->data.cexpr.concrete != NULL) {
if(n->nodeKind == AST_EXPR_PRIMITIVE) { n = n->exprVar.thing->data.cexpr.concrete;
t->array.length = n->exprPrim.val; }
t->array.lengthIsGeneric = false;
} else if(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR) { if(n->nodeKind == AST_EXPR_PRIMITIVE) {
t->array.lengthGenericParamIdx = n->exprVar.thing->data.cexpr.paramIdx; t->array.length = n->exprPrim.val;
t->array.lengthGenericParamName = n->exprVar.thing->data.cexpr.paramName; t->array.lengthIsGeneric = false;
t->array.lengthIsGeneric = true; } else if(n->nodeKind == AST_EXPR_VAR && n->exprVar.thing->kind == SCOPEITEM_CEXPR) {
} else { t->array.lengthGenericParamIdx = n->exprVar.thing->data.cexpr.paramIdx;
stahp_node(n, "Invalid parametrization expression."); t->array.lengthGenericParamName = n->exprVar.thing->data.cexpr.paramName;
} t->array.lengthIsGeneric = true;
} else {
stahp_node(n, "Invalid parametrization expression.");
} }
} }
} }

View File

@ -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) { } 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)); 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 { } else {
const char *dest = xop_sz(cg->tlc, s->stmtAssign.what, x86_max_gpr_size()); const char *dest = xop_sz(cg->tlc, s->stmtAssign.what, x86_max_gpr_size());