From 8c4e40462e2e7628d86791ad92eed2253cb40830 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 13 Aug 2021 22:35:04 -0400 Subject: Support named inputs in headers --- src/c.bqn | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/c.bqn b/src/c.bqn index b39db38d..66dedac3 100644 --- a/src/c.bqn +++ b/src/c.bqn @@ -168,31 +168,34 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn "At most two header-less bodies allowed"_err_(/CB) »⊸∧co>¯1↓ch cc←(⍋⍋«co)⊏c∾/cs # Case close rr←rev⊏r - hr←rr/˜hf←hh⊏˜⟜IT⌾((⌽g)⊸⊏)¯1=rr + hr←rr⊏˜hi←/hf←hh⊏˜⟜IT⌾((⌽g)⊸⊏)¯1=rr hl←2=hn←(1⊸»+«)hc←¯1=hr ho←(»∨·«(hr=3)∧⊢)hl↩hc⋄hr/˜↩hm⋄hx←(1»hc)/ha # Header-derived role hr and immediacy ¬hx cw←(hc/»hl∨ha)⌾(ch⊸/)1+-⟜«(»ch)<1(⊢<«)cf # Body 𝕨: 0 no, 1 allowed, 2 required "Header left argument without right"_err_(/HF) ha>hc+`⊸⊏hx∾0 - "Header operation must be a plain name"_err_(/HF) hm>ht M bI+0‿nv - "Only special name inputs allowed in headers for now!"_err_(/HF) ¬hc∨hm∨ht M bI - hl/˜↩hm⋄hx∨↩1=hr⋄hu←(𝕩 M bI)hk≠2 + "Only plain names allowed in headers for now!"_err_(/HF) 2=hk + hx∨↩1=hr + hj←(0≠hk)/hi⋄hu←1¨⌾(hj⊸⊏)0¨hf # Block properties HS←H((0‿3‿5‿6+⊑bI)⍋𝕩)⊸=⋄sp←/hf<𝕩 M bI # Has-special (𝕤𝕩𝕨/𝕣𝕗/𝕘); indices of specials fx←HS 1⋄fr←(fx∨0⊸<)⊸+ft←2(⊣⌈2×⊢)○HS 3 # Body immediacy ¬fx, type ft, role fr - "Invalid special names for block header"_err_(ch/0∾/∘CB) (hrfx "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׬fx # Header variable slot # Propagate roles through parentheses # ir is the role of the expression ending at each position (truncated to the right) @@ -271,8 +274,8 @@ Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn idor←∾2‿3/⟨di,id∾sp⟩ # Identifier bytecode ordering ido←21+uu(⊢+10×>)ia∾sa # Opcode idoc←⟨26¨di,di⊏xv, ido,idd∾0¨sp,idi∾spi⟩ # Identifier bytecode: instruction, depth, slot - idor∾˜↩3/hi←/hu∧0∨|)ps(⊢-T)+`¬ro # Train argument (first-level) -- cgit v1.2.3