diff --git a/src/ast.ts b/src/ast.ts index 92f636e..ed9b352 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -115,7 +115,7 @@ export type ExprBreak = { * The break target block. * May be any control flow block, labelled from inside out. */ - target?: number, + target?: number; }; export type ExprStructLiteral = { @@ -261,6 +261,7 @@ export const BUILTINS = [ "print", "String", "Int", + "I32", "Bool", "true", "false", @@ -282,7 +283,10 @@ export type TyString = { export type TyInt = { kind: "int"; - signed: boolean; +}; + +export type TyI32 = { + kind: "i32"; }; export type TyBool = { @@ -328,6 +332,7 @@ export type TyNever = { export type Ty = | TyString | TyInt + | TyI32 | TyBool | TyList | TyTuple @@ -343,7 +348,8 @@ export function tyIsUnit(ty: Ty): ty is TyUnit { export const TY_UNIT: Ty = { kind: "tuple", elems: [] }; export const TY_STRING: Ty = { kind: "string" }; export const TY_BOOL: Ty = { kind: "bool" }; -export const TY_INT: Ty = { kind: "int", signed: false }; +export const TY_INT: Ty = { kind: "int" }; +export const TY_I32: Ty = { kind: "i32" }; export const TY_NEVER: Ty = { kind: "never" }; export type TypeckResults = { diff --git a/src/index.ts b/src/index.ts index 25b2923..7c6f023 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,11 +10,15 @@ import fs from "fs"; import { exec } from "child_process"; const input = ` +// import "wasi_snapshot_preview1" "fd_write"(a: I32, b: I32, c: I32, d: I32): I32; + function main() = ( loop (no(break);); uwu(10); ); +function meow(a: I32): I32 = a; + function no(a: !): String = a; function uwu(a: Int) = if a != 0 then ( diff --git a/src/lower.ts b/src/lower.ts index b32eb52..0d9b0ee 100644 --- a/src/lower.ts +++ b/src/lower.ts @@ -524,6 +524,8 @@ function computeAbi(ty: TyFn): FnAbi { todo("fn abi"); case "int": return ["i64"]; + case "i32": + return ["i32"]; case "bool": return ["i32"]; case "list": @@ -572,6 +574,8 @@ function wasmTypeForBody(ty: Ty): wasm.ValType[] { return STRING_TYPES; case "int": return ["i64"]; + case "i32": + return ["i32"]; case "bool": return ["i32"]; case "list": diff --git a/src/printer.ts b/src/printer.ts index 4b28fb2..4ecd65c 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -178,6 +178,9 @@ export function printTy(ty: Ty): string { case "int": { return "Int"; } + case "i32": { + return "I32"; + } case "bool": { return "Bool"; } diff --git a/src/typeck.ts b/src/typeck.ts index e0eebf1..f15a558 100644 --- a/src/typeck.ts +++ b/src/typeck.ts @@ -15,6 +15,7 @@ import { Resolution, Ty, TY_BOOL, + TY_I32, TY_INT, TY_NEVER, TY_STRING, @@ -34,6 +35,9 @@ function builtinAsTy(name: string, span: Span): Ty { case "Int": { return TY_INT; } + case "I32": { + return TY_I32; + } case "Bool": { return TY_BOOL; } @@ -355,6 +359,10 @@ export class InferContext { if (rhs.kind === "int") return; break; } + case "i32": { + if (rhs.kind === "i32") return; + break; + } case "bool": { if (rhs.kind === "bool") return; break;