aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-10-31 18:08:32 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-10-31 20:00:03 -0400
commitae3be51b576657d68130040251f15e74ee6bdfcf (patch)
tree924e6fc75652a26c9a5d5186dfad47b4f03817f3
parent05466cf34faedfb9aa46395c41da9b860f1f0f9d (diff)
Add tests based on vm.bqn
-rw-r--r--rt.bqn19
-rw-r--r--test/README.txt5
-rwxr-xr-xtest/dz_comp4
-rw-r--r--test/ref.bqn10
-rwxr-xr-xtest/unit.bqn42
5 files changed, 70 insertions, 10 deletions
diff --git a/rt.bqn b/rt.bqn
new file mode 100644
index 00000000..3dd727a5
--- /dev/null
+++ b/rt.bqn
@@ -0,0 +1,19 @@
+# BQN runtime hosted in BQN
+
+⟨src,need⟩ ← •Import "src/pr.bqn"
+compile ← need •Import "src/c.bqn"
+glyphs ← ∾ •Import "src/glyphs.bqn"
+vm ← •Import "vm.bqn"
+
+FillFn ← (⊑1↑0↑⥊)⊘{𝕩˙⌾⊢ <𝕨}
+_fillBy_ ← {𝕘⋄𝔽}
+GroupLen ← {(𝕨⌈≠)⊸↑0 FillFn≠¨⊔𝕩}
+extra ← ⟨ •Type, FillFn, ⋆⁼, GroupLen, ∾⊔∘⊢, _fillBy_ ⟩
+provide ← { g←𝕩∊glyphs ⋄ (⍋⍋g)⊏extra∾•BQN∘⥊¨g/𝕩 } ∾need
+
+rt‿SetPrims ← VM ⟨provide,!∘0¨⟩ Compile src
+PrimInd ← rt⊸⊐⌾<
+Decompose ← ((≠glyphs)>PrimInd)◶⟨•Decompose,0⊸≍⟩
+SetPrims ⟨ Decompose, PrimInd ⟩
+
+rt
diff --git a/test/README.txt b/test/README.txt
index 2b629569..f11502b9 100644
--- a/test/README.txt
+++ b/test/README.txt
@@ -1,9 +1,10 @@
Test scripts:
Script Compiler host Output host/VM
-- this.bqn Any
+- this.bqn Any Same
+- unit.bqn Any Same + repo
- js Self-host Javascript
-- dz_comp dzaima/BQN dzaima/BQN
+- dz_comp dzaima/BQN dzaima/BQN + repo
- dz_wasm.js dzaima/BQN WebAssembly
this.bqn can be run in any implementation that supports the necessary
diff --git a/test/dz_comp b/test/dz_comp
index dd0f5e1c..9815bb40 100755
--- a/test/dz_comp
+++ b/test/dz_comp
@@ -9,7 +9,7 @@ exec ← ((rt⌈2×ref)¬nc)◶⟨
Native˙ # Native
{𝕤⋄ ⟨DRun⟩←•Import "../dc.bqn" ⋄ DRun} # Compiled; native runtime
{𝕤⋄ •Import "../bqn.bqn"} # Self-hosted
- {𝕤⋄ •Import "ref.bqn"} # Reference implementations
+ {𝕤⋄ ⟨DRun⟩←•Import "../dc.bqn" ⋄ (•Import"ref.bqn")⊸DRun} # Reference implementations
⟩ @
Cases ← (0<≠)◶0‿('#'≠⊑)¨⊸/ · •FLines "cases/"∾∾⟜".bqn"
@@ -26,4 +26,4 @@ M ← {e‿b:
("!"⊸≡◶⟨<Native,0˙⟩ e) ≢◶""‿Msg <∘Exec⎊0 b
}
r ← (M '%'⊸= (∨´⊣)◶⟨"1"≍○<⊢, Trim¨(+`-2⊸×)⊸⊔⟩ ⊢)¨ c
-•Out ("All "∾(⍕≠c)∾" passed!")⍟(0=≠) ¯1↓∾r
+•Out ("All "∾(•Repr≠c)∾" passed!")⍟(0=≠) ¯1↓∾r
diff --git a/test/ref.bqn b/test/ref.bqn
index b7fb8c3a..68719513 100644
--- a/test/ref.bqn
+++ b/test/ref.bqn
@@ -13,11 +13,11 @@ defTok ← (¯1+`·¬·»⊸∧∊⟜idChars)⊸⊔¨ defs
depend ← <∘/˘ range ∧ > (names∊LC¨)¨ (0=·+`·-˝"{"‿"}"≡⌜⊢)⊸/¨defTok
order ← {{(𝕨⊸∨𝕊⍟(𝕩<○≠⊢)𝕩∾/)(0»∨`)⊸<𝕨<∧´∘⊏⟜𝕨¨l}⟜/0¨l←𝕩} depend
-chrs ← •Import "../src/glyphs.bqn"
+chrs ← ∾⟜"⋈"⌾⊑ chrs0 ← •Import "../src/glyphs.bqn"
def‿keep ← ⊑¨⌾(1⊸⊑) (1=≠)¨⊸⊔ anames
keep∾↩"⌾⎊"
-pre←"Type←•Type"‿"_amend←{𝕨˙⌾(𝕗⊸⊑)𝕩}"‿"Identity←{𝕏´⟨⟩}"‿"Fill←•FillFn"
+pre←"Type←•Type"‿"_amend←{𝕨˙⌾(𝕗⊸⊑)𝕩}"‿"Identity←{𝕏´⟨⟩}"‿"Fill←⊑∘»1↑⥊"
GetRepls ← {
ki ← (⊑¨⊑𝕩)∊keep
@@ -26,7 +26,5 @@ GetRepls ← {
⟨E_proc⟩ ← chrs‿GetRepls •Import "../src/pp.bqn"
-rslt ← "⟨"∾"⟩"«∾","⊸∾¨∾chrs # Output all primitives
-rt ← •BQN ∾∾⟜(@+10)¨ pre ∾ order∾⟜≠⊸⊏E_proc¨ defs∾<rslt
-⟨DRun,DCompile⟩ ← •Import "../dc.bqn"
-rt⊸DRun
+rslt ← "⟨"∾"⟩"«∾","⊸∾¨∾chrs0 # Output all primitives
+•BQN ∾∾⟜(@+10)¨ pre ∾ order∾⟜≠⊸⊏E_proc¨ defs∾<rslt
diff --git a/test/unit.bqn b/test/unit.bqn
new file mode 100755
index 00000000..df2bfcf1
--- /dev/null
+++ b/test/unit.bqn
@@ -0,0 +1,42 @@
+#! /usr/bin/env bqn
+
+# Tests for components of BQN: compiler, runtime, primitive spec
+
+files‿opts ← 2 ↑ ('-'=⊑)¨⊸⊔ •args
+files ↩ (0<≠)◶⟨1,∨´"all"⊸≡¨⟩◶⟨∾⟜".bqn"¨, •file.List∘"cases"⟩ files
+nc‿rt‿ref‿noerr ← "-nocomp"‿"-rt"‿"-ref"‿"-noerr" ∊ opts
+"Can't test runtime without the compiler!" ! ¬nc∧rt∨ref
+
+Native ← •BQN
+ReBQN ← {𝕊 rt:
+ compile ← (•Import "../src/glyphs.bqn") •Import "../src/c.bqn"
+ vm ← •Import "../vm.bqn"
+ BQN ← ⟨rt,{𝕊"bqn":BQN}¨⟩⊸(VM Compile)
+}
+exec ← ((rt⌈2×ref)¬nc)◶⟨
+ Native˙ # Native
+ {𝕤⋄ ReBQN •BQN∘⥊¨ ∾•Import "../src/glyphs.bqn"} # Compiled; native runtime
+ {𝕤⋄ ReBQN •Import "../rt.bqn"} # Self-hosted
+ {𝕤⋄ ReBQN •Import "ref.bqn"} # Reference implementations
+⟩ @
+
+c ← ∾ ((0<≠)◶0‿('#'≠⊑)¨⊸/ · •file.Lines "cases/"⊸∾)¨ files
+c ↩ ('!'≠⊑)¨⊸/⍟noerr c
+•Out 1↓∾' '⊸∾¨∾⟨
+ ⟨"Running",•Repr≠c,"tests:"⟩
+ noerr/⟨"(error cases excluded)"⟩
+ ¯4↓¨files
+⟩
+
+Trim ← ((∨`∧∨`⌾⌽)' '⊸≠)⊸/
+M ← {e‿b←𝕩
+ Msg ← {∾⟨
+ """",b,""": expected "
+ "to fail"⍟("!"⊸≡)e
+ " but "
+ 0⊸≡◶⟨"received "∾·•Repr⎊"{…}"⊑,"evaluation failed"⟩𝕩
+ ⟩}
+ ("!"⊸≡◶⟨<Native,0˙⟩ e) ≢◶⟨0,1∘•Out∘Msg⟩ <∘Exec⎊0 b
+}
+r ← (M '%'⊸= (∨´⊣)◶⟨"1"≍○<⊢, Trim¨(+`-2⊸×)⊸⊔⟩ ⊢)¨ c
+•Out 0⊸<◶⟨"All passed!",•Repr∾" failed!"˙⟩ +´r