3bddc3c85e
This change allows qualified references to local labels from other sections: you can do `#send section.local` and it will take you to the appropriate `:.local` label. When `section.local` is ambiguous due to sections/locals sharing the same names, the reference resolves to the local in the first such section.
79 lines
1.0 KiB
Plaintext
79 lines
1.0 KiB
Plaintext
'Slightly contrived example: two routines
|
|
'using the same local label ".loop"
|
|
:run_w
|
|
#walk w
|
|
:.loop
|
|
#try w stop
|
|
#.loop
|
|
'
|
|
:run_e
|
|
#walk e
|
|
:.loop
|
|
#try e stop
|
|
#.loop
|
|
'
|
|
:stop
|
|
#walk i
|
|
---
|
|
'Using locals before any globals are defined
|
|
:.loop
|
|
#take gems 1 .break
|
|
#.loop
|
|
:.break
|
|
---
|
|
'Multiple sections with the same name
|
|
#end
|
|
:touch
|
|
Trying to sell you some ammo...
|
|
#take gems 10 .skip
|
|
#give ammo 10
|
|
:.skip
|
|
#zap touch
|
|
#end
|
|
:touch
|
|
Trying to sell you some torches...
|
|
#take gems 15 .skip
|
|
#give torches 5
|
|
:.skip
|
|
#restore touch
|
|
---
|
|
'Multiple locals with the same name
|
|
#end
|
|
:repeat3
|
|
:.z
|
|
:.z
|
|
:.z
|
|
#take gems 1 .skip
|
|
#give score 1
|
|
:.skip
|
|
#zap .z
|
|
#.z
|
|
:.z
|
|
---
|
|
'Addressing labels with section.local
|
|
:touch
|
|
:.foo
|
|
#end
|
|
:touch
|
|
:.foo
|
|
#end
|
|
:shot
|
|
'sends to the first one:
|
|
#touch.foo
|
|
---
|
|
@alice
|
|
:shared
|
|
'this is the 1st section named "shared"
|
|
'but its local should correspond with @bob's 2nd "shared"
|
|
:.local
|
|
#end
|
|
:shared
|
|
---
|
|
@bob
|
|
:shared
|
|
#end
|
|
:shared
|
|
'this is the 2nd section named "shared"
|
|
'but its local should correspond with @alice's 1st "shared"
|
|
:.local
|