aboutsummaryrefslogtreecommitdiff
path: root/src/pr.bqn
blob: fd2413952d06a3f3866e8bb64b390dfe936c282e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env dbqn

# Process BQN runtime

impl  •FLines "r.bqn"

chrs
  "+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"
  "˙˜˘¨⌜⁼´˝`"
  "∘○⊸⟜⌾⊘◶⎉⚇⍟"

nc  ¨chrs
glyphs  chr  chrs
itr  0˜chr

idChars  "_¯.π∞"∾∾"0aA"+¨102626

init  " "¨(/"_"¨nc/011)¨(nc/"FMD")¨(nc+´↑⥊"ABC"•a)
post  " "¨/"_"¨nc/001
out  init¨'0'¨post

Inc  {
  ichr𝕩
  n0  itr{n1+𝕩}(i⊑⊢)itr
  out((iinit)('0'+n)ipost)(i⊑⊢)out
}

# Required functionality passed in as an argument
def  "Type","Decompose","Glyph","Fill","Log","GroupLen","GroupOrd","_fillBy_"
keep  "!+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘"
len  def+keep
ki  chrkeep
dt   (+´·`'_'=0¯1)¨ def
ns  » ne+`nc
kt   (ns+≠¨dt) + neki

chrt  ¨chr
in   chrt                   def
out  ((ktchrt)(ki)out)  (ns+dt)chrt

E_isdef  (3≤≠)0,´chr," ","←↩"˜¨3
E_proc  {
  q`𝕩='"'  q`q<𝕩=''' ⋄ f←¬∨`q<𝕩='#'
  t  (¯1+`·¬(»f/q)·»∧∊idChars) f/𝕩
   (in out(<(in))¨ ) t
}
E_redef  { # handles [fmd] [←↩]
  tail  E_proc 3𝕩 # must use old def
  Inc 𝕩
  (E_proc 1𝕩)  "←"  tail
}

ref  ∾∾(@+10)¨ E_isdefE_procE_redef¨ impl∾<"⟨""⟩"«⥊","˘chr