aboutsummaryrefslogtreecommitdiff
path: root/src/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/boot3.bqn19
-rw-r--r--src/bootstrap/verify.bqn17
2 files changed, 20 insertions, 16 deletions
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<ev # Variable indices
- vv←(iv⊏rx)-vi # Variable name
- ii←3↓⊐(¯3+↕3)∾vv # Slot within frame
- vb←bG M˜ va←iv⊏»rx # Variable assignment, if it's there
- idor←∾3/⟨iv⟩ # Identifier bytecode ordering
- idoc←⟨32+vb,0¨ii,ii⟩ # Identifier bytecode: instruction, depth, slot
- dn←⟨⟨⟩,(va=⊑bG)/vv⟩ # Identifier name ID, per-block
-
# Parsing
gr←rev⊏˜g←⍋+`rev⊏p # Order by bracket depth
𝕩↩gr⊏𝕩⋄r↩gr⊏r⋄ir↩gr⊏ir
at←/aa←»a←r=¯3 # Assignment target
ao←(a/𝕩)-⊑bG # Assignment opcode
+ iv←/(𝕩≥⊑bI)∧𝕩<ev # Variable indices
+ ii←(iv⊏𝕩)-⊑bI # Variable slot
tr←ir⊏˜IT»ps←r=¯1 # tr: train or modifier expression, ps: part separator
oa←⌽/op←r=2 # op: active modifiers; op: mod or right operand
ta←tr∧2(>∨|)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 ""