Skip to content

feat(rivetc+rivet): implement boxed pointers (^T) #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 124 commits into from
Closed
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
154d377
bootstrap: parse `+T`
StunxFS Jan 1, 2024
4511129
self-host: parse boxed type
StunxFS Jan 1, 2024
600e988
remove `#[boxed]` for string and DynArray
StunxFS Jan 1, 2024
df82ed4
move `contains` method generation logic to a separate method
StunxFS Jan 1, 2024
a1c03aa
format python code
StunxFS Jan 1, 2024
b9e4a1a
parse `+Expression` (for generate boxed values)
StunxFS Jan 1, 2024
eaefdb5
parse `func (+self)` and `func (+mut self)`
StunxFS Jan 1, 2024
46b147f
start replacing old use of `boxed` with the new `+T`
StunxFS Jan 1, 2024
30e38e3
more replaces
StunxFS Jan 1, 2024
57ad02b
check boxed value mutability
StunxFS Jan 1, 2024
af33922
fix last commit
StunxFS Jan 1, 2024
02d7ee4
std: use boxed types
StunxFS Jan 1, 2024
8d5f432
core: fix test runner
StunxFS Jan 1, 2024
4a5a86b
check self type
StunxFS Jan 1, 2024
4798529
check for the receiver of a method call
StunxFS Jan 2, 2024
1819b47
check receiver in method declarations
StunxFS Jan 2, 2024
51c6e24
disallow `for &mut v in boxed_values {`
StunxFS Jan 2, 2024
eff3174
disallow enum is .BoxedType(&val)
StunxFS Jan 2, 2024
e3a7eb1
remove `Object.is_hidden_ref` field
StunxFS Jan 2, 2024
ef2e8d6
fix core tests
StunxFS Jan 2, 2024
073e6db
clean codegen of old logic of using `is_mut` as pointer
StunxFS Jan 2, 2024
9c2ca89
cleanup
StunxFS Jan 2, 2024
e9fde4b
remove test that no longer makes sense with the changes applied
StunxFS Jan 2, 2024
6b4944f
don't give error when T in `extend T` is boxed
StunxFS Jan 2, 2024
20014fa
more change
StunxFS Jan 2, 2024
cae036c
allow `value is Type(mut v)` when typematching is done on a trait
StunxFS Jan 2, 2024
2749618
more changes
StunxFS Jan 2, 2024
3169fb7
checker: check receiver mutability when using `DynamicArray` methods
StunxFS Jan 2, 2024
1a57bb2
more changes
StunxFS Jan 2, 2024
6056902
support `boxed_value.+`
StunxFS Jan 2, 2024
3019240
format python code
StunxFS Jan 2, 2024
98e30e9
more changes
StunxFS Jan 2, 2024
04c75e2
more changes, plus a small fix
StunxFS Jan 2, 2024
0331fea
fix TestRunner
StunxFS Jan 3, 2024
629da88
fix raw trait size
StunxFS Jan 3, 2024
d551b20
avoid boxed instance dup
StunxFS Jan 3, 2024
ca369ea
fix trait with fields size
StunxFS Jan 3, 2024
70ce67a
self-host: more changes
StunxFS Jan 3, 2024
97ee5da
self-host: more changes
StunxFS Jan 3, 2024
06ca035
add new file
StunxFS Jan 3, 2024
e879684
remove test binary
StunxFS Jan 3, 2024
6deef14
more changes
StunxFS Jan 3, 2024
e16ccb8
check boxedptr/ptr mutability
StunxFS Jan 3, 2024
7d47f5f
more changes
StunxFS Jan 3, 2024
6fb890d
more changes
StunxFS Jan 3, 2024
d566a9c
self-host: fix parser
StunxFS Jan 3, 2024
3b8c535
move `depgraph` module to `utils/depgraph`
StunxFS Jan 3, 2024
4d61e18
more changes
StunxFS Jan 3, 2024
41dbdc9
fix resolver module
StunxFS Jan 3, 2024
91e50a3
minor change
StunxFS Jan 3, 2024
8d16592
minor change
StunxFS Jan 3, 2024
4c9367c
changes
StunxFS Jan 5, 2024
0341560
minor change
StunxFS Jan 7, 2024
27bc18f
fix guard_expr.ri test
StunxFS Jan 7, 2024
8bcdc18
fix OrderedDepMap.ri
StunxFS Jan 7, 2024
e40a8a6
fix depgraph module
StunxFS Jan 7, 2024
3b8855c
support `+Trait`
StunxFS Jan 9, 2024
1b7815f
fix tests
StunxFS Jan 9, 2024
11175ac
more changes
StunxFS Jan 9, 2024
32dcf24
more changes
StunxFS Jan 9, 2024
8df463d
fix import ../{}
StunxFS Jan 16, 2024
edc78aa
more changes
StunxFS Jan 16, 2024
761859d
fix selector/index with ptrs/boxedptrs
StunxFS Jan 16, 2024
f2e4500
more changes
StunxFS Jan 16, 2024
8893c02
more changes
StunxFS Jan 16, 2024
b43081c
fix Throwable usage
StunxFS Jan 16, 2024
27a3e4f
fix throwable trait
StunxFS Jan 16, 2024
6f7f121
more changes
StunxFS Jan 16, 2024
95acc34
fix checker
StunxFS Jan 16, 2024
4d06f9d
rivet is compiling now!
StunxFS Jan 16, 2024
ee3c4a3
use boxdptr for strings
StunxFS Jan 16, 2024
0719287
use boxedptr for dynamic arrays
StunxFS Jan 16, 2024
7a42c36
fix
StunxFS Jan 16, 2024
ff11767
remove unnecessary code
StunxFS Jan 16, 2024
2187dcc
remove `set_enum_ref_value` builtin function
StunxFS Jan 16, 2024
1211801
Fix boxed types default value
StunxFS Jan 17, 2024
9f49968
fix tests
StunxFS Jan 17, 2024
ec5cd08
remove attribute support for traits
StunxFS Jan 17, 2024
1917eba
improve boxed type parsing
StunxFS Jan 17, 2024
faf54f3
self-hosted: parse .+ expression
StunxFS Jan 19, 2024
6bdfe90
change boxed syntax from + to ^
StunxFS Jan 19, 2024
a7342ed
fix mut
StunxFS Jan 19, 2024
cc05718
fix mut x2
StunxFS Jan 19, 2024
4c67484
fix
StunxFS Jan 19, 2024
970b04f
change
StunxFS Jan 19, 2024
89e7ba9
fix
StunxFS Jan 19, 2024
0bf195f
rename `ir.Pointer` -> `ir.Ptr`
StunxFS Jan 21, 2024
2e3d51b
rename function
StunxFS Jan 21, 2024
9217abf
fix amp operator
StunxFS Jan 21, 2024
940a1d4
format code
StunxFS Jan 21, 2024
033fff1
fix boxed value assign
StunxFS Jan 21, 2024
5ce0c5b
fix Path.c.ri
StunxFS Jan 26, 2024
c5956ec
fix File.c.ri
StunxFS Jan 26, 2024
1926fe6
update Boxedptr.c.ri
StunxFS Jan 26, 2024
2b06eec
try to fix Boxedptr.c.ri
StunxFS Jan 26, 2024
068144e
fix to_strin someg methods
StunxFS Jan 26, 2024
c583cab
remove none from boxed_ calls
StunxFS Jan 26, 2024
c6643bd
fix boxed_resize
StunxFS Jan 26, 2024
08e954c
simplify boxed_reisze
StunxFS Jan 26, 2024
64df03b
fix unary expr with index expr
StunxFS Jan 26, 2024
47df626
remove test binary
StunxFS Jan 26, 2024
224b7a6
self-hosted: fix import ../{}
StunxFS Jan 26, 2024
9e6490c
fix
StunxFS Jan 26, 2024
be57ba4
format code
StunxFS Jan 26, 2024
85d566a
update copyright year
StunxFS Jan 26, 2024
9ee2d1b
fix report messages
StunxFS Jan 26, 2024
9b6a14c
move report module to utils
StunxFS Jan 26, 2024
9700046
move build module to cmdtools/project
StunxFS Jan 26, 2024
57ba2a0
fix cmd_new.ri
StunxFS Jan 26, 2024
42e1663
move `templates` module to `project/templates`
StunxFS Jan 28, 2024
78f5587
fix TypeSym/Sym default value
StunxFS Jan 28, 2024
0af0824
fix more warns
StunxFS Jan 28, 2024
c55ef52
fix more warns
StunxFS Jan 28, 2024
c9ed8cb
add missing file
StunxFS Jan 29, 2024
4b728ba
fix Register.ri
StunxFS Jan 30, 2024
a6663e3
minor change to main_file.ri
StunxFS Mar 5, 2024
440c8bc
fix Boxedptr.c.ri
StunxFS Mar 29, 2024
6fb4698
support `rivet -v` and `rivet --version`
StunxFS Mar 29, 2024
37a40c1
fix invalid full name for imported modules
StunxFS Mar 29, 2024
1c17d72
minor change DynArray.ri
StunxFS Mar 30, 2024
6d3b7a0
update OrderedDepMap.ri
StunxFS Mar 30, 2024
f0c1d68
readd code
StunxFS Mar 31, 2024
5c8cb18
fix
StunxFS Mar 31, 2024
f759c1d
update Boxedptr.c.ri
StunxFS Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright © 2023-present Jose Mendoza
Copyright © 2023-2024 Jose Mendoza

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
7 changes: 4 additions & 3 deletions cmd/src/rivet.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

