Various improvements
This commit is contained in:
parent
3f2ee15302
commit
64034e9086
65
src/ast.odin
65
src/ast.odin
@ -35,6 +35,15 @@ NodeKind :: enum {
|
|||||||
//
|
//
|
||||||
If,
|
If,
|
||||||
For,
|
For,
|
||||||
|
|
||||||
|
// Done at type checking, should replace all instances of FieldAccess with these
|
||||||
|
// The value will be the FULL PATH to the field, only for module access
|
||||||
|
StructFieldAccess,
|
||||||
|
EnumFieldAccess,
|
||||||
|
UnionFieldAccess,
|
||||||
|
ModuleFieldAccess, // ModuleField$Field
|
||||||
|
|
||||||
|
// Example for std.println: std$println
|
||||||
}
|
}
|
||||||
|
|
||||||
Node :: struct {
|
Node :: struct {
|
||||||
@ -230,30 +239,25 @@ node_print :: proc(node: ^Node, indent := 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node_create_use :: proc(range: TextRange, path, alias: [dynamic]u8) -> (ret: ^Node) {
|
parse_use_path :: proc(path: [dynamic]u8) -> (ret: [dynamic]u8) {
|
||||||
path_ := path
|
ret = path
|
||||||
// Check if the path ends with ".cat", if not, append it.
|
// Check if the path ends with ".cat", if not, append it.
|
||||||
len_path := len(path_)
|
len_path := len(path)
|
||||||
if len(path_) < 4 ||
|
if len(path) < 4 ||
|
||||||
path_[len_path - 4] != '.' ||
|
path[len_path - 4] != '.' ||
|
||||||
path_[len_path - 3] != 'c' ||
|
path[len_path - 3] != 'c' ||
|
||||||
path_[len_path - 2] != 'a' ||
|
path[len_path - 2] != 'a' ||
|
||||||
path_[len_path - 1] != 't' {
|
path[len_path - 1] != 't' {
|
||||||
append(&path_, '.')
|
append(&ret, '.')
|
||||||
append(&path_, 'c')
|
append(&ret, 'c')
|
||||||
append(&path_, 'a')
|
append(&ret, 'a')
|
||||||
append(&path_, 't')
|
append(&ret, 't')
|
||||||
}
|
}
|
||||||
ret = new(Node)
|
return
|
||||||
ret^ = {
|
|
||||||
kind = .Use,
|
|
||||||
range = range,
|
|
||||||
value = path_,
|
|
||||||
}
|
}
|
||||||
if len(alias) != 0 {
|
|
||||||
append(&ret.children, node_create_value(.Identifier, range, alias))
|
parse_use_path2 :: proc(path: [dynamic]u8) -> (ret: [dynamic]u8) {
|
||||||
} else {
|
ret = path
|
||||||
// Get the filename, and trucate the extension, then replace any special characters with _
|
|
||||||
new_alias := [dynamic]u8{}
|
new_alias := [dynamic]u8{}
|
||||||
for i in 0 ..< len(path) {
|
for i in 0 ..< len(path) {
|
||||||
if path[i] == '.' {
|
if path[i] == '.' {
|
||||||
@ -269,6 +273,25 @@ node_create_use :: proc(range: TextRange, path, alias: [dynamic]u8) -> (ret: ^No
|
|||||||
append(&new_alias, path[i])
|
append(&new_alias, path[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
node_create_use :: proc(range: TextRange, path, alias: [dynamic]u8) -> (ret: ^Node) {
|
||||||
|
path_ := path
|
||||||
|
// Check if the path ends with ".cat", if not, append it.
|
||||||
|
path_ = parse_use_path(path)
|
||||||
|
ret = new(Node)
|
||||||
|
ret^ = {
|
||||||
|
kind = .Use,
|
||||||
|
range = range,
|
||||||
|
value = path_,
|
||||||
|
}
|
||||||
|
if len(alias) != 0 {
|
||||||
|
append(&ret.children, node_create_value(.Identifier, range, alias))
|
||||||
|
} else {
|
||||||
|
// Get the filename, and trucate the extension, then replace any special characters with _
|
||||||
|
new_alias := [dynamic]u8{}
|
||||||
|
new_alias = parse_use_path2(path_)
|
||||||
if len(new_alias) == 0 {
|
if len(new_alias) == 0 {
|
||||||
panic("Invalid alias for use statement")
|
panic("Invalid alias for use statement")
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,19 @@ main :: proc() {
|
|||||||
} else {
|
} else {
|
||||||
name = os.args[1]
|
name = os.args[1]
|
||||||
}
|
}
|
||||||
module_name := main_module_name_from_filename(name)
|
name_dyn := [dynamic]u8{}
|
||||||
|
for ch in transmute([]u8)name {
|
||||||
|
append(&name_dyn, u8(ch))
|
||||||
|
}
|
||||||
|
module_name := parse_use_path2(name_dyn)
|
||||||
|
module_name = main_module_name_from_filename(module_name)
|
||||||
|
if len(module_name) == 0 {
|
||||||
|
clear(&module_name)
|
||||||
|
append(&module_name, 'm')
|
||||||
|
append(&module_name, 'a')
|
||||||
|
append(&module_name, 'i')
|
||||||
|
append(&module_name, 'n')
|
||||||
|
}
|
||||||
ctx := LLVMContextCreate()
|
ctx := LLVMContextCreate()
|
||||||
defer LLVMContextDispose(ctx)
|
defer LLVMContextDispose(ctx)
|
||||||
module := LLVMModuleCreateWithNameInContext(cstring(raw_data(module_name[:])), ctx)
|
module := LLVMModuleCreateWithNameInContext(cstring(raw_data(module_name[:])), ctx)
|
||||||
@ -74,9 +86,9 @@ main :: proc() {
|
|||||||
LLVMPrintModuleToFile(module, cstring(raw_data(module_name[:])), nil)
|
LLVMPrintModuleToFile(module, cstring(raw_data(module_name[:])), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
main_module_name_from_filename :: proc(fname: string) -> (module_name: [dynamic]u8) {
|
main_module_name_from_filename :: proc(fname: [dynamic]u8) -> (module_name: [dynamic]u8) {
|
||||||
temp_name := [dynamic]u8{}
|
temp_name := [dynamic]u8{}
|
||||||
for ch in transmute([]u8)fname {
|
for ch in fname {
|
||||||
if ch == '/' || ch == '\\' {
|
if ch == '/' || ch == '\\' {
|
||||||
clear(&temp_name)
|
clear(&temp_name)
|
||||||
} else {
|
} else {
|
||||||
|
2
test.c
2
test.c
@ -1,7 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int32_t put_i32(int32_t x) {
|
int32_t meow(int32_t x) {
|
||||||
printf("%d\n", x);
|
printf("%d\n", x);
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
|
@ -9,27 +9,29 @@
|
|||||||
|
|
||||||
\let arr: []i32, arr2: [69]u8, ptr: ^i32
|
\let arr: []i32, arr2: [69]u8, ptr: ^i32
|
||||||
|
|
||||||
fn put_i32(val: i32) i32
|
fn meow(val: i32) i32
|
||||||
|
|
||||||
let amogus := 500 + (put_i32 8008135)
|
let amogus := 500 + (meow 8008135)
|
||||||
|
|
||||||
put_i32 69 * amogus + 420
|
meow 69 * amogus + 420
|
||||||
|
|
||||||
let a b := 5 1
|
let a b := 5 1
|
||||||
|
|
||||||
if a == 5 {
|
if a == 5 {
|
||||||
if b {
|
if b {
|
||||||
put_i32 123
|
meow 123
|
||||||
} else {
|
} else {
|
||||||
put_i32 69
|
meow 69
|
||||||
}
|
}
|
||||||
} elif a == 2 {
|
} elif a == 2 {
|
||||||
put_i32 456
|
meow 456
|
||||||
} else {
|
} else {
|
||||||
put_i32 420
|
meow 420
|
||||||
}
|
}
|
||||||
|
|
||||||
for a != 0 {
|
for a != 0 {
|
||||||
put_i32 (1 << a)
|
meow (1 << a) >> 1
|
||||||
a = a - 1
|
a = a - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meow 69 -> meow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user