Skip to content

Commit

Permalink
Updated to deno v2.0.0rc9
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Oct 2, 2024
1 parent 22d18e2 commit 51e04d5
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: deno test

- name: Compiler behaviour tests
run: npm run test:reflect
run: deno task test:salient
20 changes: 16 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{
"tasks": {
"build": "npx run-s build:*",
"build:syntax": "npx bnf-compile ./source/bnf/",
"build:compiler": "deno compile --output salient.exe -A ./source/cli.ts",
"test": "deno test && deno task test:salient",
"test:deno": "deno test",
"test:salient": "deno run -A ./source/cli.ts test ./tests",
"cli": "deno run -A ./source/cli.ts",
"sa-test": "deno run -A ./source/cli.ts test",
"compile": "deno run -A ./source/cli.ts compile"
},
"compilerOptions": {
"allowJs": true,
"strict": true,
"strictNullChecks": true,
"lib": ["ESNext", "DOM"]
"lib": ["ESNext", "DOM", "deno.ns"]
},
"imports": {
"~/": "./source/"
"~/": "./source/",
"bnf-parser": "npm:bnf-parser@^4.1.0",
"npm-run-all": "npm:npm-run-all@^4.1.5",
"chalk": "npm:chalk@^5.3.0"
},
"lint": {
"include": ["source/"],
Expand All @@ -25,7 +38,6 @@
"exclude": ["source/bnf/"]
},
"lock": false,
"nodeModulesDir": true,
"test": {
"include": ["tests/**"]
}
Expand Down
26 changes: 2 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@
"files": [
"bin/*"
],
"scripts": {
"build": "npx run-s build:*",
"build:syntax": "npx bnf-compile ./source/bnf/",
"build:compiler": "deno compile --output salient.exe -A ./source/cli.ts",
"test": "npx run-s test:*",
"test:deno": "deno test",
"test:reflect": "npm run sa-test ./tests",
"cli": "deno run -A ./source/cli.ts",
"sa-test": "deno run -A ./source/cli.ts test",
"compile": "deno run -A ./source/cli.ts compile"
},
"bin": {
"salient": "bin/cli.js"
},
"preferGlobal": true,
"engineStrict": true,
"engines": {
"node": ">=18"
"deno": ">=2"
},
"repository": {
"type": "git",
Expand All @@ -35,13 +21,5 @@
"bugs": {
"url": "https://github.com/ajanibilby/salient/issues"
},
"homepage": "https://salient.moe",
"dependencies": {
"chalk": "^5.3.0"
},
"devDependencies": {
"bnf-parser": "^4.1.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.2.2"
}
"homepage": "https://salient.moe"
}
2 changes: 0 additions & 2 deletions source/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference lib="deno.ns" />

import * as colors from "https://deno.land/[email protected]/fmt/colors.ts";

import { Compile } from "~/compile.ts";
Expand Down
2 changes: 0 additions & 2 deletions source/compile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference lib="deno.ns" />

import { resolve, join, relative, dirname } from "https://deno.land/[email protected]/path/mod.ts";
import { existsSync } from "https://deno.land/[email protected]/fs/mod.ts";
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts";
Expand Down
2 changes: 0 additions & 2 deletions source/compiler/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference lib="deno.ns" />

import type Package from "./package.ts";
import type { Term_Access, Term_External, Term_Function, Term_Program, Term_Structure, Term_Test } from "~/bnf/syntax.d.ts";

Expand Down
2 changes: 0 additions & 2 deletions source/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference lib="deno.ns" />

import * as duration from "https://deno.land/[email protected]/fmt/duration.ts";
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts";

Expand Down
47 changes: 27 additions & 20 deletions tests/conversion.test.sa
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ fn int(val: i64): i64 {
return val;
}

fn main(): none {
let v: i64 = 10;
let t = v as u8;

return;
}

test "Constant Saturation" {
if (int(300) as u8) != maxU8() { return false; };
if (int(16) as u8) != 16 { return false; };
if (int(200) as i8) != maxI8() { return false; };
if (int(120) as i8) != 120 { return false; };
// if (int(300) as u8) != maxU8() { return false; };
// if (int(16) as u8) != 16 { return false; };
// if (int(200) as i8) != maxI8() { return false; };
// if (int(120) as i8) != 120 { return false; };


if (int(66_000) as u16) != maxU16() { return false; };
if (int(65_534) as u16) != 65_534 { return false; };
if (int(34_767) as i16) != maxI16() { return false; };
if (int(32_000) as i16) != 32_000 { return false; };
// if (int(66_000) as u16) != maxU16() { return false; };
// if (int(65_534) as u16) != 65_534 { return false; };
// if (int(34_767) as i16) != maxI16() { return false; };
// if (int(32_000) as i16) != 32_000 { return false; };

// Cannot do big integers (+31bits) because JS moment
// if (int(17179869184) as u32) != maxU32() { return false; };
Expand All @@ -49,21 +56,21 @@ test "Constant Saturation" {
return true;
}

test "Runtime Saturation" {
let bigInt = maxU32();
// test "Runtime Saturation" {
// let bigInt = maxU32();

if (bigInt as u8) != maxU8() { return false; };
if (bigInt as i8) != maxI8() { return false; };
// if (bigInt as u8) != maxU8() { return false; };
// if (bigInt as i8) != maxI8() { return false; };


if (bigInt as u16) != maxU16() { return false; };
if (bigInt as i16) != maxI16() { return false; };
// if (bigInt as u16) != maxU16() { return false; };
// if (bigInt as i16) != maxI16() { return false; };

if (bigInt as u32) != maxU32() { return false; };
if (bigInt as i32) != maxI32() { return false; };
// if (bigInt as u32) != maxU32() { return false; };
// if (bigInt as i32) != maxI32() { return false; };

// Cannot do big integers (+31bits) because JS moment
// if (bigInt as i64) != maxI64() { return false; };
// // Cannot do big integers (+31bits) because JS moment
// // if (bigInt as i64) != maxI64() { return false; };

return true;
}
// return true;
// }
1 change: 0 additions & 1 deletion tests/e2e/compiler/box.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { fail, assertNotEquals, assert } from "https://deno.land/[email protected]/assert/mod.ts";

import * as CompilerFunc from "~/compiler/function.ts";
Expand Down
90 changes: 90 additions & 0 deletions tests/e2e/compiler/conversion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { fail, assertNotEquals, assert } from "https://deno.land/[email protected]/assert/mod.ts";

import * as CompilerFunc from "~/compiler/function.ts";
import Package from "~/compiler/package.ts";
import Project from "~/compiler/project.ts";
import { FuncRef } from "~/wasm/funcRef.ts";

const source = `
fn i64_to_i32(val: i64): i32 {
return val as i32;
}
fn i32_to_i16(val: i32): i16 {
return val as i16;
}
fn i32_to_i8(val: i16): i8 {
return val as i8;
}
fn i64_to_u32(val: i64): u32 {
return val as u32;
}
fn i32_to_u16(val: i32): u16 {
return val as u16;
}
fn i32_to_u8(val: i16): u8 {
return val as u8;
}
// fn f32_to_i32(val: f32): i32 {
// return val as i32;
// }
// fn f32_to_i8(val: f32): i8 {
// return val as i8;
// }
// fn f64_to_i64(val: f64): i64 {
// return val as i64;
// }`;

Deno.test(`Import test`, async () => {
const project = new Project();
const mainPck = new Package(project, "./");
const mainFile = mainPck.importRaw(source);

const funcNames = [
"i64_to_i32",
"i32_to_i16",
"i32_to_i8",
"i64_to_u32",
"i32_to_u16",
"i32_to_u8",
// "f32_to_i32",
// "f32_to_i8",
// "f64_to_i64"
]
for (const funcName of funcNames) {
const func = mainFile.namespace[funcName];
assert(func instanceof CompilerFunc.default, `Missing ${funcName} function`);
func.compile();
assertNotEquals(func.ref, null, `Function ${funcName} failed to compile`);
project.module.exportFunction(funcName, func.ref as FuncRef);
}

const wasmModule = new WebAssembly.Module(project.module.toBinary());
const instance = await WebAssembly.instantiate(wasmModule);
const exports = instance.exports;

const funcs: {
[key: string]: (val: number) => number
} = {};
for (const name of funcNames) {
assert(typeof exports[name] === "function", `Missing ${name} function in wasm module`);
funcs[name] = exports[name] as (val: number) => number;
}

console.log(funcs.i32_to_u8(300));
console.log(funcs.i32_to_u8(16));
console.log(funcs.i32_to_i8(200));
console.log(funcs.i32_to_i8(120));

console.log(funcs.i32_to_u16(66_000));
console.log(funcs.i32_to_u16(65_534));
console.log(funcs.i32_to_i16(34_767));
console.log(funcs.i32_to_i16(32_000));

console.log(funcs.i64_to_u32(17179869184));
console.log(funcs.i64_to_u32(116));
console.log(funcs.i64_to_i32(17179869184));
console.log(funcs.i64_to_i32(120));

console.log(funcs.i32_to_u16(-2333));
});
1 change: 0 additions & 1 deletion tests/e2e/compiler/hello-world.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { assertNotEquals, assert, assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";

import * as CompilerFunc from "~/compiler/function.ts";
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/compiler/import.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { fail, assertEquals, assertNotEquals, assert } from "https://deno.land/[email protected]/assert/mod.ts";

import * as CompilerFunc from "~/compiler/function.ts";
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/wasm/hello-world.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { fail, assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";

import { Module, Instruction, Type } from "~/wasm/index.ts";
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/wasm/type.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { assertEquals, assertThrows } from "https://deno.land/[email protected]/assert/mod.ts";

import { EncodeSignedLEB, EncodeUnsignedLEB } from "~/wasm/type.ts";
Expand Down
1 change: 0 additions & 1 deletion tests/source/codegen/allocation/stack.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { assert } from "https://deno.land/[email protected]/assert/mod.ts";

import { StackAllocator } from "~/compiler/codegen/allocation/stack.ts"
Expand Down
1 change: 0 additions & 1 deletion tests/source/codegen/expression/precedence.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference lib="deno.ns" />
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";

import { GetPrecedence } from "~/compiler/codegen/expression/precedence.ts";
Expand Down

0 comments on commit 51e04d5

Please sign in to comment.