We using C23 standard. An other thing to know, we use lily_base
library that's include some data structures, such as File, Vec, Stack, etc.
When we name a header guard, we use the file path to name the guard. In addition, headers must be written in upper case. Additionally, the guard name must start with LILY
and must end with the file extension, so most often H
or HPP
. Plus, the last two rules are that for example the name of the folder and the file is repeated with the same name without taking into account the extension of the file, we avoid repeating the same name. Finally, the header guard of the project file must be unique (exception in certain cases, like in tests/core/lily/scanner/util.c
).
// path: include/core/lily/analysis/analysis.h
// guard name: CORE_LILY_ANALYSIS_H (bad)
// guard name: LILY_CORE_LILY_ANALYSIS_ANALYSIS_H (bad)
// guard name: LILY_CORE_LILY_ANALYSIS_H (ok)
When you want to name a function, you must add a suffix __
+ type name. Plus, the base of the function name must be write in snake-case.
typedef struct Person {
const char *name;
Uint8 age;
} Person;
const char *
get_name(const Person *self); // bad
const char *
get_name__Person(const Person *self); // ok
However, if the function is not associated to a type (enum or struct), add a suffix __
+ name access.
// path: src/str.c
Usize
len__Str(const char *s);
NOTE: The prefix must be unique, to avoid function name conflicts.
If the function is associated to a type, the first parameter, must be named self
.
Take a look at src/ex/README.md to find out how inline functions are managed.
You must be define global variable with static
keyword.
All constants must be defined in uppercase.
const int a = 340; // bad
const int A = 340; // ok
All macros must be defined in uppercase.
#define hello(s) "Hello "s // bad
#define HELLO(s) "Hello "s // ok
For most includes we use the one with angle brackets (#include <header>
), but sometimes (e.g. in tests) we use the version with double quotes (#include "header"
).
The name of the enumeration must be written in PascalCase
. Additionally, if the enumeration is used with a structure (to be used with a union), you must add Kind
to the end of the enumeration name.
The items in the enumeration must be written in UpperCase
and each item name must begin with the name of the enum (in UpperCase
).
Finally, in most cases, you should add Lily
in front of the enumeration name (with a few exceptions).
EXCEPTION(S): lily_base
.
Here is a small example of using an enumeration with the rules previously listed:
enum LilyAnimalKind {
LILY_ANIMAL_KIND_CAT,
LILY_ANIMAL_KIND_DOG,
};
typedef struct LilyCat {
// ...
} LilyCat;
typedef struct LilyDog {
// ...
} LilyDog;
typedef struct LilyAnimal {
enum LilyAnimalKind kind;
union {
LilyCat cat;
LilyDog dog;
};
} LilyAnimal;
The name of the structure must be written in PascalCase
.
As in enumerations, you must add Lily
in front of the structure name (with exceptions).
EXCEPTION(S): lily_base
.
We're using C++20 standard.
...
- ptr: pointer
- ast, AST: Abstract Syntax Tree
- ref: reference
- vm: virtual machine
- decl: declaration
- expr: expression
- stmt: statement
- gen: generation, generator