diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-25 21:26:27 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-25 21:26:27 -0400 |
| commit | c15a166a65d55c806aea9f28f8b5bfc36954a757 (patch) | |
| tree | a5d3ccf952d4d6e39594c5f128f5cc3442548029 | |
| parent | 676bc61b903c9c3201913ac1b11ae2d3e0ad6e1d (diff) | |
Use a custom primitive set to compile the runtime
| -rw-r--r-- | bqn.bqn | 8 | ||||
| -rwxr-xr-x | dc.bqn | 5 | ||||
| -rwxr-xr-x | src/cjs.bqn | 13 | ||||
| -rwxr-xr-x | src/pr.bqn | 14 |
4 files changed, 22 insertions, 18 deletions
@@ -1,8 +1,10 @@ # BQN hosted in dzaima/BQN # Result is a function that executes BQN code. -⟨DRun,DCompile⟩ ← •Import "dc.bqn" -⟨ref,glyphs⟩ ← •Import "src/pr.bqn" +⟨ref,prims⟩ ← •Import "src/pr.bqn" +⟨DRun⟩ ← •Import "dc.bqn" +⟨DCompile⟩ ← prims •Import "dc.bqn" +glyphs ← ∾ •Import "src/glyphs.bqn" provide ← ⟨ •Type # Type @@ -12,7 +14,7 @@ provide ← ⟨ ∾⊔∘⊢ # GroupOrd !,+,-,×,÷,⋆,⌊,=,≤,≢,⥊,⊑,↕,⌜,`,•_fillBy_,⊘,⎊ ⟩ -rt‿SetPrims ← •COMP provide⊸(⊣»«)⌾(1⊸⊑) DCompile ref +rt‿SetPrims ← •COMP provide DCompile ref PrimInd ← rt⊸⊐⌾< Decompose ← ((≠glyphs)>PrimInd)◶⟨•Decompose,0⊸≍⟩ SetPrims ⟨ Decompose, PrimInd ⟩ @@ -4,13 +4,12 @@ # multiple bodies, and use variable names instead of counts. # Rearrange and make up some names so the bytecode can be run. -glyphs ← •Import "src/glyphs.bqn" +glyphs ← •Import∘"src/glyphs.bqn"⍟(0=≠) •args compile ← glyphs •Import "src/c.bqn" -prims ← •BQN∘⥊¨ ∾glyphs special←<˘∘‿2⥊"𝕤𝕩𝕨𝕣𝕗𝕘" DCompile⇐{ - ⟨bc,o,fblk,ind⟩ ← 4 ↑ (𝕨⊣prims) Compile 𝕩 + ⟨bc,o,fblk,ind⟩ ← 4 ↑ (𝕨 •BQN∘⥊¨∘∾⊘⊣ glyphs) Compile 𝕩 blk‿bdy ← <˘⍉>(↕≠fblk){ ⟨t,i,l,n⟩←𝕩 s←(3×i)↓(t⊑3‿5‿6)↑special diff --git a/src/cjs.bqn b/src/cjs.bqn index efe6cb87..cb7b1a79 100755 --- a/src/cjs.bqn +++ b/src/cjs.bqn @@ -19,21 +19,24 @@ FP ← ∞⊸=◶⟨F,"Infinity"⟩ # Format positive number Num ← 0⊸≤◶⟨"-"∾FP∘|,FP⟩ # Format number glyphs ← •Import "glyphs.bqn" -compile ← glyphs •Import "c.bqn" +_getComp ← { (3+useInd) ↑ (𝕗 •Import "c.bqn"){𝔽} } useInd ← "-i"≡⊑args←•args ⋄ args↓˜↩useInd -Comp ← (3+useInd) ↑ ((<"runtime" Ind F)¨↕62)⊸Compile +Comp ← ((<"runtime" Ind F)¨↕62) glyphs _getComp ⊢ J ← ∾∾⟜(@+10)¨ Fconst ← ≡◶⟨@⊸≤◶Num‿Char, Str, ⊑⟩ Fout ← (≠↑⟨F,Fconst,L F¨,F⟩˙) {L𝕎¨𝕩}¨ ⊢ -Frun ← "provide"⊸Cat⌾(1⊸⊑) Fout Long ← ∾ (≠↑1‿3/⟨" "⊸∾⋄((@+10)∾" ,")⊸∾⟩˙) {𝕎𝕩}¨ ⊢ LFC ← Long∘Fout∘Comp -SVG ← {∾⟨"Modify←GetHighlights←⊢⋄"⟩∾ •FChars∘∾⟜".bqn"¨ "../svg"‿𝕩} +RT ← {𝕩 + prims‿ref←•Import"pr.bqn" ⋄ l←≠∾prims + Long "provide"⊸Cat⌾(1⊸⊑) Fout l⊸↓⌾(1⊸⊑) (↕l) prims _getComp ref +} CArg ← {J (¯5⊸↓∾𝕩˙)⌾⊑ •FLines "c.bqn"} +SVG ← {∾⟨"Modify←GetHighlights←⊢⋄"⟩∾ •FChars∘∾⟜".bqn"¨ "../svg"‿𝕩} •Out (⊑"r"‿"c"‿"cc"‿"f"‿"e"‿"p"⊐⊏)◶⟨ - {𝕩⋄ref‿len←•Import"pr.bqn"⋄Long Frun len⊸↓⌾(1⊸⊑)Comp ref} + RT {𝕩⋄LFC CArg "⟨"∾"⟩"«∾","⊸∾¨'"'(⊣∾∾˜)¨glyphs} {𝕩⋄LFC "{"∾"}"∾˜CArg"𝕩"} {𝕩⋄LFC •FChars "f.bqn"} @@ -4,20 +4,20 @@ # All primitives chrs←•Import "glyphs.bqn" -glyphs ⇐ ∾chrs +glyphs ← ∾chrs # Provided values, to be passed in through the constants array -def ← ⟨"Type","Fill","Log","GroupLen","GroupOrd","_fillBy_"⟩ +alias‿def ← (⊑¨ ≍○< 1⊸↓¨) ⟨"?Type","∩Fill","⍣Log", + "$GroupLen","%GroupOrd","⍝_fillBy_"⟩ keep ← "!+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘⎊" -len ⇐ def+○≠keep + +type ← ((+´·∧`'_'=0‿¯1⊸⊏)¨def) ∾ chrs((+`≠¨)∘⊣⍋∾⊸⊐)keep +prims ⇐ type ⊔ alias∾keep GetRepls ← { c‿n ← 𝕩 ki ← (⊑¨c)⊐keep - dt ← ⊔⟜⊒ (+´·∧`'_'=0‿¯1⊸⊏)¨ def - ns ← » ne←+`≠¨chrs - kt ← ∾ (ns+≠¨dt) + ⊔⟜⊒ne⍋ki - ⟨c,(kt⊏c)⌾(ki⊸⊏)n⟩∾¨⟨def,(∾ns+dt)⊏c⟩ + ⟨c,c⊣⌾(ki⊸⊏)n⟩∾¨⟨def,⥊¨alias⟩ } ⟨E_proc⟩ ← chrs‿GetRepls •Import "pp.bqn" |
