diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-29 17:51:57 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-29 17:51:57 -0400 |
| commit | 48d8cc1401e46b8c33330f0f61fd36b40c20b789 (patch) | |
| tree | b6eca4f96525d5e2ee149ec2042ff5dd8073dd65 | |
| parent | aa37af19e967c4ff0c037b7eee9cf8d08bcea227 (diff) | |
Add tests for compiling impl.bqn (after preprocessing)
| -rwxr-xr-x | test/cmpref.bqn | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/cmpref.bqn b/test/cmpref.bqn new file mode 100755 index 00000000..54b3eabd --- /dev/null +++ b/test/cmpref.bqn @@ -0,0 +1,62 @@ +#!/usr/bin/env dbqn + +# Compile and run the primitive implementations, and testref.bqn + +impl ← •LNS •path∾"../impl.bqn" + +drun ← ((<•path∾"../c.bqn")∾<"DRun") •EX •path∾"../dzref" + +chrs←⟨ + "!+-×÷⋆√⌊⌈∧∨¬|=≠≤<>≥≡≢⊣⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔" + "˜˘¨⌜⁼´˝`" + "∘⊸⟜○⌾⎉⚇⍟◶⊘" +⟩ +nc ← ≠¨chrs +chr ← ∾chrs +itr ← 0⥊˜≠chr + +init ← " "⊸∾¨(/⟜"_"¨nc/0‿1‿1)∾¨(nc/"FMD")∾¨(nc+´⊸↑⥊"ABC"∾⌜•a) +post ← ∾⟜" "¨/⟜"_"¨nc/0‿0‿1 +names ← init∾¨(•UCS 48)∾¨post + +Inc ← { + i←⊑chr⊐𝕩 + n←0 ⋄ itr↩{n↩1+𝕩}⌾(i⊑⊢)itr + names↩((i⊑init)∾(•UCS 48+n)∾i⊑post)⌾(i⊑⊢)names +} + +# starting built-ins +inps←⟨"𝕨 ","𝕨,𝕗","𝕨,𝕘"⟩ +pre ← names∾¨(nc/("←{⟨"∾∾⟜"⟩ ⋄ ≤""Using undefined built-in ")¨inps)∾¨∾⟜"""}"¨chr + +# built-in assumptions +Mod ← {pre ∾↩ <((⊑chr⊐𝕨)⊑names) ∾ " ↩ " ∾ 𝕩} + +pre ∾↩ <"IsArray ← 0≠≡" +pre ∾↩ <"_amend ← {𝕨{𝕩⋄𝕗}⌾(𝕗⊑⊢)𝕩}" +pre ∾↩ <"Type ← ⟨⟩⥊0⊸⥊" + +'!' Mod "{𝕩 ⋄ ≤1}⍟¬" +Mod⟜⥊¨ "+-×÷⋆⌊=≤≢⥊⊑↕⌜⁼" + + +# checks if line is a builtin redefinition +E_isdef ← (3≤≠)◶⟨0,∧´⟨chr," ","←↩"⟩∊˜¨3⊸↑⟩ + +# removes comments and replaces built-ins with names +E_proc ← { + l←≠chr + q←≠`𝕩∊"""'" ⋄ f←¬∨`q¬⊸∧𝕩='#' + ∾ (((l×f/q)+chr⊸⊐) (≥⟜l)◶⟨⊑⟜names,⥊∘⊢⟩¨ ⊢) f/𝕩 +} + +E_redef ← { # handles [fmd] [←↩] + tail ← E_proc 3↓𝕩 # must use old def + Inc ⊑𝕩 + (E_proc 1↑𝕩) ∾ "←" ∾ tail +} + +pre ∾↩ E_isdef◶E_proc‿E_redef¨ impl +t ← (¬∘⊑'{'∊⊢)¨⊸/ 3⊸↓⌾(3⊸⊑) •LNS •path∾"testref.bqn" +res ← DRun ∾ ∾⟜(•UCS 10)¨ pre ∾ E_proc¨ t +• ← ("All "∾(⍕≠res)∾" passed!")⍟(0=≠) /res |
