case Ast_Kind_Directive_Remove: return sizeof(AstDirectiveRemove);
case Ast_Kind_Directive_First: return sizeof(AstDirectiveFirst);
case Ast_Kind_Directive_Export_Name: return sizeof(AstDirectiveExportName);
+ case Ast_Kind_Import: return sizeof(AstImport);
case Ast_Kind_Count: return 0;
}
"macro",
"interface",
"where",
- "import",
"", // end
"->",
}
case Token_Type_Keyword_Package: {
+ onyx_report_warning(peek_token(-1)->pos, "Use of deprecated feature: package expression.");
retval = (AstTyped *) parse_package_expression(parser);
break;
}
AstUse* use_node = make_node(AstUse, Ast_Kind_Use);
use_node->token = use_token;
use_node->expr = parse_expression(parser, 1);
+ if (!use_node->expr) return NULL;
if (consume_token_if_next(parser, '{')) {
bh_arr_new(global_heap_allocator, use_node->only, 4);
break;
}
+ if (parse_possible_directive(parser, "import")) {
+ // :LinearTokenDependent
+ retval = (AstNode *) parse_import_statement(parser, parser->curr - 2);
+ ENTITY_SUBMIT(retval);
+ needs_semicolon = 0;
+ break;
+ }
+
if (next_tokens_are(parser, 2, '#', Token_Type_Symbol)) {
retval = (AstNode *) parse_factor(parser);
break;
SYMRES(use, (AstUse *) *stmt);
break;
+ case Ast_Kind_Import:
+ if (remove) *remove = 1;
+ break;
+
default: SYMRES(expression, (AstTyped **) stmt); break;
}
#import runtime
-#if #defined(package core) {
- #import core
-}
-
//
// Explanation of `package builtin`
//
#if runtime.runtime != .Custom {
#local default_logger_proc :: (logger: &Default_Logger, level: Log_Level, msg: str, module: str) {
+ #import core;
+
if level < logger.minimum_level do return;
if module {
// This cannot be used in a custom runtime, as the other core
// packages are not included.
#if runtime.runtime != .Custom {
+ #import core
+ #import core.memory
+
new :: #match #local {}
#overload
new :: ($T: type_expr, allocator := context.allocator) -> &T {
- use package core.intrinsics.onyx { __initialize }
- memory :: package core.memory
+ use core.intrinsics.onyx { __initialize }
res := cast(&T) raw_alloc(allocator, sizeof T);
memory.set(res, 0, sizeof T);
#overload
new :: (T: type_expr, allocator := context.allocator) -> rawptr {
- memory :: package core.memory
- type_info :: package runtime.info
+ type_info :: runtime.info
info := type_info.get_type_info(T);
size := type_info.size_of(T);
// remove some confusion around the 3 different array types as dynamic arrays would clearly just be
// normal structures. With the recent addition of macros and iterators, there really wouldn't be much
// difference anyway.
-#if #defined((package core.map).Map) {
- Map :: (package core.map).Map;
+#if #defined(core.map.Map) {
+ Map :: core.map.Map;
}
-#if #defined((package core.set).Set) {
- Set :: (package core.set).Set;
+#if #defined(core.set.Set) {
+ Set :: core.set.Set;
}
map.init(&custom_parsers, default=null_proc);
#if Enable_Custom_Formatters {
- use package runtime.info;
+ use runtime.info;
for type_idx: type_table.count {
type := type_table[type_idx];
package core.intrinsics.atomics
#local {
- runtime :: package runtime
+ #import runtime
#if !runtime.Multi_Threading_Enabled {
#error "Multi-threading is not enabled so you cannot include the 'core.intrinsics.atomics' package."
// Currently, these symbols are dumped in the 'core' namespace, which means
-// most programs that just 'use package core' can access all of them, which
+// most programs that just 'use core' can access all of them, which
// is convenient; However, it doesn't hurt to wonder if they should be the
// 'core.io' package so these would become like 'io.printf(...)'. Of course,
-// you could always still do 'use package core.io', which would bring these
+// you could always still do 'use core.io', which would bring these
// in anyway.
package core
any_iter :: (arr: any) -> Iterator(any) {
base_ptr, elem_type, count := any_as_array(arr);
if count == 0 {
- return .{ null, ((_) => any.{}, false) };
+ return .{ null, ((_: rawptr) => any.{}, false) };
}
return iter.generator(
// to the same idea as 'null' in Onyx.
if this.data == 0 do return null;
- wasm :: package core.intrinsics.wasm
+ #import core.intrinsics.wasm
// Using 1 instead of 0 because a null pointer (0) converts
// to the memory address 0, not the base address for the WASM
// memory.
use core
-#local fs :: package runtime.platform
+
+#local fs :: runtime.platform
FileError :: enum {
package core.random
+#import core
+
//
// The state of a random number generator.
Random :: struct {
// Returns a random string of length `bytes_long`. If `alpha_numeric` is
// true, then the string will only consist of alpha-numeric characters.
string :: (self: &Random, bytes_long: u32, alpha_numeric := false, allocator := context.allocator) -> str {
- memory :: package core.memory
+ #import core.memory
s := memory.make_slice(u8, bytes_long, allocator=allocator);
for& s {
}
for_all_types :: macro (body: Code) {
+ #import runtime
+
for runtime.info.type_table.count {
- type_info := (package runtime.info).type_table[it];
+ type_info := runtime.info.type_table[it];
type_idx : type_expr = ~~ it;
#unquote body;
#import core
#import runtime
+#import main
use core
use runtime {
__runtime_initialize();
context.thread_id = 0;
- #if (typeof (package main).main) == #type () -> void {
- (package main).main();
+ #if (typeof main.main) == #type () -> void {
+ main.main();
} else {
args : [] cstr;
argv_buf := cast(cstr) calloc(argv_buf_size);
__args_get(args.data, argv_buf);
- (package main).main(args);
+ main.main(args);
}
__flush_stdio();
package core.env
-#local runtime :: package runtime
+#import runtime
+#import core.map
+#import core.memory
+#import core.string
+#import wasi
+
+
#if runtime.runtime != .Wasi
&& runtime.runtime != .Onyx {
#error "'core.env' is only available with the 'wasi' and 'onyx' runtimes.";
}
-use package wasi { environ_get, environ_sizes_get, Size }
-#package map :: package core.map
-#package memory :: package core.memory
-#package string :: package core.string
+use wasi { environ_get, environ_sizes_get, Size }
Environment :: struct {
vars : Map(str, str);
package runtime.platform
-#local runtime :: package runtime
+#import runtime
+#import core
+#import wasi
+
+use core
+
#if runtime.runtime != .Wasi {
#error "The file system library is currently only available on the WASI runtime, and should only be included if that is the chosen runtime."
}
-use package core
-
-#local wasi :: package wasi
-use package wasi {
+use wasi {
FileDescriptor,
FDFlags, OFlags, Rights,
LookupFlags, Errno,
//
to_dyn_str :: (x: str, allocator := context.allocator) -> dyn_str {
- return (package core.array).make(x, allocator);
+ #import core.array
+ return array.make(x, allocator);
}
delete :: macro (x: &dyn_str, idx: u32) -> u8 {
- return (package core.array).delete(x, idx);
+ #import core.array
+ return array.delete(x, idx);
}
append :: #match {
macro (x: &dyn_str, other: str) {
- (package core.array).concat(x, other);
+ #import core.array
+ array.concat(x, other);
},
macro (x: &dyn_str, other: u8) {
- (package core.array).push(x, other);
+ #import core.array
+ array.push(x, other);
},
}
clear :: macro (x: &dyn_str) {
- (package core.array).clear(x);
+ #import core.array
+ array.clear(x);
}
retreat :: macro (x: &dyn_str, chars := 1) {
- (package core.array).pop(x, chars);
+ #import core.array
+ array.pop(x, chars);
}
insert :: #match #locked {
macro (x: &dyn_str, idx: u32, new_str: str) -> bool {
- return (package core.array).insert(x, idx, new_str);
+ #import core.array
+ return array.insert(x, idx, new_str);
},
macro (x: &dyn_str, idx: u32, ch: u8) -> bool {
- return (package core.array).insert(x, idx, ch);
+ #import core.array
+ return array.insert(x, idx, ch);
}
}
use_package_breaking :: () {
println("Test 1");
- use package foo
+ use foo
println("Test 2");
}
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// The following declares a fixed-size array of 10 i32s on the stack. Currently,
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// A dummy array to demonstrate.
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// Declaring dynamic arrays in Onyx looks like this. The
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// To declare a simple, use the enum keyword.
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
x := 10 + 3 * 5;
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// Onyx does not have map type built into the language semantics,
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// Here are the uses of 'use' currently.
// You can 'use' a package. You hopefully already knew this.
// This brings in all the symbols from the core.alloc package into
// this scope.
- use package core.alloc
+ use core.alloc
// You can also restrict and partially rename the symbols that collide
- use package core.string { string_free :: free }
+ use core.string { string_free :: free }
}
{
// You can also 'use' a package that is a subpackage of another package. Here, 'string'
- // is a subpackage of 'core' and the above 'use package core' makes this package
+ // is a subpackage of 'core' and the above 'use core' makes this package
// available for you to write code like 'string.equal(...)'. However, because it is
// a namespace, you can 'use' it.
use string
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
// See the overloaded procedure defined below.
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
}
#load "core/std"
-use package core { println }
+#import core
+use core { println }
main :: (args: [] cstr) {
// These functions will be used to demo the pipe operator.
// It is not an operator you probably will not have to use very
// often; But when you have code like the first println above,
// it can clean up the code and make it easier to read.
-}
\ No newline at end of file
+}
#load "core/std"
-use package core
+#import core
+use core
// Operator overloading allows you to define what it means to perform
// a binary operation between two types. In Onyx, they are defined in
}
#load "core/std"
-use package core
\ No newline at end of file
+#import core
+use core
}
#load "core/std"
-use package core
+#import core
+use core
}
#load "core/std"
-use package core
+#import core
+use core
}
#load "core/std"
-use package core
+#import core
+use core
}
#load "core/std"
-
-use package core
-use package core.intrinsics.onyx
+#import core
+use core
+use core.intrinsics.onyx
}
#load "core/std"
-use package core
+#import core
+use core
#load "core/std"
-use package core
+#import core
+#import core.io
+#import core.array
+use core {printf}
main :: (args: [] cstr) {
contents := #file_contents "./tests/aoc-2020/input/day1.txt";
#load "core/std"
-use package core
+#import core
+use core
count_ending_paths :: (nums: [..] u32) -> u64 {
tally := array.make(u64, nums.count);
#load "core/std"
-use package core
+#import core
+use core
GameOfSeats :: struct {
width : u32;
#load "core/std"
-use package core
+#import core
+use core
main :: (args: [] cstr) {
println("Hello, World!");
#load "core/std"
-use package core
+#import core
+use core {println, printf}
some_function :: () -> f32 {
println("In some function!");
v: V2 = (.{ 10, 20 }) if true else .{ 30, 40 };
printf("{}\n", v);
-}
\ No newline at end of file
+}
#load "core/std"
-use package core
+#import core
+#import core.hash
+#import core.conv
+#import core.array
+#import core.iter
+
+use core {println, printf}
Hashable :: interface (t :$T) {
{ hash.to_u32(t) } -> u32;
#load "core/std"
-use package core
+#import core
+use core
foo :: () -> (i32, i32) {
return 50, 60;
#load "core/std"
-use package core
+#import core
main :: (args: [] cstr) {
- printf("{} {} {{}} {} {.1} {.5} {}\n", 123, "Test", false, 12.34, 12.3456789, [..] map.Map(i32, str));
+ core.printf("{} {} {{}} {} {.1} {.5} {}\n", 123, "Test", false, 12.34, 12.3456789, [..] map.Map(i32, str));
}
#load "core/std"
-use package core
+#import core
+use core {println}
overloaded :: #match {
(x: str, y: i32) do println("Called str, i32"); ,
#load "core/std"
-use package core
+#import core
+#import core.io
+use core {println}
main :: (args: [] cstr) {
some_string := "This is a test string that can be read.\n\n\n\n\n\n1234 4567";