ZealOS/docs/Doc/CosmiC.DD.html

331 lines
30 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.11">
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> CosmiC</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l2"></a>
<a name="l3"></a>* See </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/CompilerOverview.DD.html#l1"><span class=cF4>::/Doc/CompilerOverview.DD</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l4"></a>
<a name="l5"></a>* See </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/ScopingLinkage.DD.html#l1"><span class=cF4>Scoping and Linkage</span></a><span class=cF0> for details on </span><span class=cF2>extern</span><span class=cF0>, </span><span class=cF2>import</span><span class=cF0>, </span><span class=cF2>_extern</span><span class=cF0>, </span><span class=cF2>_import</span><span class=cF0>, etc.
2021-07-03 05:07:57 +01:00
<a name="l6"></a>
<a name="l7"></a>* Built-in types include </span><span class=cF2>I0, I8, I16, I32, I64</span><span class=cF0> for signed 0-8 byte ints and </span><span class=cF2>U0, U8, U16, U32, U64</span><span class=cF0> for unsigned 0-8 byte ints
<a name="l8"></a>and </span><span class=cF2>F64</span><span class=cF0> for 8 byte floats.
2021-07-03 05:07:57 +01:00
<a name="l9"></a>
<a name="l10"></a></span><span class=cF2> U0 void, but ZERO size!
<a name="l11"></a> I8 char
<a name="l12"></a> U8 unsigned char
<a name="l13"></a> I16 short
<a name="l14"></a> U16 unsigned short
<a name="l15"></a> I32 int
<a name="l16"></a> U32 unsigned int
<a name="l17"></a> I64 long (64-bit)
<a name="l18"></a> U64 unsigned long (64-bit)
<a name="l19"></a> F64 double</span><span class=cF0>
<a name="l20"></a> </span><span class=cF4>no F32 float.</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l21"></a>
<a name="l22"></a>* Function with no args, or just default args can be called without parentheses.
<a name="l23"></a>
<a name="l24"></a> &gt;</span><span class=cF2>Dir(&quot;*&quot;);</span><span class=cF0>
<a name="l25"></a> &gt;</span><span class=cF2>Dir();</span><span class=cF0>
<a name="l26"></a> &gt;</span><span class=cF2>Dir;</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l27"></a>
<a name="l28"></a>* Default args don't have to be on the end. This code is valid:
<a name="l29"></a> </span><span class=cF2>U0 Test(I64 i=4, I64 j, I64 k=5)
<a name="l30"></a> {
<a name="l31"></a> Print(&quot;%X %X %X\n&quot;, i, j, k);
2021-07-03 05:07:57 +01:00
<a name="l32"></a> }
<a name="l33"></a>
<a name="l34"></a> Test(, 3);</span><span class=cF0>
<a name="l35"></a>
<a name="l36"></a>* A char const all alone is sent to </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KeyDev.CC.html#l23"><span class=cF4>PutChars</span></a><span class=cF0>(). A string with or without args is sent to </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/StrPrint.CC.html#l1110"><span class=cF4>Print</span></a><span class=cF0>(). An empty string literal
2021-07-03 05:07:57 +01:00
<a name="l37"></a>signals a variable format_str follows.
<a name="l38"></a>
<a name="l39"></a> </span><span class=cF2>void DemoC(char drv, char *format, char *name, int age)
<a name="l40"></a> {
<a name="l41"></a> printf(&quot;Hello World!\n&quot;);
<a name="l42"></a> printf(&quot;%s age %d\n&quot;, name, age);
<a name="l43"></a> printf(format, name, age);
<a name="l44"></a> putchar(drv);
<a name="l45"></a> putchar('*');
2021-07-03 05:07:57 +01:00
<a name="l46"></a> }
<a name="l47"></a>
<a name="l48"></a> U0 DemoCosmiC(U8 drive, U8 *format, U8 *name, I64 age)
<a name="l49"></a> {
<a name="l50"></a> &quot;Hello World!\n&quot;;
<a name="l51"></a> &quot;%s age %d\n&quot;, name, age;
<a name="l52"></a> &quot;&quot; format, name, age;
<a name="l53"></a> '' drive;
<a name="l54"></a> '*';
2021-07-03 05:07:57 +01:00
<a name="l55"></a> }
<a name="l56"></a></span><span class=cF0>
<a name="l57"></a>* When dealing with function addresses such as for callbacks, precede the name with &quot;</span><span class=cF2>&amp;</span><span class=cF0>&quot;.
<a name="l58"></a>
<a name="l59"></a>* Type casting is postfix. To typecast int or F64, use </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelB.HH.html#l92"><span class=cF4>ToI64</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelB.HH.html#l90"><span class=cF4>ToBool</span></a><span class=cF0>() or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelB.HH.html#l91"><span class=cF4>ToF64</span></a><span class=cF0>(). (ZealOS follows normal C float&lt;--&gt;int
2021-07-03 05:07:57 +01:00
<a name="l60"></a>conversion, but sometimes you want to override. These functions are better than multiplying by &quot;1.0&quot; to convert to float.)
<a name="l61"></a>
<a name="l62"></a>* There is no </span><span class=cF2>main()</span><span class=cF0> function. Any code outside of functions gets executed upon start-up, in order.
<a name="l63"></a>
<a name="l64"></a>* There are no bit fields, but there are </span><span class=cF4><u>bit access</u></span><span class=cF0> routines and you can access bytes or words within any int. See </span><span class=cF4>
<a name="l65"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l103"><span class=cF4>I64 declaration</span></a><span class=cF0>. A class can be accessed as a whole are subints, if you put a type in front of the </span><span class=cF2>class</span><span class=cF0> declaration.
2021-07-03 05:07:57 +01:00
<a name="l66"></a>
<a name="l67"></a> </span><span class=cF2>public I64i union I64 //&quot;I64i&quot; is intrinsic. We are defining &quot;I64&quot;.
2021-07-03 05:07:57 +01:00
<a name="l68"></a> {
<a name="l69"></a> I8i i8[8];
<a name="l70"></a> U8i u8[8];
<a name="l71"></a> I16 i16[4];
<a name="l72"></a> U16 u16[4];
<a name="l73"></a> I32 i32[2];
<a name="l74"></a> U32 u32[2];
2021-07-03 05:07:57 +01:00
<a name="l75"></a> };
<a name="l76"></a>
<a name="l77"></a> I64 i = 0x123456780000DEF0;
<a name="l78"></a> i.u16[1] = 0x9ABC;
<a name="l79"></a></span><span class=cF0>
<a name="l80"></a>* Variable arg count functions (</span><span class=cF2>...</span><span class=cF0>) can access their args with built-in variables similar to '</span><span class=cF2>this</span><span class=cF0>' in C++. They are '</span><span class=cF2>I64
<a name="l81"></a>argc</span><span class=cF0>' and '</span><span class=cF2>I64 argv[]</span><span class=cF0>'.
<a name="l82"></a>
<a name="l83"></a> </span><span class=cF2>I64 AddNums(...)
<a name="l84"></a> {
<a name="l85"></a> I64 i, res = 0;
2021-07-03 05:07:57 +01:00
<a name="l86"></a>
<a name="l87"></a> for (i = 0; i &lt; argc; i++)
<a name="l88"></a> res += argv[i];
2021-07-03 05:07:57 +01:00
<a name="l89"></a>
<a name="l90"></a> return res;
2021-07-03 05:07:57 +01:00
<a name="l91"></a> }
<a name="l92"></a>
<a name="l93"></a> </span><span class=cF0>&gt;</span><span class=cF2>AddNums(1, 2, 3);</span><span class=cF0>
<a name="l94"></a> ans = 6
<a name="l95"></a> </span><span class=cF2>
<a name="l96"></a>
<a name="l97"></a> public U0 GrPrint(CDC *dc, I64 x, I64 y, U8 *format, ...)
<a name="l98"></a> {
<a name="l99"></a> U8 *buf = </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/StrPrint.CC.html#l249"><span class=cF4>StrPrintJoin</span></a><span class=cF2>(NULL, format, argc, argv); //SPrintF() with </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l391"><span class=cF4>MAlloc</span></a><span class=cF2>()ed string.
2021-07-03 05:07:57 +01:00
<a name="l100"></a>
<a name="l101"></a> </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Gr/GrBitMap.CC.html#l1084"><span class=cF4>GrPutS</span></a><span class=cF2>(dc, x, y, buf); //Plot string at x,y pixels. GrPutS is not public.
<a name="l102"></a> Free(buf);
2021-07-03 05:07:57 +01:00
<a name="l103"></a> }
<a name="l104"></a>
<a name="l105"></a> ...
2021-07-03 05:07:57 +01:00
<a name="l106"></a>
<a name="l107"></a> GrPrint(gr.dc, (GR_WIDTH - 10 * FONT_WIDTH) &gt;&gt; 1, (GR_HEIGHT - FONT_HEIGHT) &gt;&gt; 1, &quot;Score:%4d&quot;, score);
<a name="l108"></a> //Print score in the center of the screen.
<a name="l109"></a> ...
2021-07-03 05:07:57 +01:00
<a name="l110"></a>
<a name="l111"></a></span><span class=cF0>
<a name="l112"></a>* Allows &quot;</span><span class=cF2>5 &lt; i &lt; j + 1 &lt; 20</span><span class=cF0>&quot; instead of &quot;</span><span class=cF2>5 &lt; i &amp;&amp; i &lt; j + 1 &amp;&amp; j + 1 &lt; 20</span><span class=cF0>&quot;.
<a name="l113"></a>
<a name="l114"></a> </span><span class=cF2>if (13 &lt;= age &lt; 20)
<a name="l115"></a> &quot;Teen-ager&quot;;
2021-07-03 05:07:57 +01:00
<a name="l116"></a></span><span class=cF0>
<a name="l117"></a>* if you know a switch stmt will not exceed the lowest or highest case values. </span><span class=cF2>switch []</span><span class=cF0> is a little faster because it
<a name="l118"></a>doesn't check.
2021-07-03 05:07:57 +01:00
<a name="l119"></a>
<a name="l120"></a>* </span><span class=cF2>switch</span><span class=cF0> statements always use a jump table. Don't use them with cases with really big, sparse ranges.
<a name="l121"></a>
<a name="l122"></a>* Allows ranges like &quot;</span><span class=cF2>case 4...7:</span><span class=cF0>&quot; in </span><span class=cF2>switch</span><span class=cF0> statements.
<a name="l123"></a>
<a name="l124"></a>* A no case number causes next higher int case in </span><span class=cF2>switch</span><span class=cF0> statements. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/NullCase.CC.html#l1"><span class=cF4>::/Demo/NullCase.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l125"></a>
<a name="l126"></a> </span><span class=cF2>I64 i;
<a name="l127"></a>
<a name="l128"></a> for (i = 0; i &lt; 20; i++)
<a name="l129"></a> switch (i)
<a name="l130"></a> {
<a name="l131"></a> case: &quot;Zero\n&quot;; break; //Starts at zero
<a name="l132"></a> case: &quot;One\n&quot;; break; //One plus prev case.
<a name="l133"></a> case: &quot;Two\n&quot;; break;
<a name="l134"></a> case: &quot;Three\n&quot;; break;
<a name="l135"></a> case 10: &quot;Ten\n&quot;; break;
<a name="l136"></a> case: &quot;Eleven\n&quot;; break; //One plus prev case.
<a name="l137"></a> }</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l138"></a>
<a name="l139"></a>* Switch statements can be nestled with a single switch expression! This is known as a &quot;sub_switch&quot; statement. </span><span class=cF2>start</span><span class=cF0>/</span><span class=cF2>end</span><span class=cF0> are
<a name="l140"></a>used to group cases. Don't goto out of, throw an exception out of, or return out of the </span><span class=cF2>start</span><span class=cF0> front porch area. See </span><span class=cF4>
<a name="l141"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/SubSwitch.CC.html#l1"><span class=cF4>::/Demo/SubSwitch.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l142"></a>
<a name="l143"></a> </span><span class=cF2>I64 i;
<a name="l144"></a>
<a name="l145"></a> for (i = 0; i &lt; 10; i++)
<a name="l146"></a> switch (i)
<a name="l147"></a> {
<a name="l148"></a> case 0: &quot;Zero &quot;; break;
<a name="l149"></a> case 2: &quot;Two &quot;; break;
<a name="l150"></a> case 4: &quot;Four &quot;; break;
<a name="l151"></a> start:
<a name="l152"></a> &quot;[&quot;;
<a name="l153"></a> case 1: &quot;One&quot;; break;
<a name="l154"></a> case 3: &quot;Three&quot;; break;
<a name="l155"></a> case 5: &quot;Five&quot;; break;
<a name="l156"></a> end:
<a name="l157"></a> &quot;] &quot;;
<a name="l158"></a> break;
<a name="l159"></a> }</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l160"></a> OutPut:
<a name="l161"></a> &gt;</span><span class=cF2>Zero [One] Two [Three] Four [Five]</span><span class=cF0>
<a name="l162"></a>
<a name="l163"></a>* A </span><span class=cF2>no_warn</span><span class=cF0> stmt will suppress an unused var warning.
<a name="l164"></a>
<a name="l165"></a>* You can have multiple member vars of a class named &quot;</span><span class=cF2>pad</span><span class=cF0>&quot; or &quot;</span><span class=cF2>reserved</span><span class=cF0>&quot;, and it won't issue warnings.
<a name="l166"></a>
<a name="l167"></a>* </span><span class=cF2>noreg</span><span class=cF0> or </span><span class=cF2>reg</span><span class=cF0> can be placed before a function local var name. You can, optionally, specify a reg after the </span><span class=cF2>reg</span><span class=cF0> keyword.
<a name="l168"></a>
<a name="l169"></a> </span><span class=cF2>U0 Main()
<a name="l170"></a> {
<a name="l171"></a> //Only use </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1939"><span class=cF4>REGG_LOCAL_VARS</span></a><span class=cF2> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1940"><span class=cF4>REGG_LOCAL_NON_PTR_VARS</span></a><span class=cF2> for reg vars or else clobbered.
<a name="l172"></a> I64 reg R15 i = 5, noreg j = 4;
<a name="l173"></a> no_warn i;
<a name="l174"></a> asm {
<a name="l175"></a> MOV RAX, R15
<a name="l176"></a> CALL &amp;PUT_HEX_U64
<a name="l177"></a> MOV RAX, '\n'
<a name="l178"></a> CALL &amp;PUT_CHARS
<a name="l179"></a> MOV RAX, U64 &amp;j[RBP]
<a name="l180"></a> CALL &amp;PUT_HEX_U64
<a name="l181"></a> MOV RAX, '\n'
<a name="l182"></a> CALL &amp;PUT_CHARS
<a name="l183"></a> }
2021-07-03 05:07:57 +01:00
<a name="l184"></a> }
<a name="l185"></a></span><span class=cF0>
<a name="l186"></a>* </span><span class=cF2>interrupt</span><span class=cF0>, </span><span class=cF2>haserrcode</span><span class=cF0>, </span><span class=cF2>public</span><span class=cF0>, </span><span class=cF2>argpop</span><span class=cF0> or </span><span class=cF2>noargpop</span><span class=cF0> are function flags. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/SerialDev/Keyboard.CC.html#l477"><span class=cF4>IRQKbd</span></a><span class=cF0>().
2021-07-03 05:07:57 +01:00
<a name="l187"></a>
<a name="l188"></a>* A single quote can encompass multiple characters. </span><span class=cF2>'ABC'</span><span class=cF0> is equ to </span><span class=cF2>0x434241</span><span class=cF0>. </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KeyDev.CC.html#l23"><span class=cF4>PutChars</span></a><span class=cF0>() takes multiple characters.
2021-07-03 05:07:57 +01:00
<a name="l189"></a>
<a name="l190"></a> </span><span class=cF2>asm {
<a name="l191"></a> HELLO_WORLD::
<a name="l192"></a> PUSH RBP
<a name="l193"></a> MOV RBP, RSP
<a name="l194"></a> MOV RAX, 'Hello '
<a name="l195"></a> CALL &amp;PUT_CHARS
<a name="l196"></a> MOV RAX, 'World\n'
<a name="l197"></a> CALL &amp;PUT_CHARS
<a name="l198"></a> LEAVE
<a name="l199"></a> RET
2021-07-03 05:07:57 +01:00
<a name="l200"></a> }
<a name="l201"></a> Call(HELLO_WORLD);
<a name="l202"></a> PutChars('Hello ');
<a name="l203"></a> PutChars('World\n');
<a name="l204"></a></span><span class=cF0>
<a name="l205"></a>* The &quot;</span><span class=cF2>`</span><span class=cF0>&quot; operator raises a base to a power.
<a name="l206"></a>
<a name="l207"></a>* There is no question-colon operator.
<a name="l208"></a>
<a name="l209"></a>* ZealOS </span><a href="https://zeal-operating-system.github.io/ZealOS/Compiler/CInit.CC.html#l508"><span class=cF4>operator precedence</span></a><span class=cF0>
<a name="l210"></a> </span><span class=cF2>`</span><span class=cF0>, </span><span class=cF2>&gt;&gt;</span><span class=cF0>, </span><span class=cF2>&lt;&lt;</span><span class=cF0>
<a name="l211"></a> </span><span class=cF2>*</span><span class=cF0>, </span><span class=cF2>/</span><span class=cF0>, </span><span class=cF2>%</span><span class=cF0>
<a name="l212"></a> </span><span class=cF2>&amp;</span><span class=cF0>
<a name="l213"></a> </span><span class=cF2>^</span><span class=cF0>
<a name="l214"></a> </span><span class=cF2>|</span><span class=cF0>
<a name="l215"></a> </span><span class=cF2>+</span><span class=cF0>, </span><span class=cF2>-</span><span class=cF0>
<a name="l216"></a> </span><span class=cF2>&lt;</span><span class=cF0>, </span><span class=cF2>&gt;</span><span class=cF0>, </span><span class=cF2>&lt;=</span><span class=cF0>, </span><span class=cF2>&gt;=</span><span class=cF0>
<a name="l217"></a> </span><span class=cF2>==</span><span class=cF0>, </span><span class=cF2>!=</span><span class=cF0>
<a name="l218"></a> </span><span class=cF2>&amp;&amp;</span><span class=cF0>
<a name="l219"></a> </span><span class=cF2>^^</span><span class=cF0>
<a name="l220"></a> </span><span class=cF2>||</span><span class=cF0>
<a name="l221"></a> </span><span class=cF2>=</span><span class=cF0>, </span><span class=cF2>&lt;&lt;=</span><span class=cF0>, </span><span class=cF2>&gt;&gt;=</span><span class=cF0>, </span><span class=cF2>*=</span><span class=cF0>, </span><span class=cF2>/=</span><span class=cF0>, </span><span class=cF2>&amp;=</span><span class=cF0>, </span><span class=cF2>|=</span><span class=cF0>, </span><span class=cF2>^=</span><span class=cF0>, </span><span class=cF2>+=</span><span class=cF0>, </span><span class=cF2>-=</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l222"></a>
<a name="l223"></a>* You can use </span><a href="https://zeal-operating-system.github.io/ZealOS/Compiler/CMisc.CC.html#l1"><span class=cF4>Option</span></a><span class=cF0>(</span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1679"><span class=cF4>OPTf_WARN_PAREN</span></a><span class=cF0>, ON) to find unnecessary parentheses in code.
2021-07-03 05:07:57 +01:00
<a name="l224"></a>
<a name="l225"></a>* You can use </span><a href="https://zeal-operating-system.github.io/ZealOS/Compiler/CMisc.CC.html#l1"><span class=cF4>Option</span></a><span class=cF0>(</span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1680"><span class=cF4>OPTf_WARN_DUP_TYPES</span></a><span class=cF0>, ON) to find dup local var type statements.
2021-07-03 05:07:57 +01:00
<a name="l226"></a>
<a name="l227"></a>* With the </span><span class=cF2>#exe{}</span><span class=cF0> feature in your src code, you can place programs that insert text into the stream of code being compiled.
<a name="l228"></a>See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KMain.CC.html#l252"><span class=cF4>#exe {}</span></a><span class=cF0> for an example where the date/time and compile-time prompting for configuration data is placed into a program. </span><span class=cF4>
<a name="l229"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Compiler/CMisc.CC.html#l71"><span class=cF4>StreamPrint</span></a><span class=cF0>() places text into a src program stream following the conclusion of the </span><span class=cF2>#exe{}</span><span class=cF0> blk.
2021-07-03 05:07:57 +01:00
<a name="l230"></a>
<a name="l231"></a>* No </span><span class=cF2>#define</span><span class=cF0> functions exist (Terry was not a fan)
2021-07-03 05:07:57 +01:00
<a name="l232"></a>
<a name="l233"></a>* No </span><span class=cF2>typedef</span><span class=cF0>, use </span><span class=cF2>class</span><span class=cF0>.
<a name="l234"></a>
<a name="l235"></a>* No type-checking
<a name="l236"></a>
<a name="l237"></a>* Can't use </span><span class=cF2>&lt;&gt;</span><span class=cF0> with </span><span class=cF2>#include</span><span class=cF0>, use </span><span class=cF2>&quot;&quot;</span><span class=cF0>.
<a name="l238"></a>
<a name="l239"></a>* &quot;</span><span class=cF2>$</span><span class=cF0>&quot; is an escape character. Two dollar signs signify an ordinary $. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/DolDocOverview.DD.html#l1"><span class=cF4>DolDoc</span></a><span class=cF0>. In </span><span class=cF2>asm</span><span class=cF0> or </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/CosmiC.DD.html#l1"><span class=cF4>CosmiC</span></a><span class=cF0> code, it also refers to
<a name="l240"></a>the instruction's address or the offset in a </span><span class=cF2>class</span><span class=cF0> definition.
2021-07-03 05:07:57 +01:00
<a name="l241"></a>
<a name="l242"></a>* </span><span class=cF2>union</span><span class=cF0> is more like a class, so you don't reference it with a </span><span class=cF2>union</span><span class=cF0> label after you define it. Some common unions are
<a name="l243"></a>declared in </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l65"><span class=cF4>KernelA.HH</span></a><span class=cF0> for 1,2,4 and 8 byte objects. If you place a type in front of a union declaration, that is the type
<a name="l244"></a>when used by itself. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/SubIntAccess.CC.html#l1"><span class=cF4>::/Demo/SubIntAccess.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l245"></a>
<a name="l246"></a>* </span><span class=cF2>class</span><span class=cF0> member vars can have meta data. </span><span class=cF2>format</span><span class=cF0> and </span><span class=cF2>data</span><span class=cF0> are two meta data types now used. All compiler structures are saved
<a name="l247"></a>and you can access the compiler's info about classes and vars. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/ClassMeta.CC.html#l1"><span class=cF4>::/Demo/ClassMeta.CC</span></a><span class=cF0> and </span><a href="https://zeal-operating-system.github.io/ZealOS/System/DolDoc/DocForm.CC.html#l263"><span class=cF4>DocForm</span></a><span class=cF0>().
2021-07-03 05:07:57 +01:00
<a name="l248"></a>
<a name="l249"></a>* There is a keyword </span><span class=cF2>lastclass</span><span class=cF0> you use as a default arg. It is set to the class name of the prev arg. See </span><span class=cF4>
<a name="l250"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/LastClass.CC.html#l1"><span class=cF4>::/Demo/LastClass.CC</span></a><span class=cF0>, </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Debug.CC.html#l216"><span class=cF4>ClassRep</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/System/DolDoc/DocForm.CC.html#l263"><span class=cF4>DocForm</span></a><span class=cF0>() and </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/Disk/BlkDevRep.CC.html#l1"><span class=cF4>::/Demo/Disk/BlkDevRep.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l251"></a>
<a name="l252"></a>* See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/Exceptions.CC.html#l1"><span class=cF4>::/Demo/Exceptions.CC</span></a><span class=cF0>. </span><span class=cF2>try{} catch{}</span><span class=cF0> and </span><span class=cF2>throw</span><span class=cF0> are different from C++. </span><span class=cF2>throw</span><span class=cF0> is a function with an 8-byte or less char
2021-07-03 05:07:57 +01:00
<a name="l253"></a>arg. The char string passed in </span><span class=cF2>throw()</span><span class=cF0> can be accessed from within a </span><span class=cF2>catch{}</span><span class=cF0> using the </span><span class=cF2>Fs-&gt;except_ch</span><span class=cF0>. Within a </span><span class=cF2>catch {}</span><span class=cF0> blk,
<a name="l254"></a>set the var </span><span class=cF2>Fs-&gt;catch_except</span><span class=cF0> to </span><span class=cF2>TRUE</span><span class=cF0> if you want to terminate the search for a handler. Use </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KExcept.CC.html#l46"><span class=cF4>PutExcept</span></a><span class=cF0>() as a handler, if you
2021-07-03 05:07:57 +01:00
<a name="l255"></a>like.
<a name="l256"></a>
<a name="l257"></a>* A function is available similar to </span><span class=cF2>sizeof</span><span class=cF0> which provides the offset of a member of a class. It's called </span><span class=cF2>offset</span><span class=cF0>. You place
<a name="l258"></a>the class name and member inside as in </span><span class=cF2>offset(classname.membername)</span><span class=cF0>. It has nothing to do with 16-bit code. Both </span><span class=cF2>sizeof</span><span class=cF0>
<a name="l259"></a>and </span><span class=cF2>offset</span><span class=cF0> only accept one level of member vars. That is, you can't do </span><span class=cF2>sizeof(classname.membername.submembername)</span><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l260"></a>
<a name="l261"></a>* There is no </span><span class=cF2>continue</span><span class=cF0> stmt. Use </span><span class=cF2>goto</span><span class=cF0>.
<a name="l262"></a>
<a name="l263"></a>* </span><span class=cF2>lock{}</span><span class=cF0> can be used to apply asm </span><span class=cF2>LOCK</span><span class=cF0> prefixes to code for safe multicore read-modify-write accesses. The code bracked with
<a name="l264"></a>have </span><span class=cF2>LOCK</span><span class=cF0> asm prefix's applied to relevant insts within. It's a little shoddy. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/MultiCore/Lock.CC.html#l1"><span class=cF4>::/Demo/MultiCore/Lock.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l265"></a>
<a name="l266"></a>* There is a function called </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l388"><span class=cF4>MSize</span></a><span class=cF0>() which gives the size of an object alloced off the heap. For larger size allocations,
<a name="l267"></a>the system rounds-up to a power of two, so </span><span class=cF2>MSize()</span><span class=cF0> lets you know the real size and you can take full advantage of it.
2021-07-03 05:07:57 +01:00
<a name="l268"></a>
<a name="l269"></a>* You CAN </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l387"><span class=cF4>Free</span></a><span class=cF0>() a </span><span class=cF2>NULL</span><span class=cF0> ptr. Useful variants of </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l391"><span class=cF4>MAlloc</span></a><span class=cF0>() can be found </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l399"><span class=cF4>Here</span></a><span class=cF0>. Each task has a heap and you can </span><span class=cF2>MAlloc</span><span class=cF0> and </span><span class=cF2>Free</span><span class=cF0>
<a name="l270"></a>off-of other task's heaps, or make an independent heap with </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/HeapCtrl.CC.html#l1"><span class=cF4>HeapCtrlInit</span></a><span class=cF0>(). See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Utils/HeapLog.CC.html#l83"><span class=cF4>HeapLog</span></a><span class=cF0>() for an example.
2021-07-03 05:07:57 +01:00
<a name="l271"></a>
<a name="l272"></a>* The stack does not grow because virtual mem is not used. It's recommended to allocate large local vars from the heap. Yo
<a name="l273"></a>u can change </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l3549"><span class=cF4>MEM_DEFAULT_STACK</span></a><span class=cF0> and recompile </span><span class=cF2>Kernel</span><span class=cF0> or request more when doing a </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KTask.CC.html#l264"><span class=cF4>Spawn</span></a><span class=cF0>(). You can use </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KTask.CC.html#l129"><span class=cF4>CallStackGrow</span></a><span class=cF0>(), but
<a name="l274"></a>it's odd. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/StackGrow.CC.html#l1"><span class=cF4>::/Demo/StackGrow.CC</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l275"></a>
<a name="l276"></a>* Only one base class is allowed.
<a name="l277"></a>
<a name="l278"></a>* </span><span class=cF2>printf()</span><span class=cF0> has new codes. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Print.DD.html#l1"><span class=cF4>Print(&quot;&quot;) Format Strings</span></a><span class=cF0>.
2021-07-03 05:07:57 +01:00
<a name="l279"></a>
<a name="l280"></a>* All values are extended to 64-bit when accessed. Intermediate calculations are done with 64-bit values.
2021-07-03 05:07:57 +01:00
<a name="l281"></a>
<a name="l282"></a> </span><span class=cF2>U0 Main()
<a name="l283"></a> {
<a name="l284"></a> I16 i1;
<a name="l285"></a> I32 j1;
2021-07-03 05:07:57 +01:00
<a name="l286"></a>
<a name="l287"></a> j1 = i1 = 0x12345678; //Resulting i1 is 0x5678 but j1 is 0x12345678
2021-07-03 05:07:57 +01:00
<a name="l288"></a>
<a name="l289"></a> I64 i2 = 0x8000000000000000;
<a name="l290"></a> Print(&quot;%X\n&quot;, i2 &gt;&gt; 1); //Res is 0xC000000000000000 as expected
2021-07-03 05:07:57 +01:00
<a name="l291"></a>
<a name="l292"></a> U64 u3 = 0x8000000000000000;
<a name="l293"></a> Print(&quot;%X\n&quot;, u3 &gt;&gt; 1); //Res is 0x4000000000000000 as expected
2021-07-03 05:07:57 +01:00
<a name="l294"></a>
<a name="l295"></a> I32 i4 = 0x80000000; //const is loaded into a 64-bit reg var.
<a name="l296"></a> Print(&quot;%X\n&quot;, i4 &gt;&gt; 1); //Res is 0x40000000
2021-07-03 05:07:57 +01:00
<a name="l297"></a>
<a name="l298"></a> I32 i5 = -0x80000000;
<a name="l299"></a> Print(&quot;%X\n&quot;, i5 &gt;&gt; 1); //Res is 0xFFFFFFFFC0000000
2021-07-03 05:07:57 +01:00
<a name="l300"></a> }
<a name="l301"></a></span><span class=cF0>
</span></pre></body>
</html>