ZealOS/docs/Doc/ScopingLinkage.DD.html

165 lines
18 KiB
HTML
Raw Normal View History

2021-07-03 05:07:57 +01:00
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.15">
2021-07-03 05:07:57 +01:00
<style type="text/css">
body {background-color:#fef1f0;}
.cF0{color:#000000;background-color:#fef1f0;}
.cF1{color:#0148a4;background-color:#fef1f0;}
.cF2{color:#3b7901;background-color:#fef1f0;}
.cF3{color:#057c7e;background-color:#fef1f0;}
.cF4{color:#bb2020;background-color:#fef1f0;}
.cF5{color:#9e42ae;background-color:#fef1f0;}
.cF6{color:#b57901;background-color:#fef1f0;}
.cF7{color:#b2b6af;background-color:#fef1f0;}
.cF8{color:#555753;background-color:#fef1f0;}
.cF9{color:#678fbb;background-color:#fef1f0;}
.cFA{color:#82bc49;background-color:#fef1f0;}
.cFB{color:#0097a2;background-color:#fef1f0;}
.cFC{color:#e26a6a;background-color:#fef1f0;}
.cFD{color:#c671bc;background-color:#fef1f0;}
.cFE{color:#c7ab00;background-color:#fef1f0;}
.cFF{color:#fef1f0;background-color:#fef1f0;}
2021-07-03 05:07:57 +01:00
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF5> Scoping and Linkage</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l2"></a></span><span class=cF4>
<a name="l3"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Glossary.DD.html#l188"><span class=cF4>JIT Compile Mode</span></a><span class=cF0> makes use of the current task's hash sym table and its parent tasks' tables. It fetches syms from parent
2021-07-03 05:07:57 +01:00
<a name="l4"></a>tasks' tables if not found locally in the current task's table and it places new syms in the current task's table.
<a name="l5"></a>Conceptually, syms are at the scope of environment vars in other operating systems.
<a name="l6"></a>
<a name="l7"></a>When a sym is placed into a table, older syms with ident names will be overshadowed if they exist. Duplicates are not allowed
<a name="l8"></a>in many cases, especially in asm blks. Dupicates are allowed, by design in other cases, so that you can repeatedly </span><span class=cF2>#include</span><span class=cF0>
<a name="l9"></a>the same file from the cmd line while developing it. Or, so you can repeatedly declare a function with a standard name,
<a name="l10"></a>like </span><span class=cF2>DrawIt()</span><span class=cF0>. This case might occur when the </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Glossary.DD.html#l154"><span class=cF4>System Task</span></a><span class=cF0> is starting-up loading-in many little utilities.
2021-07-03 05:07:57 +01:00
<a name="l11"></a>
<a name="l12"></a></span><span class=cF2>extern</span><span class=cF0> binds a new </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l828"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l825"><span class=cF4>HTT_GLOBAL_VAR</span></a><span class=cF0> sym to an existing sym of the same name if it exists in the sym table (just in
<a name="l13"></a>just-in-time code). It also can be used to generate a forward reference.
2021-07-03 05:07:57 +01:00
<a name="l14"></a>
<a name="l15"></a></span><span class=cF2>import</span><span class=cF0> binds a new </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l828"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l825"><span class=cF4>HTT_GLOBAL_VAR</span></a><span class=cF0> sym to a sym of the same name imported from the task's sym table at </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KLoad.CC.html#l208"><span class=cF4>Load</span></a><span class=cF0>() time.
<a name="l16"></a>If no sym exists to bind to at </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KLoad.CC.html#l208"><span class=cF4>Load</span></a><span class=cF0>() time, the code using this sym will be left incomplete until the sym is defined.
2021-07-03 05:07:57 +01:00
<a name="l17"></a>
<a name="l18"></a>
<a name="l19"></a></span><span class=cF2>_extern</span><span class=cF0> binds a new </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l828"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l825"><span class=cF4>HTT_GLOBAL_VAR</span></a><span class=cF0> sym to an existing sym, of a <blink>different</blink> name. It must exists in the sym table.
2021-07-03 05:07:57 +01:00
<a name="l20"></a>Basically, this binds C to asm.
<a name="l21"></a>
<a name="l22"></a></span><span class=cF2>_import</span><span class=cF0> binds a new </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l828"><span class=cF4>HTT_FUN</span></a><span class=cF0> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l825"><span class=cF4>HTT_GLOBAL_VAR</span></a><span class=cF0> sym to a sym, of a <blink>different</blink> name imported from the task's sym table at </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KLoad.CC.html#l208"><span class=cF4>Load</span></a><span class=cF0>()
<a name="l23"></a>time. If no sym exists to bind to at </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KLoad.CC.html#l208"><span class=cF4>Load</span></a><span class=cF0>() time, the code using this sym will be left incomplete until the sym is defined.
2021-07-03 05:07:57 +01:00
<a name="l24"></a>Basically, this binds C to asm from elsewhere.
<a name="l25"></a>
<a name="l26"></a>
<a name="l27"></a></span><span class=cF5>Ahead of Time Compilation</span><span class=cF0>
<a name="l28"></a> </span><span class=cF2>G</span><span class=cF0>lobalScope / </span><span class=cF2>F</span><span class=cF0>unctionScope
<a name="l29"></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="l30"></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="l31"></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="l32"></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="l33"></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="l34"></a> | | | || | Are dups allowed within the namespace? A dup overshadows the original.
<a name="l35"></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
2021-07-03 05:07:57 +01:00
<a name="l36"></a>
<a name="l37"></a>asm export </span><span class=cF2>label::</span><span class=cF0> G C S MG N
<a name="l38"></a>asm </span><span class=cF2>label:</span><span class=cF0> G C MG N
<a name="l39"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> G C AL N
<a name="l40"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> G C MR N
<a name="l41"></a>asm export </span><span class=cF2>label::</span><span class=cF0> F C S BG N
<a name="l42"></a>asm </span><span class=cF2>label:</span><span class=cF0> F C BG N
<a name="l43"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> F C AL N
<a name="l44"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> F C BR N
<a name="l45"></a>C goto </span><span class=cF2>label:</span><span class=cF0> F C FG N
2021-07-03 05:07:57 +01:00
<a name="l46"></a>
<a name="l47"></a> </span><span class=cF2>#define</span><span class=cF0> x MR D
<a name="l48"></a> function G C S MR D
<a name="l49"></a> var F R FR N
<a name="l50"></a> var F S FR N
<a name="l51"></a></span><span class=cF2>static</span><span class=cF0> var F C FR D N
<a name="l52"></a> var G C S MR D D
<a name="l53"></a> var G D MR N D
<a name="l54"></a> </span><span class=cF2>class</span><span class=cF0> G MR D
<a name="l55"></a>class member G MR P
<a name="l56"></a></span><span class=cF2>extern class</span><span class=cF0> G MR D
<a name="l57"></a></span><span class=cF2>extern</span><span class=cF0> function G C MR W
<a name="l58"></a></span><span class=cF2>import</span><span class=cF0> function G C MR D
<a name="l59"></a></span><span class=cF2>import</span><span class=cF0> var G C MR D
<a name="l60"></a></span><span class=cF2>_extern</span><span class=cF0> function G C MR D
<a name="l61"></a></span><span class=cF2>_extern</span><span class=cF0> var G C MR D
<a name="l62"></a></span><span class=cF2>_import</span><span class=cF0> function G C MR D
<a name="l63"></a></span><span class=cF2>_import</span><span class=cF0> var G C MR D
2021-07-03 05:07:57 +01:00
<a name="l64"></a>
<a name="l65"></a>
<a name="l66"></a></span><span class=cF5>Just in Time Compilation</span><span class=cF0>
<a name="l67"></a> </span><span class=cF2>G</span><span class=cF0>lobalScope / </span><span class=cF2>F</span><span class=cF0>unctionScope
<a name="l68"></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="l69"></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="l70"></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="l71"></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="l72"></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="l73"></a> | | | || | Are dups allowed within the namespace? A dup overshadows the original.
<a name="l74"></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
2021-07-03 05:07:57 +01:00
<a name="l75"></a>
<a name="l76"></a>asm export </span><span class=cF2>label::</span><span class=cF0> G C S Tg N
<a name="l77"></a>asm </span><span class=cF2>label:</span><span class=cF0> G C BG N
<a name="l78"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> G C AL N
<a name="l79"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> G C TR N
<a name="l80"></a>asm export </span><span class=cF2>label::</span><span class=cF0> F C BG N
<a name="l81"></a>asm </span><span class=cF2>label:</span><span class=cF0> F C BG N
<a name="l82"></a>asm local </span><span class=cF2>@@label:</span><span class=cF0> F C AL N
<a name="l83"></a>asm </span><span class=cF2>IMPORT label;</span><span class=cF0> F C BR N
<a name="l84"></a>C goto </span><span class=cF2>label:</span><span class=cF0> F C FG N
2021-07-03 05:07:57 +01:00
<a name="l85"></a>
<a name="l86"></a> </span><span class=cF2>#define</span><span class=cF0> x D TR D
<a name="l87"></a> function G C F TR D
<a name="l88"></a> var F R FR N
<a name="l89"></a> var F S FR N
<a name="l90"></a></span><span class=cF2>static</span><span class=cF0> var F C FR D N
<a name="l91"></a> var G C G TR D D
<a name="l92"></a> var G D G TR S D
<a name="l93"></a> </span><span class=cF2>class</span><span class=cF0> G C TR D
<a name="l94"></a>class member G TR P
<a name="l95"></a></span><span class=cF2>extern class</span><span class=cF0> G C TR D
<a name="l96"></a></span><span class=cF2>extern</span><span class=cF0> function G C F TR W
<a name="l97"></a></span><span class=cF2>extern</span><span class=cF0> var G C G TR D
<a name="l98"></a></span><span class=cF2>extern</span><span class=cF0> var G D G TR D
<a name="l99"></a></span><span class=cF2>_extern</span><span class=cF0> function G C F TR D
<a name="l100"></a></span><span class=cF2>_extern</span><span class=cF0> var G C G TR D
2021-07-03 05:07:57 +01:00
<a name="l101"></a>
<a name="l102"></a>
<a name="l103"></a>* 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
2021-07-03 05:07:57 +01:00
<a name="l104"></a>add code to fix this. You will get errors if a collision happens, so it's not very dangerous, but the error message is
<a name="l105"></a>baffling.
<a name="l106"></a>
<a name="l107"></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 the same name are allowed in a class.
<a name="l108"></a>
<a name="l109"></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 allocation. You can, optionally, specify a reg
2021-07-03 05:07:57 +01:00
<a name="l110"></a>after the </span><span class=cF2>reg</span><span class=cF0> keyword.
<a name="l111"></a>
<a name="l112"></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 example.
<a name="l113"></a>
<a name="l114"></a>* Global vars and functions can be accessed in asm with and </span><span class=cF2>&amp;</span><span class=cF0> as in
<a name="l115"></a> </span><span class=cF2>MOV RAX, I64 [&amp;global_var]
<a name="l116"></a> CALL I32 &amp;Fun
<a name="l117"></a> CALL I32 &amp;SYS_SYM</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l118"></a>
<a name="l119"></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="l120"></a>
<a name="l121"></a>* All offspring tasks of a task inherit syms.
<a name="l122"></a>
<a name="l123"></a>* The </span><span class=cF2>sizeof()</span><span class=cF0> and CosmiC structure members can be used in asm blks.
<a name="l124"></a>
<a name="l125"></a>* Using </span><span class=cF2>&amp;i</span><span class=cF0> in </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/CosmiC.DD.html#l1"><span class=cF4>CosmiC</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>.
2021-07-03 05:07:57 +01:00
<a name="l126"></a>
<a name="l127"></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="l128"></a>
<a name="l129"></a>* An unused gap on the stack is left for </span><span class=cF2>reg</span><span class=cF0> vars.
<a name="l130"></a>
<a name="l131"></a>* Note: </span><span class=cF2>static</span><span class=cF0> function vars do not go on the data heap, no matter the setting of the </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1685"><span class=cF4>OPTf_GLOBALS_ON_DATA_HEAP</span></a><span class=cF0>. They may
<a name="l132"></a>in the future.
2021-07-03 05:07:57 +01:00
<a name="l133"></a>
<a name="l134"></a>* </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1682"><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>. This allows a header to be used either as a </span><span class=cF2>JIT
2021-07-03 05:07:57 +01:00
<a name="l135"></a>compiled</span><span class=cF0> or </span><span class=cF2>AOT compiled</span><span class=cF0> header.
</span></pre></body>
</html>