@@ -23,6 +23,7 @@ Commands:
help Print this help and exit.

General Options:
-v, --version Print version number and exit.
-h, --help Print command-specific usage.
";

@@ -36,15 +37,15 @@ func main() {
"build", "run", "test", "check" -> {
// These commands are handled directly by the compiler.
is_test := cmd == "test";
mut prefs_ := prefs.Prefs.from_args(
prefs_ := prefs.Prefs.from_args(
process.args[2:], is_test, is_test || cmd == "run", cmd == "check"
)!;
prefs_.load_module_info()!;
rivet.compile(prefs_)!;
},
"new", "init" -> tools.cmd_new(process.args[2:], cmd == "init")!,
"fmt" -> tools.cmd_fmt(process.args[2:])!,
"version" -> {
"-v", "--version", "version" -> {
console.ewriteln(utils.full_version());
process.exit(0);
},
11 changes: 6 additions & 5 deletions cmd/src/tools/cmd_fmt.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

@@ -9,7 +9,7 @@ var fmt_desc := "Formats the given Rivet source files or recursively formats all
directory, then prints their formatted source to stdout.";

pub func cmd_fmt(args: [:]string) -> ! {
mut fp := flag.FlagParser.new(args);
fp := flag.FlagParser.new(args);
fp.set_application_name("rivet fmt");
fp.set_arguments_description("[FILES|DIRECTORIES]");
fp.set_application_short_description(fmt_desc);
@@ -27,13 +27,14 @@ pub func cmd_fmt(args: [:]string) -> ! {
utils.error("no input received");
}
for input in remaining {
mut prefs_ := prefs.Prefs(is_fmt: true, hide_all_warns: true);
prefs_ := ^mut prefs.Prefs(is_fmt: true, hide_all_warns: true);
prefs_.set_input(input);
prefs_.load_module_info()!;
env := ast.Env.new(prefs_);
files := Directory.walk(input, ".ri")!;
mut formatter := fmt.Formatter(prefs_, write_to_file: write_to_file);
for source_file in parser.Parser(env: env).parse_module_files(files) {
formatter := ^mut fmt.Formatter(prefs_, write_to_file: write_to_file);
parser_ := ^mut parser.Parser(env: env);
for source_file in parser_.parse_module_files(files) {
utils.info("Formatting file `{}`...", source_file.path);
output := formatter.format(source_file);
console.writeln(output);
22 changes: 10 additions & 12 deletions cmd/src/tools/cmd_new.ri
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

import std/{
import std/{
flag, semver, strings, console, process, fs.{self, Path, Directory}
};
import rivet/{ build, utils };
import rivet/utils;

import ./templates;
import ./{project.*, project/templates};

var new_desc := "Sets up a new Rivet project and performs `git init` (if `git` is installed
on the system).";
@@ -26,7 +26,7 @@ var available_templates := "Available templates:

pub func cmd_new(args: [:]string, is_init: bool) -> ! {
mut template := "";
mut fp := flag.FlagParser.new(args);
fp := flag.FlagParser.new(args);
if is_init {
fp.set_limit_free_args_to_exactly(0)!;
} else {
@@ -54,7 +54,7 @@ pub func cmd_new(args: [:]string, is_init: bool) -> ! {
utils.error(err_fp.to_string())
};

mut project := build.Project();
mut project := Project(version: semver.Version.build(0, 1, 0));
if is_init {
project.name = Path.base_name(process.get_cwd()!);
} else {
@@ -72,8 +72,6 @@ pub func cmd_new(args: [:]string, is_init: bool) -> ! {
project.version = semver.Version.from_string(version) catch |err| {
utils.error(err.to_string())
};
} else {
project.version = semver.Version.build(0, 1, 0);
}
if license := readln("License (optional):") {
project.license = license;
@@ -85,7 +83,7 @@ pub func cmd_new(args: [:]string, is_init: bool) -> ! {
project.repository_url = repo_url;
}
}
check_project(project);
check_project(&mut project);

if is_init {
utils.info("initializing project `{}`...", project.name);
@@ -131,7 +129,7 @@ pub func cmd_new(args: [:]string, is_init: bool) -> ! {
}
}

func check_project(mut project: build.Project) {
func check_project(project: &mut Project) {
if project.name.is_empty() {
utils.error("project name cannot be empty");
}
@@ -154,15 +152,15 @@ func check_project(mut project: build.Project) {
}
}

func create_rivet_json(project: build.Project, is_init: bool) -> ! {
func create_rivet_json(project: Project, is_init: bool) -> ! {
path_ := if is_init { "rivet.json" } else { Path.join(project.name, "rivet.json")! };
if !Path.exists(path_) {
utils.info("creating `rivet.json` file...");
fs.write_file(path_, generate_rivet_json(project))!;
}
}

func generate_rivet_json(project: build.Project) -> string {
func generate_rivet_json(project: Project) -> string {
mut sb := strings.Builder.new();
sb.writeln("{");
sb.write_fmt(" \"name\": \"{}\"", project.name);
4 changes: 2 additions & 2 deletions lib/rivet/src/build/mod.ri → cmd/src/tools/project/mod.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

@@ -9,7 +9,7 @@ pub alias Version := semver.Version;
pub struct Project {
pub mut name: string;
pub mut description: string;
pub mut version: Version;
pub mut version: ^Version;
pub mut license: string;
pub mut authors: []string;
pub mut dependencies: []Dependency;
19 changes: 19 additions & 0 deletions cmd/src/tools/project/templates/main_file.ri
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

pub var main_file := "import std/console;

func main() {
console.writeln(\"Hello World!\");
}
";

pub var lib_file := "pub func add(a: int, b: int) -> int {
return a + b;
}

test \"test `add` function\" {
@assert(add(2, 2) == 4);
}
";
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

pub var main_file := "import std/console;

func main() {
console.writeln(\"Hello World!\");
}
";

pub var lib_file := "pub func add(a: int32, b: int32) -> int32 {
return a + b;
}

test \"test `add` function\" {
@assert(add(2, 2) == 4);
}
";

pub var git_ignore_file := "# Binaries for programs and plugins
{}
*.exe
2 changes: 1 addition & 1 deletion cmd/src/tools/utils.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/ctypes/mod.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

9 changes: 4 additions & 5 deletions lib/c/src/errno.c.ri
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

import c/libc;

#[boxed]
pub struct ErrnoError < Throwable {
pub msg: string;
pub code: int32;

pub func to_string(self) -> string {
pub func to_string(^self) -> string {
return "errno: {} (code: {})".fmt(self.msg, self.code);
}
}
@@ -35,6 +34,6 @@ pub func errno_msg(code: int32 := errno()) -> string {
}

#[inline]
pub func last_errno_error() -> ErrnoError {
return ErrnoError(errno_msg(), errno());
pub func last_errno_error() -> ^ErrnoError {
return ^ErrnoError(errno_msg(), errno());
}
2 changes: 1 addition & 1 deletion lib/c/src/lib.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/dirent.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/dlfcn.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/errno.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/mod.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/signal.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/stat.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/stdio.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/stdlib.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/string.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/time.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/libc/unistd.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

2 changes: 1 addition & 1 deletion lib/c/src/wyhash.ri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
// Copyright (C) 2023-2024 Jose Mendoza - All rights reserved. Use of this
// source code is governed by an MIT license that can be found in the LICENSE
// file.

Loading