Welcome to HolyC!

This covers the core language, syntax and constructs to get started with `HolyC`. This guide covers the fundamentals of the language however it is not an introduction to programming more generally. The standalone compiler can be downloaded: here and TempleOS: here the guide assumues usage of the standalone compiler.

Most importantly, have fun experimenting with the language. Please open issues on the github page.

For how to install the compiler please see here

Program entry point

Using the standalone compiler a HolyC program can be written in two ways; with `Main` as an entry point or a file being treated as a script which is essentially the mechanism of TempleOS. In this respect the standalone compiler is more like `C`.

U0 Main(I32 argc, U8 **argv)
{
  for (I32 i = 0; i < argc; ++i) {
    "[%d] => %s\n",i,argv[i];
  }
}

c-like printing command line arguments to stdout.

This same code can be written as follows, argc and argv are passed to a file as global variables a bit like bash

for (I32 i = 0; i < argc; ++i) {
  "[%d] => %s\n",i,argv[i];
}

TempleOS-like printing command line arguments to stdout.

Top level definitions in the standalone compiler is not as robust as TempleOS and your milage may vary.

Functions

As with TempleOS printing values can be done by omitting printf, internally libc printf is called and the same format specifiers are applied. Functions can be declared with default arguments and called without parenthesis and called at a top level.

U0 Function(U8 *name="Bob")
{
  "%s\n",name;
}

Function; 
Function("Terry");

Prints "Bob" and "Terry"

Functions can also make use of default arguments in any order

U0 Function(U8 *name="Bob", I64 age=32)
{
  "%s %d\n",name,age;
}

Function;
Function(,42);
Function("Rob", 42);

Prints "Bob" 32, "Bob" 42 and "Rob" 42

Including files

Including files is done through the #include directive. The libraries which accompany the compiler can be included with #include <name.HC>. Local files can be included with: #include "./path/to/code.HC". TempleOS library functions are usually always present and do not need a #include.

Below MAlloc and MemCpy, two library functions, are included from memory.HC.

#include <memory.HC>

class Person
{
  U8 name[10];
  I64 age;
};

Person *PersonNew(U8 *name, I64 age)
{
  Person *p = MAlloc(sizeof(Person));
  MemCpy(p->name,name,sizeof(p->name));
  p->age = age;
  return p;
}

Person *p1 = PersonNew("Brian", 45);
"%s %d\n",p->name,p->age;

Example of including memory.HC. Prints: "Brian" 45

HolyC 2024
HolyC Compiler
TempleOS