Prelude of builtin functions #7

Merged
defunkt merged 45 commits from prelude into main 2025-10-29 20:15:37 +00:00
2 changed files with 8 additions and 8 deletions
Showing only changes of commit b738e6cfd1 - Show all commits

View File

@ -78,7 +78,7 @@ export const globalFunctions = {
},
// modules
use: async function (this: VM, path: string): Promise<Record<string, Value>> {
load: async function (this: VM, path: string): Promise<Record<string, Value>> {
const scope = this.scope
const pc = this.pc

View File

@ -4,38 +4,38 @@ import { globalFunctions } from '#prelude'
describe('use', () => {
test(`imports all a file's functions`, async () => {
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math.double 4
`).toEvaluateTo(8, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math.double (math.double 4)
`).toEvaluateTo(16, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
dbl = math.double
dbl (dbl 2)
`).toEvaluateTo(8, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math.pi
`).toEvaluateTo(3.14, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math | at 🥧
`).toEvaluateTo(3.14159265359, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math.🥧
`).toEvaluateTo(3.14159265359, globalFunctions)
expect(`
math = use ./src/prelude/tests/math
math = load ./src/prelude/tests/math
math.add1 5
`).toEvaluateTo(6, globalFunctions)
})