package builtin
+use package build_opts as build_opts
str :: #type []u8;
cstr :: #type ^u8;
allocator : Allocator;
temp_allocator : Allocator;
+ logger : Logger = .{ default_logger, null };
+
assert_handler : (msg: str, file: str) -> void;
}
+#if build_opts.Runtime != build_opts.Runtime_Custom {
+ #private_file default_logger :: (data: rawptr, msg: str) {
+ use package core
+ println(msg);
+ }
+
+} else {
+ #private_file default_logger :: (data: rawptr, msg: str) {
+ // In a custom runtime, there is no way to know how to log something.
+ }
+}
+
// @Robustness
// Currently, because the only compilation target is WebAssembly, which is only
// single threaded for the moment, it is safe to store the context in a global
}
+//
+// Basic logging
+//
+
+Logger :: struct {
+ func : (data: rawptr, msg: str) -> void;
+ data : rawptr;
+}
+
+log :: (msg: str, use logger: Logger = context.logger) {
+ func(data, msg);
+}
+
+
//
// Basic allocation structures.
// The implementations of all of the allocators can be found in core/alloc/.
Resize;
}
+#private_file
allocator_proc :: #type (data: rawptr, action: AllocationAction, size: u32, align: u32, old_ptr: rawptr) -> rawptr;
Allocator :: struct {
cresize :: (ptr: rawptr, size: u32) -> rawptr do return raw_resize(context.allocator, ptr, size);
cfree :: (ptr: rawptr) do raw_free(context.allocator, ptr);
-use package build_opts as build_opts
#if build_opts.Runtime != build_opts.Runtime_Custom {
use package core.intrinsics.wasm { __initialize }
return ~~ file_stat.size;
},
}
+
+
+
+
+file_logger_open :: (filename: str, allocator := context.allocator) -> Logger {
+ file := new(File, allocator);
+ success := false;
+
+ *file, success = file_open(filename, mode=OpenMode.Append);
+ assert(success, "Unable to open file for logging.");
+
+ return .{ file_logger_proc, file };
+}
+
+file_logger_close :: (logger := context.logger) {
+ file_close(*cast(^File) logger.data);
+
+ // @Robustness: this could be the wrong allocator if the context allocator wasn't used.
+ cfree(logger.data);
+}
+
+#private_file
+file_logger_proc :: (data: ^File, msg: str) {
+ file_write(*data, msg);
+ file_write(*data, "\n");
+}
use package core
use package main as main
+use package core.intrinsics.wasm { __initialize }
output_str :: (s: str) -> u32 #foreign "host" "print_str" ---
proc () #export "_start" {
alloc.init();
+ __initialize(^context);
context.allocator = alloc.heap_allocator;
context.temp_allocator = alloc.temp_allocator;
context.assert_handler = assert_handler;
use package wasi
use package core
use package main as main
+use package core.intrinsics.wasm { __initialize }
STDOUT_FILENO :: 1
proc () #export "_start" {
alloc.init();
+ __initialize(^context);
context.allocator = alloc.heap_allocator;
context.temp_allocator = alloc.temp_allocator;
context.assert_handler = assert_handler;
There should be an #error directive that when hit just produces a compile time error and prevents
compilation. It would be useful to ensure certain files that are only for a particular
-backend will not compile with the wrong one, such as webgl.onyx.
\ No newline at end of file
+backend will not compile with the wrong one, such as webgl.onyx.
+
+Another thing to think about is having things like 'defined(...)' in C. In other words, a
+method for knowing whether or not a symbol exists. Other things similar to this idea:
+ - defined(...) if the symbol is defined as anything
+ - is_procedure(...) if the symbol is a procedure
+ - argument_count(...) the number of required arguments the procedure has
+
+ main :: () {
+ ....
+ }
+
+ #if argument_count(main) > 0 {
+ main(args);
+ } else {
+ main();
+ }
+
assignment2->left = builtin_context_variable;
assignment2->right = (AstTyped *) context_tmp;
+ AstBlock* context_block = parse_block(parser);
+ assignment->next = (AstNode *) context_block;
+
AstDefer* defer_node = make_node(AstDefer, Ast_Kind_Defer);
defer_node->stmt = (AstNode *) assignment2;
- assignment->next = (AstNode *) defer_node;
+ defer_node->next = context_block->body;
+ context_block->body = (AstNode *) defer_node;
- AstBlock* context_block = parse_block(parser);
needs_semicolon = 0;
- defer_node->next = (AstNode *) context_block;
-
retval = (AstNode *) context_tmp;
break;
}