Basic Concepts
Compilation Pipeline
Frost's compilation process is flexible and leverages LLVM's powerful infrastructure:
Compilation Options
Optimization Levels
Frost's backend is LLVM, which means we inherit the use of the opt
tool for optimization:
Language Fundamentals
All Frost programs must have one main
function, which is the entry point. It takes optionally 3 parameters: argc
, argv
, and envp
:
The main function can return an integer value, which is the exit code of the program. The argc
parameter is the number of arguments passed to the program, argv
is an array of strings containing the arguments, and envp
is an array of strings containing the environment variables.
Module System
Frost uses a clean import syntax with explicit paths, allowing for both relative and HTTP imports:
If the remote server needs authentication, credentials are accepted as an environment variable when running the compiler. This will be set as the Authorization
header in the request, with a Bearer
token:
Frost supports up to 25
levels of nested imports. This limit is arbitrary and can be increased if needed. The compiler supports both kinds of imports, and they can be mixed in the same file.
Standard Library
Frost has a somewhat limited Standard Library, but it provides essential modules:
inet.ff: Network operations
io.ff: Input/output operations
lib.ff: Core utilities
math.ff: Mathematical functions
socket.ff: Socket operations
string.ff: String manipulation
uni.ff: POSIX system calls
opengl.ff: OpenGL bindings
sdl2.ff: SDL2 bindings
Standard C
libraries are linked by default when using llc
/clang
/lli
or equivalent. In order to use OpenGL
andSDL2
bindings, the corresponding libraries must be installed on the system.
For example, to compile a program using SDL2
, you need to link the library with clang
or similar:
All of these are available at https://frost-lang.deno.dev/std/
.
We also host all examples under the root route of the server. You can access them at https://frost-lang.deno.dev/
.
For example, if you want to render a 3d
ASCII donut, you can import the donut.ff
example and run it out of the box:
And then JIT-compile and run it:
Variables and Types
Variables in Frost are statically typed. They support implicit conversion out of the box. They can be either local
or global
. The syntax is the same for both, globals are declared outside of functions:
Frost also supports pointers and references:
And arrays and structs:
Control Flow
Frost supports control flow constructs like loops and conditionals.
Loops
Frost supports loops and iteration with ranges:
Conditionals
Frost supports basic conditional statements. Else branches are optional:
Memory Management
Frost provides safe memory management with explicit allocation. The defer
keyword is used to ensure cleanup, and will place the cleanup code at the end of the current scope. It can also be a block:
Functions
Functions in Frost can take multiple parameters and return a single value.
Frost also supports a special kind of function: foreign
functions. These are functions that are implemented in another language and are linked at runtime:
For instance, this printf
function is implemented in C and linked at runtime. It takes a format string and a variable number of arguments, denoted by ...
.
Type System
Basic Types
int
: Integer numbersdouble
: Floating-point numbersbyte
: 8-bit valuesbool
: Boolean valuesnever
: No value, known asvoid
in other languages
Custom Types
Users are able to use user-defined types out of the box, such as custom width integers and structs:
Type Casting
Frost supports explicit type casting with the @type(expr)
syntax. This is useful for converting between different types:
This also works with pointers and references:
Operations
Frost support both unary and binary operations, including arithmetic, bitwise, logical, and comparison operations. These are just a few examples:
Preprocessor Directives
Another powerful feature of Frost is the preprocessor. It allows for conditional compilation, macro definitions, and file inclusion.
For instance, you can define a macro for a specific platform in a module:
Frost supports macros that are available in the current user's environment. This means that you can define a macro in the command line and use it in your code.
For example, to enable the __APPLE__
macro, you can compile the code with:
This will enable the __APPLE__
macro in the code, and the compiler will evaluate the conditionals accordingly, using the correct struct definition.
Best Practices
Use meaningful variable names
Avoid magic numbers
Always handle memory cleanup with
defer
Structure code with clear module organization
Use comments for complex algorithms
Remember, Frost encourages writing clean, readable code that maintains both beauty and performance. The syntax is designed to be intuitive while providing low-level control when needed.
Last updated