--- /dev/null
+package core
+
+use package memory
+
+Buffer :: struct {
+ length : u32 = 0;
+ data : rawptr = null;
+}
+
+string :: struct {
+ length : u32 = 0;
+ data : ^u8 = null;
+}
+
+string_make :: proc #overloaded { string_make_from_u8 }
+
+#private
+string_make_from_u8 :: proc (s: ^u8) -> string {
+ len :: string_length(s);
+
+ return string.{ length = len, data = s };
+}
+
+
+string_length :: proc #overloaded {
+ proc (s: ^u8) -> u32 {
+ len := 0;
+ c := s;
+ while *c != #char "\0" {
+ len += 1;
+ c += 1;
+ }
+
+ return len;
+ },
+
+ proc (s: string) -> u32 {
+ return s.length;
+ },
+}
+
+#private
+string_length_string :: proc (s: string) -> u32 do return s.length;
+
+string_concat :: proc (a: Allocator, s1: string, s2: string) -> string {
+ len1 :: string_length(s1);
+ len2 :: string_length(s2);
+
+ data := cast(^u8) alloc(a, len1 + len2);
+ for i: 0, len1 do data[i] = s1.data[i];
+ for i: 0, len2 do data[i + len1] = s2.data[i];
+
+ return string.{ len1 + len2, data };
+}
+
+string_free :: proc (a: Allocator, s: string) do free(a, s.data);
+
+#private print_str_with_len :: proc #foreign "host" "print_str_with_len" (s: ^u8, len: u32) ---
+string_print :: proc (s: string) do print_str_with_len(s.data, s.length);
+++ /dev/null
-package core
-
-use package memory { null }
-
-Buffer :: struct {
- length : u32 = 0;
- data : rawptr = null;
-}
\ No newline at end of file
[X] returning structs
- This will put forward a lot of the work that will be done for multiple return values
+
+ [ ] Add slices
+ - Arrays without a size
+ - Converted to a struct that looks like:
+ []T :: struct {
+ count : u32;
+ data : ^T;
+ }
[ ] 'use' enums and packages at an arbitrary scope
[ ] Type parameterized structs
- [ ] Add slices
- - Arrays without a size
- - Converted to a struct that looks like:
- []T :: struct {
- count : u32;
- data : ^T;
- }
[ ] Arrays need to be much better
- Currently, they are basically just a pointer.
#include_file "printing"
#include_file "alloc"
-#include_file "test"
+#include_file "string"
use package printing
use package memory
-use package core as core
+use package core
sort :: proc (arr: [N]i32, cmp: proc (i32, i32) -> i32) -> [N] i32 {
for i: 0, N {
print(v2.y);
print(v2.z);
- buf := core.Buffer.{ length = 16 };
-
un : UnionTest;
un.f = 1.25f;
print_hex(cast(u64) un.i);
+
+ s1 :: string_make("Hello, ");
+ s2 :: string_make("World!");
+ s3 :: string_concat(heap_allocator, s1, s2);
+ defer string_free(heap_allocator, s3);
+ string_print(s3);
}
vadd :: proc (v1: Vec3, v2: Vec3) -> Vec3 {
return Vec3.{
- x = v1.x + v2.x,
- y = v1.y + v2.y,
- z = v1.z + v2.z,
+ v1.x + v2.x,
+ v1.y + v2.y,
+ v1.z + v2.z,
};
}
vmul :: proc (use v: Vec3, s: i32) -> Vec3 {
- return Vec3.{ x = x * s, y = y * s, z = z * s };
+ return Vec3.{ x * s, y * s, z * s };
}
UnionTest :: struct #union {
if (check_expression(&fornode->end)) return 1;
if (check_expression(&fornode->step)) return 1;
- fornode->var->type_node = fornode->start->type_node;
- if (check_expression((AstTyped **) &fornode->var)) return 1;
+ if (fornode->var->type_node == NULL)
+ fornode->var->type_node = fornode->start->type_node;
+ fill_in_type((AstTyped *) fornode->var);
if (!type_is_integer(fornode->start->type)) {
onyx_message_add(Msg_Type_Literal,
parser->curr->pos,
token_name(';'),
token_name(parser->curr->type));
-
- find_token(parser, ';');
}
consume_token(parser);
}
while (parser->curr->type != '}') {
if (parser->hit_unexpected_token) return (AstFunction *) ofunc;
- AstTyped* sym_node = make_node(AstTyped, Ast_Kind_Symbol);
- sym_node->token = expect_token(parser, Token_Type_Symbol);
+ AstTyped* o_node = parse_expression(parser);
- bh_arr_push(ofunc->overloads, sym_node);
+ bh_arr_push(ofunc->overloads, o_node);
if (parser->curr->type != '}')
expect_token(parser, ',');
case Ast_Kind_Param: {
u64 localidx = bh_imap_get(&mod->local_map, (u64) expr);
- WIL(WI_LOCAL_GET, localidx);
+ if (expr->type->kind == Type_Kind_Struct) {
+ TypeStruct* st = &expr->type->Struct;
+
+ fori (idx, 0, st->mem_count) {
+ WIL(WI_LOCAL_GET, localidx + idx);
+ }
+
+ } else {
+ WIL(WI_LOCAL_GET, localidx);
+ }
+
break;
}
case Ast_Kind_Local: {
u64 tmp = bh_imap_get(&mod->local_map, (u64) expr);
+
if (tmp & LOCAL_IS_WASM) {
if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == tmp) {
bh_arr_last(code).type = WI_LOCAL_TEE;