mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 16:35:03 +01:00
Add I32, mirroring Wasm i32
This commit is contained in:
parent
89dbb50add
commit
50e82066c9
5 changed files with 28 additions and 3 deletions
12
src/ast.ts
12
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 = {
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -178,6 +178,9 @@ export function printTy(ty: Ty): string {
|
|||
case "int": {
|
||||
return "Int";
|
||||
}
|
||||
case "i32": {
|
||||
return "I32";
|
||||
}
|
||||
case "bool": {
|
||||
return "Bool";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue