From: Brendan Hansen Date: Tue, 9 Feb 2021 04:24:51 +0000 (-0600) Subject: working on build_opts variables X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8c2e4dba69cbbad8a52294b0ede5c4c4cc12e0d6;p=onyx.git working on build_opts variables --- diff --git a/bin/onyx b/bin/onyx index 44334388..86d696fd 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/build_opts.onyx b/core/build_opts.onyx index ddebe1a5..11f1cf95 100644 --- a/core/build_opts.onyx +++ b/core/build_opts.onyx @@ -1,9 +1,13 @@ -// This following sybmols are not meant to be included in any compilation. +// This following sybmols are not meant to be included in any compilation. // Instead, all of the commented out symbols are defined automatically by the compiler // and can be used in compile time #if statements. // Runtime :: Runtime_Wasi OR Runtime_Js OR Runtime_Custom + + + + package build_opts diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 0df44681..069fdbfb 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -1101,6 +1101,7 @@ extern bh_table(OnyxIntrinsic) intrinsic_table; extern bh_arr(AstTyped *) operator_overloads[Binary_Op_Count]; void initialize_builtins(bh_allocator a); +void introduce_build_options(bh_allocator a); // NOTE: Useful not inlined functions diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index 686f20df..d1ac05f4 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -2,15 +2,19 @@ use package core -max_f32 :: #solidify math.max { T = f32 }; +max_f32 :: #solidify math.max_poly { T = f32 }; compose :: proc (a: $A, f: proc (A) -> $B, g: proc (B) -> $C) -> C do return g(f(a)); -specific_compose_0 :: #solidify compose { B = f32 }; specific_compose_1 :: #solidify specific_compose_0 { A = f32 }; +specific_compose_0 :: #solidify compose { B = f32 }; specific_compose_2 :: #solidify specific_compose_1 { C = f64 }; main :: proc (args: [] cstr) { + use package build_opts + println(Runtime); + println("=================================================="); + printf("max(1, 2) = %i\n", math.max(1, 2)); printf("max_f32(1.0, 2.0) = %f\n", max_f32(1, 2)); @@ -47,7 +51,7 @@ main :: proc (args: [] cstr) { } array_map :: proc (arr: [..] $T, f: proc (T) -> T) { - foo := #solidify math.max { T = T }; + foo := #solidify math.max_poly { T = T }; is := (#type InternalStruct(T)).{ foo = foo(6, 2) }; printf("%i\n", is.foo); diff --git a/src/onyx.c b/src/onyx.c index 4fc4d438..dfdbf481 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -129,7 +129,6 @@ typedef enum CompilerProgress { static OnyxToken implicit_load_token = { '#', 1, 0, { 0, 0, 0, 0, 0 } }; static AstInclude* create_load(bh_allocator alloc, char* filename) { - AstInclude* include_node = onyx_ast_node_new(alloc, sizeof(AstInclude), Ast_Kind_Load_File); include_node->name = filename; include_node->token = &implicit_load_token; @@ -321,6 +320,7 @@ static b32 process_entity(Entity* ent) { if (!builtins_initialized) { builtins_initialized = 1; initialize_builtins(context.ast_alloc); + introduce_build_options(context.ast_alloc); } process_load_entity(ent); diff --git a/src/onyxbuiltins.c b/src/onyxbuiltins.c index d036182d..ca4ddb01 100644 --- a/src/onyxbuiltins.c +++ b/src/onyxbuiltins.c @@ -379,3 +379,10 @@ void initialize_builtins(bh_allocator a) { intrinsic++; } } + +void introduce_build_options(bh_allocator a) { + Package* p = package_lookup_or_create("build_opts", context.global_scope, a); + + AstNumLit* runtime_type = make_int_literal(a, 1); + symbol_builtin_introduce(p->scope, "Runtime", (AstNode *) runtime_type); +} \ No newline at end of file