mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
generate more code
This commit is contained in:
parent
ccd8008731
commit
42bc96dbce
7 changed files with 306 additions and 51 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue