aboutsummaryrefslogtreecommitdiff
path: root/dzref_full
blob: ab1c9886cf8c28a0430324966a37bec808f372a5 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env dbqn

# This version of dzref defines every primitive that spec/reference.bqn
# does. It's intended to test out these implementations for use in the
# BQN runtime; use plain dzref if you just want to run BQN as it's much
# faster and supports inverses better.

impl  LNS "src/r.bqn"

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

  init  " "⊸∾¨(/"_"¨nc/011)∾¨(nc/"FMD")∾¨(nc+´⊸↑⥊"ABC"∾⌜•a)
  post  ∾⟜" "¨/"_"¨nc/001
  names  init∾¨'0'∾¨post

  Inc  {
    i←⊑chr𝕩
    n0  itr↩{n1+𝕩}⌾(i⊑⊢)itr
    names((iinit)('0'+n)ipost)(i⊑⊢)names
  }

  # built-in assumptions
  Mod  {((chr𝕨)names)  " ← "  𝕩}

  ⍎¨ 
    "IsArray ← 0≠≡"
    "Type    ← ⊑⟨⟩⥊0⊸⥊"
    "Log     ← ⋆⁼"
    "GroupLen← ≠¨⊔"
    "GroupOrd← ∾⊔∘⊢"
    '!' Mod "{𝕩 ⋄ ≤1}⍟(1≢⊢)"
  ⟩∾Mod⟜⥊¨ "+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘"


  # checks if line is a builtin redefinition
  E_isdef  (3≤≠)◶⟨0,∧´⟨chr," ","←↩"⟩∊˜¨3⊸↑⟩

  # removes comments and replaces built-ins with names
  E_proc  {
    l←≠chr
    q←≠`𝕩='"'  q∨↩≠`q<𝕩=''' ⋄ f←¬∨`q<𝕩='#'
     (((l×f/q)+chr⊸⊐) (≥⟜l)◶⟨⊑⟜names,⥊∘⊢⟩¨ ) f/𝕩
  }

  E_redef  { # handles [fmd] [←↩]
    tail  E_proc 3𝕩 # must use old def
    Inc 𝕩
    (E_proc 1𝕩)  "←"  tail
  }

  lf  @+10
  pre  E_isdefE_procE_redef¨ impl
  Raw↩⍎
  ExecFile←{Raw  ∾⟜lf¨ E_proc¨ LNS 𝕩}
  XRawE_proc
    ∾⟜lf¨ pre
  ≠◶X‿{ExecFile 𝕩}‿{ExecFile 𝕩  X 1𝕩} args
}