Docs · HolyC
HolyC reference.
The language in eight short sections.
Overview
HolyC is the one language of TempleOS. It is compiled just in time, so there is no separate build step: a file you #include is compiled and run, and a line typed at the prompt is compiled and run the same way. It looks like C with different edges.
"Hello, world!\n"; // a string statement printsTypes
Integer and float types say their size. I64 is the default integer.
| Name | Meaning |
|---|---|
U0 | void, no value |
I8, U8 | 8 bit signed, unsigned |
I16, U16 | 16 bit |
I32, U32 | 32 bit |
I64, U64 | 64 bit |
F64 | 64 bit float (there is no 32 bit float) |
Bool | true or false, stored in a byte |
Functions
No main. Parameters can have defaults. A call with no arguments can drop the parentheses.
U0 Count(I64 n=3)
{
I64 i;
for (i=0;i<n;i++)
"Line %d\n",i;
}
Count; // n is 3
Count(5);Strings and printing
A string literal used as a statement prints, and extra arguments after a comma are format arguments. A $ starts a DolDoc command in a string, so a literal dollar sign is written $$.
"x = %d, name = %s\n",x,name;
Print("Total: $$%d\n",total);Operators
Differences from C that surprise people:
- Comparisons chain:
5<x<10meansxis between 5 and 10. `is the power operator:2`3is 8.- Shifts and power bind tighter than multiplication, so parenthesise when mixing.
if (5<x<10)
"in range\n";
"%d\n",2`3;Classes
A class is a struct. It can contain nested classes and unions, and a class can be used as a base to share a leading set of members.
class Pt
{
I64 x,y;
};
Pt p;
p.x=3; p.y=4;Control flow
if, for, while, do and switch work as in C. switch has a bracketed sub-switch form, start: and end:, for shared setup and teardown. try, catch and throw raise and handle errors.
try {
throw('Oops');
} catch {
"caught\n";
Fs->catch_except=TRUE;
}Also worth knowing
- Everything runs at ring 0 in one address space. A bad pointer can take the system down, so a VM is the safe place to experiment.
- The assembler is built in and takes
asmblocks. - DolDoc is the document format that source files, the editor and the shell share, so a source file can hold pictures and links.
This reference is a summary written for this site. For exact behaviour, read the system source and the pages listed under Docs. Snippets are untested sketches.