aboutsummaryrefslogtreecommitdiff
path: root/dc.bqn
blob: c00d0e139e235f6cb1f42bd1a0460e31f125665a (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
#! /usr/bin/env dbqn

# dzaima/BQN block headers have a different format to account for
# multiple bodies, and use variable names instead of counts.
# Rearrange and make up some names so the bytecode can be run.

compile ← β€’Import "src/c.bqn"
prims ← (β€’Import "dzref"){𝔽} "⟨
  +,-,Γ—,Γ·,⋆,√,⌊,⌈,|,Β¬,∧,∨,<,>,β‰ ,=,≀,β‰₯,≑,β‰’,⊣,⊒,β₯Š,∾,≍,↑,↓,↕,Β«,Β»,⌽,⍉,/,⍋,⍒,⊏,βŠ‘,⊐,βŠ’,∊,⍷,βŠ”,!
  Λ™,˜,˘,Β¨,⌜,⁼,Β΄,˝,`
  ∘,β—‹,⊸,⟜,⌾,⊘,β—Ά,βŽ‰,βš‡,⍟
⟩"

special←<Λ˜βˆ˜β€Ώ2β₯Š"π•€π•©π•¨π•£π•—π•˜"
DCompile⇐{
  ⟨bc,o,fblk,ind⟩ ← 4 ↑ (π•¨βŠ£prims) Compile 𝕩
  blkβ€Ώbdy ← <Λ˜β‰>(↕≠fblk){
    ⟨t,i,l,nβŸ©β†π•©
    s←(3Γ—i)↓(tβŠ‘3β€Ώ5β€Ώ6)↑special
    ⟨⟨t,i,𝕨,π•¨βŸ© β‹„ ⟨l, s∾β₯ŠΒ¨'a'+↕n-β‰ s⟩⟩
  }Β¨fblk
  ⟨bc,o,blk,βŠ‘blk,bdy,βŠ‘ind,1βŠ‘ind,π•©βŸ©
}
DRun⇐‒COMP∘DCompile