generate more code

This commit is contained in:
nora 2023-07-26 20:50:48 +02:00
parent ccd8008731
commit 42bc96dbce
7 changed files with 306 additions and 51 deletions

View file

@ -147,7 +147,7 @@ export function typeck(ast: Ast): Ast {
const returnType = item.node.returnType && {
...item.node.returnType,
ty: fnTy.returnTy,
};
};
return {
kind: "function",
node: {
@ -506,11 +506,11 @@ function checkBinary(expr: Expr & ExprBinary): Expr {
let lhsTy = expr.lhs.ty!;
let rhsTy = expr.rhs.ty!;
if (lhsTy.kind === "int" && rhsTy.kind === "int") {
return { ...expr, ty: TY_INT };
}
if (COMPARISON_KINDS.includes(expr.binaryKind)) {
if (lhsTy.kind === "int" && rhsTy.kind === "int") {
return { ...expr, ty: TY_BOOL };
}
if (lhsTy.kind === "string" && rhsTy.kind === "string") {
return { ...expr, ty: TY_BOOL };
}
@ -522,6 +522,10 @@ function checkBinary(expr: Expr & ExprBinary): Expr {
}
}
if (lhsTy.kind === "int" && rhsTy.kind === "int") {
return { ...expr, ty: TY_INT };
}
if (LOGICAL_KINDS.includes(expr.binaryKind)) {
if (lhsTy.kind === "bool" && rhsTy.kind === "bool") {
return { ...expr, ty: TY_BOOL };
@ -547,7 +551,7 @@ function checkUnary(expr: Expr & ExprUnary): Expr {
}
if (expr.unaryKind === "-" && rhsTy.kind == "int") {
return { ...expr, ty: rhsTy };
// Negating an unsigned integer is a bad idea.
}
throw new CompilerError(