From 027b59a117d305ca872031cf4a07bb026f271d9c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 6 Jun 2020 17:52:52 -0400 Subject: Add a four-function APL expression to wasm binary compiler --- c.bqn | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 c.bqn diff --git a/c.bqn b/c.bqn new file mode 100755 index 00000000..7c7bb665 --- /dev/null +++ b/c.bqn @@ -0,0 +1,51 @@ +#!/usr/bin/env bqn +Parse←{ + l←≠x←𝕩 + o←x='('⋄c←x=')'⋄v←x∊•d⋄f←¬o∨c∨v + na←f×1+l↑0∾c∨v + e←/c⋄d←+`o-c + ed←e⊏d⋄b←(⍋⍋ed)⊏(⍋⊏⟜d)⊸⊏/o + s←e-(e∾l)⊏˜{u←(≠e)¨𝕩⋄{(𝕩⊏u)↩𝕨⊏˜𝕨⍋𝕩}¨´˘2↕⊔𝕩⋄u}ed + fe←f×(l-1)++`(-⊸≍s)⌾((e≍b)⊸⊏)l⥊0 + ia←+`l↑0∾f-l↑/⁼∧f/fe + sel←¬∘⊏⟜(o∨c)⊸/⍋(fe⌈↕l)-ia + sel⊸⊏¨x‿na +} + +GenFn←{ + x‿na←𝕩 + D←16⊥(•d∾"ABCDEF")⊸⊐ + fns←{ + n←•d⊐<𝕩 + n=0:8⥊0 + l←2(⌊⋆⁼)n + (D"44")∾2⊥˘⌽8‿8(⊣⥊×´⊸↑)∾⟨⥊0,(11⥊2)⊤1023+l,(2⥊˜0⌈l)⊤n⟩ + }‿{ + ⟨⥊D"9A"⟩⊑˜"-"⊐<𝕩 + }‿{ + (⥊∘D¨"A0"‿"A1"‿"A2"‿"A3")⊑˜"+-×÷"⊐<𝕩 + } + (D"0B")∾˜∾na⊑⟜fns⊸{𝕎𝕩}¨x +} + +Gen←{ + LEB←{0≡𝕩:⥊0⋄128⊸+⌾(¯1⊸↓) 2⊥⌽⍉ (∨`⌾⌽∨´˘)⊸/ 10‿7(⊣⥊×´⊸↑) ⍉⌽(8⥊2)⊤𝕩} + C←LEB∘≠⊸∾ + S←∾⟜C + V←≠∾∾ + I←C∘•UCS + t‿n‿b←𝕩 + ∾⟨ + 0∾(•UCS"asm")∾4↑1 + 1 S V (96∾⟜∾C¨)¨t + 3 S V ⥊¨↕≠n + 7 S V I⊸(⊣∾0∾⊢)¨⟜(↕∘≠)n + 10 S V (C⟨⟩V⊸∾⊢)¨ b + ⟩ +} + +Compile←{ + body←GenFn Parse 𝕩 + (1↓∾)(","∾⥊∘⍕)¨ Gen ⟨⟨0‿1⟩/¨¨127-3 ⋄ ⥊<"fn" ⋄ ⥊