-
-
Notifications
You must be signed in to change notification settings - Fork 346
alang
Lubos Lenco edited this page Dec 29, 2024
·
3 revisions
alang is a TypeScript to C transpiler. A small subset of TypeScript is supported which maps well with C in order to achieve the best performance.
- a simple mark and sweep garbage collector is used with option for manual memory management
- value type always has to be specified
- a custom api is used which maps directly to the C api
- nested functions are supported but they can not access values from the parent function scope
alang.js
: TS transpiler written in JS. This is used during amake build process to translate alang.ts
(see below) into C.
alang.ts
: Transpiler written in TS itself. It is a part of amake binary and is used to transpile all .ts
files contained in the project.
// TS
type point_t = {
x: f32;
y: f32;
};
function add(a: point_t, b: point_t) {
a.x += b.x;
a.y += b.y;
}
function main() {
let a: point_t = { x: 1.0, y: 2.0 };
let b: point_t = { x: 3.0, y: 4.0 };
add(a, b);
}
// C
#include <iron.h>
typedef struct point {
f32 x;
f32 y;
} point_t;
void add(point_t *a, point_t *b) {
a->x += b->x;
a->y += b->y;
}
void main() {
point_t *a = GC_ALLOC_INIT(point_t, { .x = 1.0, .y = 2.0 });
point_t *b = GC_ALLOC_INIT(point_t, { .x = 3.0, .y = 4.0 });
add(a, b);
}