Skip to content

Commit

Permalink
Rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Oct 4, 2024
1 parent 29fddd6 commit 231fddc
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 135 deletions.
36 changes: 18 additions & 18 deletions test/case/array.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t('array: basic', t => {
let wat = compileSruti(`x = [1]`)
let wat = compileZ(`x = [1]`)
let mod = compileWat(wat)

wat = compileSruti(`x = [1.1, 2.22, 3.333], y = [4.1234,5.54321,654321.123456,7.7777777]; x,y,xl=x[],yl=y[]`)
wat = compileZ(`x = [1.1, 2.22, 3.333], y = [4.1234,5.54321,654321.123456,7.7777777]; x,y,xl=x[],yl=y[]`)
mod = compileWat(wat)
let { memory, x, y, xl, yl } = mod.instance.exports
let xarr = new Float64Array(memory.buffer, x.value, 3)
Expand All @@ -23,7 +23,7 @@ t('array: basic', t => {
})

t('array: basic local', t => {
let wat = compileSruti(`x() = [1, 2]`)
let wat = compileZ(`x() = [1, 2]`)
let mod = compileWat(wat)
let { memory, x } = mod.instance.exports
let x0 = new Float64Array(memory.buffer, x(), 2)
Expand All @@ -34,7 +34,7 @@ t('array: basic local', t => {
})

t.todo('array: from static range', t => {
let wat = compileSruti(`x=[..3], y=[0..4]; z=[4..0], x,y,xl=x[],yl=y[]`)
let wat = compileZ(`x=[..3], y=[0..4]; z=[4..0], x,y,xl=x[],yl=y[]`)
// console.log(wat)
let mod = compileWat(wat)
let { memory, x, y, xl, yl, z } = mod.instance.exports
Expand All @@ -57,7 +57,7 @@ t.todo('array: from static range', t => {
})

t('array: from dynamic range', t => {
let wat = compileSruti(`a=3, x=[0..a], xl=x[]`)
let wat = compileZ(`a=3, x=[0..a], xl=x[]`)
// , y=[1, x[0]..x[2], 2..-2]; x,y, xl=x[],yl=y[]`)
// console.log(wat)
let mod = compileWat(wat)
Expand All @@ -71,14 +71,14 @@ t('array: from dynamic range', t => {

t('array: from invalid ranges', t => {
let wat
throws(() => { wat = compileSruti(`x=[2..]`) }, /range/)
throws(() => { wat = compileSruti(`x=[..]`) }, /range/)
throws(() => { wat = compileSruti(`x=[..-2]`) }, /range/)
throws(() => { wat = compileZ(`x=[2..]`) }, /range/)
throws(() => { wat = compileZ(`x=[..]`) }, /range/)
throws(() => { wat = compileZ(`x=[..-2]`) }, /range/)
})

t('array: nested static', t => {
let wat = compileSruti(`x=[1, y=[2, [3,3.14]]], w=[4,5]`)
// let wat = compileSruti(`y=[2], x=[1, y], w=[4,5]`)
let wat = compileZ(`x=[1, y=[2, [3,3.14]]], w=[4,5]`)
// let wat = compileZ(`y=[2], x=[1, y], w=[4,5]`)
// console.log(wat)
let mod = compileWat(wat)
let { memory, x, y, w } = mod.instance.exports
Expand All @@ -101,19 +101,19 @@ t('array: nested static', t => {
})

t.todo('array: comprehension', t => {
let wat = compileSruti(`x = [1..3 |> _ * 2]`)
let wat = compileZ(`x = [1..3 |> _ * 2]`)
let mod = compileWat(wat)
let { memory, x } = mod.instance.exports
let xarr = new Float64Array(memory.buffer, x, 2)
is(xarr, [1, 2])
})

t.todo('array: nested comprehension', t => {
let wat = compileSruti(`x = [1..3 <| [0.._ <| _ * 2]]`)
let wat = compileZ(`x = [1..3 <| [0.._ <| _ * 2]]`)
})

t('array: simple write', t => {
let wat = compileSruti(`x=[..3]; x[0]=1; x[1]=2; x[-1]=x[]; x`)
let wat = compileZ(`x=[..3]; x[0]=1; x[1]=2; x[-1]=x[]; x`)
// console.log(wat)
let mod = compileWat(wat)
let { memory, x } = mod.instance.exports
Expand All @@ -124,7 +124,7 @@ t('array: simple write', t => {
})

t('array: simple read', t => {
let wat = compileSruti(`x = [1, 2, 3]; a=x[0],b=x[1],c=x[2],d=x[-1]`)
let wat = compileZ(`x = [1, 2, 3]; a=x[0],b=x[1],c=x[2],d=x[-1]`)
// console.log(wat)
let mod = compileWat(wat)
let { a, b, c, d } = mod.instance.exports
Expand All @@ -135,7 +135,7 @@ t('array: simple read', t => {
})

t('array: group read', t => {
let wat = compileSruti(`x = [1, 2, 3]; (a,b,c)=x[0,1,2]`)
let wat = compileZ(`x = [1, 2, 3]; (a,b,c)=x[0,1,2]`)
// console.log(wat)
let mod = compileWat(wat)
let { a, b, c } = mod.instance.exports
Expand All @@ -145,7 +145,7 @@ t('array: group read', t => {
})

t('array: group write', t => {
let wat = compileSruti(`x = [..3]; x[0,1,2]=(1,2,3)`)
let wat = compileZ(`x = [..3]; x[0,1,2]=(1,2,3)`)
// console.log(wat)
let mod = compileWat(wat)
let { x, memory } = mod.instance.exports
Expand All @@ -156,7 +156,7 @@ t('array: group write', t => {
})

t('compile: sublist', t => {
let wat = compileSruti(`x = [1,2,3], y = [x]`)
let wat = compileZ(`x = [1,2,3], y = [x]`)
let mod = compileWat(wat)
let { memory, x, y } = mod.instance.exports
let xarr = new Float64Array(memory.buffer, x, 3), yarr = new Float64Array(memory.buffer, y, 1)
Expand Down
4 changes: 2 additions & 2 deletions test/case/comments.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t('comments: base', t => {
let wat = compileSruti(`x(a,w,h)=(
let wat = compileZ(`x(a,w,h)=(
a=1
;; a=2
), y()=(
Expand Down
30 changes: 15 additions & 15 deletions test/case/cond.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t('condition: base', t => {
let wat, mod
wat = compileSruti(`a=1;b=2;c=a?1:2`)
wat = compileZ(`a=1;b=2;c=a?1:2`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 1)

wat = compileSruti(`a=1;b=2;a?c=b;c`)
wat = compileZ(`a=1;b=2;a?c=b;c`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 2)

wat = compileSruti(`a=0;b=2;a?c=b;c`)
wat = compileZ(`a=0;b=2;a?c=b;c`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 0)

wat = compileSruti(`a=0.0;b=2.1;a?c=b;c`)
wat = compileZ(`a=0.0;b=2.1;a?c=b;c`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 0)

wat = compileSruti(`a=0.1;b=2.1;a?c=b;c`)
wat = compileZ(`a=0.1;b=2.1;a?c=b;c`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 2.1)

wat = compileSruti(`a=0.0;b=2.1;c=a?b`)
wat = compileZ(`a=0.0;b=2.1;c=a?b`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 0)

wat = compileSruti(`a=0.1;b=2.1;c=a?b`)
wat = compileZ(`a=0.1;b=2.1;c=a?b`)
mod = compileWat(wat)
is(mod.instance.exports.c.value, 2.1)

console.log('--------------')
wat = compileSruti(`x(px) = (px < 0 ? px = 0; px)`)
wat = compileZ(`x(px) = (px < 0 ? px = 0; px)`)
mod = compileWat(wat)
is(mod.instance.exports.x(-10), 0)
is(mod.instance.exports.x(10), 10)
})

t('compile: conditions - or/and', t => {
let wat, mod
wat = compileSruti(`z=1||0`)
wat = compileZ(`z=1||0`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 1)
wat = compileSruti(`z=1.2||0.0`)
wat = compileZ(`z=1.2||0.0`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 1.2)
wat = compileSruti(`z=1.2||0`)
wat = compileZ(`z=1.2||0`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 1.2)
wat = compileSruti(`z=1||0.0`)
wat = compileZ(`z=1||0.0`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 1)
wat = compileSruti(`z=1.2&&0.2`)
wat = compileZ(`z=1.2&&0.2`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 0.2)
wat = compileSruti(`z=1&&2`)
wat = compileZ(`z=1&&2`)
mod = compileWat(wat)
is(mod.instance.exports.z.value, 2)
})
10 changes: 5 additions & 5 deletions test/case/defer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t('defer: - basics', () => {
let wat = compileSruti(`f()=(*t=0;^t++;t)`)
let wat = compileZ(`f()=(*t=0;^t++;t)`)
let mod = compileWat(wat), f = mod.instance.exports.f;
is([f(), f(), f()], [0, 1, 2])

wat = compileSruti(`f()=(*t=0;/t;^++t)`)
wat = compileZ(`f()=(*t=0;/t;^++t)`)
mod = compileWat(wat), f = mod.instance.exports.f;
is([f(), f(), f()], [0, 1, 2], 'after return')
})

t.skip('defer: - errors', () => {
// throws(() => compileSruti(`f()=(*t=0;/t;^++t)`), 'defer after return')
// throws(() => compileSruti(`f()=(^++t;*t=0;)`), 'defer before stateful')
// throws(() => compileZ(`f()=(*t=0;/t;^++t)`), 'defer after return')
// throws(() => compileZ(`f()=(^++t;*t=0;)`), 'defer before stateful')
})
8 changes: 4 additions & 4 deletions test/case/examples.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t.todo('example: audio-gain', t => {
let wat = compileSruti(`
let wat = compileZ(`
blockSize = 1024;
gain = ([blockSize]data, volume ~ 0..1000) -> [data | x -> x * volume];
`)
let mod = compileWat(wat)
let { gain } = mod.instance.exports
is(gain([1, 2, 3], 2), [2, 4, 6])

// let wat = compileSruti(`
// let wat = compileZ(`
// blockSize = 1024;
// gain = ([2, blockSize]data, volume ~ 0..1000) -> [data | ch -> (ch | x -> x * volume)];
// `)
})

t.todo('example: sine gen', t => {
let wat = compileSruti(analyse(parse(`
let wat = compileZ(analyse(parse(`
pi = 3.14;
pi2 = pi*2;
sampleRate = 44100;
Expand Down
4 changes: 2 additions & 2 deletions test/case/export.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t.skip('export: - no junk exports', () => {
let wat = compileSruti(`w()=(); y=[1]; x()=(*i=0), z=[y[0], v=[1]]`)
let wat = compileZ(`w()=(); y=[1]; x()=(*i=0), z=[y[0], v=[1]]`)
let mod = compileWat(wat)
same(Object.keys(mod.instance.exports), ['memory', 'x', 'z'])
})
18 changes: 9 additions & 9 deletions test/case/funcs.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import t, { almost, is, not, ok, same, throws } from 'tst'
import compileSruti from '../../src/compile.js'
import compileZ from '../../src/compile.js'
import { compileWat } from '../util.js'

t.todo('funcs: oneliners', t => {
let wat, mod

wat = compileSruti(`mult(a, b=2) = a * b`)
wat = compileZ(`mult(a, b=2) = a * b`)
mod = compileWat(wat)
is(mod.instance.exports.mult(2, 4), 8)
is(mod.instance.exports.mult(2), 4)

mod = compileWat(compileSruti(` mult(a, b) = (a * b)`))
mod = compileWat(compileZ(` mult(a, b) = (a * b)`))
is(mod.instance.exports.mult(2, 4), 8)

console.log('------')
mod = compileWat(compileSruti(` mult(a, b) = (b; a * b)`))
mod = compileWat(compileZ(` mult(a, b) = (b; a * b)`))
is(mod.instance.exports.mult(2, 4), 8)

mod = compileWat(compileSruti(` mult(a, b) = (b; a * b;)`))
mod = compileWat(compileZ(` mult(a, b) = (b; a * b;)`))
is(mod.instance.exports.mult(2, 4), 8)

mod = compileWat(compileSruti(` mult(a, b) = (b; a * b; /)`))
mod = compileWat(compileZ(` mult(a, b) = (b; a * b; /)`))
is(mod.instance.exports.mult(2, 4), undefined)

mod = compileWat(compileSruti(`f()=( *t; ^t++; t; );`))
mod = compileWat(compileZ(`f()=( *t; ^t++; t; );`))
is([mod.instance.exports.f(), mod.instance.exports.f()], [0, 1])
})

t('funcs: first line inits local', t => {
let mod = compileWat(compileSruti(`a=1, x() = (a=2)`))
let mod = compileWat(compileZ(`a=1, x() = (a=2)`))
is(mod.instance.exports.a.value, 1)
is(mod.instance.exports.x(), 2)
is(mod.instance.exports.a.value, 1)

mod = compileWat(compileSruti(`a=1, x() = (;a=2)`))
mod = compileWat(compileZ(`a=1, x() = (;a=2)`))
is(mod.instance.exports.a.value, 1)
is(mod.instance.exports.x(), 2)
is(mod.instance.exports.a.value, 2)
Expand Down
Loading

0 comments on commit 231fddc

Please sign in to comment.