organizing, documentation

This commit is contained in:
Judah Caruso 2025-05-17 04:17:08 -06:00
parent 4c4aa60c7b
commit ca27aedae7
2 changed files with 23 additions and 8 deletions

View file

@ -5,18 +5,18 @@
old := Vector3.{ 10, 20, 30 }; // 10, 20, 30
new := with(old, .{ y = -20 }); // 10, -20, 30
*/
with :: (old: $T, $new: Code, location := #caller_location) -> T
with :: (old: $T, $fields: Code, location := #caller_location) -> T
#modify { return T.(*Type_Info).type == .STRUCT, "with can only be used on structs"; }
#expand {
using compiler;
ensure :: (cond: bool, message: string, args: ..Any, loc := location) {
if !cond compiler_report(basic.tprint(message, ..args), loc);
}
#insert,scope() -> string {
using compiler;
ensure :: (cond: bool, message: string, args: ..Any, loc := location) {
if !cond compiler_report(basic.tprint(message, ..args), loc);
}
b: basic.String_Builder;
root := compiler_get_nodes(new).(*Code_Literal);
root := compiler_get_nodes(fields).(*Code_Literal);
ensure(root.kind == .LITERAL, "argument must be a struct literal");
ensure(root.value_type == .STRUCT, "argument must be a struct literal");
@ -32,6 +32,9 @@ with :: (old: $T, $new: Code, location := #caller_location) -> T
ensure(n_type.result == t_info, "mismatched types, % vs. %", t_info.name, n_typename);
}
// @note(judah): if the value we're trying to copy is a constant,
// we have to create a local so we can assign to the fields.
// Doing this allows this usecase: 'with(Default_Entity, .{ kind = .Player })'
receiver := "old";
#if is_constant(old) {
receiver = "copy";

View file

@ -1,3 +1,15 @@
/*
A very simple test runner that can be used at compile-time.
Usage:
test :: #import "jx/test";
#if RUN_TESTS #run {
test.run("collection of tests", t => {
test.expect(t, some_condition, "error message: %", value);
});
}
*/
T :: struct {
location: Source_Code_Location;
expects_run: sint;