organizing, documentation
This commit is contained in:
parent
4c4aa60c7b
commit
ca27aedae7
2 changed files with 23 additions and 8 deletions
|
|
@ -5,18 +5,18 @@
|
||||||
old := Vector3.{ 10, 20, 30 }; // 10, 20, 30
|
old := Vector3.{ 10, 20, 30 }; // 10, 20, 30
|
||||||
new := with(old, .{ y = -20 }); // 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"; }
|
#modify { return T.(*Type_Info).type == .STRUCT, "with can only be used on structs"; }
|
||||||
#expand {
|
#expand {
|
||||||
|
#insert,scope() -> string {
|
||||||
using compiler;
|
using compiler;
|
||||||
|
|
||||||
ensure :: (cond: bool, message: string, args: ..Any, loc := location) {
|
ensure :: (cond: bool, message: string, args: ..Any, loc := location) {
|
||||||
if !cond compiler_report(basic.tprint(message, ..args), loc);
|
if !cond compiler_report(basic.tprint(message, ..args), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#insert,scope() -> string {
|
|
||||||
b: basic.String_Builder;
|
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.kind == .LITERAL, "argument must be a struct literal");
|
||||||
ensure(root.value_type == .STRUCT, "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);
|
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";
|
receiver := "old";
|
||||||
#if is_constant(old) {
|
#if is_constant(old) {
|
||||||
receiver = "copy";
|
receiver = "copy";
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
T :: struct {
|
||||||
location: Source_Code_Location;
|
location: Source_Code_Location;
|
||||||
expects_run: sint;
|
expects_run: sint;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue