From 9820a3c86b00fe480ec11b397887d6d068c51215 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 28 Jan 2023 12:22:20 -0500 Subject: Use text order instead of evaluation order for variables in boot3 --- src/bootstrap/boot3.bqn | 19 ++++++------------- src/bootstrap/verify.bqn | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/boot3.bqn b/src/bootstrap/boot3.bqn index bc912bc2..f26e8499 100644 --- a/src/bootstrap/boot3.bqn +++ b/src/bootstrap/boot3.bqn @@ -70,21 +70,13 @@ # Reverse each expression: *more* complicated than it looks rev←⍋+`¯1↓(¯1∾gb)(⊣⍋⊸⊏⊏˜⟜⍋¬⊏˜)⍋+`⊸+1∾gb⊏r=¯1 - # Lexical resolution, no nesting - rx←rev⊏𝕩 - iv←/(rx≥⊑bI)∧rx∨|)ps(⊢-TT)+`¬op # Train argument (first-level) @@ -103,11 +95,12 @@ # Object code generation: numbers oc ordered by source location (after rev) oi fsc←3×fx←↕2 # Body immediacy ¬fx, special name count - or←⍋idor∾g⊏˜∾⟨cn,cn,bk,bk,lb,lb,at,dr,oa+1⌈oa⊏os,fl,rt⟩ - oc←or⊏∾idoc∾⟨0¨cn,ob,1¨bk,1+↕≠bk,11+lb⊏aa,ll,48+ao,6¨dr - 24+oa⊏r,16+dy+4×fa⊏tr,¯1↓rc←7¨fx⟩ + or←⍋g⊏˜∾⟨iv,iv,iv,cn,cn,bk,bk,lb,lb,at,dr,oa+1⌈oa⊏os,fl,rt⟩ + oc←or⊏ ∾⟨32+iv⊏aa,0¨iv,ii,0¨cn,ob,1¨bk,1+↕≠bk,11+lb⊏aa,ll,48+ao,6¨dr + 24+oa⊏r,16+dy+4×fa⊏tr,¯1↓rc←7¨fx⟩ # Output fz←⟨0¨fx,¬fx,↕≠fx⟩ # Per-function data + dn←⟨⟨⟩,↕+´0=ao⟩ # Identifier name ID, per-block cz←⟨/1∾or≥oc-○≠rt,fsc+≠¨dn,dn,0¨¨dn⟩ # Per-body data ⟨oc∾¯1⊑rc,∾⟨u⊏𝕨⟩∾1↓k,<˘⍉>fz,<˘⍉>cz⟩ # Overall output } diff --git a/src/bootstrap/verify.bqn b/src/bootstrap/verify.bqn index 88b661f3..6a24dceb 100644 --- a/src/bootstrap/verify.bqn +++ b/src/bootstrap/verify.bqn @@ -9,13 +9,24 @@ t ← (∾∾⟜(@+10)¨)¨ (¯5⊸↓∾gl˙)⌾⊑⌾⊑ •FLines¨ f # Compi # Check that compiler 𝕩 compiles 𝕩-1 same as full compiler Ver ← { norm ← {𝕎𝕏}˜´ 𝕩 ↑ ⟨ - 4⊸↑ # Strip source info, always - ⋈⁼∘∾⍟=¨⌾(2⊑¨2⊸⊑) # Turn only-dyadic functions to ambivalent, only ≥2 - (⊢-2×34⊸=)⌾⊑ # VARU to VARO, could hit non-opcode numbers, oh well + 4⊸↑ # Strip source info, always + ⋈⁼∘∾⍟=¨⌾(2⊑¨2⊸⊑) # Turn only-dyadic functions to ambivalent if ≥2 + NormVar⌾(⊑⋈2⊑¯1⊑3⊑⊢) # Normalize variable opcodes if =3, defined below ⟩ ! ≡○Norm´ (0‿𝕩⊏c) {𝕎𝕩}¨ (𝕩-1)⊏t •Out ∾⟨"Boot -",'0'+𝕩," verified!"⟩ } +NormVar ← { + ba ← /´'0'-˜⟨ # For each instruction, number of: + "11411311121111111315114131131111=111" # Codes until next opcode + "111000111100000000002221100000000111" # Arguments + ⟩ + Se←≠(>/⊢)∾⟜≠{(⊏˜𝕨)𝕊⍟(≠○(¯1⊸⊑))𝕩∾𝕩⊏𝕨}⟨0⟩˙ + m ← (≠𝕩)↑/⁼ Se (↕≠𝕩)+1+ba(⊣⊏˜≠⊸>×⊢)𝕩 # Mask of opcode starts + 𝕩 (⊢-m∧2×34⊸=)↩ # VARU to VARO + ⟨⊏⟜((↕⊸-3)∾𝕨)⌾((0‿0»m∧𝕩∊32‿33)⊸/) 𝕩,↕≠𝕨⟩ +}˜´ + Ver¨ 1+↕3 •Out "" -- cgit v1.2.3