This tree includes the code for a compiler for the language specified by WinZigC language spectification. It generates LLVM bitcode for the WinZigC program and compiles the bitcode to an executable binary using the Clang backend.
You can find a set of example programs in example-programs and optimized and non optimized control flow graphs for the corresponding programs in cfg.
Visit developer guide.
We stay in stack memory (within functions) and global static memory (program-global memory) until the program exits. Therefore, there is no heap memory allocation or access.
You can declare variables in the global scope that can be modified from anywhere in your program. Global variables are cleaned up when your program exits.
Memory is allocated for variables declared within a function (parameters and local variable declarations). All local variable memory allocations are cleaned up when the function exits.
-
integer
- 32 bit.If your input or the program processes intermediate values that do not fit into 32 bits, unexpected results may occur.
-
char
- 8 bit ASCII characters.No Unicode characters.
-
boolean
- Think of it as 1 bit. You can assigntrue
andfalse
values.
Users can define enumetated types:
type Result = ( Composite, Prime, TooBig );
Users can define functions and call them. For example:
Define a function:
function Factor ( i : integer ):integer;
var
j : integer;
begin
if i > 0 then
for (j := 1; j <= i; j:=j+1)
if i mod j = 0 then output ( j )
end Factor;
Call the function:
d := Factor(120);
To discard a function output by assigning it to a discard variable d
:
d := MyPrintFunc(12, 'c', true);
WinZigC supports two ways to change the return value:
- Assign a value to the function name:
FuncName := 7;
This will not cause the function to exit.
- Using a return statement:
return 7;
This will cause the function to exit.
-
read
- Read user input from the command line.Note: [Enter] key press is considered as input when reading to a char.
-
output
- Write output to the command line.
- Single-line comment:
# Please ingore this line of text
- Multi-line/block comments:
{ Zero line of comment
First line of the comment
Second line of the comment
ingore this as well }
if-else
two-way branchingif n > 0 then return (n + fact(sum(n-1))) else return (0)
case
multi-way branchingcase R of Composite: output ('C'); Prime: output ('P'); TooBig: output ('B'); end
for
loopingfor (i:=1; i<=7; i:=i+1) begin output (fibonacci(i)) end
while
loopingwhile ((c = '+') or (c = '-')) do begin if (c = '+') then begin d:=GetNext(3); v := v + T(3); end else begin { c = '-' } d:=GetNext(3); v := v - T(3) end; end;
repeat-until
loopingrepeat read(i); d:=Factor(i) until i <= 0
:=
- Assignment:=:
- Swap assignment
*
- Multiplication/
- Divisionmod
- Modulus+
- Addition-
- Subtraction<
- Less than<=
- Less than or equal to>
- Greater than>=
- Greater than or equal to=
- Equal to<>
- Not equal toand
- Logical andor
- Logical or
not
- Logical not-
- Negative+
- Positivesucc(..)
- Successive value (++
operator semantics as in other languages)pred(..)
- Predecessor value (--
operator semantics as in other languages)