colgm/bootstrap
ValKmjolnir 563617b6d3 🔥 use list to implement hashmap 2024-11-21 20:32:49 +08:00
..
ast 🐛 [WIP] try fixing type replace pass 2024-11-19 01:01:14 +08:00
mir 🐛 fix name quotion bug 2024-11-19 00:42:36 +08:00
package 🔥 move global_symbol into module 2024-11-02 00:37:47 +08:00
sema 🔥 use list to implement hashmap 2024-11-21 20:32:49 +08:00
sir 🐛 fix name quotion bug 2024-11-19 00:42:36 +08:00
CMakeLists.txt 🎨 replace primitive size as constants 2024-11-16 01:08:05 +08:00
README.md 📝 change comment syntax 2024-10-27 00:15:01 +08:00
colgm.h 🔥 adjust directory 2024-10-25 00:30:08 +08:00
lexer.cpp 🎨 add syntax parse for optional comment 2024-11-09 00:48:01 +08:00
lexer.h 🎨 add syntax parse for optional comment 2024-11-09 00:48:01 +08:00
main.cpp 🐛 [WIP] try fixing type replace pass 2024-11-19 01:01:14 +08:00
misc.cpp 🎨 add syntax parse for optional comment 2024-11-09 00:48:01 +08:00
parse.cpp 🎨 [WIP] try support complex generic syntax 2024-11-17 01:20:11 +08:00
parse.h 🎨 [WIP] try support complex generic syntax 2024-11-17 01:20:11 +08:00
report.cpp 🔥 adjust directory 2024-10-25 00:30:08 +08:00
report.h 🔥 adjust directory 2024-10-25 00:30:08 +08:00

README.md

Colgm Bootstrap Compiler

bootstrap

This directory stores the source file of colgm bootstrap compiler.

Build

In the top level directory, use these commands:

mkdir build && cd build && cmake ../bootstrap -DCMAKE_BUILD_TYPE=Release && make -j

Usage

Use this command to get usage:

./build/colgm -h

Literal

func main() -> i32 {
    var a = 1;              // i64
    var b = 2.0;            // f64
    var c = "hello world!"; // i8*
    var d = 'd';            // i8
    var e = [i8; 128];      // const i8*
    var f = true;           // bool
    return 0 => i32;
}

Operators

Arithmetic Operator

Colgm allows these arithmetic operators:

a + b;
a - b;
a * b;
a / b;
a % b;

Bitwise Operator

Colgm now supports these bitwise operators:

a | b;
a ^ b;
a & b;

Logical Operator

Support basic logical operators: == != < <= > >=.

Logical operators for and/or all have two types:

1==1 and 2==2 && 3==3;
1==1 or 2==2 || 3==3;

Definition

Colgm allows two kinds of definition.

var variable_name: type = expression; # with type
var variable_name = expression; # without type

Assignment

Colgm allows these assignment operators:

a += b;
a -= b;
a *= b;
a /= b;
a %= b;
a |= b;
a ^= b;
a &= b;

Control Flow

While

while loop is directly translated to mir_loop in colgm mir.

while (1 == 1) {
    ...
    continue;
    break;
}

Condition/Branch

if (1 == 1) {
    ...
} elsif (1 == 1) {
    ...
} else if (1 == 1) {
    ...
} else {
    ...
}

Match

match (variable) {
    EnumType::a => ...
    EnumType::b => ...
}

For

for (var i = 0; i < 10; i += 1)  {}
=>
var i = 0;
while (i < 10) {
    i += 1;
}

Foreach/ForIndex [WIP]

foreach (var i; container) {}
=>
var tmp_i = container.begin();
while (tmp_i != container.end()) {
    var i = tmp_i.value();
    tmp_i = tmp_i.next();
}
forindex (var i; container) {}
=>
var tmp_i = 0;
while (tmp_i < container.size()) {
    var i = tmp_i;
    tmp_i += 1;
}

Type Conversion

A bit like rust, using => instead of as:

func main() -> i32 {
    return 0 => i32;
}

Struct Definition

struct StructName {
    field1: i64,
    field2: i64
}

struct StructWithGeneric<T> {
    __size: i64,
    __data: T*
}

Struct Initializer

func test() {
    var s1 = StructName {};
    var s2 = StructName { field1: 1 };
    var s3 = StructName { field1: 1, field2: 2 };
}

Implementation

impl StructName {
    func method(self) -> type {
        ...
        return ...;
    }
    func static_method() -> type {
        ...
        return ...;
    }
}

impl StructWithGeneric<T> {
    ...
}

Enum Definition

enum EnumExample {
    kind_a,
    kind_b,
    kind_c
}

enum EnumSpecified {
    kind_a = 0x1,
    kind_b = 0x2,
    kind_c = 0x3
}