templeos-info/public/Wb/Doc/ScopingLinkage.DD.HTML

179 lines
17 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF5> Scoping and Linkage</span><span class=cF0>
<a name="l2"></a></span><span class=cF4>
<a name="l3"></a></span><a href="/Wb/Doc/Glossary.DD.HTML#l221"><span class=cF4>JIT Compile Mode</span></a><span class=cF0> makes use of the current task's hash sym table and its parent
<a name="l4"></a>tasks' tables. It fetches syms from parent tasks' tables if not found locally
<a name="l5"></a>in the current task's table and it places new syms in the current task's table.
<a name="l6"></a>Conceptually, syms are at the scope of environment vars in other operating
<a name="l7"></a>systems.
<a name="l8"></a>
<a name="l9"></a>When a sym is placed into a table, older syms with ident names will be
<a name="l10"></a>overshadowed if they exist. Duplicates are not allowed in many cases,
<a name="l11"></a>especially in asm blks. Dupicates are allowed, by design in other cases, so
<a name="l12"></a>that you can repeatedly </span><span class=cF2>#include</span><span class=cF0> the same file from the cmd line while
<a name="l13"></a>developing it. Or, so you can repeatedly declare a function with a standard
<a name="l14"></a>name, like </span><span class=cF2>DrawIt()</span><span class=cF0>. This case might occur when the </span><a href="/Wb/Doc/Glossary.DD.HTML#l171"><span class=cF4>Adam Task</span></a><span class=cF0> is starting-up
<a name="l15"></a>loading-in many little utilities.
<a name="l16"></a>
<a name="l17"></a></span><span class=cF2>extern</span><span class=cF0> binds a new </span><a href="/Wb/Kernel/KernelA.HH.HTML#l692"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="/Wb/Kernel/KernelA.HH.HTML#l689"><span class=cF4>HTT_GLBL_VAR</span></a><span class=cF0> sym to an existing sym of the same
<a name="l18"></a>name if it exists in the sym table (just in just-in-time code). It also can be
<a name="l19"></a>used to generate a fwd reference.
<a name="l20"></a>
<a name="l21"></a></span><span class=cF2>import</span><span class=cF0> binds a new </span><a href="/Wb/Kernel/KernelA.HH.HTML#l692"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="/Wb/Kernel/KernelA.HH.HTML#l689"><span class=cF4>HTT_GLBL_VAR</span></a><span class=cF0> sym to a sym of the same name
<a name="l22"></a>imported from the task's sym table at </span><a href="/Wb/Kernel/KLoad.HC.HTML#l181"><span class=cF4>Load</span></a><span class=cF0>() time. If no sym exists to bind to
<a name="l23"></a>at </span><a href="/Wb/Kernel/KLoad.HC.HTML#l181"><span class=cF4>Load</span></a><span class=cF0>() time, the code using this sym will be left incomplete until the sym is
<a name="l24"></a>defined.
<a name="l25"></a>
<a name="l26"></a>
<a name="l27"></a></span><span class=cF2>_extern</span><span class=cF0> binds a new </span><a href="/Wb/Kernel/KernelA.HH.HTML#l692"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="/Wb/Kernel/KernelA.HH.HTML#l689"><span class=cF4>HTT_GLBL_VAR</span></a><span class=cF0> sym to an existing sym, of a <blink>differe
<a name="l28"></a>nt</blink> name. It must exists in the sym table. Basically, this binds C to asm.
<a name="l29"></a>
<a name="l30"></a></span><span class=cF2>_import</span><span class=cF0> binds a new </span><a href="/Wb/Kernel/KernelA.HH.HTML#l692"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="/Wb/Kernel/KernelA.HH.HTML#l689"><span class=cF4>HTT_GLBL_VAR</span></a><span class=cF0> sym to a sym, of a <blink>different</blink> name
<a name="l31"></a>imported from the task's sym table at </span><a href="/Wb/Kernel/KLoad.HC.HTML#l181"><span class=cF4>Load</span></a><span class=cF0>() time. If no sym exists to bind to
<a name="l32"></a>at </span><a href="/Wb/Kernel/KLoad.HC.HTML#l181"><span class=cF4>Load</span></a><span class=cF0>() time, the code using this sym will be left incomplete until the sym is
<a name="l33"></a>defined. Basically, this binds C to asm from elsewhere.
<a name="l34"></a>
<a name="l35"></a>
<a name="l36"></a></span><span class=cF5>Ahead of Time Compilation</span><span class=cF0>
<a name="l37"></a> </span><span class=cF2>G</span><span class=cF0>lobalScope/</span><span class=cF2>F</span><span class=cF0>unctionScope
<a name="l38"></a> | </span><span class=cF2>C</span><span class=cF0>odeHeap/</span><span class=cF2>D</span><span class=cF0>ataHeap/</span><span class=cF2>S</span><span class=cF0>tack/</span><span class=cF2>R</span><span class=cF0>egister
<a name="l39"></a> | | TaskHashEntry:Export</span><span class=cF2>S</span><span class=cF0>ysSym/</span><span class=cF2>D</span><span class=cF0>efine/</span><span class=cF2>F</span><span class=cF0>unction/</span><span class=cF2>C</span><span class=cF0>lass
<a name="l40"></a> | | | UsageScope: </span><span class=cF2>M</span><span class=cF0>odule/</span><span class=cF2>A</span><span class=cF0>smLocal/Asm</span><span class=cF2>B</span><span class=cF0>lk/</span><span class=cF2>T</span><span class=cF0>askAndChildren/</span><span class=cF2>F</span><span class=cF0>unction
<a name="l41"></a> | | | |UsageScope: </span><span class=cF2>G</span><span class=cF0>lbl/Asm</span><span class=cF2>L</span><span class=cF0>ocal/</span><span class=cF2>R</span><span class=cF0>emainder/</span><span class=cF2>g</span><span class=cF0>lblThisBlkAndRemainder
<a name="l42"></a> | | | || </span><span class=cF2>S</span><span class=cF0>taticVarInit/</span><span class=cF2>D</span><span class=cF0>ynamicVarInitAllowed/</span><span class=cF2>N</span><span class=cF0>oInitAllowed
<a name="l43"></a> | | | || | Are dups allowed within the namespace? A dup overshadows the original.
<a name="l44"></a> | | | || | </span><span class=cF2>D</span><span class=cF0>upsAllowed/</span><span class=cF2>N</span><span class=cF0>oDups/NoDupsBut</span><span class=cF2>P</span><span class=cF0>ad/</span><span class=cF2>W</span><span class=cF0>arningUnlessClosedOut
<a name="l45"></a>
<a name="l46"></a>asm export </span><span class=cF2>label::</span><span class=cF0> G C S MG N
<a name="l47"></a>asm </span><span class=cF2>label:</span><span class=cF0> G C MG N
<a name="l48"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> G C AL N
<a name="l49"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> G C MR N
<a name="l50"></a>asm export </span><span class=cF2>label::</span><span class=cF0> F C S BG N
<a name="l51"></a>asm </span><span class=cF2>label:</span><span class=cF0> F C BG N
<a name="l52"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> F C AL N
<a name="l53"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> F C BR N
<a name="l54"></a>C goto </span><span class=cF2>label:</span><span class=cF0> F C FG N
<a name="l55"></a>
<a name="l56"></a> </span><span class=cF2>#define</span><span class=cF0> x MR D
<a name="l57"></a> function G C S MR D
<a name="l58"></a> var F R FR N
<a name="l59"></a> var F S FR N
<a name="l60"></a></span><span class=cF2>static</span><span class=cF0> var F C FR D N
<a name="l61"></a> var G C S MR D D
<a name="l62"></a> var G D MR N D
<a name="l63"></a> </span><span class=cF2>class</span><span class=cF0> G MR D
<a name="l64"></a>class member G MR P
<a name="l65"></a></span><span class=cF2>extern class</span><span class=cF0> G MR D
<a name="l66"></a></span><span class=cF2>extern</span><span class=cF0> function G C MR W
<a name="l67"></a></span><span class=cF2>import</span><span class=cF0> function G C MR D
<a name="l68"></a></span><span class=cF2>import</span><span class=cF0> var G C MR D
<a name="l69"></a></span><span class=cF2>_extern</span><span class=cF0> function G C MR D
<a name="l70"></a></span><span class=cF2>_extern</span><span class=cF0> var G C MR D
<a name="l71"></a></span><span class=cF2>_import</span><span class=cF0> function G C MR D
<a name="l72"></a></span><span class=cF2>_import</span><span class=cF0> var G C MR D
<a name="l73"></a>
<a name="l74"></a>
<a name="l75"></a></span><span class=cF5>Just in Time Compilation</span><span class=cF0>
<a name="l76"></a> </span><span class=cF2>G</span><span class=cF0>lobalScope/</span><span class=cF2>F</span><span class=cF0>unctionScope
<a name="l77"></a> | </span><span class=cF2>C</span><span class=cF0>odeHeap/</span><span class=cF2>D</span><span class=cF0>ataHeap/</span><span class=cF2>S</span><span class=cF0>tack/</span><span class=cF2>R</span><span class=cF0>egister
<a name="l78"></a> | | TaskHashEntry:Export</span><span class=cF2>S</span><span class=cF0>ysSym/</span><span class=cF2>D</span><span class=cF0>efine/</span><span class=cF2>F</span><span class=cF0>unction/</span><span class=cF2>C</span><span class=cF0>lass
<a name="l79"></a> | | | UsageScope: </span><span class=cF2>M</span><span class=cF0>odule/</span><span class=cF2>A</span><span class=cF0>smLocal/Asm</span><span class=cF2>B</span><span class=cF0>lk/</span><span class=cF2>T</span><span class=cF0>askAndChildren/</span><span class=cF2>F</span><span class=cF0>unction
<a name="l80"></a> | | | |UsageScope: </span><span class=cF2>G</span><span class=cF0>lbl/Asm</span><span class=cF2>L</span><span class=cF0>ocal/</span><span class=cF2>R</span><span class=cF0>emainder/</span><span class=cF2>g</span><span class=cF0>lblThisBlkAndRemainder
<a name="l81"></a> | | | || </span><span class=cF2>S</span><span class=cF0>taticVarInit/</span><span class=cF2>D</span><span class=cF0>ynamicVarInitAllowed/</span><span class=cF2>N</span><span class=cF0>oInitAllowed
<a name="l82"></a> | | | || | Are dups allowed within the namespace? A dup overshadows the original.
<a name="l83"></a> | | | || | </span><span class=cF2>D</span><span class=cF0>upsAllowed/</span><span class=cF2>N</span><span class=cF0>oDups/NoDupsBut</span><span class=cF2>P</span><span class=cF0>ad/</span><span class=cF2>W</span><span class=cF0>arningUnlessClosedOut
<a name="l84"></a>
<a name="l85"></a>asm export </span><span class=cF2>label::</span><span class=cF0> G C S Tg N
<a name="l86"></a>asm </span><span class=cF2>label:</span><span class=cF0> G C BG N
<a name="l87"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> G C AL N
<a name="l88"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> G C TR N
<a name="l89"></a>asm export </span><span class=cF2>label::</span><span class=cF0> F C BG N
<a name="l90"></a>asm </span><span class=cF2>label:</span><span class=cF0> F C BG N
<a name="l91"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> F C AL N
<a name="l92"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> F C BR N
<a name="l93"></a>C goto </span><span class=cF2>label:</span><span class=cF0> F C FG N
<a name="l94"></a>
<a name="l95"></a> </span><span class=cF2>#define</span><span class=cF0> x D TR D
<a name="l96"></a> function G C F TR D
<a name="l97"></a> var F R FR N
<a name="l98"></a> var F S FR N
<a name="l99"></a></span><span class=cF2>static</span><span class=cF0> var F C FR D N
<a name="l100"></a> var G C G TR D D
<a name="l101"></a> var G D G TR S D
<a name="l102"></a> </span><span class=cF2>class</span><span class=cF0> G C TR D
<a name="l103"></a>class member G TR P
<a name="l104"></a></span><span class=cF2>extern class</span><span class=cF0> G C TR D
<a name="l105"></a></span><span class=cF2>extern</span><span class=cF0> function G C F TR W
<a name="l106"></a></span><span class=cF2>extern</span><span class=cF0> var G C G TR D
<a name="l107"></a></span><span class=cF2>extern</span><span class=cF0> var G D G TR D
<a name="l108"></a></span><span class=cF2>_extern</span><span class=cF0> function G C F TR D
<a name="l109"></a></span><span class=cF2>_extern</span><span class=cF0> var G C G TR D
<a name="l110"></a>
<a name="l111"></a>
<a name="l112"></a>* Goto labels must not have the same name as global scope objects. GoTo's are
<a name="l113"></a>rare and I don't want to slow the compiler and add code to fix this. You will
<a name="l114"></a>get errors if a collision happens, so it's not very dangerous, but the error
<a name="l115"></a>message is baffling.
<a name="l116"></a>
<a name="l117"></a>* The member names </span><span class=cF2>pad</span><span class=cF0> and </span><span class=cF2>reserved</span><span class=cF0> are special because multiple instances with
<a name="l118"></a>the same name are allowed in a class.
<a name="l119"></a>
<a name="l120"></a>* Use </span><span class=cF2>reg</span><span class=cF0> or </span><span class=cF2>noreg</span><span class=cF0> in front of local var names to override automatic reg var
<a name="l121"></a>allocation. You can, optionally, specify a reg after the </span><span class=cF2>reg</span><span class=cF0> keyword.
<a name="l122"></a>
<a name="l123"></a>* Local non-reg function vars can be accessed in asm blks with </span><span class=cF2>&amp;i[RBP]</span><span class=cF0> for
<a name="l124"></a>example.
<a name="l125"></a>
<a name="l126"></a>* Glbl vars and functions can be accessed in asm with and </span><span class=cF2>&amp;</span><span class=cF0> as in
<a name="l127"></a> </span><span class=cF2>MOV RAX,I64 [&amp;glbl_var]
<a name="l128"></a> CALL I32 &amp;Fun
<a name="l129"></a> CALL I32 &amp;SYS_SYM</span><span class=cF0>
<a name="l130"></a>
<a name="l131"></a>* In </span><span class=cF2>JIT</span><span class=cF0> asm code, &amp;SYS_SYM and &amp;Fun don't need </span><span class=cF2>IMPORT</span><span class=cF0>.
<a name="l132"></a>
<a name="l133"></a>* All offspring tasks of a task inherit syms.
<a name="l134"></a>
<a name="l135"></a>* The </span><span class=cF2>sizeof()</span><span class=cF0> and HolyC structure members can be used in asm blks.
<a name="l136"></a>
<a name="l137"></a>* Using </span><span class=cF2>&amp;i</span><span class=cF0> in </span><a href="/Wb/Doc/HolyC.DD.HTML#l1"><span class=cF4>HolyC</span></a><span class=cF0> or </span><span class=cF2>i.u8[2]</span><span class=cF0> on a local var, </span><span class=cF2>i</span><span class=cF0>, will force it to </span><span class=cF2>noreg</span><span class=cF0>.
<a name="l138"></a>
<a name="l139"></a>* Using </span><span class=cF2>try</span><span class=cF0>/</span><span class=cF2>catch</span><span class=cF0> in a function will force all local vars to </span><span class=cF2>noreg</span><span class=cF0>.
<a name="l140"></a>
<a name="l141"></a>* An unused gap on the stk is left for </span><span class=cF2>reg</span><span class=cF0> vars.
<a name="l142"></a>
<a name="l143"></a>* Note: </span><span class=cF2>static</span><span class=cF0> function vars do not go on the data heap, no matter the setting
<a name="l144"></a>of the </span><a href="/Wb/Kernel/KernelA.HH.HTML#l1555"><span class=cF4>OPTf_GLBLS_ON_DATA_HEAP</span></a><span class=cF0>. They may in the future.
<a name="l145"></a>
<a name="l146"></a>* </span><a href="/Wb/Kernel/KernelA.HH.HTML#l1552"><span class=cF4>OPTf_EXTERNS_TO_IMPORTS</span></a><span class=cF0> will treat </span><span class=cF2>_extern</span><span class=cF0> as </span><span class=cF2>_import</span><span class=cF0> and </span><span class=cF2>extern</span><span class=cF0> as </span><span class=cF2>import</span><span class=cF0>.
<a name="l147"></a>This allows a header to be used either as a </span><span class=cF2>JIT compiled</span><span class=cF0> or </span><span class=cF2>AOT compiled</span><span class=cF0> header.
</span></pre></body>
</html>