Repository navigation
Expand file tree
/
Copy pathscmc.html
More file actions
1 lines (1 loc) · 66.7 KB
/
Copy pathscmc.html
File metadata and controls
1 lines (1 loc) · 66.7 KB
1
<html><style>table {border-collapse: collapse;} th, td {border:1px solid; text-align :center}</style> <head><meta charset="UTF8"></head> <h1 align="center">The SCMC Programming Lagnuage</h1> <h2>1 Introduction</h2> <p>The SCMC programming language is a scheme like lisp dialect of which the core part can be viewed as the "S-expression" version of the C programming language. So in this document, we will mainly introduce how the SCMC compiler compiles the SCMC code into C. Reader should be familiar with the C and the scheme programming languages. Books such as <i>The C Programming Language</i> , <i>The Little Schemer</i> , <i>Structure and Interpretation of Computer Programs</i> , <i>The Scheme Programming Language</i> and <i>ANSI Common Lisp</i> are suggested for reference.</p> <h3>1.1 The first program: Hellow world</h3> <p>In SCMC, one possible program to print "Hellow world" is</p> <script> function func_mcl_1() {var x = document.getElementById("DIV_ID_1");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_1" onClick="event.cancelBubble=true;func_mcl_1()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(0,128,32);">include<</block> <block style="color:RGB(224,0,192)">"stdio.h"</block>)<br> <script> function func_mcl_2() {var x = document.getElementById("DIV_ID_2");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_2" onClick="event.cancelBubble=true;func_mcl_2()">(<block style="color:RGB(192,0,0);">defun</block> main int ((int argc) (char** argv))<br> (printf <block style="color:RGB(224,0,192)">"Hellow world\n"</block>)<br> (<block style="color:RGB(192,0,0);">return</block> <block style="color:RGB(192,0,192);">0</block>))</div>)</div> <p>Save the above code as <i>hellow.scmc</i> . Then use the following command to compile it to C</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block>$ scmc_compile_passes hellow.scmc</block> <br> </div> <p>If everything is right, a C file with name <i>hellow.c</i> should be generated. Its content should be something like:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> $ cat hellow.c</block> <br> <block> #include <stdio.h></block> <br> <block> int main (int argc ,char * * argv ){</block> <br> <block> printf ( "Hellow world\n" );</block> <br> <block> return 0 ;}</block> <br> <block> $</block> <br> </div> <p>We can see that it is just a C version of a <i>Hellow world</i> program. So a C compiler can be used to compile it into executable file and then we may run it.</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> $ cc hellow.c</block> <br> <block> $ ./a.out</block> <br> <block> Hellow world</block> <br> <block> $</block> <br> </div> <p>As we stated, the core part of SCMC programming language can be viewed as the "S-expression" version of the C programming language.</p> <p>The code of <i>hellow.scmc</i> is just one S-expression of which the first symbol is <i>begin</i> . The <i>begin</i> plays the role just like the role it plays in the scheme programming language. It tells the compiler to compile the rest of that S-expression in sequence.</p> <p>The following code</p> (<block style="color:RGB(0,128,32);">include<</block> <block style="color:RGB(224,0,192)">"stdio.h"</block>) <p>is compiled to</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">#include <stdio.h></div> <p>in C which is used to include information about the standard input/output library.</p> <p>The main body of this code is a main function definition, its syntax can be stated as follows:</p> <script> function func_mcl_3() {var x = document.getElementById("DIV_ID_3");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_3" onClick="event.cancelBubble=true;func_mcl_3()">(<block style="color:RGB(192,0,0);">defun</block> <i>function_name</i> <i>return_type</i> <i>((type_1 arg_1) (type_2 arg_2) ...)</i><br> <i>body1</i><br> <i>body2</i><br> ...)</div> <which>will be compiled to</which> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> return_type function_name (type_1 arg_1, type_2 arg_2, ...){</block> <br> <block> body1;</block> <br> <block> body2;</block> <br> <block> ...</block> <br> <block> }</block> <br> </div> <p>in the C code.</p> <p>Function calls will be converted correspondingly, for example:</p> <i>(function_name arg_1 arg_2 ...)</i> <p>will be compiled to</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">function_name (arg_1, arg_2, ...)</div> <p>As we can see, this simple Hellow world program is just an "S-expression" version of a Hellow world program in the C programming language. We will continue to introduce the key idea of writing an SCMC code and its structures and syntaxes.</p> <h3>1.2 SCMC codes</h3> <p>The core part of an SCMC code is the "S-expression" version of C code, so why don't we just write the C code other than the SCMC code? The reason is simple, S-expressiones can be easily manipulated and reused through macros and procedures in scheme codes. So the rest of this document will be divided into two chapters, of which the first one introduces all counterparts of C codes in SCMC, and the second one introduces the macro system and the built-in standard libs for manipulate S-expressiones in SCMC.</p> <h2>2 "S-expression" version of C</h2> <p>In this section, we will introduce all counterparts of C codes in SCMC. Note that in the C programming language, statements, declarations, statements and declarations in expressions (A GNU C extension that can be found in <a href="http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html">here</a> ), and expressions are very different and the C compiler can not automatically distinguish most of them. However in the scheme programming language they can be automatically decided. So in this chapter we will not distinguish the appearance of statements, declarations and expressions in the C code.</p> <h3>2.1 Include directive</h3> <div><h3>Include files in implementation-defined places</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">include<</block> <i>file_name</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">#include <file_name></div> <p>where file_name should be a string or symbol</p> <p>Example:</p> (<block style="color:RGB(0,128,32);">include<</block> <block style="color:RGB(224,0,192)">"stdlib.h"</block>)</div></div> <div><h3>Include files firstly in the location of source path</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">include-</block> <i>file_name</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">#include "file_name"</div> <p>where file_name should be a string or symbol .</p> <p>Example:</p> (<block style="color:RGB(0,128,32);">include-</block> <block style="color:RGB(224,0,192)">"local_headers.h"</block>)</div></div> <h3>2.2 Declarations and definitions</h3> <div><h3>Declarations</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">declare</block> <i>type</i> <i>var_name_1</i> <i>var_name_2</i> ...) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">type var_name_1, var_name_2, ...</div> <p>Note that declare type can be written as declare-type.</p> <p>Example:</p> <script> function func_mcl_4() {var x = document.getElementById("DIV_ID_4");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_4" onClick="event.cancelBubble=true;func_mcl_4()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">declare</block> int var1 var2 var3)<br> (<block style="color:RGB(192,0,0);">declare-int</block> var4 var5))</div></div></div> <div><h3>Declarations with initializing</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">declare</block> <i>type</i> <i>(var_name_1 init_1)</i> <i>(var_name_2 init_2)</i> ...) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> type var_name_1, var_name_2, ...;</block> <br> <block> var_name_1=init_1;</block> <br> <block> var_name_2=init_2;</block> <br> <block> ...</block> <br> </div> <p>Note that declare type can be written as declare-type.</p> <p>Example:</p> <script> function func_mcl_5() {var x = document.getElementById("DIV_ID_5");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_5" onClick="event.cancelBubble=true;func_mcl_5()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">declare</block> double (var1 init_1) (var2 init_2) var3 var4)<br> (<block style="color:RGB(192,0,0);">declare-float</block> var5 (var6 init_6) var7))</div></div></div> <div><h3>Definition</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (define-<i>type</i> var_name init) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> type var_name;</block> <br> <block> var_name=init;</block> <br> </div> <p>Note that the <i>init</i> can be empty.</p> <p>Example:</p> <script> function func_mcl_6() {var x = document.getElementById("DIV_ID_6");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_6" onClick="event.cancelBubble=true;func_mcl_6()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define-double</block> arg0)<br> (<block style="color:RGB(192,0,0);">define-double</block> arg1 (<block style="color:RGB(0,128,32);">cos</block> (<block style="color:RGB(0,128,32);">+</block> arg0 <block style="color:RGB(192,0,192);">1</block>)))<br> (<block style="color:RGB(192,0,0);">define-int*</block> arg2 <block style="color:RGB(0,128,32);">NULL</block>))</div></div></div> <div><h3>Definition with type inference</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">define</block> var_name init) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> typeof(init) var_name;</block> <br> <block> var_name=init;</block> <br> </div> <p>Note that the <i>typeof(init)</i> will use the type inferenc feature in SCMC compiler to decide the type of <i>init</i> . Some times it may failed when <i>init</i> is complex.</p> <p>Example:</p> <script> function func_mcl_7() {var x = document.getElementById("DIV_ID_7");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_7" onClick="event.cancelBubble=true;func_mcl_7()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define</block> arg0 <block style="color:RGB(192,0,192);">4.00000000000000022e-01</block>)<br> (<block style="color:RGB(192,0,0);">define</block> arg1 (<block style="color:RGB(0,128,32);">cos</block> (<block style="color:RGB(0,128,32);">+</block> arg0 <block style="color:RGB(192,0,192);">1</block>)))<br> (<block style="color:RGB(192,0,0);">define</block> arg2 (<block style="color:RGB(0,128,32);">-</block> arg1 <block style="color:RGB(192,0,192);">7</block>)))</div></div></div> <h3>2.3 Set</h3> <div><h3>Set a value to a variable</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (set! <i>var</i> <i>val</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> var=val;</block> <br> </div> <p></p> <p>Example:</p> <script> function func_mcl_8() {var x = document.getElementById("DIV_ID_8");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_8" onClick="event.cancelBubble=true;func_mcl_8()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define</block> a <block style="color:RGB(192,0,192);">2.00000000000000011e-01</block>)<br> (set! a <block style="color:RGB(192,0,192);">1.50000000000000000e+00</block>))</div></div></div> <h3>2.4 Functions</h3> <div><h3>Function definition</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_9() {var x = document.getElementById("DIV_ID_9");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_9" onClick="event.cancelBubble=true;func_mcl_9()">(<block style="color:RGB(192,0,0);">defun</block> <i>function_name</i> <i>return_type</i> <i>((type_1 arg_1) (type_2 arg_2) ...)</i><br> <i>body1</i><br> <i>body2</i><br> ...)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> return_type function_name (type_1 arg_1, type_2 arg_2, ...){</block> <br> <block> body1;</block> <br> <block> body2;</block> <br> <block> ...</block> <br> }</div> <p></p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> <script> function func_mcl_10() {var x = document.getElementById("DIV_ID_10");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,243,243);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_10" onClick="event.cancelBubble=true;func_mcl_10()">(<block style="color:RGB(192,0,0);">defun</block> fun1 double ((double arg0))<br> (<block style="color:RGB(192,0,0);">return</block> (<block style="color:RGB(0,128,32);">+</block> arg0 <block style="color:RGB(192,0,192);">4</block>)))</div>)</div></div> <div><h3>Function declaration</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (dec-fun <i>function_name</i> <i>return_type</i> <i>((type_1 arg_1) (type_2 arg_2) ...)</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">return_type function_name (type_1 arg_1, type_2 arg_2, ...);</div> <p></p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> <script> function func_mcl_11() {var x = document.getElementById("DIV_ID_11");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,243,243);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_11" onClick="event.cancelBubble=true;func_mcl_11()">(<block style="color:RGB(192,0,0);">defun</block> fun1 double ((double arg0)))</div>)</div></div> <div><h3>Function pointer variable declaration</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">declare</block> (function-pointer <i>return_type</i> <i>type_1</i> <i>type_2</i> ...) function_name) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">typedef return_type (* function_name) (type_1, type_2, ...);</div> <p></p> <p>Example:</p> <script> function func_mcl_12() {var x = document.getElementById("DIV_ID_12");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_12" onClick="event.cancelBubble=true;func_mcl_12()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">declare</block> (function-pointer double double) <block style="color:RGB(0,128,32);">sin</block>)<br> (<block style="color:RGB(192,0,0);">define-double</block> m (<block style="color:RGB(0,128,32);">sin</block> <block style="color:RGB(192,0,192);">2.00000000000000011e-01</block>)))</div></div></div> <div><h3>Function call</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <i>(function_name arg_1 arg_2 ...)</i> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">function_name (arg_1, arg_2, ...)</div> <p></p> <p>Example:</p> <script> function func_mcl_13() {var x = document.getElementById("DIV_ID_13");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_13" onClick="event.cancelBubble=true;func_mcl_13()">(<block style="color:RGB(192,0,0);">begin</block><br> (function_name_1 arg_1 arg_2 <block style="color:RGB(192,0,192);">3.00000000000000000e+00</block> <block style="color:RGB(224,0,192)">"text"</block>)<br> (<block style="color:RGB(192,0,0);">define-int</block> rt1 (function_name_2)))</div></div></div> <div><h3>Return statement in function</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">return</block> <i>retvar</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">return retvar;</div> <p></p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> <script> function func_mcl_14() {var x = document.getElementById("DIV_ID_14");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,243,243);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_14" onClick="event.cancelBubble=true;func_mcl_14()">(<block style="color:RGB(192,0,0);">defun</block> fun1 double ((double arg0))<br> (<block style="color:RGB(192,0,0);">return</block> (<block style="color:RGB(0,128,32);">+</block> arg0 <block style="color:RGB(192,0,192);">4</block>)))</div>)</div></div> <h3>2.5 Arithmetic operations</h3> <p>All arithmetic operations are treated as functions in SCMC, for example:</p> <script> function func_mcl_15() {var x = document.getElementById("DIV_ID_15");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_15" onClick="event.cancelBubble=true;func_mcl_15()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(0,128,32);">+</block> <block style="color:RGB(192,0,192);">3</block> <block style="color:RGB(192,0,192);">4</block>)<br> (<block style="color:RGB(0,128,32);">*</block> <block style="color:RGB(192,0,192);">4.20000000000000018e+00</block> (<block style="color:RGB(0,128,32);">sin</block> <block style="color:RGB(192,0,192);">2.99999999999999989e-01</block>))<br> (<block style="color:RGB(0,128,32);">b-and</block> <block style="color:RGB(192,0,192);">1</block> <block style="color:RGB(192,0,192);">0</block>))</div> <h3>2.6 Type Conversion</h3> <div><h3>Convet a type</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (type-convert <i>to_type</i> <i>expr</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">((to_type)expr)</div> <p></p> <p>Example:</p> <script> function func_mcl_16() {var x = document.getElementById("DIV_ID_16");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_16" onClick="event.cancelBubble=true;func_mcl_16()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define-double</block> a <block style="color:RGB(192,0,192);">0.00000000000000000e+00</block>)<br> (<block style="color:RGB(192,0,0);">define-int*</block> p_a (type-convert double* (<block style="color:RGB(224,0,192)">"&"</block> a))))</div></div></div> <h3>2.7 Pointers</h3> <div><h3>Get memory address of a variable</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(224,0,192)">"&"</block> <i>var</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">&var</div> <p></p> <p>Example:</p> <script> function func_mcl_17() {var x = document.getElementById("DIV_ID_17");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_17" onClick="event.cancelBubble=true;func_mcl_17()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define-int</block> a <block style="color:RGB(192,0,192);">0</block>)<br> (<block style="color:RGB(192,0,0);">define-int*</block> p_a (<block style="color:RGB(224,0,192)">"&"</block> a)))</div></div></div> <h3>2.8 Control flow</h3> <div><h3>If statements and expressions</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_18() {var x = document.getElementById("DIV_ID_18");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_18" onClick="event.cancelBubble=true;func_mcl_18()">(<block style="color:RGB(192,0,0);">if</block> <i>p</i><br> <i>v_1</i><br> <i>v_2</i>)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> if(p){</block> <br> <block> v_1;</block> <br> <block> }else{</block> <br> <block> v_2</block> <br> }</div> <p></p> <p>Example:</p> <script> function func_mcl_19() {var x = document.getElementById("DIV_ID_19");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_19" onClick="event.cancelBubble=true;func_mcl_19()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_20() {var x = document.getElementById("DIV_ID_20");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_20" onClick="event.cancelBubble=true;func_mcl_20()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">4</block>)<br> i<br> <block style="color:RGB(192,0,192);">0</block>)</div><br> <script> function func_mcl_21() {var x = document.getElementById("DIV_ID_21");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_21" onClick="event.cancelBubble=true;func_mcl_21()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);">></block> g <block style="color:RGB(192,0,192);">3</block>)<br> <script> function func_mcl_22() {var x = document.getElementById("DIV_ID_22");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_22" onClick="event.cancelBubble=true;func_mcl_22()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define</block> g1 (<block style="color:RGB(0,128,32);">+</block> g <block style="color:RGB(192,0,192);">4.50000000000000000e+00</block>))<br> (<block style="color:RGB(0,128,32);">*</block> g1 g1))</div><br> (<block style="color:RGB(0,128,32);">-</block> g <block style="color:RGB(192,0,192);">4</block>))</div><br> <script> function func_mcl_23() {var x = document.getElementById("DIV_ID_23");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_23" onClick="event.cancelBubble=true;func_mcl_23()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);"><</block> (<block style="color:RGB(0,128,32);">+</block> <block style="color:RGB(192,0,192);">4</block> g) <block style="color:RGB(192,0,192);">0</block>)<br> (set! g <block style="color:RGB(192,0,192);">0</block>))</div>)</div></div></div> <div><h3>Cond structure</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (cond (<i>p1</i> <i>v1p1</i> <i>v2p1</i> ...) (<i>p2</i> <i>v1p2</i> <i>v2p2</i> ...) ... (<block style="color:RGB(192,0,0);">else</block> <i>velse1</i> <i>velse2</i> ...)) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> if(p1){</block> <br> <block> v1p1;</block> <br> <block> v2p1;</block> <br> <block> ...</block> <br> <block> }else if(p2){</block> <br> <block> v1p2;</block> <br> <block> v2p2;</block> <br> <block> ...</block> <br> <block> }else if ... </block> <br> <block> else{</block> <br> <block> velse1;</block> <br> <block> velse2;</block> <br> <block> ...</block> <br> }</div> <p></p> <p>Example:</p> (<block style="color:RGB(192,0,0);">cond</block> <script> function func_mcl_24() {var x = document.getElementById("DIV_ID_24");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_24" onClick="event.cancelBubble=true;func_mcl_24()">((<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">4</block>)<br> <block style="color:RGB(192,0,192);">5</block>)</div> <script> function func_mcl_25() {var x = document.getElementById("DIV_ID_25");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_25" onClick="event.cancelBubble=true;func_mcl_25()">((<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">8</block>)<br> (<block style="color:RGB(0,128,32);">*</block> i <block style="color:RGB(192,0,192);">4</block>))</div> <script> function func_mcl_26() {var x = document.getElementById("DIV_ID_26");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_26" onClick="event.cancelBubble=true;func_mcl_26()">((<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">12</block>)<br> (<block style="color:RGB(192,0,0);">define</block> g <block style="color:RGB(192,0,192);">4</block>)<br> (<block style="color:RGB(0,128,32);">cos</block> g))</div> <script> function func_mcl_27() {var x = document.getElementById("DIV_ID_27");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_27" onClick="event.cancelBubble=true;func_mcl_27()">(<block style="color:RGB(192,0,0);">else</block><br> (<block style="color:RGB(0,128,32);">sin</block> i))</div>)</div></div> <h3>2.9 Loop</h3> <div><h3>For loop</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_28() {var x = document.getElementById("DIV_ID_28");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_28" onClick="event.cancelBubble=true;func_mcl_28()">(<block style="color:RGB(192,0,0);">for</block> <i>beg</i> <i>condition</i> <i>iter</i><br> <i>body1</i><br> <i>body2</i><br> ...)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> for (beg;condition;iter) {</block> <br> <block> body1;</block> <br> <block> body2;</block> <br> <block> ...</block> <br> <block> }</block> <br> </div> <p></p> <p>Example:</p> <script> function func_mcl_29() {var x = document.getElementById("DIV_ID_29");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_29" onClick="event.cancelBubble=true;func_mcl_29()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define-int</block> i)<br> <script> function func_mcl_30() {var x = document.getElementById("DIV_ID_30");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_30" onClick="event.cancelBubble=true;func_mcl_30()">(<block style="color:RGB(192,0,0);">for</block> (set! i <block style="color:RGB(192,0,192);">0</block>) (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">10</block>) (incf! i)<br> (printf <block style="color:RGB(224,0,192)">"%d\n"</block> i))</div>)</div></div></div> <div><h3>Break and Continue</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> break continue <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">break continue</div> <p></p> <p>Example:</p> <script> function func_mcl_31() {var x = document.getElementById("DIV_ID_31");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_31" onClick="event.cancelBubble=true;func_mcl_31()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define-int</block> i)<br> <script> function func_mcl_32() {var x = document.getElementById("DIV_ID_32");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_32" onClick="event.cancelBubble=true;func_mcl_32()">(<block style="color:RGB(192,0,0);">for</block> (set! i <block style="color:RGB(192,0,192);">0</block>) (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">100</block>) (incf! i)<br> <script> function func_mcl_33() {var x = document.getElementById("DIV_ID_33");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_33" onClick="event.cancelBubble=true;func_mcl_33()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);">></block> i <block style="color:RGB(192,0,192);">80</block>)<br> <block style="color:RGB(192,0,0);">break</block>)</div><br> <script> function func_mcl_34() {var x = document.getElementById("DIV_ID_34");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_34" onClick="event.cancelBubble=true;func_mcl_34()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">40</block>)<br> <block style="color:RGB(192,0,0);">continue</block>)</div><br> (printf <block style="color:RGB(224,0,192)">"%d\n"</block> i))</div>)</div></div></div> <h3>2.10 Program structure</h3> <div><h3>Block structure</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_35() {var x = document.getElementById("DIV_ID_35");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_35" onClick="event.cancelBubble=true;func_mcl_35()">(<block style="color:RGB(192,0,0);">block</block><br> <i>exp1</i><br> <i>exp2</i><br> ...)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> {</block> <br> <block> exp1;</block> <br> <block> exp2;</block> <br> <block> ...</block> <br> }</div> <p></p> <p>Example:</p> <script> function func_mcl_36() {var x = document.getElementById("DIV_ID_36");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_36" onClick="event.cancelBubble=true;func_mcl_36()">(<block style="color:RGB(192,0,0);">block</block><br> (<block style="color:RGB(192,0,0);">define</block> i <block style="color:RGB(192,0,192);">1</block>)<br> <script> function func_mcl_37() {var x = document.getElementById("DIV_ID_37");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_37" onClick="event.cancelBubble=true;func_mcl_37()">(<block style="color:RGB(192,0,0);">block</block><br> (<block style="color:RGB(192,0,0);">define</block> i <block style="color:RGB(192,0,192);">4</block>)<br> (printf <block style="color:RGB(224,0,192)">"inner block: i=%d\n"</block> i))</div><br> (printf <block style="color:RGB(224,0,192)">"outter block: i=%d\n"</block> i)<br> (<block style="color:RGB(192,0,0);">begin</block> (<block style="color:RGB(192,0,0);">define-double</block> a <script> function func_mcl_38() {var x = document.getElementById("DIV_ID_38");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_38" onClick="event.cancelBubble=true;func_mcl_38()">(<block style="color:RGB(192,0,0);">block</block><br> (<block style="color:RGB(192,0,0);">define-double</block> b (<block style="color:RGB(0,128,32);">cos</block> <block style="color:RGB(192,0,192);">5.00000000000000000e-01</block>))<br> (<block style="color:RGB(0,128,32);">+</block> b <block style="color:RGB(192,0,192);">1</block>))</div>)))</div></div></div> <h3>2.11 Goto and Labels</h3> <div><h3>Labels</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (label <i>lab</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">lab:</div> <p></p> <p>Example:</p> <script> function func_mcl_39() {var x = document.getElementById("DIV_ID_39");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_39" onClick="event.cancelBubble=true;func_mcl_39()">(<block style="color:RGB(192,0,0);">begin</block><br> (label l1)<br> <script> function func_mcl_40() {var x = document.getElementById("DIV_ID_40");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_40" onClick="event.cancelBubble=true;func_mcl_40()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">4</block>)<br> (goto l1))</div>)</div></div></div> <div><h3>Goto</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (goto <i>lab</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">goto lab;</div> <p></p> <p>Example:</p> <script> function func_mcl_41() {var x = document.getElementById("DIV_ID_41");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_41" onClick="event.cancelBubble=true;func_mcl_41()">(<block style="color:RGB(192,0,0);">begin</block><br> (label l1)<br> <script> function func_mcl_42() {var x = document.getElementById("DIV_ID_42");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_42" onClick="event.cancelBubble=true;func_mcl_42()">(<block style="color:RGB(192,0,0);">if</block> (<block style="color:RGB(0,128,32);"><</block> i <block style="color:RGB(192,0,192);">4</block>)<br> (goto l1))</div>)</div></div></div> <h3>2.12 Arrays</h3> <div><h3>Declare arrays</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(192,0,0);">dec-array</block> <i>type</i> <i>name</i> <i>dim_1</i> <i>dim_2</i> ...) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">type name[dim_1][dim_2]...</div> <p></p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> (<block style="color:RGB(192,0,0);">dec-array</block> double arr1 <block style="color:RGB(192,0,192);">4</block> <block style="color:RGB(192,0,192);">8</block> <block style="color:RGB(192,0,192);">3</block>))</div></div> <div><h3>Reference array or pointer element</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">vector-ref</block> <i>name</i> <i>i</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">name[i]</div> <p></p> <p>Example:</p> <script> function func_mcl_43() {var x = document.getElementById("DIV_ID_43");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_43" onClick="event.cancelBubble=true;func_mcl_43()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">dec-array</block> double arr0 <block style="color:RGB(192,0,192);">8</block>)<br> (<block style="color:RGB(192,0,0);">define</block> m (<block style="color:RGB(0,128,32);">vector-ref</block> arr0 <block style="color:RGB(192,0,192);">2</block>)))</div></div></div> <div><h3>Set array element</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">vector-set!</block> <i>name</i> <i>i</i> <i>val</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">name[i]=val</div> <p></p> <p>Example:</p> <script> function func_mcl_44() {var x = document.getElementById("DIV_ID_44");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_44" onClick="event.cancelBubble=true;func_mcl_44()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">dec-array</block> double arr1 <block style="color:RGB(192,0,192);">4</block> <block style="color:RGB(192,0,192);">8</block> <block style="color:RGB(192,0,192);">3</block>)<br> (<block style="color:RGB(0,128,32);">vector-set!</block> (<block style="color:RGB(0,128,32);">vector-ref</block> (<block style="color:RGB(0,128,32);">vector-ref</block> arr1 <block style="color:RGB(192,0,192);">0</block>) <block style="color:RGB(192,0,192);">2</block>) <block style="color:RGB(192,0,192);">1</block> <block style="color:RGB(192,0,192);">4.00000000000000022e-01</block>))</div></div></div> <h3>2.13 Struct</h3> <div><h3>Declare a struct</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_45() {var x = document.getElementById("DIV_ID_45");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_45" onClick="event.cancelBubble=true;func_mcl_45()">(<block style="color:RGB(192,0,0);">typedef-struct</block> <i>name</i><br> <i>(type_1 var_1)</i><br> <i>(type_2 var_2)</i><br> ...)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> typedef struct{</block> <br> <block> type_1 var_1;</block> <br> <block> type_2 var_2;</block> <br> <block> ...</block> <br> <block> } name;</block> <br> </div> <p></p> <p>Example:</p> <script> function func_mcl_46() {var x = document.getElementById("DIV_ID_46");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_46" onClick="event.cancelBubble=true;func_mcl_46()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_47() {var x = document.getElementById("DIV_ID_47");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_47" onClick="event.cancelBubble=true;func_mcl_47()">(<block style="color:RGB(192,0,0);">typedef-struct</block> point_4d<br> (double x)<br> (double y)<br> (double z)<br> (double w))</div><br> (<block style="color:RGB(192,0,0);">define-point_4d</block> p1))</div></div></div> <div><h3>Reference a variable from struct pointer</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (structp-ref <i>name</i> <i>var</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">name->var</div> <p></p> <p>Example:</p> <script> function func_mcl_48() {var x = document.getElementById("DIV_ID_48");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_48" onClick="event.cancelBubble=true;func_mcl_48()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_49() {var x = document.getElementById("DIV_ID_49");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_49" onClick="event.cancelBubble=true;func_mcl_49()">(<block style="color:RGB(192,0,0);">typedef-struct</block> point_4d<br> (double x)<br> (double y)<br> (double z)<br> (double w))</div><br> (<block style="color:RGB(192,0,0);">define-point_4d</block> p1)<br> (<block style="color:RGB(192,0,0);">define-point_4d*</block> pp1 (<block style="color:RGB(224,0,192)">"&"</block> p1))<br> (set! (structp-ref pp1 x) <block style="color:RGB(192,0,192);">5.00000000000000000e-01</block>)<br> (set! pp1->y <block style="color:RGB(192,0,192);">2.00000000000000011e-01</block>))</div></div></div> <div><h3>Reference a variable in struct</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (struct-ref <i>name</i> <i>var</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">name.var</div> <p></p> <p>Example:</p> <script> function func_mcl_50() {var x = document.getElementById("DIV_ID_50");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_50" onClick="event.cancelBubble=true;func_mcl_50()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_51() {var x = document.getElementById("DIV_ID_51");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_51" onClick="event.cancelBubble=true;func_mcl_51()">(<block style="color:RGB(192,0,0);">typedef-struct</block> point_4d<br> (double x)<br> (double y)<br> (double z)<br> (double w))</div><br> (<block style="color:RGB(192,0,0);">define-point_4d</block> p1)<br> (set! (struct-ref p1 x) <block style="color:RGB(192,0,192);">5.00000000000000000e-01</block>)<br> (set! p1.y <block style="color:RGB(192,0,192);">2.00000000000000011e-01</block>))</div></div></div> <div><h3>SIMD parallel for</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (paraforn (<i>simd_length</i> <i>align_length</i> <i>type_map</i> <i>var</i> <block style="color:RGB(192,0,192);">0</block> <i>range</i>) body1 body2 ...) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"><block> {</block> <br> <block> long var;</block> <br> <block> for(var=0;var<range;var++){</block> <br> <block> body1;</block> <br> <block> body2;</block> <br> <block> ...</block> <br> }}</div> <p>This syntax is designed to convert a parallelable for statement block to SIMD optimized version. Currently not all expressions and statements are supported in this structure, you may try if it is supported.</p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> (paraforn (<block style="color:RGB(192,0,192);">4</block> <block style="color:RGB(192,0,192);">32</block> ((double __m256d) (long __m256i) (set-single _mm256_setr_pd))) g <block style="color:RGB(192,0,192);">0</block> len (<block style="color:RGB(192,0,0);">define-double</block> ag (<block style="color:RGB(0,128,32);">vector-ref</block> a g)) (<block style="color:RGB(192,0,0);">define-double</block> bg (<block style="color:RGB(0,128,32);">vector-ref</block> b g)) (force-simd-ver (set! ag (<block style="color:RGB(0,128,32);">+</block> bg (<block style="color:RGB(0,128,32);">*</block> ag ag <block style="color:RGB(192,0,192);">5.00000000000000000e-01</block>)))) (<block style="color:RGB(0,128,32);">vector-set!</block> a g ag)))</div></div> <div><h3>Force use SIMD intrin in the paraforn</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (force-simd-ver <i>expr</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>This syntax is used in the paraforn syntax to generate intrin SIMD codes.</p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> (paraforn (<block style="color:RGB(192,0,192);">4</block> <block style="color:RGB(192,0,192);">32</block> ((double __m256d) (long __m256i) (set-single _mm256_setr_pd))) g <block style="color:RGB(192,0,192);">0</block> len (<block style="color:RGB(192,0,0);">define-double</block> ag (<block style="color:RGB(0,128,32);">vector-ref</block> a g)) (<block style="color:RGB(192,0,0);">define-double</block> bg (<block style="color:RGB(0,128,32);">vector-ref</block> b g)) (force-simd-ver (set! ag (<block style="color:RGB(0,128,32);">+</block> bg (<block style="color:RGB(0,128,32);">*</block> ag ag <block style="color:RGB(192,0,192);">5.00000000000000000e-01</block>)))) (<block style="color:RGB(0,128,32);">vector-set!</block> a g ag)))</div></div> <h2>3 Macros and the standard library in SCMC</h2> <h3>3.1 Macros</h3> <p>In the SCMC language, macros can be defined by the <i>defmacro</i> structure, which behaves like <i>defmacro</i> in the common lisp programming language.</p> <div><h3>DEFMACRO</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_52() {var x = document.getElementById("DIV_ID_52");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_52" onClick="event.cancelBubble=true;func_mcl_52()">(<block style="color:RGB(192,0,0);">defmacro</block> <i>macro_name</i> <i>(var1 var2 ...)</i><br> <i>body1</i><br> <i>body2</i><br> ...)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>No C counterpart for this structure.</p> <p>Example:</p> <script> function func_mcl_53() {var x = document.getElementById("DIV_ID_53");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_53" onClick="event.cancelBubble=true;func_mcl_53()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_54() {var x = document.getElementById("DIV_ID_54");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_54" onClick="event.cancelBubble=true;func_mcl_54()">(<block style="color:RGB(192,0,0);">defmacro</block> print_double_variables var_list<br> `<script> function func_mcl_55() {var x = document.getElementById("DIV_ID_55");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_55" onClick="event.cancelBubble=true;func_mcl_55()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_56() {var x = document.getElementById("DIV_ID_56");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,213,213);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_56" onClick="event.cancelBubble=true;func_mcl_56()">(<block style="color:RGB(192,0,0);">begin</block><br> unquote<br> (<block style="color:RGB(0,128,32);">map</block> <script> function func_mcl_57() {var x = document.getElementById("DIV_ID_57");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,195,195);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_57" onClick="event.cancelBubble=true;func_mcl_57()">(<block style="color:RGB(192,0,0);">lambda</block> (v)<br> `(printf <block style="color:RGB(224,0,192)">"%e "</block> ,v))</div> var_list))</div><br> (printf <block style="color:RGB(224,0,192)">"\n"</block>))</div>)</div><br> (<block style="color:RGB(192,0,0);">declare-double</block> (v1 <block style="color:RGB(192,0,192);">2.00000000000000011e-01</block>) (v2 <block style="color:RGB(192,0,192);">2.99999999999999989e-01</block>) (v3 <block style="color:RGB(192,0,192);">1.00000000000000006e-01</block>))<br> (print_double_variables v1)<br> (print_double_variables v1 v2)<br> (print_double_variables v2 v1 v3)<br> <script> function func_mcl_58() {var x = document.getElementById("DIV_ID_58");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_58" onClick="event.cancelBubble=true;func_mcl_58()">(<block style="color:RGB(192,0,0);">defmacro</block> vrf (vector-name . ref_ids)<br> (<block style="color:RGB(192,0,0);">cond</block> <script> function func_mcl_59() {var x = document.getElementById("DIV_ID_59");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_59" onClick="event.cancelBubble=true;func_mcl_59()">((<block style="color:RGB(0,128,32);">null?</block> ref_ids)<br> vector-name)</div> <script> function func_mcl_60() {var x = document.getElementById("DIV_ID_60");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,225,225);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_60" onClick="event.cancelBubble=true;func_mcl_60()">(<block style="color:RGB(192,0,0);">else</block><br> (<block style="color:RGB(192,0,0);">define</block> lst (<block style="color:RGB(0,128,32);">reverse</block> ref_ids))<br> (<block style="color:RGB(192,0,0);">define</block> rem (<block style="color:RGB(0,128,32);">reverse</block> (<block style="color:RGB(0,128,32);">cdr</block> lst)))<br> (set! lst (<block style="color:RGB(0,128,32);">car</block> lst))<br> `(<block style="color:RGB(0,128,32);">vector-ref</block> (vrf ,vector-name unquote rem) ,lst))</div>))</div><br> (<block style="color:RGB(192,0,0);">dec-array</block> double m <block style="color:RGB(192,0,192);">4</block> <block style="color:RGB(192,0,192);">3</block>)<br> (set! (vrf m <block style="color:RGB(192,0,192);">2</block> <block style="color:RGB(192,0,192);">1</block>) <block style="color:RGB(192,0,192);">0</block>))</div></div></div> <h3>3.2 Standard Libs in SCMC</h3> <div><h3>input-scmc</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">input-scmc</block> <i>scmc_source</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>No C counterpart for this structure. This operation will evaluate all source put in the file located at <i>scmc_source</i> .</p> <p>Example:</p> (<block style="color:RGB(0,128,32);">input-scmc</block> <block style="color:RGB(224,0,192)">"local_defs.scmc"</block>)</div></div> <div><h3>eval-scmc-global</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> <i>scmc_expression</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>No C counterpart for this structure. This operation will evaluate the S-expression <i>scmc_expression</i> .</p> <p>Example:</p> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> (<block style="color:RGB(0,128,32);">list</block> '<block style="color:RGB(192,0,0);">define-double</block> s <block style="color:RGB(192,0,192);">0.00000000000000000e+00</block>))</div></div> <div><h3>()</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> () <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>No C counterpart for this structure. The empty list will not be generated in the C code.</p> <p>Example:</p> <script> function func_mcl_61() {var x = document.getElementById("DIV_ID_61");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_61" onClick="event.cancelBubble=true;func_mcl_61()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> <script> function func_mcl_62() {var x = document.getElementById("DIV_ID_62");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,231,231);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_62" onClick="event.cancelBubble=true;func_mcl_62()">(<block style="color:RGB(192,0,0);">begin</block><br> (<block style="color:RGB(192,0,0);">define</block> tmp-type 'double)<br> '())</div>)<br> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> `(<block style="color:RGB(192,0,0);">declare</block> ,tmp-type var1)))</div></div></div> <div><h3>define-scmc-global</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> <script> function func_mcl_63() {var x = document.getElementById("DIV_ID_63");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_63" onClick="event.cancelBubble=true;func_mcl_63()">(<block style="color:RGB(192,0,0);">define-scmc-global</block> <i>var</i><br> <i>val</i>)</div> <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>No C counterpart for this structure. This operation will define a global variable named <i>var</i> and set it to <i>val</i></p> <p>Example:</p> <script> function func_mcl_64() {var x = document.getElementById("DIV_ID_64");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_64" onClick="event.cancelBubble=true;func_mcl_64()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_65() {var x = document.getElementById("DIV_ID_65");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_65" onClick="event.cancelBubble=true;func_mcl_65()">(<block style="color:RGB(192,0,0);">define-scmc-global</block> tmp-type<br> 'double)</div><br> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> `(<block style="color:RGB(192,0,0);">declare</block> ,tmp-type var1)))</div></div></div> <div><h3>begin-map</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (begin-map <i>procedure</i> <i><block style="color:RGB(0,128,32);">list</block></i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>This is a scheme procedure which is used to generate `(begin . ,(map structure</p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> (<block style="color:RGB(0,128,32);">eval-scmc-global</block> (begin-map <script> function func_mcl_66() {var x = document.getElementById("DIV_ID_66");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,231,231);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_66" onClick="event.cancelBubble=true;func_mcl_66()">(<block style="color:RGB(192,0,0);">lambda</block> (v)<br> (set! v <block style="color:RGB(192,0,192);">0.00000000000000000e+00</block>))</div> '(v1 v2 v3))))</div></div> <div><h3>multi-concat</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (multi-concat <i>sym1</i> <i>sym2</i> ...) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;"></div> <p>This is a scheme procedure which is used to concatenate multiple strings or symbols.</p> <p>Example:</p> <script> function func_mcl_67() {var x = document.getElementById("DIV_ID_67");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,249,249);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_67" onClick="event.cancelBubble=true;func_mcl_67()">(<block style="color:RGB(192,0,0);">begin</block><br> <script> function func_mcl_68() {var x = document.getElementById("DIV_ID_68");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,237,237);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_68" onClick="event.cancelBubble=true;func_mcl_68()">(<block style="color:RGB(192,0,0);">defmacro</block> def-multi-variables (type . var-init)<br> (begin-map <script> function func_mcl_69() {var x = document.getElementById("DIV_ID_69");if (x.style.height == "") {x.style.height="1.5em";} else {x.style.height="";}} </script><div style="overflow:hidden;margin-left:20px;background-color:RGB(255,219,219);border-style:solid;border-color: RGB(128,192,192);border-width:thin thin thin thin;" id="DIV_ID_69" onClick="event.cancelBubble=true;func_mcl_69()">(<block style="color:RGB(192,0,0);">lambda</block> (x)<br> (<block style="color:RGB(192,0,0);">define</block> var (<block style="color:RGB(0,128,32);">car</block> x))<br> (<block style="color:RGB(192,0,0);">define</block> val (<block style="color:RGB(0,128,32);">cadr</block> x))<br> `(,(multi-concat '<block style="color:RGB(192,0,0);">define-</block> type) ,var ,val))</div> var-init))</div><br> (def-multi-variables double (var1 init1) (var2 init2)))</div></div></div> <div><h3>pure-text</h3> <div style="margin-left:20px;"><p>Codes in SCMC:</p> (pure-text <i>text</i>) <p>Conterpart in C:</p> <div style="color:RGB(0,255,0);background-color:RGB(24,24,24);font-family:monospace;">text</div> <p>To make sure that some syntaxes in C are not implemented in SCMC, we give a final pure-text structure, which is used to directly put string to the generated C code.</p> <p>Example:</p> (<block style="color:RGB(192,0,0);">begin</block> (pure-text <block style="color:RGB(224,0,192)">"\n#ifndef var\n#define var\n#endif\n"</block>))</div></div></html>