-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79dafc8
commit 3db919d
Showing
32 changed files
with
761 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ jobs: | |
run: deno test | ||
|
||
- name: Compiler behaviour tests | ||
run: npm run test:reflect | ||
run: deno task test:salient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
/// <reference lib="deno.ns" /> | ||
|
||
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
|
||
import { Compile } from "~/compile.ts"; | ||
import { Panic } from "~/compiler/helper.ts"; | ||
import { Test } from "~/test.ts"; | ||
|
||
if (Deno.args.includes("--version")) { | ||
console.log("version: 0.0.0"); | ||
console.info("version: 0.0.0"); | ||
Deno.exit(0); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/// <reference lib="deno.ns" /> | ||
|
||
import { resolve, join, relative } from "https://deno.land/[email protected]/path/mod.ts"; | ||
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"; | ||
|
||
|
@@ -9,6 +7,7 @@ import Package from "~/compiler/package.ts"; | |
import Project from "~/compiler/project.ts"; | ||
import { DisplayTimers, TimerStart, TimerEnd } from "~/helper.ts"; | ||
import { Panic } from "~/compiler/helper.ts"; | ||
import { File } from "~/compiler/file.ts"; | ||
|
||
|
||
export async function Compile(entry: string, config: { | ||
|
@@ -22,9 +21,16 @@ export async function Compile(entry: string, config: { | |
); | ||
|
||
const project = new Project(); | ||
const mainPck = new Package(project, root); | ||
const mainPck = new Package(project, dirname(root)); | ||
|
||
let mainFile: File; | ||
try { | ||
mainFile = mainPck.import(root); | ||
} catch (e) { | ||
console.error(e); | ||
Deno.exit(1); | ||
} | ||
|
||
const mainFile = mainPck.import(root); | ||
const mainFunc = mainFile.namespace["main"]; | ||
if (!(mainFunc instanceof Function)) Panic( | ||
`Main namespace is not a function: ${colors.cyan(mainFunc.constructor.name)}` | ||
|
@@ -58,8 +64,8 @@ export async function Compile(entry: string, config: { | |
} | ||
if (config.time) TimerEnd("wasm2wat"); | ||
|
||
console.log(new TextDecoder().decode(stdout)); | ||
console.log(` out: "out.wasm" + "out.wat"\n`); | ||
console.info(new TextDecoder().decode(stdout)); | ||
console.info(` out: "out.wasm" + "out.wat"\n`); | ||
|
||
if (config.time) DisplayTimers(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import type * as Syntax from "~/bnf/syntax.d.ts"; | ||
import { red } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
|
||
import * as WasmTypes from "~/wasm/type.ts"; | ||
import { AssertUnreachable, LatentOffset } from "~/helper.ts"; | ||
import { BasePointerType, LinearType } from "~/compiler/codegen/expression/type.ts"; | ||
import { ReferenceRange } from "~/bnf/shared.js"; | ||
import { IntrinsicType } from "~/compiler/intrinsic.ts"; | ||
import { IntrinsicType, f32, f64, i32, i64 } from "~/compiler/intrinsic.ts"; | ||
import { Instruction } from "~/wasm/index.ts"; | ||
import { SourceView } from "~/parser.ts"; | ||
import { Context } from "~/compiler/codegen/context.ts"; | ||
|
@@ -57,6 +58,53 @@ export function Load(ctx: Context, type: IntrinsicType, offset: number | LatentO | |
} | ||
|
||
|
||
export function InlineClamp(ctx: Context, type: IntrinsicType, min: number | null, max: number | null) { | ||
let scope; | ||
switch (type.bitcode) { | ||
case WasmTypes.Intrinsic.i32: scope = Instruction.i32; break; | ||
case WasmTypes.Intrinsic.i64: scope = Instruction.i64; break; | ||
case WasmTypes.Intrinsic.f32: scope = Instruction.f32; break; | ||
case WasmTypes.Intrinsic.f64: scope = Instruction.f64; break; | ||
default: throw "Assert failed"; | ||
} | ||
|
||
const x = ctx.scope.register.allocate(type.bitcode); | ||
if (min !== null) { | ||
ctx.block.push(Instruction.local.tee(x.ref)); | ||
ctx.block.push(scope.const(min)); | ||
|
||
if ("lt" in scope) ctx.block.push(scope.lt()); // float | ||
else { | ||
if (type.signed) ctx.block.push(scope.lt_s()); | ||
else ctx.block.push(scope.lt_u()); | ||
} | ||
|
||
ctx.block.push(Instruction.if(type.bitcode, | ||
[ scope.const(min) ], | ||
[ Instruction.local.get(x.ref) ], | ||
)); | ||
} | ||
|
||
if (max !== null) { | ||
ctx.block.push(Instruction.local.tee(x.ref)); | ||
ctx.block.push(scope.const(max)); | ||
|
||
if ("gt" in scope) ctx.block.push(scope.gt()); // float | ||
else { | ||
if (type.signed) ctx.block.push(scope.gt_s()); | ||
else ctx.block.push(scope.gt_u()); | ||
} | ||
|
||
ctx.block.push(Instruction.if(type.bitcode, | ||
[ scope.const(max) ], | ||
[ Instruction.local.get(x.ref) ], | ||
)); | ||
} | ||
|
||
x.free(); | ||
} | ||
|
||
|
||
export function ResolveLinearType(ctx: Context, type: LinearType, ref: ReferenceRange, strict = true) { | ||
if (strict) { | ||
const errs = type.getCompositionErrors(); | ||
|
Oops, something went wrong.