hschumann2/TempleOS-Source-Code
0838
1 2 Scoping and Linkage3 4JIT Compile Mode makes use of the current task's hash sym table and its parent5tasks' tables. It fetches syms from parent tasks' tables if not found locally6in the current task's table and it places new syms in the current task's table.7Conceptually, syms are at the scope of environment vars in other operating8systems.9 10When a sym is placed into a table, older syms with ident names will be11overshadowed if they exist. Duplicates are not allowed in many cases,12especially in asm blks. Dupicates are allowed, by design in other cases, so13that you can repeatedly #include the same file from the cmd line while14developing it. Or, so you can repeatedly declare a function with a standard15name, like DrawIt(). This case might occur when the Adam Task is starting-up16loading-in many little utilities.17 18extern binds a new HTT_FUN or HTT_GLBL_VAR sym to an existing sym of the same19name if it exists in the sym table (just in just-in-time code). It also can be20used to generate a fwd reference.21 22import binds a new HTT_FUN or HTT_GLBL_VAR sym to a sym of the same name23imported from the task's sym table at Load() time. If no sym exists to bind to24at Load() time, the code using this sym will be left incomplete until the sym is25defined.26 27 28_extern binds a new HTT_FUN or HTT_GLBL_VAR sym to an existing sym, of a differe29nt name. It must exists in the sym table. Basically, this binds C to asm.30 31_import binds a new HTT_FUN or HTT_GLBL_VAR sym to a sym, of a different name32imported from the task's sym table at Load() time. If no sym exists to bind to33at Load() time, the code using this sym will be left incomplete until the sym is34defined. Basically, this binds C to asm from elsewhere.35 36 37Ahead of Time Compilation38 GlobalScope/FunctionScope39 | CodeHeap/DataHeap/Stack/Register40 | | TaskHashEntry:ExportSysSym/Define/Function/Class41 | | | UsageScope: Module/AsmLocal/AsmBlk/TaskAndChildren/Function42 | | | |UsageScope: Glbl/AsmLocal/Remainder/glblThisBlkAndRemainder43 | | | || StaticVarInit/DynamicVarInitAllowed/NoInitAllowed44 | | | || | Are dups allowed within the namespace? A dup overshadows the original.45 | | | || | DupsAllowed/NoDups/NoDupsButPad/WarningUnlessClosedOut46 47asm export label:: G C S MG N48asm label: G C MG N49asm local @@label: G C AL N50asm IMPORT label; G C MR N51asm export label:: F C S BG N52asm label: F C BG N53asm local @@label: F C AL N54asm IMPORT label; F C BR N55C goto label: F C FG N56 57 #define x MR D58 function G C S MR D59 var F R FR N60 var F S FR N61static var F C FR D N62 var G C S MR D D63 var G D MR N D64 class G MR D65class member G MR P66extern class G MR D67extern function G C MR W68import function G C MR D69import var G C MR D70_extern function G C MR D71_extern var G C MR D72_import function G C MR D73_import var G C MR D74 75 76Just in Time Compilation77 GlobalScope/FunctionScope78 | CodeHeap/DataHeap/Stack/Register79 | | TaskHashEntry:ExportSysSym/Define/Function/Class80 | | | UsageScope: Module/AsmLocal/AsmBlk/TaskAndChildren/Function81 | | | |UsageScope: Glbl/AsmLocal/Remainder/glblThisBlkAndRemainder82 | | | || StaticVarInit/DynamicVarInitAllowed/NoInitAllowed83 | | | || | Are dups allowed within the namespace? A dup overshadows the original.84 | | | || | DupsAllowed/NoDups/NoDupsButPad/WarningUnlessClosedOut85 86asm export label:: G C S Tg N87asm label: G C BG N88asm local @@label: G C AL N89asm IMPORT label; G C TR N90asm export label:: F C BG N91asm label: F C BG N92asm local @@label: F C AL N93asm IMPORT label; F C BR N94C goto label: F C FG N95 96 #define x D TR D97 function G C F TR D98 var F R FR N99 var F S FR N100static var F C FR D N101 var G C G TR D D102 var G D G TR S D103 class G C TR D104class member G TR P105extern class G C TR D106extern function G C F TR W107extern var G C G TR D108extern var G D G TR D109_extern function G C F TR D110_extern var G C G TR D111 112 113* Goto labels must not have the same name as global scope objects. GoTo's are114rare and I don't want to slow the compiler and add code to fix this. You will115get errors if a collision happens, so it's not very dangerous, but the error116message is baffling.117 118* The member names pad and reserved are special because multiple instances with119the same name are allowed in a class.120 121* Use reg or noreg in front of local var names to override automatic reg var122allocation. You can, optionally, specify a reg after the reg keyword.123 124* Local non-reg function vars can be accessed in asm blks with &i[RBP] for125example.126 127* Glbl vars and functions can be accessed in asm with and & as in128 MOV RAX,I64 [&glbl_var]129 CALL I32 &Fun130 CALL I32 &SYS_SYM131 132* In JIT asm code, &SYS_SYM and &Fun don't need IMPORT.133 134* All offspring tasks of a task inherit syms.135 136* The sizeof() and HolyC structure members can be used in asm blks.137 138* Using &i in HolyC or i.u8[2] on a local var, i, will force it to noreg.139 140* Using try/catch in a function will force all local vars to noreg.141 142* An unused gap on the stk is left for reg vars.143 144* Note: static function vars do not go on the data heap, no matter the setting145of the OPTf_GLBLS_ON_DATA_HEAP. They may in the future.146 147* OPTf_EXTERNS_TO_IMPORTS will treat _extern as _import and extern as import.148This allows a header to be used either as a JIT compiled or AOT compiled header.149 