Compare commits
2 commits
80b47d63cb
...
9d045e0717
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d045e0717 | |||
| c33f635536 |
123 changed files with 183 additions and 199 deletions
2
TODO
2
TODO
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
[Judah]
|
||||
000 [math] add easing procedures
|
||||
010 [x] make base jai files standalone (ie. [array], [memory], etc... big maybe)
|
||||
|
||||
[Jesse]
|
||||
001 [arch] create module to determine simd support
|
||||
|
|
@ -51,3 +50,4 @@
|
|||
|
||||
|
||||
*** DONE ***
|
||||
010 [x] make base jai files standalone (ie. [array], [memory], etc... big maybe)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
compiler :: #import "Compiler";
|
||||
compiler.set_build_options_dc(.{ do_output = false });
|
||||
|
||||
#import,file "./module.jai"(true);
|
||||
#import,file "./array/module.jai"(true);
|
||||
#import,file "./encoding/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);
|
||||
// dmath :: #import,file "./math/module.jai"(.degrees, true);
|
||||
|
|
|
|||
9
array/module.jai
Normal file
9
array/module.jai
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#module_parameters(RUN_TESTS := false);
|
||||
|
||||
#load "static_array.jai";
|
||||
|
||||
#scope_module;
|
||||
|
||||
#if RUN_TESTS {
|
||||
test :: #import,file "../test/module.jai";
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ Static_Array :: struct(capacity: int, T: Type) {
|
|||
items: [capacity]T;
|
||||
count: int;
|
||||
|
||||
Default :: #run default_of(T);
|
||||
Default :: #run mem.default_of(T);
|
||||
}
|
||||
|
||||
operator [] :: inline (a: Static_Array, index: int, loc := #caller_location) -> a.T #no_abc {
|
||||
|
|
@ -77,12 +77,15 @@ make_dynamic :: (a: *Static_Array) -> [..]a.T {
|
|||
|
||||
#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 {
|
||||
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 {
|
||||
test :: #import,file "./test/module.jai";
|
||||
test :: #import,file "../test/module.jai";
|
||||
|
||||
test.run("basic operations", (t) => {
|
||||
a: Static_Array(10, int);
|
||||
29
base.jai
29
base.jai
|
|
@ -1,29 +0,0 @@
|
|||
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;
|
||||
data: []u8;
|
||||
error: string;
|
||||
offset: uint;
|
||||
line: uint;
|
||||
offset: u64;
|
||||
line: u64;
|
||||
}
|
||||
|
||||
Token :: struct {
|
||||
|
|
@ -387,7 +387,7 @@ get_next_token :: (p: *Parser) -> Token {
|
|||
}
|
||||
|
||||
// Comments
|
||||
if c == #char "/" && p.offset + 1 < p.data.count.(uint) && p.data[p.offset+1] == #char "/" {
|
||||
if c == #char "/" && p.offset + 1 < p.data.count.(u64) && p.data[p.offset+1] == #char "/" {
|
||||
capture_while(p, c => c != #char "\n");
|
||||
return get_next_token(p);
|
||||
}
|
||||
|
|
@ -583,7 +583,7 @@ skip_whitespace :: (p: *Parser) {
|
|||
}
|
||||
|
||||
capture_while :: (p: *Parser, proc: (u8) -> bool) -> string {
|
||||
basic.assert(p.offset < p.data.count.(uint));
|
||||
basic.assert(p.offset < p.data.count.(u64));
|
||||
|
||||
capture := p.data;
|
||||
capture.data += p.offset;
|
||||
|
|
@ -595,17 +595,15 @@ capture_while :: (p: *Parser, proc: (u8) -> bool) -> string {
|
|||
p.offset += 1;
|
||||
}
|
||||
|
||||
capture.count = ((p.data.data + p.offset) - capture.data).(sint);
|
||||
capture.count = ((p.data.data + p.offset) - capture.data).(s64);
|
||||
return capture.(string);
|
||||
}
|
||||
|
||||
at_end :: inline (p: *Parser) -> bool {
|
||||
return p.offset >= p.data.count.(uint);
|
||||
return p.offset >= p.data.count.(u64);
|
||||
}
|
||||
|
||||
basic :: #import "Basic";
|
||||
strings :: #import "String";
|
||||
|
||||
#import,file "../base.jai";
|
||||
|
||||
|
||||
|
|
|
|||
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
|
||||
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
||||
res: Vec(l.N, l.T) = ---;
|
||||
for l res[it_index] = it + r;
|
||||
return res;
|
||||
}
|
||||
|
||||
operator - :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
||||
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
||||
res: Vec(l.N, l.T) = ---;
|
||||
for l res[it_index] = it - r;
|
||||
return res;
|
||||
}
|
||||
operator - :: inline (l: $R, r: Vec) -> Vec(l.N, l.T) #no_abc
|
||||
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
||||
res: Vec(l.N, l.T) = ---;
|
||||
for l res[it_index] = r - it;
|
||||
return res;
|
||||
}
|
||||
|
||||
operator * :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc #symmetric
|
||||
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
||||
res: Vec(l.N, l.T) = ---;
|
||||
for l res[it_index] = it*r;
|
||||
return res;
|
||||
}
|
||||
|
||||
operator / :: inline (l: Vec, r: $R) -> Vec(l.N, l.T) #no_abc
|
||||
#modify { return is_type_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return types.is_scalar(R), "type is not integer or float"; } {
|
||||
res: Vec(l.N, l.T) = ---;
|
||||
for l res[it_index] = it/r;
|
||||
return res;
|
||||
|
|
@ -289,7 +289,7 @@ reflect :: (v: Vec2, p: Vec2) -> Vec2 #no_abc {
|
|||
}
|
||||
|
||||
round :: (v: Vec($N, $T)) -> Vec(N, T) #no_abc
|
||||
#modify { return is_type_float(T), "Used non-float vector on round"; } {
|
||||
#modify { return types.is_float(T), "Used non-float vector on round"; } {
|
||||
r: Vec(N, T) = ---;
|
||||
n := N - 1;
|
||||
while n >= 0 {
|
||||
|
|
@ -310,37 +310,37 @@ Vec4 :: Vec(4, float);
|
|||
Quat :: Vec4;
|
||||
|
||||
v2f :: (x: $T = 0, y: T = 0) -> Vec2
|
||||
#modify { return is_type_float(T), "use v2i for integer arguments"; }
|
||||
#modify { return types.is_float(T), "use v2i for integer arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y };
|
||||
}
|
||||
|
||||
v2i :: (x: $T = 0, y: T = 0) -> Vec(2, T)
|
||||
#modify { return is_type_integer(T), "use v2f for float arguments"; }
|
||||
#modify { return types.is_integer(T), "use v2f for float arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y };
|
||||
}
|
||||
|
||||
v3f :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec3
|
||||
#modify { return is_type_float(T), "use v3i for integer arguments"; }
|
||||
#modify { return types.is_float(T), "use v3i for integer arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y, z = z };
|
||||
}
|
||||
|
||||
v3i :: (x: $T = 0, y: T = 0, z: T = 0) -> Vec(3, T)
|
||||
#modify { return is_type_integer(T), "use v3f for float arguments"; }
|
||||
#modify { return types.is_integer(T), "use v3f for float arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y, z = z };
|
||||
}
|
||||
|
||||
v4f :: (x: $T = 0, y: T = 0, z: T = 0, w: T = 0) -> Vec4
|
||||
#modify { return is_type_float(T), "use v4i for integer arguments"; }
|
||||
#modify { return types.is_float(T), "use v4i for integer arguments"; }
|
||||
#expand {
|
||||
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)
|
||||
#modify { return is_type_integer(T), "use v4f for float arguments"; }
|
||||
#modify { return types.is_integer(T), "use v4f for float arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y, z = z, w = w };
|
||||
}
|
||||
|
|
@ -351,16 +351,5 @@ quat :: (x: float = 0, y: float = 0, z: float = 0, w: float = 0) -> Quat #expand
|
|||
|
||||
#scope_file
|
||||
|
||||
math :: #import "Math";
|
||||
|
||||
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);
|
||||
}
|
||||
types :: #import,file "../types/module.jai";
|
||||
math :: #import "Math"; // @future
|
||||
|
|
|
|||
|
|
@ -1,13 +1,40 @@
|
|||
#module_parameters(RUN_TESTS := false);
|
||||
|
||||
Kilobyte :: 1024;
|
||||
Megabyte :: 1024 * Kilobyte;
|
||||
Gigabyte :: 1024 * Megabyte;
|
||||
|
||||
power_of_two :: (x: uint) -> bool {
|
||||
Default_Align :: #run 2 * align_of(*void);
|
||||
|
||||
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;
|
||||
return x & (x - 1) == 0;
|
||||
}
|
||||
|
||||
align_forward :: (ptr: uint, align: uint = Default_Align) -> uint {
|
||||
align_forward :: (ptr: u64, align: u64 = Default_Align) -> u64 {
|
||||
basic.assert(power_of_two(align), "alignment must be a power of two");
|
||||
|
||||
p := ptr;
|
||||
|
|
@ -32,7 +59,7 @@ init_or_zero :: inline (ptr: *$T, custom_init: (*T) = null) {
|
|||
|
||||
make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
||||
#modify {
|
||||
ok, info := type_is_array(T);
|
||||
ok, info := types.is_array(T);
|
||||
if ok && info.array_type == .RESIZABLE {
|
||||
T = compiler.get_type(info.element_type);
|
||||
return true;
|
||||
|
|
@ -41,7 +68,7 @@ make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
|||
return false;
|
||||
}
|
||||
{
|
||||
size := align_forward(size_of(T) * basic.max(reserved, 0).(uint)).(sint);
|
||||
size := align_forward(size_of(T) * basic.max(reserved, 0).(u64)).(s64);
|
||||
data := basic.alloc(size);
|
||||
|
||||
#if init if size != 0 {
|
||||
|
|
@ -57,7 +84,7 @@ make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
|||
}
|
||||
|
||||
make :: ($T: Type, $init := true) -> *T
|
||||
#modify { return !type_is_array(T); }
|
||||
#modify { return !types.is_array(T); }
|
||||
{
|
||||
ptr := basic.alloc(size_of(T)).(*T);
|
||||
#if init init_or_zero(ptr);
|
||||
|
|
@ -127,7 +154,7 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
|
|||
basic.assert(power_of_two(alignment));
|
||||
|
||||
end := a.memory.(*u8) + a.offset;
|
||||
ptr := align_forward(end.(uint), alignment);
|
||||
ptr := align_forward(end.(u64), alignment);
|
||||
total_size := (count + ptr.(*u8) - end.(*u8)).(u64);
|
||||
|
||||
basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc);
|
||||
|
|
@ -136,11 +163,17 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
|
|||
return ptr.(*void);
|
||||
}
|
||||
|
||||
#scope_module;
|
||||
|
||||
types :: #import,file "../types/module.jai";
|
||||
|
||||
#scope_file;
|
||||
|
||||
basic :: #import "Basic"; // @future
|
||||
compiler :: #import "Compiler"; // @future
|
||||
|
||||
#if RUN_TESTS #run {
|
||||
test :: #import,file "./test/module.jai";
|
||||
test :: #import,file "../test/module.jai";
|
||||
|
||||
test.run("make:dynamic arrays", (t) => {
|
||||
a1 := make([..]int);
|
||||
|
|
@ -129,8 +129,8 @@ c_call :: (call: Code, ctx: #Context) #expand {
|
|||
for_expansion :: (v: *Named_Block, code: Code, _: For_Flags) #expand {
|
||||
#insert #run basic.tprint(#string END
|
||||
for `%: 0..0 {
|
||||
`it :: #run zero_of(void);
|
||||
`it_index :: #run zero_of(void);
|
||||
`it :: #run mem.zero_of(void);
|
||||
`it_index :: #run mem.zero_of(void);
|
||||
#insert,scope(code) code;
|
||||
}
|
||||
END,
|
||||
|
|
@ -242,9 +242,6 @@ Unrolled_Loop :: struct(N: int, T: Type = void) {
|
|||
}
|
||||
}
|
||||
|
||||
pp :: #import "Program_Print";
|
||||
compiler :: #import "Compiler";
|
||||
|
||||
#if RUN_TESTS #run {
|
||||
test.run("this_block", (t) => {
|
||||
i := 0;
|
||||
|
|
@ -300,3 +297,8 @@ compiler :: #import "Compiler";
|
|||
});
|
||||
}
|
||||
|
||||
mem :: #import,file "../memory/module.jai";
|
||||
|
||||
basic :: #import "Basic"; // @future
|
||||
pp :: #import "Program_Print"; // @future
|
||||
compiler :: #import "Compiler"; // @future
|
||||
49
meta/module.jai
Normal file
49
meta/module.jai
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#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
19
module.jai
|
|
@ -1,19 +0,0 @@
|
|||
#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";
|
||||
}
|
||||
|
||||
|
|
@ -12,8 +12,8 @@
|
|||
*/
|
||||
T :: struct {
|
||||
location: Source_Code_Location;
|
||||
expects_run: sint;
|
||||
expects_ok: sint;
|
||||
expects_run: s64;
|
||||
expects_ok: s64;
|
||||
failed: bool;
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,11 @@ expect :: (t: *T, cond: bool, message := "", args: ..Any, loc := #caller_locatio
|
|||
}
|
||||
|
||||
run :: (name: string, proc: Proc, loc := #caller_location) {
|
||||
filename := strings.path_filename(loc.fully_pathed_filename);
|
||||
basic.print("%,%: %...", filename, loc.line_number, name);
|
||||
idx := strings.find_index_from_left(loc.fully_pathed_filename, "./") + 2;
|
||||
path := loc.fully_pathed_filename;
|
||||
path.data += idx;
|
||||
path.count -= idx;
|
||||
basic.print("%,%: %...", path, loc.line_number, name);
|
||||
|
||||
t: T;
|
||||
proc(*t);
|
||||
|
|
@ -58,8 +61,6 @@ run :: (name: string, proc: Proc, loc := #caller_location) {
|
|||
|
||||
#scope_file;
|
||||
|
||||
#import,file "../base.jai";
|
||||
|
||||
basic :: #import "Basic";
|
||||
strings :: #import "String";
|
||||
compiler :: #import "Compiler";
|
||||
basic :: #import "Basic"; // @future
|
||||
strings :: #import "String"; // @future
|
||||
compiler :: #import "Compiler"; // @future
|
||||
|
|
|
|||
0
hmm/README → thirdparty/hmm/README
vendored
0
hmm/README → thirdparty/hmm/README
vendored
0
hmm/module.jai → thirdparty/hmm/module.jai
vendored
0
hmm/module.jai → thirdparty/hmm/module.jai
vendored
0
raylib/README → thirdparty/raylib/README
vendored
0
raylib/README → thirdparty/raylib/README
vendored
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue