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 prints

Types

Integer and float types say their size. I64 is the default integer.

NameMeaning
U0void, no value
I8, U88 bit signed, unsigned
I16, U1616 bit
I32, U3232 bit
I64, U6464 bit
F6464 bit float (there is no 32 bit float)
Booltrue 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<10 means x is between 5 and 10.
  • ` is the power operator: 2`3 is 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 asm blocks.
  • 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.

Try it yourself.

Boot the desktop and type these at the prompt.