Skip to content

Commit

Permalink
Merge branch 'main' into rivet_fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS authored Dec 10, 2023
2 parents 64c6f21 + c4d4df4 commit c3d57dd
Show file tree
Hide file tree
Showing 69 changed files with 1,310 additions and 1,210 deletions.
4 changes: 2 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
- [ ] Constant-folding: `x := 2 * 2;` => `x := 4;`.
- [ ] Optimize code, inline functions/methods annotated with `inline`,
delete unused code, etc.
- [ ] (Atomic) Reference-Counting for traits, boxed enums, strings, dynamic arrays and structs.
- [ ] (Atomic) Reference-Counting for traits, tagged enums, strings, dynamic arrays and structs.
- [ ] Better support for embedded structs.
- [ ] `undefined` for uninitialized variables: `x: [5]uint8 := undefined;`.
- [ ] Disallow empty array literal (`x := []!; -> ERROR`).
- [ ] Disallow empty array literal (`x := []; -> ERROR`).
- [ ] Add `@is_flag_defined()` builtin function.
- [ ] Generic support: `Struct<T> { f: T; }` => `Struct:<T>(f: @default(T))`.
- [ ] Lambdas + Closures: `sum := |a: int32, b: int32| [my_inherited_var] a + b;`.
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/array.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func array_slice(arr: rawptr, elem_size: uint, size: uint, start: uint, end: uin
}
len := end - start;
return unsafe {
DynArray.from_array(
if len == size { arr } else { @ptr_add(arr, start) }, elem_size, len
DynArray.from_array_no_alloc(
if len == size { arr } else { @ptr_add(arr, start * elem_size) }, elem_size, len
)
};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/process.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import c/libc;

/// Returns the path name of the executable that started the current process.
pub func process_executable() -> !string {
res: [libc.MAX_PATH_LEN]uint8 := []!;
res: [libc.MAX_PATH_LEN]uint8 := [];
count := unsafe {
libc.readlink(c"/proc/self/exe", &res[0], libc.MAX_PATH_LEN)
};
Expand All @@ -28,7 +28,7 @@ pub func process_set_cwd(path: string) -> ! {
/// Returns the absolute path of the current working directory.
pub func process_get_cwd() -> !string {
unsafe {
buf: [libc.MAX_PATH_LEN]mut uint8 := []!;
buf: [libc.MAX_PATH_LEN]mut uint8 := [];
if _ := libc.getcwd(&mut buf[0], libc.MAX_PATH_LEN) {
return string.from_raw(&buf[0]).clone();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/tests/string_test.ri
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test "string.parse_int()" {
test "string.substr()" {
str := "hello world!";
@assert(str.substr() == str);
@assert(str.substr(5) == "world!");
@assert(str.substr(end: 4) == "hello");
@assert(str.substr(1, 8) == "llo wor");
@assert(str.substr(6) == "world!");
@assert(str.substr(end: 5) == "hello");
@assert(str.substr(2, 9) == "llo wor");
}
6 changes: 3 additions & 3 deletions lib/core/tests/vector_test.ri
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test "dynamic arrays: push and pop" {
mut vec := ["A", "B"];
mut vec := +["A", "B"];
@assert(vec.len == 2);

vec.push("C");
Expand All @@ -12,14 +12,14 @@ test "dynamic arrays: push and pop" {
}

test "dynamic arrays: clear" {
mut vec := ["A", "B"];
mut vec := +["A", "B"];
@assert(vec.len == 2);
@assert(vec[0] == "A");
@assert(vec[1] == "B");

vec.clear();
@assert(vec.len == 0);
@assert(vec == []);
@assert(vec == +[]);

vec.push("C");
@assert(vec.len == 1);
Expand Down
14 changes: 7 additions & 7 deletions lib/rivet/src/ast/CHeader.ri
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct CDefine < traits.Stringable {
has_value: bool;
is_macro: bool;

mut cvalue: CImportValue := .Invalid();
mut cvalue: CImportValue := .Invalid;
mut has_cvalue: bool;

pub func to_string(&self) -> string {
Expand Down Expand Up @@ -97,14 +97,14 @@ struct CDefines {

enum CImportValue {
Invalid,
Float: float64,
Int: int,
Uint: uint;
Float(float64),
Int(int),
Uint(uint);

#[inline]
pub func to_bool(self) -> bool {
return (self is .Int as int and int == 1)
or (self is .Uint as uint and uint == 1);
return (self is .Int(int_) and int_ == 1)
or (self is .Uint(uint_) and uint_ == 1);
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ extend Table {
}
return paths;
}
return [];
return +[];
}

func search_c_header(self, is_local: bool, header: string) -> ?string {
Expand Down
14 changes: 7 additions & 7 deletions lib/rivet/src/ast/Decl.ri
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ../token;

pub enum Decl {
Empty: token.Pos,
Empty(token.Pos),
Comment: Comment,
Import {
attributes: Attributes;
Expand Down Expand Up @@ -55,7 +55,7 @@ pub enum Decl {
mut underlying_type: Type;
bases: []mut Type;
variants: []EnumVariantDecl;
is_boxed: bool;
is_tagged: bool;
decls: []Decl;
pos: token.Pos;
mut sym: Sym;
Expand Down Expand Up @@ -170,11 +170,11 @@ pub enum Decl {

pub func decls(self) -> ?[]Self {
return match self is {
.Extern as extern_decl -> extern_decl.decls,
.Trait as trait_decl -> trait_decl.decls,
.Enum as enum_decl -> enum_decl.decls,
.Struct as struct_decl -> struct_decl.decls,
.Extend as extend_decl -> extend_decl.decls,
.Extern(extern_decl) -> extern_decl.decls,
.Trait(trait_decl) -> trait_decl.decls,
.Enum(enum_decl) -> enum_decl.decls,
.Struct(struct_decl) -> struct_decl.decls,
.Extend(extend_decl) -> extend_decl.decls,
else -> none
};
}
Expand Down
Loading

0 comments on commit c3d57dd

Please sign in to comment.