Scope modifiers: Difference between revisions

m
Line 791:
Modules ? ' list of modules show two: A and A.Checkit
Print Module$ ' print A
</lang>
Subs are searched first time for current module/function, or from parent code, and stored in a list as name, internal number of code source and position in code. Modules can replaced (we sy decorated) with other modules, before call (see CheckThis changed for a call with ChangeOther).
 
Internal M2000 Interpreter uses "Execution Objects", named Basetasks, which hold code for consuming. Modules and functions run on own Basetasks, but subs use the current basetask. There are routines using Gosub and Return like Basic.
 
Threads are part of modules/functions. They have own stack of values. own static variables, but they see everything like code in module:
 
<lang M2000 Interpreter>
Module CheckIt {
Module CheckSub {
Read Z
M=5000
Module CheckThis {
Z=500
Hello("Bob")
}
Function CheckFun {
Z=50
Hello("Mary")
}
Call CheckFun()
CheckThis
Hello("George")
Gosub label1
\\ sub work as exit here
Sub Hello(a$)
\\ any new definition erased at exit of sub
Local M=100
Print "Hello ";a$, Z, M
End Sub
label1:
\\ this light subs have no "erased new definition mode"
\\ they are like code of module
Print Z, M
Return
}
CheckSub 10
Module CheckOther {
Z=1000
Hello("John")
}
\\ we can replace CheckThis with CheckOther
CheckSub 20; CheckThis as CheckOther
}
Call Checkit
Module Alfa {
x=1
Thread {
x++
} as K interval 20
Thread {
PrintMe()
} as J interval 20
Main.Task 20 {
if x>99 then exit
}
Wait 100
Sub PrintMe()
Print x
End Sub
}
Call Alfa
</lang>
 
Anonymous user