-
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.
Merge branch 'develop' of github.com:voidlanguage/void into drew/voi-…
…16-basic-nominal-object-support
- Loading branch information
Showing
7 changed files
with
130 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Node.js CI | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22.x" | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, it } from "node:test"; | ||
import { e2eVoidText } from "./fixtures/e2e-file.mjs"; | ||
import { compileText } from "../api.mjs"; | ||
import { strict as assert } from "node:assert"; | ||
|
||
describe("API: E2E", () => { | ||
it("Can compile and run a basic void file", async () => { | ||
const mod = await compileText(e2eVoidText); | ||
const bin = mod.emitBinary(); | ||
const compiled = new WebAssembly.Module(bin); | ||
const instance = new WebAssembly.Instance(compiled); | ||
|
||
const fn = | ||
typeof instance.exports.main === "function" | ||
? instance.exports.main | ||
: undefined; | ||
|
||
assert(fn, "Function exists"); | ||
assert.equal(fn(), 55, "Main function returns correct value"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const e2eVoidText = ` | ||
use std::all | ||
fn fib(n: i32) -> i32 | ||
if n < 2 then: | ||
n | ||
else: | ||
fib(n - 1) + fib(n - 2) | ||
pub fn main() | ||
fib(10) | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ParsedFiles, parseDirectory } from "./lib/parse-directory.mjs"; | ||
import { parseFile } from "./lib/parse-file.mjs"; | ||
import { parseStd, stdPath } from "./lib/parse-std.mjs"; | ||
import { resolveSrc } from "./lib/resolve-src.mjs"; | ||
import { File } from "./lib/file.mjs"; | ||
import { parse } from "./parser.mjs"; | ||
import { expandSyntaxMacrosOfFiles } from "./syntax-macros/index.mjs"; | ||
import { resolveFileModules } from "./modules.mjs"; | ||
import { expandRegularMacros } from "./regular-macros.mjs"; | ||
import { typeCheck } from "./semantics/index.mjs"; | ||
import binaryen from "binaryen"; | ||
import { genWasmCode } from "./wasm-code-gen.mjs"; | ||
|
||
export type ParsedModule = { | ||
files: ParsedFiles; | ||
/** Path to src directory (a folder containing index.void that acts as entry) if available */ | ||
srcPath?: string; | ||
/** Path to root void file */ | ||
indexPath: string; | ||
}; | ||
|
||
export const compileText = async (text: string) => { | ||
const parsedModule = await parseText(text); | ||
return compileParsedModule(parsedModule); | ||
}; | ||
|
||
export const compilePath = async (path: string) => { | ||
const parsedModule = await parsePath(path); | ||
return compileParsedModule(parsedModule); | ||
}; | ||
|
||
export const compileParsedModule = (module: ParsedModule): binaryen.Module => { | ||
const syntaxExpandedFiles = expandSyntaxMacrosOfFiles(module.files); | ||
const moduleResolvedModule = resolveFileModules({ | ||
...module, | ||
files: syntaxExpandedFiles, | ||
stdPath: stdPath, | ||
}); | ||
const regularMacroExpandedModule = expandRegularMacros(moduleResolvedModule); | ||
const typeCheckedModule = typeCheck(regularMacroExpandedModule); | ||
return genWasmCode(typeCheckedModule); | ||
}; | ||
|
||
export const parseText = async (text: string): Promise<ParsedModule> => { | ||
const file = new File(text, "index"); | ||
return { | ||
files: { | ||
index: parse(file), | ||
...(await parseStd()), | ||
}, | ||
indexPath: "index", | ||
}; | ||
}; | ||
|
||
export const parsePath = async (path: string): Promise<ParsedModule> => { | ||
const src = await resolveSrc(path); | ||
|
||
const srcFiles = src.srcRootPath | ||
? await parseDirectory(src.srcRootPath) | ||
: { [src.indexPath]: await parseFile(src.indexPath) }; | ||
|
||
return { | ||
files: { | ||
...srcFiles, | ||
...(await parseStd()), | ||
}, | ||
srcPath: src.srcRootPath, | ||
indexPath: src.indexPath, | ||
}; | ||
}; |
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