aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-28 14:01:15 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-28 14:01:15 -0400
commit5199bc3835b6509f01560660750cd102cd5cf033 (patch)
treeb4a114fa0fc251be7b8b025094c9a166fb2c48c3 /src
parenta4de4b3f2d3a0b38588c013e2200f08f100fc1d5 (diff)
Split r.bqn into r0.bqn and r1.bqn, but compile as one unit
Diffstat (limited to 'src')
-rwxr-xr-xsrc/pr.bqn3
-rw-r--r--src/r0.bqn47
-rw-r--r--src/r1.bqn (renamed from src/r.bqn)66
3 files changed, 65 insertions, 51 deletions
diff --git a/src/pr.bqn b/src/pr.bqn
index 29337498..df1b1ac8 100755
--- a/src/pr.bqn
+++ b/src/pr.bqn
@@ -24,5 +24,6 @@ GetRepls ← {
gd ← "glyphs←"""∾glyphs∾"%"""
rslt ← "⟨"∾"⟩"«∾","⊸∾¨glyphs # Output all primitives
-src ← ∾⟨⟨gd⟩,•FLines"r.bqn",⟨"{PrimInd↩⊑𝕩⊐<⋄𝕩‿SetPrims}"∾rslt⟩⟩
+rr ← •FLines¨ "r0.bqn"‿"r1.bqn"
+src ← ∾⟨⟨gd⟩,∾rr,⟨"{PrimInd↩⊑𝕩⊐<⋄𝕩‿SetPrims}"∾rslt⟩⟩
ref ⇐ ∾∾⟜(@+10)¨ E_proc¨ src
diff --git a/src/r0.bqn b/src/r0.bqn
new file mode 100644
index 00000000..2dc08d62
--- /dev/null
+++ b/src/r0.bqn
@@ -0,0 +1,47 @@
+# BQN runtime part 0. Requires:
+# Fill _fillBy_
+# +-×⌊=≤≢⥊⊑↕⌜
+# Provides:
+# ⌊⌈|<>≠≥⊢⊣∾↑↓⊏˙˜´∘○⊸⟜◶⍟
+# ^^^^^^^ ^^^^ ^ ^^ are limited, suitable for r1
+
+⊢ ← {𝕩}
+⊣ ← {𝕩}⊘{𝕨}
+˙ ← {𝕩⋄𝕗}
+˜ ← {𝕩𝔽𝕨⊣𝕩}
+∘ ← {𝔽𝕨𝔾𝕩}
+○ ← {(𝔾𝕨)𝔽𝔾𝕩}
+⊸ ← {(𝔽𝕨⊣𝕩)𝔾𝕩}
+⟜ ← {(𝕨⊣𝕩)𝔽𝔾𝕩}
+◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # LIMITED to number left operand result
+⍟ ← {𝕨((𝕨𝔾𝕩)⊑⊢‿𝕗){𝔽}𝕩} # LIMITED to boolean right operand result
+
+Box ← {𝕩Fill⟨⟩⥊⟨𝕩⟩}
+# LIMITED to numeric arguments for arithmetic cases
+≥ ← ≤˜
+< ← Box ⊘ (1-≥)
+> ← (1-≤)
+⌊ ↩ ⌊ ⊘ (⊣-≥×-)
+⌈ ← -∘⌊∘- ⊘ (⊣-≤×-)
+| ← 0⊸≤◶-‿⊢
+≠ ← (0<=)◶⟨1⋄0⊑≢⟩ # LIMITED to monadic case
+
+∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two list arguments
+↑ ← {⊑⟜𝕩⌜↕𝕨} # LIMITED to number 𝕨 and list 𝕩
+↓ ← {(𝕨⊸+⊑𝕩˙)⌜↕(≠𝕩)-𝕨} # LIMITED to number 𝕨 and list 𝕩
+
+_fold0←{
+ l←≠𝕩 ⋄ F←𝔽
+ r←𝕨 {l↩l-1⋄l⊑𝕩}⊘⊣ 𝕩
+ ({r↩𝕩 F r}(l-1)⊸-⊑𝕩˙)⌜↕l
+ r
+}
+´ ← _fold0 # LIMITED to nonempty list 𝕩, or 𝕨 and list 𝕩
+
+GetCells←(1==∘⊢)◶{
+ c←1×´s←1↓≢𝕩
+ (c⊸×⌜𝕨)(+⊑(⥊𝕩)˙)⌜s⥊↕c
+}‿{
+ ⊑⟜𝕩⌜𝕨
+} _fillBy_ ⊢
+⊏ ← GetCells # LIMITED to depth-1 natural number left argument
diff --git a/src/r.bqn b/src/r1.bqn
index 9208a598..7944f2b6 100644
--- a/src/r.bqn
+++ b/src/r1.bqn
@@ -1,61 +1,21 @@
-# BQN runtime. Requires:
+# BQN runtime part 1. Requires:
# Type Fill Log GroupLen GroupOrd _fillBy_
-# !+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘
+# +-×÷⋆⌊⌈|<>=≠≤≥≢⊢⊣⥊∾↑↓↕⊏⊑!⌜˙˜´`∘○⊸⟜◶⊘⍟
# Filled in by runtime: glyphs and default PrimInd
+# Provides: all BQN primitives
+
Decompose ← {0‿𝕩}
PrimInd ← {𝕩}
SetPrims ← {Decompose‿PrimInd ↩ 𝕩}
-◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # LIMITED to number left operand result
-⊢ ← {𝕩}
-⊣ ← {𝕩}⊘{𝕨}
-˙ ← {𝕩⋄𝕗}
-˜ ← {𝕩𝔽𝕨⊣𝕩}
-∘ ← {𝔽𝕨𝔾𝕩}
-○ ← {(𝔾𝕨)𝔽𝔾𝕩}
-⊸ ← {(𝔽𝕨⊣𝕩)𝔾𝕩}
-⟜ ← {(𝕨⊣𝕩)𝔽𝔾𝕩}
-⍟ ← {𝕨((𝕨𝔾𝕩)⊑⊢‿𝕗){𝔽}𝕩} # LIMITED to boolean right operand result
-
-IsArray←0=Type
-Int←(1=Type)◶⟨0,⌊⊸=⟩
-Nat←(1=Type)◶⟨0,0⊸≤×⌊⊸=⟩
-Deshape←IsArray◶{𝕩Fill⟨𝕩⟩}‿⥊
+IsArray ← 0=Type
+Int ← (1=Type)◶⟨0,⌊⊸=⟩
+Nat ← (1=Type)◶⟨0,0⊸≤×⌊⊸=⟩
+Deshape ← IsArray◶{𝕩Fill⟨𝕩⟩}‿⥊
Pair ← {⟨𝕩⟩} ⊘ {⟨𝕨,𝕩⟩}
-Box ← {𝕩Fill⟨⟩⥊⟨𝕩⟩}
-ToArray ← Box⍟(1-IsArray)
-
-# LIMITED to numeric arguments for arithmetic cases
-≥ ← ≤˜
-< ← Box ⊘ (1-≥)
-> ← (1-≤)
-⌊ ↩ ⌊ ⊘ (⊣-≥×-)
-⌈ ← -∘⌊∘- ⊘ (⊣-≤×-)
-| ← 0⊸≤◶-‿⊢
-≠ ← (0<=)◶⟨1⋄0⊑≢⟩ # LIMITED to monadic case
-
-_fold←{
- "´: 𝕩 must be a list" ! 1==𝕩
- l←≠v←𝕩 ⋄ F←𝔽
- r←𝕨 (0<l)◶{𝕩⋄Identity f}‿{l↩l-1⋄l⊑𝕩}⊘⊣ 𝕩
- ({r↩𝕩 F r}(l-1)⊸-⊑𝕩˙)⌜↕l
- r
-}
-´ ← _fold
-
-∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two list arguments
-↑ ← {⊑⟜𝕩⌜↕𝕨} # LIMITED to number 𝕨 and list 𝕩
-↓ ← {(𝕨⊸+⊑𝕩˙)⌜↕(≠𝕩)-𝕨} # LIMITED to number 𝕨 and list 𝕩
+ToArray ← <⍟(1-IsArray)
Cell ← ↓⟜≢
-GetCells←(1==∘⊢)◶{
- c←1×´s←1 Cell 𝕩
- (c⊸×⌜𝕨)(+⊑(⥊𝕩)˙)⌜s⥊↕c
-}‿{
- ⊑⟜𝕩⌜𝕨
-} _fillBy_ ⊢
-⊏ ← GetCells # LIMITED to depth-1 natural number left argument
-
_qSearch ← {+´·×`𝕗(1-=)⌜<}
_glyphLookup_ ← {
{PrimInd𝕩} ⊑ ((𝕘⊑˜𝕗_qSearch)⌜glyphs)˙
@@ -77,6 +37,11 @@ Identity ← {𝕏0} ("´: Identity not found"!0˙) _lookup_ ⟨
'>',0 , '≥',1
+_fold←{
+ "´: 𝕩 must be a list" ! 1==𝕩
+ 𝕨 (0<≠)⊘1◶⟨Identity 𝕗˙, 𝔽´⟩ 𝕩
+}
+
_eachd←{
_d←{ # Equal ranks
p←≢𝕨
@@ -618,7 +583,7 @@ GroupGen←{
∧ ← ⍋⊸⊏ ⊘ (× _perv)
∨ ← ⍒⊸⊏ ⊘ ((+-×) _perv)
× ↩ (0⊸(<->) ⊘ ×) _perv
-< ↩ Box ⊘ ((1-≥) _perv)
+< ↩ < ⊘ ((1-≥) _perv)
> ↩ Merge ⊘ ((1-≤) _perv)
≠ ↩ ≠ ⊘ ((1-=) _perv)
= ↩ = ⊘ (= _perv)
@@ -850,6 +815,7 @@ Mod2Inverse ← INF˙ _lookup_ ⟨
'⟜', {(𝕨IsConstant∘⊢◶⟨IA∘0˙,{𝕩𝕎{SwapInverse𝕗}⊢}⟩𝕩)⊘(𝕏⁼𝕎⁼)}
⟩ { inv˙⊸=◶⟨𝔽,{𝕏_inv_𝕎}˙⟩ }
+´ ← _fold
˝ ← _insert
⁼ ↩ _undo
⊑ ↩ First ⊘ Pick