mirror of https://github.com/colgm/colgm.git
🐛 bug fixes
This commit is contained in:
parent
f036669307
commit
c884d66444
|
@ -14,7 +14,7 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mac-x86_64-build-bootstrap:
|
mac-aarch64-build-bootstrap:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
|
|
|
@ -41,6 +41,7 @@ out.ll
|
||||||
# Directory
|
# Directory
|
||||||
build
|
build
|
||||||
.vscode
|
.vscode
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
dump
|
dump
|
||||||
|
|
|
@ -66,5 +66,4 @@ See simple tutorial in [bootstrap/README.md](./bootstrap/README.md).
|
||||||
- foreach loop, container should have iterator-like stuff
|
- foreach loop, container should have iterator-like stuff
|
||||||
2. llvm debug info, may not support in bootstrap compiler
|
2. llvm debug info, may not support in bootstrap compiler
|
||||||
3. develop bootstrapped compiler
|
3. develop bootstrapped compiler
|
||||||
4. conditional compilation
|
4. array type like `[i32; 128]`
|
||||||
5. array type like `[i32; 128]`
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ void cond_compile::accept(visitor* v) {
|
||||||
|
|
||||||
cond_compile* cond_compile::clone() const {
|
cond_compile* cond_compile::clone() const {
|
||||||
auto ret = new cond_compile(location, condition_name);
|
auto ret = new cond_compile(location, condition_name);
|
||||||
for(const auto& i : comments) {
|
for(const auto& i : conds) {
|
||||||
ret->add_comment(i.first, i.second);
|
ret->add_condition(i.first, i.second);
|
||||||
}
|
}
|
||||||
if (enabled_decl) {
|
if (enabled_decl) {
|
||||||
ret->enabled_decl = enabled_decl->clone();
|
ret->enabled_decl = enabled_decl->clone();
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
class cond_compile: public decl {
|
class cond_compile: public decl {
|
||||||
public:
|
public:
|
||||||
std::string condition_name;
|
std::string condition_name;
|
||||||
std::unordered_map<std::string, std::string> comments;
|
std::unordered_map<std::string, std::string> conds;
|
||||||
decl* enabled_decl;
|
decl* enabled_decl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -35,13 +35,13 @@ public:
|
||||||
void accept(visitor*) override;
|
void accept(visitor*) override;
|
||||||
cond_compile* clone() const override;
|
cond_compile* clone() const override;
|
||||||
|
|
||||||
void add_comment(const std::string& key, const std::string& value) {
|
void add_condition(const std::string& key, const std::string& value) {
|
||||||
comments[key] = value;
|
conds[key] = value;
|
||||||
}
|
}
|
||||||
void set_enabled_decl(decl* node) { enabled_decl = node; }
|
void set_enabled_decl(decl* node) { enabled_decl = node; }
|
||||||
|
|
||||||
const auto& get_condition_name() const { return condition_name; }
|
const auto& get_condition_name() const { return condition_name; }
|
||||||
const auto& get_comments() const { return comments; }
|
const auto& get_conds() const { return conds; }
|
||||||
auto get_enabled_decl() const { return enabled_decl; }
|
auto get_enabled_decl() const { return enabled_decl; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,26 +9,26 @@ bool delete_disabled_node::check_enable_if(cond_compile* cc) {
|
||||||
if (cc->get_condition_name() != "enable_if") {
|
if (cc->get_condition_name() != "enable_if") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(const auto& i : cc->get_comments()) {
|
for(const auto& i : cc->get_conds()) {
|
||||||
if (i.first != "target_os" && i.first != "arch") {
|
if (i.first != "target_os" && i.first != "arch") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc->get_comments().count("target_os") &&
|
if (cc->get_conds().count("target_os") &&
|
||||||
cc->get_comments().count("arch")) {
|
cc->get_conds().count("arch")) {
|
||||||
const auto& target_os = cc->get_comments().at("target_os");
|
const auto& target_os = cc->get_conds().at("target_os");
|
||||||
const auto& arch = cc->get_comments().at("arch");
|
const auto& arch = cc->get_conds().at("arch");
|
||||||
return target_os == get_platform() && arch == get_arch();
|
return target_os == get_platform() && arch == get_arch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc->get_comments().count("target_os")) {
|
if (cc->get_conds().count("target_os")) {
|
||||||
const auto& target_os = cc->get_comments().at("target_os");
|
const auto& target_os = cc->get_conds().at("target_os");
|
||||||
return target_os == get_platform();
|
return target_os == get_platform();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc->get_comments().count("arch")) {
|
if (cc->get_conds().count("arch")) {
|
||||||
const auto& arch = cc->get_comments().at("arch");
|
const auto& arch = cc->get_conds().at("arch");
|
||||||
return arch == get_arch();
|
return arch == get_arch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ bool dumper::visit_cond_compile(cond_compile* node) {
|
||||||
std::cout << format_location(node);
|
std::cout << format_location(node);
|
||||||
push_indent();
|
push_indent();
|
||||||
std::vector<std::pair<std::string, std::string>> keys;
|
std::vector<std::pair<std::string, std::string>> keys;
|
||||||
for(const auto& i : node->get_comments()) {
|
for(const auto& i : node->get_conds()) {
|
||||||
keys.push_back(i);
|
keys.push_back(i);
|
||||||
}
|
}
|
||||||
for(const auto& i : keys) {
|
for(const auto& i : keys) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ cond_compile* parse::conditional_compile() {
|
||||||
match(tok::tk_eq);
|
match(tok::tk_eq);
|
||||||
auto value = toks[ptr].str;
|
auto value = toks[ptr].str;
|
||||||
match(tok::tk_str);
|
match(tok::tk_str);
|
||||||
result->add_comment(key, value);
|
result->add_condition(key, value);
|
||||||
if (look_ahead(tok::tk_comma)) {
|
if (look_ahead(tok::tk_comma)) {
|
||||||
match(tok::tk_comma);
|
match(tok::tk_comma);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,6 +2,7 @@ use err::span::{ span };
|
||||||
use std::libc::{ malloc, realloc, free, exit };
|
use std::libc::{ malloc, realloc, free, exit };
|
||||||
use std::io::{ io };
|
use std::io::{ io };
|
||||||
use std::str::{ str };
|
use std::str::{ str };
|
||||||
|
use std::map::{ hashmap };
|
||||||
|
|
||||||
pub enum ast_kind {
|
pub enum ast_kind {
|
||||||
ast_null,
|
ast_null,
|
||||||
|
@ -789,6 +790,7 @@ impl ast_assignment {
|
||||||
pub struct ast_cond_compile {
|
pub struct ast_cond_compile {
|
||||||
base: ast,
|
base: ast,
|
||||||
cond_name: str,
|
cond_name: str,
|
||||||
|
conds: hashmap<str, str>,
|
||||||
enabled_decl: ast*
|
enabled_decl: ast*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,16 +799,22 @@ impl ast_cond_compile {
|
||||||
var res = ast_cond_compile::__alloc__();
|
var res = ast_cond_compile::__alloc__();
|
||||||
res->base = ast::instance(ast_kind::ast_cond_compile, loc);
|
res->base = ast::instance(ast_kind::ast_cond_compile, loc);
|
||||||
res->cond_name = cond_name->copy_instance();
|
res->cond_name = cond_name->copy_instance();
|
||||||
|
res->conds = hashmap<str, str>::instance();
|
||||||
res->enabled_decl = nil => ast*;
|
res->enabled_decl = nil => ast*;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func delete(self) {
|
pub func delete(self) {
|
||||||
self->cond_name.delete();
|
self->cond_name.delete();
|
||||||
|
self->conds.delete();
|
||||||
if (self->enabled_decl => i8* != nil) {
|
if (self->enabled_decl => i8* != nil) {
|
||||||
self->enabled_decl->delete();
|
self->enabled_decl->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub func add_condition(self, key: str*, value: str*) {
|
||||||
|
self->conds.insert(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ast_type_def {
|
pub struct ast_type_def {
|
||||||
|
|
|
@ -30,7 +30,11 @@ impl cli_option {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func version() -> i8* {
|
pub func version() -> i8* {
|
||||||
return "colgm compiler version 0.2 (beta)";
|
return "0.2";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub func print_version() {
|
||||||
|
io::stdout().out("colgm compiler version ").out(version()).out("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func help() {
|
pub func help() {
|
||||||
|
|
|
@ -69,7 +69,7 @@ func main(argc: i32, argv: i8**) -> i32 {
|
||||||
return 0 => i32;
|
return 0 => i32;
|
||||||
}
|
}
|
||||||
if (argc==(2 => i32) && (streq(argv[1], "-v") || streq(argv[1], "--version"))) {
|
if (argc==(2 => i32) && (streq(argv[1], "-v") || streq(argv[1], "--version"))) {
|
||||||
io::stderr().out(version()).endln();
|
print_version();
|
||||||
return 0 => i32;
|
return 0 => i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl hashmap<K, V> {
|
||||||
bucket_list = bucket_list->next;
|
bucket_list = bucket_list->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bucket_list => i8* == nil) {
|
if (self->data[hash] => i8* == nil) {
|
||||||
self->data[hash] = bucket<K, V>::__alloc__();
|
self->data[hash] = bucket<K, V>::__alloc__();
|
||||||
bucket_list = self->data[hash];
|
bucket_list = self->data[hash];
|
||||||
bucket_list->pair.key = key->copy();
|
bucket_list->pair.key = key->copy();
|
||||||
|
|
|
@ -10,29 +10,31 @@ func test_hashmap() {
|
||||||
var map = hashmap<str, str>::instance();
|
var map = hashmap<str, str>::instance();
|
||||||
var stored = vec<str>::instance();
|
var stored = vec<str>::instance();
|
||||||
|
|
||||||
for(var i = 0; i < 16; i += 1) {
|
for(var i = 0; i < 32; i += 1) {
|
||||||
var num = rand() % (4096 => i32);
|
var num = rand() % (4096 => i32);
|
||||||
itoa(num => i64, buff, 10);
|
itoa(num => i64, buff, 10);
|
||||||
var k = str::instance();
|
var k = str::instance();
|
||||||
var v = str::instance();
|
var v = str::instance();
|
||||||
k.append_i8_vec(buff);
|
k.append_i8_vec(buff);
|
||||||
v.append_i8_vec("test hashmap<str, str> ");
|
v.append_i8_vec("[test hashmap<str, str> ");
|
||||||
v.append_i8_vec(buff);
|
v.append_i8_vec(buff)->append_i8_vec("]");
|
||||||
map.insert(k.__ptr__(), v.__ptr__());
|
map.insert(k.__ptr__(), v.__ptr__());
|
||||||
stored.push(k.__ptr__());
|
stored.push(k.__ptr__());
|
||||||
k.delete();
|
k.delete();
|
||||||
v.delete();
|
v.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = 0; i < 16; i += 1) {
|
for(var i = 0; i < 32; i += 1) {
|
||||||
var key = stored.get(i => u64);
|
var key = stored.get(i => u64);
|
||||||
if (map.has(key)) {
|
if (map.has(key)) {
|
||||||
io::stdout().out("[").green().out("test").reset().out("] hashmap");
|
io::stdout().out("[").green().out("test").reset().out("] hashmap ");
|
||||||
io::stdout().out(" test ").out_i64(i).out(": ");
|
io::stdout().out_i64(i).out(": key ");
|
||||||
|
io::stdout().out(key->c_str).out(" found -> ");
|
||||||
io::stdout().out(map.get(key)->c_str).endln();
|
io::stdout().out(map.get(key)->c_str).endln();
|
||||||
} else {
|
} else {
|
||||||
io::stdout().out("[").red().out("test").reset().out("] hashmap");
|
io::stdout().out("[").red().out("test").reset().out("] hashmap ");
|
||||||
io::stdout().out(" test ").out_i64(i).out(": ").out("not found\n");
|
io::stdout().out_i64(i).out(": ");
|
||||||
|
io::stdout().out(key->c_str).out(" not found\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@ func test_list() {
|
||||||
var str_list = list<str>::instance();
|
var str_list = list<str>::instance();
|
||||||
var int_list = primitive_list<i64>::instance();
|
var int_list = primitive_list<i64>::instance();
|
||||||
|
|
||||||
for(var i = 0; i < 16; i += 1) {
|
for(var i = 0; i < 32; i += 1) {
|
||||||
var num = rand() % (4096 => i32);
|
var num = rand() % (4096 => i32);
|
||||||
var buff = [i8; 1024];
|
var buff = [i8; 1024];
|
||||||
itoa(num => i64, buff, 10);
|
itoa(num => i64, buff, 10);
|
||||||
|
@ -99,7 +101,7 @@ func test_vector() {
|
||||||
var s = str::instance();
|
var s = str::instance();
|
||||||
var str_vec = vec<str>::instance();
|
var str_vec = vec<str>::instance();
|
||||||
var int_vec = primitive_vec<i64>::instance();
|
var int_vec = primitive_vec<i64>::instance();
|
||||||
for(var i = 0; i < 16; i += 1) {
|
for(var i = 0; i < 32; i += 1) {
|
||||||
var num = rand() % (4096 => i32);
|
var num = rand() % (4096 => i32);
|
||||||
var buff = [i8; 1024];
|
var buff = [i8; 1024];
|
||||||
itoa(num => i64, buff, 10);
|
itoa(num => i64, buff, 10);
|
||||||
|
|
Loading…
Reference in New Issue