[X] Enum types
- [ ] Static pointers to sized data
+ [X] Static pointers to sized data
- [ ] 'using' parameters
+ [X] 'using' parameters
- The following example will bring the members of the struct into the scope as field accesses
and allow for a more OO style programming, without diving into the crap that is OO
+ foo :: proc (use data: ^Data, other_arg: i32) {
+ member1_of_data = other_arg;
+ bar(member2_of_data);
+ }
+
[ ] Start work on evaluating compile time known values.
- An expression marked COMPTIME will be reduced to its value in the parse tree.
// Expression flags
Ast_Flag_Expr_Ignored = BH_BIT(8),
Ast_Flag_Param_Splatted = BH_BIT(9),
+ Ast_Flag_Param_Use = BH_BIT(10),
// Type flags
Ast_Flag_Type_Is_Resolved = BH_BIT(8),
use "progs/print_funcs"
+use "progs/intrinsics"
use package printing {
print, PrintableArray,
- print_f32 as pf32,
- print_buf
+ print_f32 as pf32
}
Foo :: struct {
st : SomeType;
}
-foo_sum :: proc (foo: ^Foo) -> i32 {
- return foo.x + foo.y;
+foo_sum :: proc (use foo: ^Foo) -> i32 {
+ return x + y;
}
asdf :: proc (pa: PrintableArray) {
Value4;
}
-print_st :: proc (st: SomeType) {
+print_st :: proc (st: SomeType, other: i32) {
print(st as i32);
}
print(__heap_start as i32);
- print(print_buf as i32);
-
single_int = 10 as u8;
print(single_int as i32);
array[4].y = 1234;
print(array[4].y);
- st := SomeType.Value4;
- print_st(st);
+ st: SomeType = SomeType.Value4;
+ print_st(st, 10);
foo := __heap_start as ^Foo;
foo.x = 123;
print(alignof Foo);
print(sizeof Foo);
print(foo.foo_sum());
- print_st(foo.st);
+ print_st(foo.st, 20);
pa := (__heap_start as i32 + sizeof Foo) as ^PrintableArray;
pa.data = __heap_start as ^u8;
print(1234);
- pf32(123.0f);
+ pf32(sqrt_f32(123.0f));
}
package printing
-use package main {
- N as buf_size
-}
-
print_bool :: proc #foreign "host" "print" (value: bool) ---
print_i32 :: proc #foreign "host" "print" (value: i32) ---
print_f32 :: proc #foreign "host" "print" (value: f32) ---
print_str,
print_str_len,
}
-
-print_buf : [buf_size] u8
\ No newline at end of file
y : f32;
}
-vec2_magnitude :: proc (v: ^Vec2) -> i32 {
- return sqrt_f32(v.x * v.x + v.y * v.y) as i32;
+vec2_magnitude :: proc (use v: ^Vec2) -> i32 {
+ return sqrt_f32(x * x + y * y) as i32;
}
Vec3 :: struct {
z : f32;
}
-vec3_magnitude :: proc (v: ^Vec3) -> f32 {
- return sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z);
+vec3_magnitude :: proc (use v: ^Vec3) -> f32 {
+ return sqrt_f32(x * x + y * y + z * z);
}
magnitude :: proc #overloaded {
AstLocal* curr_param = NULL;
AstLocal* trailer = NULL;
+ b32 param_use = 0;
OnyxToken* symbol;
while (parser->curr->type != ')') {
- if (parser->curr->type == ',') consume_token(parser);
+ if (parser->curr->type == Token_Type_Keyword_Use) {
+ consume_token(parser);
+ param_use = 1;
+ }
symbol = expect_token(parser, Token_Type_Symbol);
expect_token(parser, ':');
curr_param->flags |= Ast_Flag_Const;
curr_param->type_node = parse_type(parser);
+ if (param_use) {
+ curr_param->flags |= Ast_Flag_Param_Use;
+ param_use = 0;
+ }
+
if (first_param == NULL) first_param = curr_param;
curr_param->next = NULL;
if (trailer) trailer->next = (AstNode *) curr_param;
trailer = curr_param;
+
+ if (parser->curr->type != ')')
+ expect_token(parser, ',');
}
consume_token(parser); // Skip the )
param->type_node = symres_type(param->type_node);
symbol_introduce(semstate.curr_scope, param->token, (AstNode *) param);
+
+ if (param->flags & Ast_Flag_Param_Use) {
+ if (param->type_node->kind != Ast_Kind_Pointer_Type
+ || ((AstPointerType *) param->type_node)->elem->kind != Ast_Kind_Struct_Type) {
+ onyx_message_add(Msg_Type_Literal,
+ param->token->pos,
+ "can only 'use' pointers to structures.");
+ } else {
+ AstStructType* st = (AstStructType *) ((AstPointerType *) param->type_node)->elem;
+
+ bh_arr_each(AstStructMember *, mem, st->members) {
+ AstFieldAccess* fa = onyx_ast_node_new(semstate.node_allocator, sizeof(AstFieldAccess), Ast_Kind_Field_Access);
+ fa->token = (*mem)->token;
+ fa->type_node = (*mem)->type_node;
+ fa->expr = (AstTyped *) param;
+
+ symbol_introduce(semstate.curr_scope, (*mem)->token, (AstNode *) fa);
+ }
+ }
+ }
}
if (func->type_node != NULL) {