diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-16 15:28:55 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-16 15:28:55 -0500 |
| commit | cf142346760cb30c781e28d7178ad88772e3b5a7 (patch) | |
| tree | af707c3466ee63789f642a061b5856fb15725950 /src | |
| parent | 06ca057eeb92d072e705b7383bca3724e6f7d4fe (diff) | |
Comments and cleanup in pr.bqn
Diffstat (limited to 'src')
| -rwxr-xr-x | src/pr.bqn | 62 |
1 files changed, 35 insertions, 27 deletions
@@ -1,9 +1,12 @@ #!/usr/bin/env dbqn # Process BQN runtime +# r.bqn begins with provided values and defines primitives as it goes. +# Defining a primitive shadows previous definitions, so earlier uses +# of the primitive still use the old definition. +# This is handled by using a new name each time it's defined. -impl ← •FLines "r.bqn" - +# All primitives chrs←⟨ "+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!" "˙˜˘¨⌜⁼´˝`" @@ -11,21 +14,8 @@ chrs←⟨ ⟩ nc ← ≠¨chrs glyphs ⇐ chr ← ∾chrs -itr ← 0⥊˜≠chr - -idChars ← "_¯.π∞"∾∾"0aA"+⟜↕¨10‿26‿26 - -init ← " "⊸∾¨(/⟜"_"¨nc/0‿1‿1)∾¨(nc/"FMD")∾¨(nc+´⊸↑⥊"ABC"∾⌜•a) -post ← ∾⟜" "¨/⟜"_"¨nc/0‿0‿1 -out ← init∾¨'0'∾¨post -Inc ← { - i←⊑chr⊐𝕩 - n←0 ⋄ itr↩{n↩1+𝕩}⌾(i⊑⊢)itr - out↩((i⊑init)∾('0'+n)∾i⊑post)⌾(i⊑⊢)out -} - -# Required functionality passed in as an argument +# Provided values, to be passed in through the constants array def ← ⟨"Type","Decompose","Glyph","Fill","Log","GroupLen","GroupOrd","_fillBy_"⟩ keep ← "!+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘" len ⇐ def+○≠keep @@ -34,20 +24,38 @@ dt ← ⊔⟜⊒ (+´·∧`'_'=0‿¯1⊸⊏)¨ def ns ← » ne←+`nc kt ← ∾ (ns+≠¨dt) + ⊔⟜⊒ne⍋ki +# Initial primitive replacement names +init ← (nc/(' '∾¨1‿2/↑"_")∾¨"FMD")∾¨('A'+nc+´⊸↑⥊3∾⌜○↕26) +post ← nc/(2‿1/↑"_")∾¨' ' +pn ← init∾¨'0'∾¨post + +# All replacements: input and output chrt ← ⥊¨chr -in ← chrt ∾ def -out ↩ ((kt⊏chrt)⌾(ki⊸⊏)out) ∾ (∾ns+dt)⊏chrt +in ← chrt ∾ def +out ← ((kt⊏chrt)⌾(ki⊸⊏)pn) ∾ (∾ns+dt)⊏chrt +# Make a new name for primitive 𝕩 +itr ← 0⥊˜≠chr +Shadow ← { + i←⊑chr⊐𝕩 + n←0 ⋄ itr↩{n↩1+𝕩}⌾(i⊑⊢)itr + out↩((i⊑init)∾('0'+n)∾i⊑post)⌾(i⊑⊢)out +} +# Does the expression define a primitive? E_isdef ← (3≤≠)◶⟨0,∧´⟨chr," ","←↩"⟩∊˜¨3⊸↑⟩ -E_proc ← { - q←≠`𝕩='"' ⋄ q∨↩≠`q<𝕩=''' ⋄ f←¬∨`q<𝕩='#' - t ← (¯1+`·¬(»f/q)∨·»⊸∧∊⟜idChars)⊸⊔ f/𝕩 - ∾ (in⊸⊐ ⊑⟜out⍟(<⟜(≠in))¨ ⊢) t +# Process ordinary expression +E_nodef ← { + idChars ← "_¯.π∞"∾∾"0aA"+⟜↕¨10‿26‿26 + q←≠`𝕩='"' ⋄ q∨↩≠`q<𝕩=''' ⋄ f←¬∨`q<𝕩='#' # Quotes and comments + t ← (¯1+`·¬(»f/q)∨·»⊸∧∊⟜idChars)⊸⊔ f/𝕩 # Tokenize + ∾ (in⊸⊐ ⊑⟜out⍟(<⟜(≠in))¨ ⊢) t # Replace } -E_redef ← { # handles [fmd] [←↩] - tail ← E_proc 3↓𝕩 # must use old def - Inc ⊑𝕩 - (E_proc 1↑𝕩) ∾ "←" ∾ tail +# Process expression, possibly redefining a primitive +E_proc ← E_isdef◶E_nodef‿{ + tail ← E_proc 3↓𝕩 # RHS + Shadow ⊑𝕩 # New name + (E_proc 1↑𝕩) ∾ "←" ∾ tail # LHS } -ref ⇐ ∾∾⟜(@+10)¨ E_isdef◶E_proc‿E_redef¨ impl∾<"⟨"∾"⟩"«⥊","⊸∾˘chr +rslt ← "⟨"∾"⟩"«∾","⊸∾¨chrt # Output all primitives +ref ⇐ ∾∾⟜(@+10)¨ E_proc¨ (•FLines "r.bqn")∾<rslt |
