@echo off
+set SOURCE_FILES=src/onyx.c src/onyxbuiltins.c src/onyxchecker.c src/onyxclone.c src/onyxdoc.c src/onyxentities.c src/onyxerrors.c src/onyxlex.c src/onyxparser.c src/onyxsempass.c src/onyxsymres.c src/onyxtypes.c src/onyxutils.c src/onyxwasm.c
+
+if "%1" == "1" (
+ set FLAGS=/O2 /MT /Z7
+) else (
+ set FLAGS=/Od /MDd /Z7
+)
+
del *.pdb > NUL 2> NUL
del *.ilk > NUL 2> NUL
-cl.exe /Od /MDd /Z7 /I include /std:c17 /Tc src/onyx.c src/onyxbuiltins.c src/onyxchecker.c src/onyxclone.c src/onyxdoc.c src/onyxentities.c src/onyxerrors.c src/onyxlex.c src/onyxparser.c src/onyxsempass.c src/onyxsymres.c src/onyxtypes.c src/onyxutils.c src/onyxwasm.c /link /DEBUG /OUT:onyx.exe /incremental:no /opt:ref /subsystem:console
+cl.exe %FLAGS% /I include /std:c17 /Tc %SOURCE_FILES% /link /DEBUG /OUT:onyx.exe /incremental:no /opt:ref /subsystem:console
del *.obj > NUL 2> NUL
\ No newline at end of file
+// Slices are a useful and simple data structure that are commonly
+// used throughout almost all Onyx programs. A slice in Onyx simply
+// represents a two member structure, consisting of a pointer, and
+// an unsigned count. Although that sounds deceptively simple, it
+// is a powerful construct to have. In fact, strings in Onyx, i.e.
+// the 'str' type, is actually just a slice of u8.
+
#load "core/std/wasi"
use package core
main :: proc (args: [] cstr) {
+ // A dummy array to demonstrate.
+ arr := i32.[ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ];
+
+ // In Onyx a slice type is simply written as an empty pair of
+ // square brackets, with the type of elements of the slice
+ // immediately following.
+ slice : [] i32;
+
+ // Slices have two members, data and count. You can set them directly.
+ slice.data = ^arr[3];
+ slice.count = 4;
+
+ // You can iterate over slices directly using a for-loop.
+ for elem: slice do printf("%i ", elem);
+ print("\n");
+
+ // Another equivalent way of writing lines 21 and 22 is to
+ // use the array subscript notation, but provide a range for
+ // the index as so. This is generally called the slice literal
+ // notation.
+ slice = arr[3 .. 7];
+
+ // Printing it out to verify it is the same.
+ for elem: slice do printf("%i ", elem);
+ print("\n");
+
+ // Since strings are represented as slices in Onyx, substrings
+ // are easily accessed using the same slice literal syntax.
+ some_string := "This is a test string for demoing purposes.";
+ substr := some_string.data[10 .. 14];
+ println(substr);
}
+// Dynamic arrays are arguably the most useful data structure of
+// all time. They allow for the array to be dynamically resized,
+// which means you don't need to know upfront the maximum number
+// of elements that will be in your array. It can always grow to
+// the size it needs to.
+
+// Dynamic arrays in Onyx are easy to use on purpose, because I
+// know how useful they are in almost every program I write.
+
#load "core/std/wasi"
use package core
main :: proc (args: [] cstr) {
+ // Declaring dynamic arrays in Onyx looks like this. The
+ // '..' makes it a dynamic array, as opposed to a slice
+ // or fixed size array.
+ arr : [..] i32;
+
+ // Currently, there are no implicit procedure calls anywhere
+ // in the language because I find explicitly specifying
+ // everything to be less bug prone in the long run, at the
+ // trade off of being mildly tedious. Since there are implicit
+ // procedure calls, we have to initialize and free the dynamic
+ // array explicitly. The 'defer' simply runs array.free at the
+ // end of this procedure scope. We will talk more about how to
+ // use the defer keyword later.
+ array.init(^arr);
+ defer array.free(^arr);
+
+ // Once the dynamic array has been initialized, we can begin
+ // to use it. The most common function you will probably use
+ // is array.push. It simply appends a new element to end of
+ // the array.
+ for i: 0 .. 10 do array.push(^arr, i);
+
+ // Now if we print the array, we will see the numbers from 0 to 9.
+ print_array(arr);
+
+ // We can remove elements from the end using array.pop.
+ for i: 0 .. 4 do array.pop(^arr);
+ print_array(arr);
+
+ // We can insert elements at the beginning using array.insert.
+ for i: 6 .. 10 do array.insert(^arr, 0, i);
+ print_array(arr);
+
+ // There are many other useful functions in the core.array package.
+ // You can look in core/array.onyx for a list of all of them.
}
}
char* arg_str = bh_alloc(global_scratch_allocator, 1024);
+ arg_str[0] = '\0';
bh_arr_each(AstArgument *, arg, call->arg_arr) {
strncat(arg_str, type_get_name((*arg)->value->type), 1023);
- if ((*arg)->next != NULL)
+ if (arg != &bh_arr_last(call->arg_arr))
strncat(arg_str, ", ", 1023);
}