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