diff options
| -rwxr-xr-x | dc.bqn | 30 | ||||
| -rwxr-xr-x | spec/dzref | 52 | ||||
| -rw-r--r-- | test/testref.bqn | 36 |
3 files changed, 61 insertions, 57 deletions
@@ -2,20 +2,20 @@ nl‿tab←•UCS 10‿9 charSet←∾charGroups←⟨ - chF←"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔" ⍝ Function - "˜˘¨⌜⁼´`" ⍝ Modifier - "∘○⊸⟜⌾⊘◶⎉⚇⍟" ⍝ Composition - ¯1⊏˘10‿2⥊"𝕨𝕎𝕩𝕏𝕗𝔽𝕘𝔾𝕤𝕊" ⍝ Input (𝕣 pending; ℝ not allowed) - nl∾"⋄," ⍝ Separator - "←↩→" ⍝ Gets - "(){}⟨⟩" ⍝ Bracket - "‿" ⍝ Ligature - •d ⍝ +⟜(↕10)⌾•UCS'0' ⍝ Digit - "¯.π∞" ⍝ Numeric - "_"∾' '(⊢∾+)⌾•UCS•a ⍝ Alphabetic - 1↑"𝕨" ⍝ Prefix for input (hack around UTF-16) - " "∾tab ⍝ Whitespace -⍝ #'" eliminated during tokenization + chF←"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔" # Function + "˜˘¨⌜⁼´`" # Modifier + "∘○⊸⟜⌾⊘◶⎉⚇⍟" # Composition + ¯1⊏˘10‿2⥊"𝕨𝕎𝕩𝕏𝕗𝔽𝕘𝔾𝕤𝕊" # Input (𝕣 pending; ℝ not allowed) + nl∾"⋄," # Separator + "←↩→" # Gets + "(){}⟨⟩" # Bracket + "‿" # Ligature + •d # +⟜(↕10)⌾•UCS'0' # Digit + "¯.π∞" # Numeric + "_"∾' '(⊢∾+)⌾•UCS•a # Alphabetic + 1↑"𝕨" # Prefix for input (hack around UTF-16) + " "∾tab # Whitespace +# #'" eliminated during tokenization ⟩ bF‿bM‿bC‿bI‿bS‿bG‿bB‿bL‿bD‿bN‿bA‿bP‿bW←⊔/≠¨charGroups vi←+´≠¨8↑charGroups @@ -117,7 +117,7 @@ Compile←{ } -⍝ Targetting dzaima/BQN bytecode: +# Targetting dzaima/BQN bytecode: DParse ← { l←≠𝕩⋄sep←𝕩∊bS⋄𝕩↩(⌽⍋⍋⌽+`(≠↑0∾⊢)⊸∨sep)⊏𝕩 @@ -5,28 +5,28 @@ impl ← "◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} ∨ ← (+-×) -⍝⌜ -⍝ LAYER 2: Pervasion -⍝ After defining _perv, we apply it to all scalar functions, -⍝ making them pervasive. I'm not going to write that out. +#⌜ +# LAYER 2: Pervasion +# After defining _perv, we apply it to all scalar functions, +# making them pervasive. I'm not going to write that out. ToArray ← IsArray◶<‿⊢ -_perv←{ ⍝ Pervasion +_perv←{ # Pervasion (⊢⊘∨○IsArray)◶⟨𝔽⋄𝔽{𝕨𝔽_perv𝕩}¨⟩ } -⍝⌜ -⍝ LAYER 3: Remove other limits -⍝ Now all implementations are full but ↕ is monadic only +#⌜ +# LAYER 3: Remove other limits +# Now all implementations are full but ↕ is monadic only Int←IsArray◶⟨⌊⊸=,0⟩ Nat←IsArray◶⟨0⊸≤∧⌊⊸=,0⟩ -⍝⌜ -⍝ LAYER 4: Operators +#⌜ +# LAYER 4: Operators Cell ← ↓⟜≢ @@ -64,15 +64,15 @@ _iterate_←{ ⍟ ← _iterate_ -⍝⌜ -⍝ LAYER 5: Structural functions +#⌜ +# LAYER 5: Structural functions _onAxes_←{ F←𝔽 - (𝔾<≡)∘⊣◶{ ⍝ One axis + (𝔾<≡)∘⊣◶{ # One axis ! 1≤≠≢𝕩 𝕨F𝕩 - }‿{ ⍝ Multiple axes + }‿{ # Multiple axes ! 1≥≠≢𝕨 ! 𝕨≤○≠≢𝕩 R←{(⊑𝕨)F(1↓𝕨)⊸R˘𝕩}⍟{0<≠𝕨} @@ -117,12 +117,12 @@ Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep ⌽ ← Reverse ⊘ Rotate -⍝⌜ -⍝ LAYER 6: Everything else +#⌜ +# LAYER 6: Everything else Join←{ - C←(<⟨⟩)⥊⊸∾⌜´⊢ ⍝ Cartesian array product + C←(<⟨⟩)⥊⊸∾⌜´⊢ # Cartesian array product ! IsArray 𝕩 s←≢¨𝕩 d←≠⊑s @@ -146,7 +146,7 @@ Group←{ ∾ ↩ Join ⊘ ∾ ⊔ ← Group⟜(↕≠⚇1) ⊘ Group -⍝ Searching +# Searching IndexOf←{ c←1-˜≠≢𝕨 ! 0≤c @@ -181,10 +181,10 @@ ReorderAxes←{ Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢) ⍉ ← Transpose ⊘ ReorderAxes -⍝ Sorting -Cmp ← ∨○IsArray◶{ ⍝ No arrays - 𝕨(>-<)𝕩 ⍝ Assume they're numbers -}‿{ ⍝ At least one array +# Sorting +Cmp ← ∨○IsArray◶{ # No arrays + 𝕨(>-<)𝕩 # Assume they're numbers +}‿{ # At least one array e←𝕨-˜○(0∨´0=≢)𝕩 𝕨(e=0)◶e‿{ c←𝕨×∘-○(IsArray+≠∘≢)𝕩 @@ -257,8 +257,12 @@ X←Raw←{≤4} ⍝ checks if line is a builtin redefinition E_isdef ← (3≤≠)◶⟨0,∧´⟨chr," ","←↩"⟩∊˜¨3⊸↑⟩ - ⍝ replaces built-ins with their corresponding names - E_proc ← {l←≠chr ⋄ ∾ ((l×≠`𝕩∊"""'")+chr⊐𝕩) (≥⟜l)◶⟨⊑⟜names,⥊∘⊢⟩¨ 𝕩} + ⍝ 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 diff --git a/test/testref.bqn b/test/testref.bqn index 59313beb..a9229cdf 100644 --- a/test/testref.bqn +++ b/test/testref.bqn @@ -1,9 +1,9 @@ -⍝ Tests of primitive functionality -⍝ Ordering matches the reference implementations +# Tests of primitive functionality +# Ordering matches the reference implementations •←/¬∾⟨ -⟨ ⍝ LAYER 0 - ⍝ [0,34) +⟨ # LAYER 0 + # [0,34) 0≡¯2+2 1e4≡5e3+5e3 ¯∞≡1e6-∞ @@ -39,8 +39,8 @@ ⟨0⟩≡↕1 ⟨0,1,2,3,4,5,6⟩≡↕7 - ⍝ LAYER 1 - ⍝ [34,56) + # LAYER 1 + # [34,56) 3≡4>◶+‿-1 3≡4⊢◶+‿-1 3≡4 1◶+‿-1 @@ -63,7 +63,7 @@ 20≡×⟜(-⟜1)5 4≡5+⟜ׯ3 7≡5+⟜2 ¯3 - ⍝ [56,95) + # [56,95) 2≡√4 3≡3√27 6≡2∧3 @@ -103,7 +103,7 @@ 5≡⌈4.01 ⟨⟩≡≢'a' ⟨⟩≡≢0 - ⍝ [95,104) + # [95,104) ⟨0⟩‿⟨1⟩‿⟨2⟩≡⥊¨↕3 (↕6)≡⟜(≠¨)○(2‿3⊸⥊)⟨⟩‿"a"‿"ab"‿"abc"‿"abcd"‿"abcde"‿"abcdef" ≡⟜(≠¨)4‿0‿2⥊↕0 @@ -114,8 +114,8 @@ 2(⊣≡⊢´)"a"‿2‿(3‿"d") 7‿10≡+¨´⟨⟨2,3⟩,⟨5,7⟩⟩ - ⍝ LAYER 2 - ⍝ [104,117) + # LAYER 2 + # [104,117) ⟨⟩≡⟨⟩∾"" "a"≡⟨⟩∾"a" "a"≡"a"∾⟨⟩ @@ -130,8 +130,8 @@ 3‿4‿5‿6‿6≡{F:F⍟(×≡)⊸∾⟜⥊´𝕩}⟨2,1⟩+⟨⟨⟨⟨1,2⟩,3⟩,4⟩,5⟩ (=¨⟜(⥊⟜(↕×´)3‿4)≡(↕4)=⌜˜4|⊢)1‿6‿8 - ⍝ LAYER 3 - ⍝ [117,152) + # LAYER 3 + # [117,152) 2≡⊑⟨2⟩ "ab"≡⊑⟨"ab"⟩ 0≡⊑↕20 @@ -168,8 +168,8 @@ 2≡≡⟨5,⟨'c',+,2⟩⟩ 0≡≡⊑⟨-⟩ - ⍝ LAYER 4 - ⍝ [152,183) + # LAYER 4 + # [152,183) ≡⟜><'a' ≡⟜><∞ ≡⟜>↕5 @@ -202,8 +202,8 @@ ⟨⟩≡×`⟨⟩ ≡⟜(!∘0`)3‿0‿2⥊"" - ⍝ LAYER 5 - ⍝ [183,230) + # LAYER 5 + # [183,230) (<'a')≡⊏"abc" "a"≡⊏⥊˘"abc" (<'c')≡2⊏"abc" @@ -253,8 +253,8 @@ ⟨⟩(/≡⊢)≍"ab" ⟩ -⟨ ⍝ LAYER 6 - ⍝ [230,270) +⟨ # LAYER 6 + # [230,270) ≡⟜(∾⥊¨)"abc" (∾´≡∾)"ab"‿"cde"‿"" 1‿2‿3‿4‿6‿9≡∾(⊢×≠↑↓)1+↕3 |
