context.temp_allocator = alloc.temp_allocator;
context.assert_handler = assert_handler;
- argc : Size;
+ args : [] cstr;
argv_buf_size : Size;
- args_sizes_get(^argc, ^argv_buf_size);
+ args_sizes_get(^args.count, ^argv_buf_size);
- argv := cast(^cstr) calloc(sizeof cstr * argc);
+ args = memory.make_slice(cstr, args.count);
argv_buf := cast(cstr) calloc(argv_buf_size);
- args_get(argv, argv_buf);
+ args_get(args.data, argv_buf);
// This post processing of the argv array needs to happen if the target is using
// But for right now, WASI will give the argv array 32-bit pointers, instead of
// 64-bit pointers. This loops expands the 32-bit pointers into 64-bit pointers
// while not clobbering any of them.
- while i := cast(i32) (argc - 1); i >= 0 {
+ while i := cast(i32) (args.count - 1); i >= 0 {
defer i -= 1;
- argv[i] = cast(cstr) (cast(^u32) argv)[i];
+ args[i] = cast(cstr) (cast(^u32) args.data)[i];
}
stdio_init();
- main.main(argv[0 .. argc]);
+ main.main(args);
print_stream_flush();
}
--- /dev/null
+With the recent addition of compile time if statements, there should be a set of variables
+that give information about the current compilation. These would include things such as:
+ - Chosen backend (JS, WASI, others in the future)
+ - 32-Bit pointers are enabled
+
+The standard library will be rewritten to use these variables to conditionally include file
+that are only supported on a particular system.
+
+For the moment, I think that the choice of backend will be given by compiler flags. It will
+set the variables described below to their value.
+
+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
// Things that need to be cleaned up in the parser:
// - control block local variables should be more extensible and reuse more code
-// - outermost loops that parse the top level elements
// - package name parsing
#include "onyxlex.h"
if (parser->hit_unexpected_token) return root_if;
AstIfWhile* elseif_node = make_node(AstIfWhile, Ast_Kind_If);
+ elseif_node->token = parser->curr - 1;
cond = parse_expression(parser, 1);
true_stmt = parse_block(parser);
expect_token(parser, ',');
}
}
-
+
+ ENTITY_SUBMIT(upack);
return (AstNode *) upack;
} else {
else curr_param.vararg_kind = VA_Kind_Typed;
}
- i32 old_len = 0, new_len = 0;
if (curr_param.vararg_kind != VA_Kind_Untyped) {
// CLEANUP: This is mess and it is hard to follow what is going on here.
// I think with recent rewrites, this should be easier to do.
- old_len = bh_arr_length(*parser->polymorph_context.poly_params);
+ i32 old_len = bh_arr_length(*parser->polymorph_context.poly_params);
curr_param.local->type_node = parse_type(parser);
- new_len = bh_arr_length(*parser->polymorph_context.poly_params);
+ i32 new_len = bh_arr_length(*parser->polymorph_context.poly_params);
if (curr_param.vararg_kind == VA_Kind_Typed) {
AstVarArgType* va_type = make_node(AstVarArgType, Ast_Kind_VarArg_Type);
va_type->token = curr_param.local->type_node->token;
curr_param.local->type_node = (AstType *) va_type;
}
- }
- i32 new_poly_params = new_len - old_len;
- fori (i, 0, new_poly_params) {
- (*parser->polymorph_context.poly_params)[old_len + i].type_expr = curr_param.local->type_node;
- (*parser->polymorph_context.poly_params)[old_len + i].idx = param_idx;
+ fori (i, 0, new_len - old_len) {
+ (*parser->polymorph_context.poly_params)[old_len + i].type_expr = curr_param.local->type_node;
+ (*parser->polymorph_context.poly_params)[old_len + i].idx = param_idx;
+ }
}
}
return (AstTyped *) func_node;
}
- else if (parser->curr->type == Token_Type_Keyword_Global) {
- return parse_global_declaration(parser);
- }
- else if (parser->curr->type == Token_Type_Keyword_Struct) {
- return (AstTyped *) parse_struct(parser);
- }
- else if (parse_possible_directive(parser, "type")) {
+
+ if (parser->curr->type == Token_Type_Keyword_Global) return parse_global_declaration(parser);
+ if (parser->curr->type == Token_Type_Keyword_Struct) return (AstTyped *) parse_struct(parser);
+ if (parser->curr->type == Token_Type_Keyword_Enum) return (AstTyped *) parse_enum_declaration(parser);
+
+ if (parse_possible_directive(parser, "type")) {
AstTypeAlias* alias = make_node(AstTypeAlias, Ast_Kind_Type_Alias);
alias->to = parse_type(parser);
return (AstTyped *) alias;
}
- else if (parser->curr->type == Token_Type_Keyword_Enum) {
- return (AstTyped *) parse_enum_declaration(parser);
- }
- else {
- return parse_expression(parser, 1);
- }
+
+ return parse_expression(parser, 1);
}
static AstBinding* parse_top_level_binding(OnyxParser* parser, OnyxToken* symbol) {
AstUsePackage* implicit_use_builtin = make_node(AstUsePackage, Ast_Kind_Use_Package);
implicit_use_builtin->package_name = &builtin_package_token;
ENTITY_SUBMIT(implicit_use_builtin);
-
+
while (parser->curr->type != Token_Type_End_Stream) {
if (parser->hit_unexpected_token) break;
if (onyx_has_errors()) break;