Scoping and Linkage
JIT Compile Mode makes use of the current task's hash symbol table and its parent tasks' tables. It fetches symbols from
parent tasks' tables if not found locally in the current task's table and it places new symbols in the current task's table.
Conceptually, symbols are at the scope of environment variables in other operating systems.
When a symbol is placed into a table, older symbols with ident names will be overshadowed if they exist. Duplicates are not
allowed in many cases, especially in asm blocks. Dupicates are allowed, by design in other cases, so that you can repeatedly
#include the same file from the cmd line while developing it. Or, so you can repeatedly declare a function with a standard
name, like DrawIt(). This case might occur when the System Task is starting-up loading-in many little utilities.
extern binds a new HTT_FUN or HTT_GLOBAL_VAR symbol to an existing symbol of the same name if it exists in the symbol table
(just in just-in-time code). It also can be used to generate a forward reference.
import binds a new HTT_FUN or HTT_GLOBAL_VAR symbol to a symbol of the same name imported from the task's symbol table at
Load() time. If no symbol exists to bind to at Load() time, the code using this symbol will be left incomplete until the
symbol is defined.
_extern binds a new HTT_FUN or HTT_GLOBAL_VAR symbol to an existing symbol, of a name. It must exists in the symbol
table. Basically, this binds C to asm.
_import binds a new HTT_FUN or HTT_GLOBAL_VAR symbol to a symbol, of a name imported from the task's symbol table at
Load() time. If no symbol exists to bind to at Load() time, the code using this symbol will be left incomplete until the
symbol is defined. Basically, this binds C to asm from elsewhere.
Ahead of Time Compilation
GlobalScope / FunctionScope
| CodeHeap / DataHeap / Stack / Register
| | TaskHashEntry: ExportSysSym / Define / Function / Class
| | | UsageScope: Module / AsmLocal / AsmBlk / TaskAndChildren / Function
| | | |UsageScope: Glbl / AsmLocal / Remainder / glblThisBlkAndRemainder
| | | || StaticVarInit / DynamicVarInitAllowed / NoInitAllowed
| | | || | Are dups allowed within the namespace? A dup overshadows the original.
| | | || | DupsAllowed / NoDups / NoDupsButPad / WarningUnlessClosedOut
asm export label:: G C S MG N
asm label: G C MG N
asm local @@label: G C AL N
asm IMPORT label; G C MR N
asm export label:: F C S BG N
asm label: F C BG N
asm local @@label: F C AL N
asm IMPORT label; F C BR N
C goto label: F C FG N
#define x MR D
function G C S MR D
variable F R FR N
variable F S FR N
static variable F C FR D N
variable G C S MR D D
variable G D MR N D
class G MR D
class member G MR P
extern class G MR D
extern function G C MR W
import function G C MR D
import variable G C MR D
_extern function G C MR D
_extern variable G C MR D
_import function G C MR D
_import variable G C MR D
Just in Time Compilation
GlobalScope / FunctionScope
| CodeHeap / DataHeap / Stack / Register
| | TaskHashEntry: ExportSysSym / Define / Function / Class
| | | UsageScope: Module / AsmLocal / AsmBlk / TaskAndChildren / Function
| | | |UsageScope: Glbl / AsmLocal / Remainder / glblThisBlkAndRemainder
| | | || StaticVarInit / DynamicVarInitAllowed / NoInitAllowed
| | | || | Are dups allowed within the namespace? A dup overshadows the original.
| | | || | DupsAllowed / NoDups / NoDupsButPad / WarningUnlessClosedOut
asm export label:: G C S Tg N
asm label: G C BG N
asm local @@label: G C AL N
asm IMPORT label; G C TR N
asm export label:: F C BG N
asm label: F C BG N
asm local @@label: F C AL N
asm IMPORT label; F C BR N
C goto label: F C FG N
#define x D TR D
function G C F TR D
variable F R FR N
variable F S FR N
static variable F C FR D N
variable G C G TR D D
variable G D G TR S D
class G C TR D
class member G TR P
extern class G C TR D
extern function G C F TR W
extern variable G C G TR D
extern variable G D G TR D
_extern function G C F TR D
_extern variable G C G TR D
* Goto labels must not have the same name as global scope objects. GoTo's are rare and we don't want to slow the compiler and
add code to fix this. You will get errors if a collision happens, so it's not very dangerous, but the error message is
baffling.
* The member names pad and reserved are special because multiple instances with the same name are allowed in a class.
* Use reg or noreg in front of local variable names to override automatic register variable allocation. You can, optionally,
specify a register after the reg keyword.
* Local non-reg function variables can be accessed in asm blocks with &i[RBP] for example.
* Global variables and functions can be accessed in asm with and & as in
MOV RAX, I64 [&global_var]
CALL I32 &Fun
CALL I32 &SYS_SYM
* In JIT asm code, &SYS_SYM and &Fun don't need IMPORT.
* All offspring tasks of a task inherit symbols.
* The sizeof() and CosmiC structure members can be used in asm blocks.
* Using &i in CosmiC or i.u8[2] on a local variable, i, will force it to noreg.
* Using try/catch in a function will force all local variables to noreg.
* An unused gap on the stack is left for reg variables.
* Note: static function variables do not go on the data heap, no matter the setting of the OPTf_GLOBALS_ON_DATA_HEAP. They
may in the future.
* OPTf_EXTERNS_TO_IMPORTS will treat _extern as _import and extern as import. This allows a header to be used either as a JIT
compiled or AOT compiled header.