diff --git a/src/ast.ts b/src/ast.ts index 82cd512..d652445 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -174,7 +174,7 @@ export type IntTy = export type UnaryOp = | "Not" - | "Negate" + | "Neg" | "Ref" | "RefMut" | "Deref"; @@ -194,10 +194,10 @@ export type BinaryOp = | "Shl" | "Shr" | "Add" - | "Subtract" - | "Multiply" - | "Divide" - | "Remainder"; + | "Sub" + | "Mul" + | "Div" + | "Rem"; export type RangeLimit = "Inclusive" | "Exclusive"; diff --git a/src/front/check.ts b/src/front/check.ts index 28cb47b..6c9b9eb 100644 --- a/src/front/check.ts +++ b/src/front/check.ts @@ -409,7 +409,7 @@ class ExprChecker { private checkUnaryExpr(node: ast.NodeWithKind<"UnaryExpr">): Ty { const exprTy = this.cx.expr(node.kind.expr); - if (node.kind.op === "Negate" && exprTy.compatibleWith(Ty.I32)) { + if (node.kind.op === "Neg" && exprTy.compatibleWith(Ty.I32)) { return Ty.I32; } if (node.kind.op === "Not" && exprTy.compatibleWith(Ty.Bool)) { @@ -605,7 +605,13 @@ type BinaryOpTest = (op: ast.BinaryOp, left: Ty, right: Ty) => Ty | null; const binaryOpTests: BinaryOpTest[] = [ (op, left, right) => { - const ops = ["Add", "Subtract", "Multiply", "Divide", "Remainder"]; + const ops: ast.BinaryOp[] = [ + "Add", + "Sub", + "Mul", + "Div", + "Rem", + ]; if ( ops.includes(op) && left.is("Int") && left.compatibleWith(right) ) { @@ -614,7 +620,7 @@ const binaryOpTests: BinaryOpTest[] = [ return null; }, (op, left, right) => { - const ops = ["Eq", "Ne", "Lt", "Gt", "Lte", "Gte"]; + const ops: ast.BinaryOp[] = ["Eq", "Ne", "Lt", "Gt", "Lte", "Gte"]; if ( ops.includes(op) && left.is("Int") && left.compatibleWith(right) ) { diff --git a/src/front/parse.ts b/src/front/parse.ts index 4267f47..2965b0c 100644 --- a/src/front/parse.ts +++ b/src/front/parse.ts @@ -197,10 +197,10 @@ export class Parser { ["<<", "Shl", 3], [">>", "Shr", 3], ["+", "Add", 2], - ["-", "Subtract", 2], - ["*", "Multiply", 1], - ["/", "Divide", 1], - ["%", "Remainder", 1], + ["-", "Sub", 2], + ["*", "Mul", 1], + ["/", "Div", 1], + ["%", "Rem", 1], ]; let left = this.parseBinary(prec - 1); @@ -228,7 +228,7 @@ export class Parser { const loc = this.loc(); const ops: [Tok["type"], ast.UnaryOp][] = [ ["not", "Not"], - ["-", "Negate"], + ["-", "Neg"], ["*", "Deref"], ]; for (const [tok, op] of ops) { diff --git a/src/middle.ts b/src/middle.ts index d17c359..8f29fbe 100644 --- a/src/middle.ts +++ b/src/middle.ts @@ -356,7 +356,7 @@ class FnLowerer { const resultTy = this.tys.expr(expr); const operandTy = this.tys.expr(expr.kind.expr); if ( - expr.kind.op === "Negate" && + expr.kind.op === "Neg" && operandTy.compatibleWith(Ty.I32) && resultTy.compatibleWith(Ty.I32) ) { @@ -435,21 +435,14 @@ type BinaryOpTest = ( const binaryOpTests: BinaryOpTest[] = [ (op, left, right, result) => { - const ops = ["Add", "Subtract", "Multiply", "Divide", "Remainder"]; - const tags: Record = { - "Add": "Add", - "Subtract": "Sub", - "Multiply": "Mul", - "Divide": "Div", - "Remainder": "Rem", - }; + const ops: ast.BinaryOp[] = ["Add", "Sub", "Mul", "Div", "Rem"]; if ( ops.includes(op) && left.is("Int") && left.compatibleWith(right) && result.compatibleWith(left) ) { - return tags[op]; + return op as BinaryOp; } return null; },