Compile Command¶
The compile command transpiles FastC source code to C11.
Usage¶
Arguments¶
| Argument | Description |
|---|---|
<INPUT> |
Input FastC source file (.fc) |
Options¶
| Option | Description |
|---|---|
-o, --output <FILE> |
Output file (default: stdout) |
--emit-header |
Also generate a C header file |
-h, --help |
Print help |
Examples¶
Compile to Stdout¶
Output is printed to the terminal.
Compile to File¶
Generate Header¶
This creates both build/main.c and build/main.h.
Output Format¶
The generated C code includes:
- Header comment
- Runtime include
- Standard library includes
- Forward declarations
- Type definitions (structs, enums)
- Function implementations
Example Output¶
Input (hello.fc):
Output:
/* Generated by fastc - do not edit */
#include "fastc_runtime.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
int32_t add(int32_t a, int32_t b);
int32_t main(void);
int32_t add(int32_t a, int32_t b) {
int32_t __tmp0;
if (__builtin_add_overflow(a, b, (&__tmp0))) {
fc_trap();
}
return __tmp0;
}
int32_t main(void) {
return add(1, 2);
}
Header Generation¶
With --emit-header, a header file is generated with:
- Include guards
- Type definitions
- Function declarations (public only)
Example Header¶
#ifndef MAIN_H
#define MAIN_H
#include <stdint.h>
#include <stdbool.h>
int32_t add(int32_t a, int32_t b);
int32_t main(void);
#endif /* MAIN_H */
Check Command¶
To type-check without generating code:
This runs all compiler phases except code generation:
- Lexing
- Parsing
- Name resolution
- Type checking
Success Output¶
Error Output¶
error: undefined name 'undefined_var'
--> src/main.fc:5:12
|
5 | return undefined_var;
| ^^^^^^^^^^^^^
Format Command¶
Format FastC source code:
# Format in place
fastc fmt src/main.fc
# Output to stdout
fastc fmt src/main.fc -o -
# Check formatting (exit 1 if not formatted)
fastc fmt src/main.fc --check
Compiling Generated C¶
After generating C code, compile with your C compiler:
# Generate C
fastc compile src/main.fc -o main.c
# Compile with gcc
gcc -I/path/to/runtime main.c -o main
# Compile with clang
clang -I/path/to/runtime main.c -o main
Or use fastc build --cc for automatic compilation.
See Also¶
- Build & Run - Automatic compilation
- Project Management - Project configuration