Compare commits
No commits in common. "9d045e0717e7e4c48be5304ce850f37168d87e1c" and "80b47d63cb5930ea10f04e8212c5096210bb5fdb" have entirely different histories.
9d045e0717
...
80b47d63cb
123 changed files with 199 additions and 183 deletions
2
TODO
2
TODO
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
[Judah]
|
[Judah]
|
||||||
000 [math] add easing procedures
|
000 [math] add easing procedures
|
||||||
|
010 [x] make base jai files standalone (ie. [array], [memory], etc... big maybe)
|
||||||
|
|
||||||
[Jesse]
|
[Jesse]
|
||||||
001 [arch] create module to determine simd support
|
001 [arch] create module to determine simd support
|
||||||
|
|
@ -50,4 +51,3 @@
|
||||||
|
|
||||||
|
|
||||||
*** DONE ***
|
*** DONE ***
|
||||||
010 [x] make base jai files standalone (ie. [array], [memory], etc... big maybe)
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
compiler :: #import "Compiler";
|
compiler :: #import "Compiler";
|
||||||
compiler.set_build_options_dc(.{ do_output = false });
|
compiler.set_build_options_dc(.{ do_output = false });
|
||||||
|
|
||||||
#import,file "./array/module.jai"(true);
|
#import,file "./module.jai"(true);
|
||||||
#import,file "./encoding/module.jai"(true);
|
#import,file "./encoding/module.jai"(true);
|
||||||
#import,file "./hash/module.jai"(true);
|
#import,file "./hash/module.jai"(true);
|
||||||
#import,file "./memory/module.jai"(true);
|
|
||||||
#import,file "./meta/module.jai"(true);
|
|
||||||
|
|
||||||
rmath :: #import,file "./math/module.jai"(.radians, true);
|
rmath :: #import,file "./math/module.jai"(.radians, true);
|
||||||
// dmath :: #import,file "./math/module.jai"(.degrees, true);
|
// dmath :: #import,file "./math/module.jai"(.degrees, true);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ Static_Array :: struct(capacity: int, T: Type) {
|
||||||
items: [capacity]T;
|
items: [capacity]T;
|
||||||
count: int;
|
count: int;
|
||||||
|
|
||||||
Default :: #run mem.default_of(T);
|
Default :: #run default_of(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator [] :: inline (a: Static_Array, index: int, loc := #caller_location) -> a.T #no_abc {
|
operator [] :: inline (a: Static_Array, index: int, loc := #caller_location) -> a.T #no_abc {
|
||||||
|
|
@ -77,15 +77,12 @@ make_dynamic :: (a: *Static_Array) -> [..]a.T {
|
||||||
|
|
||||||
#scope_file;
|
#scope_file;
|
||||||
|
|
||||||
mem :: #import,file "../memory/module.jai";
|
|
||||||
basic :: #import "Basic"; // @future
|
|
||||||
|
|
||||||
ensure_array_has_room :: (array: *Static_Array, count: int, loc := #caller_location) #expand {
|
ensure_array_has_room :: (array: *Static_Array, count: int, loc := #caller_location) #expand {
|
||||||
basic.assert(array.count + count <= array.capacity, "attempt to add too many elements! want: %, Max: %", array.count + count, array.capacity, loc = loc);
|
basic.assert(array.count + count <= array.capacity, "attempt to add too many elements! want: %, Max: %", array.count + count, array.capacity, loc = loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RUN_TESTS #run {
|
#if RUN_TESTS #run {
|
||||||
test :: #import,file "../test/module.jai";
|
test :: #import,file "./test/module.jai";
|
||||||
|
|
||||||
test.run("basic operations", (t) => {
|
test.run("basic operations", (t) => {
|
||||||
a: Static_Array(10, int);
|
a: Static_Array(10, int);
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
#module_parameters(RUN_TESTS := false);
|
|
||||||
|
|
||||||
#load "static_array.jai";
|
|
||||||
|
|
||||||
#scope_module;
|
|
||||||
|
|
||||||
#if RUN_TESTS {
|
|
||||||
test :: #import,file "../test/module.jai";
|
|
||||||
}
|
|
||||||
29
base.jai
Normal file
29
base.jai
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
uint :: #type u64;
|
||||||
|
sint :: #type s64;
|
||||||
|
rune :: #type u32;
|
||||||
|
rawptr :: #type *void;
|
||||||
|
|
||||||
|
Default_Align :: #run 2 * align_of(rawptr);
|
||||||
|
|
||||||
|
align_of :: ($T: Type) -> uint #expand {
|
||||||
|
return #run -> uint {
|
||||||
|
info := type_info(struct{ p: u8; t: T; });
|
||||||
|
return info.members[1].offset_in_bytes.(uint);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
default_of :: ($T: Type) -> T #expand {
|
||||||
|
default: T;
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
zero_of :: ($T: Type) -> T #expand {
|
||||||
|
zero: T = ---;
|
||||||
|
memset(*zero, 0, size_of(T));
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
bitcast :: ($T: Type, expr: Code) -> T #expand {
|
||||||
|
value := expr;
|
||||||
|
return (*value).(*T).*;
|
||||||
|
}
|
||||||
|
|
@ -342,8 +342,8 @@ Parser :: struct {
|
||||||
allocator: Allocator;
|
allocator: Allocator;
|
||||||
data: []u8;
|
data: []u8;
|
||||||
error: string;
|
error: string;
|
||||||
offset: u64;
|
offset: uint;
|
||||||
line: u64;
|
line: uint;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token :: struct {
|
Token :: struct {
|
||||||
|
|
@ -387,7 +387,7 @@ get_next_token :: (p: *Parser) -> Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
if c == #char "/" && p.offset + 1 < p.data.count.(u64) && p.data[p.offset+1] == #char "/" {
|
if c == #char "/" && p.offset + 1 < p.data.count.(uint) && p.data[p.offset+1] == #char "/" {
|
||||||
capture_while(p, c => c != #char "\n");
|
capture_while(p, c => c != #char "\n");
|
||||||
return get_next_token(p);
|
return get_next_token(p);
|
||||||
}
|
}
|
||||||
|
|
@ -583,7 +583,7 @@ skip_whitespace :: (p: *Parser) {
|
||||||
}
|
}
|
||||||
|
|
||||||
capture_while :: (p: *Parser, proc: (u8) -> bool) -> string {
|
capture_while :: (p: *Parser, proc: (u8) -> bool) -> string {
|
||||||
basic.assert(p.offset < p.data.count.(u64));
|
basic.assert(p.offset < p.data.count.(uint));
|
||||||
|
|
||||||
capture := p.data;
|
capture := p.data;
|
||||||
capture.data += p.offset;
|
capture.data += p.offset;
|
||||||
|
|
@ -595,15 +595,17 @@ capture_while :: (p: *Parser, proc: (u8) -> bool) -> string {
|
||||||
p.offset += 1;
|
p.offset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
capture.count = ((p.data.data + p.offset) - capture.data).(s64);
|
capture.count = ((p.data.data + p.offset) - capture.data).(sint);
|
||||||
return capture.(string);
|
return capture.(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
at_end :: inline (p: *Parser) -> bool {
|
at_end :: inline (p: *Parser) -> bool {
|
||||||
return p.offset >= p.data.count.(u64);
|
return p.offset >= p.data.count.(uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
basic :: #import "Basic";
|
basic :: #import "Basic";
|
||||||
strings :: #import "String";
|
strings :: #import "String";
|
||||||
|
|
||||||
|
#import,file "../base.jai";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,8 +129,8 @@ c_call :: (call: Code, ctx: #Context) #expand {
|
||||||
for_expansion :: (v: *Named_Block, code: Code, _: For_Flags) #expand {
|
for_expansion :: (v: *Named_Block, code: Code, _: For_Flags) #expand {
|
||||||
#insert #run basic.tprint(#string END
|
#insert #run basic.tprint(#string END
|
||||||
for `%: 0..0 {
|
for `%: 0..0 {
|
||||||
`it :: #run mem.zero_of(void);
|
`it :: #run zero_of(void);
|
||||||
`it_index :: #run mem.zero_of(void);
|
`it_index :: #run zero_of(void);
|
||||||
#insert,scope(code) code;
|
#insert,scope(code) code;
|
||||||
}
|
}
|
||||||
END,
|
END,
|
||||||
|
|
@ -242,6 +242,9 @@ Unrolled_Loop :: struct(N: int, T: Type = void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pp :: #import "Program_Print";
|
||||||
|
compiler :: #import "Compiler";
|
||||||
|
|
||||||
#if RUN_TESTS #run {
|
#if RUN_TESTS #run {
|
||||||
test.run("this_block", (t) => {
|
test.run("this_block", (t) => {
|
||||||
i := 0;
|
i := 0;
|
||||||
|
|
@ -297,8 +300,3 @@ Unrolled_Loop :: struct(N: int, T: Type = void) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mem :: #import,file "../memory/module.jai";
|
|
||||||
|
|
||||||
basic :: #import "Basic"; // @future
|
|
||||||
pp :: #import "Program_Print"; // @future
|
|
||||||
compiler :: #import "Compiler"; // @future
|
|
||||||
39
math/vec.jai
39
math/vec.jai
|
|
@ -127,34 +127,34 @@ operator / :: inline (l: Vec, r: Vec(l.N, l.T)) -> Vec(l.N, l.T) #no_abc {
|
||||||
}
|
}
|
||||||
|
|
||||||
operator + :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc #symmetric
|
operator + :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc #symmetric
|
||||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||||
res: Vec(l.N, l.T) = ---;
|
res: Vec(l.N, l.T) = ---;
|
||||||
for l res[it_index] = it + r;
|
for l res[it_index] = it + r;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator - :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
operator - :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
||||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||||
res: Vec(l.N, l.T) = ---;
|
res: Vec(l.N, l.T) = ---;
|
||||||
for l res[it_index] = it - r;
|
for l res[it_index] = it - r;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
operator - :: inline (l: $R, r: Vec) -> Vec(l.N, l.T) #no_abc
|
operator - :: inline (l: $R, r: Vec) -> Vec(l.N, l.T) #no_abc
|
||||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||||
res: Vec(l.N, l.T) = ---;
|
res: Vec(l.N, l.T) = ---;
|
||||||
for l res[it_index] = r - it;
|
for l res[it_index] = r - it;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator * :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc #symmetric
|
operator * :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc #symmetric
|
||||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||||
res: Vec(l.N, l.T) = ---;
|
res: Vec(l.N, l.T) = ---;
|
||||||
for l res[it_index] = it*r;
|
for l res[it_index] = it*r;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator / :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
operator / :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
||||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||||
res: Vec(l.N, l.T) = ---;
|
res: Vec(l.N, l.T) = ---;
|
||||||
for l res[it_index] = it/r;
|
for l res[it_index] = it/r;
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -289,7 +289,7 @@ reflect :: (v: Vec2, p: Vec2) -> Vec2 #no_abc {
|
||||||
}
|
}
|
||||||
|
|
||||||
round :: (v: Vec($N, $T)) -> Vec(N, T) #no_abc
|
round :: (v: Vec($N, $T)) -> Vec(N, T) #no_abc
|
||||||
#modify { return types.is_float(T), "Used non-float vector on round"; } {
|
#modify { return is_type_float(T), "Used non-float vector on round"; } {
|
||||||
r: Vec(N, T) = ---;
|
r: Vec(N, T) = ---;
|
||||||
n := N - 1;
|
n := N - 1;
|
||||||
while n >= 0 {
|
while n >= 0 {
|
||||||
|
|
@ -310,37 +310,37 @@ Vec4 :: Vec(4, float);
|
||||||
Quat :: Vec4;
|
Quat :: Vec4;
|
||||||
|
|
||||||
v2f :: (x: $T = 0, y: T = 0) -> Vec2
|
v2f :: (x: $T = 0, y: T = 0) -> Vec2
|
||||||
#modify { return types.is_float(T), "use v2i for integer arguments"; }
|
#modify { return is_type_float(T), "use v2i for integer arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y };
|
return .{ x = x, y = y };
|
||||||
}
|
}
|
||||||
|
|
||||||
v2i :: (x: $T = 0, y: T = 0) -> Vec(2, T)
|
v2i :: (x: $T = 0, y: T = 0) -> Vec(2, T)
|
||||||
#modify { return types.is_integer(T), "use v2f for float arguments"; }
|
#modify { return is_type_integer(T), "use v2f for float arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y };
|
return .{ x = x, y = y };
|
||||||
}
|
}
|
||||||
|
|
||||||
v3f :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec3
|
v3f :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec3
|
||||||
#modify { return types.is_float(T), "use v3i for integer arguments"; }
|
#modify { return is_type_float(T), "use v3i for integer arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y, z = z };
|
return .{ x = x, y = y, z = z };
|
||||||
}
|
}
|
||||||
|
|
||||||
v3i :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec(3, T)
|
v3i :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec(3, T)
|
||||||
#modify { return types.is_integer(T), "use v3f for float arguments"; }
|
#modify { return is_type_integer(T), "use v3f for float arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y, z = z };
|
return .{ x = x, y = y, z = z };
|
||||||
}
|
}
|
||||||
|
|
||||||
v4f :: (x: $T = 0, y: T = 0, z: T = 0, w: T = 0) -> Vec4
|
v4f :: (x: $T = 0, y: T = 0, z: T = 0, w: T = 0) -> Vec4
|
||||||
#modify { return types.is_float(T), "use v4i for integer arguments"; }
|
#modify { return is_type_float(T), "use v4i for integer arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y, z = z, w = w };
|
return .{ x = x, y = y, z = z, w = w };
|
||||||
}
|
}
|
||||||
|
|
||||||
v4i :: (x: $T = 0, y: T = 0, z: T = 0, w: T = 0) -> Vec(4, T)
|
v4i :: (x: $T = 0, y: T = 0, z: T = 0, w: T = 0) -> Vec(4, T)
|
||||||
#modify { return types.is_integer(T), "use v4f for float arguments"; }
|
#modify { return is_type_integer(T), "use v4f for float arguments"; }
|
||||||
#expand {
|
#expand {
|
||||||
return .{ x = x, y = y, z = z, w = w };
|
return .{ x = x, y = y, z = z, w = w };
|
||||||
}
|
}
|
||||||
|
|
@ -351,5 +351,16 @@ quat :: (x: float = 0, y: float = 0, z: float = 0, w: float = 0) -> Quat #expand
|
||||||
|
|
||||||
#scope_file
|
#scope_file
|
||||||
|
|
||||||
types :: #import,file "../types/module.jai";
|
math :: #import "Math";
|
||||||
math :: #import "Math"; // @future
|
|
||||||
|
is_type_integer :: (t: Type) -> bool {
|
||||||
|
return t.(*Type_Info).type == .INTEGER;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_type_float :: (t: Type) -> bool {
|
||||||
|
return t.(*Type_Info).type == .FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_type_scalar :: (t: Type) -> bool {
|
||||||
|
return is_type_integer(t) || is_type_float(t);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,13 @@
|
||||||
#module_parameters(RUN_TESTS := false);
|
|
||||||
|
|
||||||
Kilobyte :: 1024;
|
Kilobyte :: 1024;
|
||||||
Megabyte :: 1024 * Kilobyte;
|
Megabyte :: 1024 * Kilobyte;
|
||||||
Gigabyte :: 1024 * Megabyte;
|
Gigabyte :: 1024 * Megabyte;
|
||||||
|
|
||||||
Default_Align :: #run 2 * align_of(*void);
|
power_of_two :: (x: uint) -> bool {
|
||||||
|
|
||||||
align_of :: ($T: Type) -> u64 #expand {
|
|
||||||
return #run -> u64 {
|
|
||||||
info := type_info(struct{ p: u8; t: T; });
|
|
||||||
return info.members[1].offset_in_bytes.(u64);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
default_of :: ($T: Type) -> T #expand {
|
|
||||||
default: T;
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
zero_of :: ($T: Type) -> T #expand {
|
|
||||||
zero: T = ---;
|
|
||||||
memset(*zero, 0, size_of(T));
|
|
||||||
return zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitcast :: ($T: Type, expr: Code) -> T #expand {
|
|
||||||
value := expr;
|
|
||||||
return (*value).(*T).*;
|
|
||||||
}
|
|
||||||
|
|
||||||
power_of_two :: (x: u64) -> bool {
|
|
||||||
if x == 0 return false;
|
if x == 0 return false;
|
||||||
return x & (x - 1) == 0;
|
return x & (x - 1) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
align_forward :: (ptr: u64, align: u64 = Default_Align) -> u64 {
|
align_forward :: (ptr: uint, align: uint = Default_Align) -> uint {
|
||||||
basic.assert(power_of_two(align), "alignment must be a power of two");
|
basic.assert(power_of_two(align), "alignment must be a power of two");
|
||||||
|
|
||||||
p := ptr;
|
p := ptr;
|
||||||
|
|
@ -59,7 +32,7 @@ init_or_zero :: inline (ptr: *$T, custom_init: (*T) = null) {
|
||||||
|
|
||||||
make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
||||||
#modify {
|
#modify {
|
||||||
ok, info := types.is_array(T);
|
ok, info := type_is_array(T);
|
||||||
if ok && info.array_type == .RESIZABLE {
|
if ok && info.array_type == .RESIZABLE {
|
||||||
T = compiler.get_type(info.element_type);
|
T = compiler.get_type(info.element_type);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -68,7 +41,7 @@ make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
size := align_forward(size_of(T) * basic.max(reserved, 0).(u64)).(s64);
|
size := align_forward(size_of(T) * basic.max(reserved, 0).(uint)).(sint);
|
||||||
data := basic.alloc(size);
|
data := basic.alloc(size);
|
||||||
|
|
||||||
#if init if size != 0 {
|
#if init if size != 0 {
|
||||||
|
|
@ -84,7 +57,7 @@ make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
||||||
}
|
}
|
||||||
|
|
||||||
make :: ($T: Type, $init := true) -> *T
|
make :: ($T: Type, $init := true) -> *T
|
||||||
#modify { return !types.is_array(T); }
|
#modify { return !type_is_array(T); }
|
||||||
{
|
{
|
||||||
ptr := basic.alloc(size_of(T)).(*T);
|
ptr := basic.alloc(size_of(T)).(*T);
|
||||||
#if init init_or_zero(ptr);
|
#if init init_or_zero(ptr);
|
||||||
|
|
@ -154,7 +127,7 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
|
||||||
basic.assert(power_of_two(alignment));
|
basic.assert(power_of_two(alignment));
|
||||||
|
|
||||||
end := a.memory.(*u8) + a.offset;
|
end := a.memory.(*u8) + a.offset;
|
||||||
ptr := align_forward(end.(u64), alignment);
|
ptr := align_forward(end.(uint), alignment);
|
||||||
total_size := (count + ptr.(*u8) - end.(*u8)).(u64);
|
total_size := (count + ptr.(*u8) - end.(*u8)).(u64);
|
||||||
|
|
||||||
basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc);
|
basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc);
|
||||||
|
|
@ -163,17 +136,11 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
|
||||||
return ptr.(*void);
|
return ptr.(*void);
|
||||||
}
|
}
|
||||||
|
|
||||||
#scope_module;
|
|
||||||
|
|
||||||
types :: #import,file "../types/module.jai";
|
|
||||||
|
|
||||||
#scope_file;
|
#scope_file;
|
||||||
|
|
||||||
basic :: #import "Basic"; // @future
|
|
||||||
compiler :: #import "Compiler"; // @future
|
|
||||||
|
|
||||||
#if RUN_TESTS #run {
|
#if RUN_TESTS #run {
|
||||||
test :: #import,file "../test/module.jai";
|
test :: #import,file "./test/module.jai";
|
||||||
|
|
||||||
test.run("make:dynamic arrays", (t) => {
|
test.run("make:dynamic arrays", (t) => {
|
||||||
a1 := make([..]int);
|
a1 := make([..]int);
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
#module_parameters(RUN_TESTS := false);
|
|
||||||
|
|
||||||
// Can be passed directly to using,map
|
|
||||||
remap_snake_to_pascal :: (names: []string) {
|
|
||||||
for names {
|
|
||||||
names[it_index] = snake_to_pascal(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
snake_to_pascal :: (name: string) -> string {
|
|
||||||
basic :: #import "Basic"; // @future
|
|
||||||
b: basic.String_Builder;
|
|
||||||
|
|
||||||
upper := true;
|
|
||||||
for i: 0..name.count - 1 {
|
|
||||||
c := name[i];
|
|
||||||
if c == #char "_" {
|
|
||||||
upper = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if upper {
|
|
||||||
basic.append(*b, basic.to_upper(c));
|
|
||||||
upper = false;
|
|
||||||
} else {
|
|
||||||
basic.append(*b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return basic.builder_to_string(*b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#load "macros.jai";
|
|
||||||
|
|
||||||
#scope_module;
|
|
||||||
|
|
||||||
#if RUN_TESTS {
|
|
||||||
test :: #import,file "../test/module.jai";
|
|
||||||
|
|
||||||
#run test.run("snake_to_pascal", t => {
|
|
||||||
test.expect(t, snake_to_pascal("some_name") == "SomeName");
|
|
||||||
test.expect(t, snake_to_pascal("_some_name") == "SomeName");
|
|
||||||
test.expect(t, snake_to_pascal("some__name") == "SomeName");
|
|
||||||
test.expect(t, snake_to_pascal("some_name_") == "SomeName");
|
|
||||||
test.expect(t, snake_to_pascal("X_Y_Z") == "XYZ");
|
|
||||||
test.expect(t, snake_to_pascal("XY_Z") == "XYZ");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
19
module.jai
Normal file
19
module.jai
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#module_parameters(RUN_TESTS := false);
|
||||||
|
|
||||||
|
#load "base.jai";
|
||||||
|
#load "utils.jai";
|
||||||
|
#load "memory.jai";
|
||||||
|
#load "macros.jai";
|
||||||
|
#load "array.jai";
|
||||||
|
|
||||||
|
|
||||||
|
#scope_module;
|
||||||
|
|
||||||
|
basic :: #import "Basic";
|
||||||
|
compiler :: #import "Compiler";
|
||||||
|
|
||||||
|
#if RUN_TESTS {
|
||||||
|
// so files within this module can use 'test' without directly importing it.
|
||||||
|
test :: #import,file "test/module.jai";
|
||||||
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue