From 8480fd5393721e57ec3bc0171513f3239d193f6d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 27 Sep 2021 21:21:29 -0400 Subject: Add support for ? predicates --- src/c.bqn | 35 +++++++++++++++++++---------------- src/pr.bqn | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/c.bqn b/src/c.bqn index 39d7664e..40c85159 100644 --- a/src/c.bqn +++ b/src/c.bqn @@ -5,7 +5,7 @@ charSet‿cgl←(∾ ≍○< ≠¨)⟨ mod1 # 1-modifier mod2 # 2-modifier "⋄,"∾lf # Separator - ":;" # Header punctuation + ":;?" # Header punctuation "⇐←↩" # Gets "(){}⟨⟩" # Bracket "‿" # Ligature @@ -161,13 +161,13 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn g⊏˜↩gs←⍋gr⊏sl⋄gr↩g⊏rev⋄gi←⍋g # Send strand prefixes *‿ to the end # Headers - hh←𝕩=⊑bH⋄cs←𝕩=1+⊑bH # Case header : and separator ; - "Punctuation : and ; not allowed outside blocks"_err_(↕∘≠) (∨`b)¯1↓ch + "Header-less bodies must come last"_err_(/CB) 1(-⊸↓¯1↓cq cc←(⍋⍋«co)⊏c∾/cs # Case close hi←/hf←hh⊏˜⟜IT⌾((⌽g)⊸⊏)cb∨hh # Header component indices un←0=us←swap_undo(≠∘⊣-⊐)hi⊏𝕩 @@ -186,7 +186,7 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn "Incorrect special name"_err_(HI) (0=hk)∧ht≠hv+⊑bI hk×↩¬hc∨hl∧0=hr # Treat subject labels like special names hm>↩hc⋄hr/˜↩hm⋄hx←(1»hc)/ha # Header-derived role hr and immediacy ¬hx - cw←1+-⟜«(»ch)<1(⊢<«)cf + cw←1+-⟜«(»cq)<1(⊢<«)cf cw↩(hc/»hla¬⊸×hl⌈ha×1+he←0≠hk)⌾(ch⊸/)cw # Body 𝕨: 0 no, 1 allowed, 2 required "Invalid Undo header syntax"_err_(HI) hm<×ut cu←(hm/ut)⌾(ch⊸/)0¨cw⋄cw⌈↩2×2=cu @@ -202,7 +202,7 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn "Invalid special names for block header"_err_(ch/0∾/∘CB) (hrfx + "Only blocks with explicit arguments can have multiple bodies"_err_(/CB) 1↓(»⊸∨cq>ch)fx "Block bodies must be of the same kind"_err_(/CB) 1↓cf<»⊸≠ft fsc←(ft⊏0‿2‿3)+3×fx # Special name count hv-↩(»+`hc)⊏3׬ch/fx # Header variable slot @@ -251,7 +251,7 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn {"Can't return Nothing (·)"_err_(𝕩⊏⍋∘Rev) 2=fw⌈↩nf¬⊸×𝕩⊏nr} 1-˜0∾cc⊏rev fv←fw⋄fw≥○I1T↩cf # If a body fails on 𝕨, later ones won't see 𝕨 (∨´(1↓fv)⊸<)◶"Invalid use of 𝕨 in monadic case"‿"Unreachable body"_err_(/CB) 1↓fw∧cw=0 - cw⌈↩2×fw + cw⌈↩2×fw⋄cw×↩fx nn←fo+`⊸⊏2=cw⋄no(⊣-=)↩nn⋄ne(⊣-=)↩nn # 2=cw indicates 𝕨 is never Nothing aid←(¯6⊸≤∧<⟜nv)𝕩-vi # Assignable identifer hq←/hp←(g⊏ah)∧𝕩≥nv+vi # Header constant @@ -303,26 +303,29 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn bk←c⊏gi # Block loads ll←sll∾˜(¬lo/1«ps)+-⟜»1↓(lo∾1)/+`ls∾0 # List Length dr←(hd¬⊸/hj)∾/s>(2=ne)∨ls∨»r=¯5⋄rt←/fo # Drop (block separator) and return + qp←/𝕩=2+⊑bH # Predicate fl←(dy×⊏⟜os)⊸+fa+dy # Function application site dr∾↩((1+dy)×fn←2=fm←fa⊏ne)/fl # Turn function applications on · to drops fn↩¬fn⋄fa/˜↩fn⋄fl/˜↩fn # And remove them # Object code generation: numbers oc ordered by source location (after rev) oi ao←48+(0⌈(1+⊑bG)-˜ai⊏𝕩+ma+mm)∾-hd # Assignment opcode - or←⍋oi←idor∾g⊏˜∾⟨cn,cn,bk,bk,hq,2/l,at,dr,al+1,al+1,oa+1⌈oa⊏os,fl,rt⟩ - oc←or⊏∾idoc∾⟨0¨cn,ob,1¨bk,1+↕≠bk,43¨hq,⥊⍉(11+l⊏aa)≍ll,ao,6¨dr,66¨al,vi-˜(al-1)⊏𝕩 + or←⍋oi←idor∾g⊏˜∾⟨cn,cn,bk,bk,hq,2/l,at,dr,qp,al+1,al+1,oa+1⌈oa⊏os,fl,rt⟩ + oc←or⊏∾idoc∾⟨0¨cn,ob,1¨bk,1+↕≠bk,43¨hq,⥊⍉(11+l⊏aa)≍ll,ao,6¨dr,42¨qp,66¨al,vi-˜(al-1)⊏𝕩 24+oa⊏r,16+(fn/dy+2×fm⌈1=ny)+4×0