move types into meta module
This commit is contained in:
parent
9d045e0717
commit
07570f459c
6 changed files with 64 additions and 60 deletions
28
math/vec.jai
28
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 types.is_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return meta.type_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 types.is_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return meta.type_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 types.is_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return meta.type_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 types.is_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return meta.type_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 types.is_scalar(R), "type is not integer or float"; } {
|
||||
#modify { return meta.type_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 types.is_float(T), "Used non-float vector on round"; } {
|
||||
#modify { return meta.type_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 types.is_float(T), "use v2i for integer arguments"; }
|
||||
#modify { return meta.type_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 types.is_integer(T), "use v2f for float arguments"; }
|
||||
#modify { return meta.type_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 types.is_float(T), "use v3i for integer arguments"; }
|
||||
#modify { return meta.type_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 types.is_integer(T), "use v3f for float arguments"; }
|
||||
#modify { return meta.type_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 types.is_float(T), "use v4i for integer arguments"; }
|
||||
#modify { return meta.type_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 types.is_integer(T), "use v4f for float arguments"; }
|
||||
#modify { return meta.type_is_integer(T), "use v4f for float arguments"; }
|
||||
#expand {
|
||||
return .{ x = x, y = y, z = z, w = w };
|
||||
}
|
||||
|
|
@ -351,5 +351,5 @@ quat :: (x: float = 0, y: float = 0, z: float = 0, w: float = 0) -> Quat #expand
|
|||
|
||||
#scope_file
|
||||
|
||||
types :: #import,file "../types/module.jai";
|
||||
math :: #import "Math"; // @future
|
||||
meta :: #import,file "../meta/module.jai";
|
||||
math :: #import "Math"; // @future
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ init_or_zero :: inline (ptr: *$T, custom_init: (*T) = null) {
|
|||
|
||||
make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
||||
#modify {
|
||||
ok, info := types.is_array(T);
|
||||
ok, info := meta.type_is_array(T);
|
||||
if ok && info.array_type == .RESIZABLE {
|
||||
T = compiler.get_type(info.element_type);
|
||||
return true;
|
||||
|
|
@ -84,7 +84,7 @@ make :: ($T: Type, reserved := 0, $init := true) -> [..]T
|
|||
}
|
||||
|
||||
make :: ($T: Type, $init := true) -> *T
|
||||
#modify { return !types.is_array(T); }
|
||||
#modify { return !meta.type_is_array(T); }
|
||||
{
|
||||
ptr := basic.alloc(size_of(T)).(*T);
|
||||
#if init init_or_zero(ptr);
|
||||
|
|
@ -163,12 +163,15 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
|
|||
return ptr.(*void);
|
||||
}
|
||||
|
||||
#scope_module;
|
||||
|
||||
types :: #import,file "../types/module.jai";
|
||||
|
||||
#scope_file;
|
||||
|
||||
// @note(judah): this will cause a cyclic import cycle if we import meta's module.jai
|
||||
// @todo(judah): switch to abslote imports everywhere (ie. "jc/meta")
|
||||
meta :: #import,file "../meta/type_info.jai";
|
||||
|
||||
|
||||
basic :: #import "Basic"; // @future
|
||||
compiler :: #import "Compiler"; // @future
|
||||
|
||||
|
|
|
|||
|
|
@ -297,8 +297,6 @@ 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
|
||||
|
|
|
|||
|
|
@ -30,11 +30,14 @@ snake_to_pascal :: (name: string) -> string {
|
|||
return basic.builder_to_string(*b);
|
||||
}
|
||||
|
||||
|
||||
#load "macros.jai";
|
||||
#load "type_info.jai";
|
||||
|
||||
|
||||
#scope_module;
|
||||
|
||||
mem :: #import,file "../memory/module.jai";
|
||||
|
||||
#if RUN_TESTS {
|
||||
test :: #import,file "../test/module.jai";
|
||||
|
||||
|
|
|
|||
39
meta/type_info.jai
Normal file
39
meta/type_info.jai
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// These return the bool first so you can check in a conditional,
|
||||
// rather than having to do '_, ok := ...'
|
||||
|
||||
check_type_tag :: ($$T: Type, tag: Type_Info_Tag) -> bool, *Type_Info {
|
||||
#if is_constant(T) {
|
||||
info :: type_info(T);
|
||||
if info.type == tag return true, info;
|
||||
}
|
||||
else {
|
||||
info := T.(*Type_Info);
|
||||
if info.type == tag return true, info;
|
||||
}
|
||||
|
||||
return false, null;
|
||||
}
|
||||
|
||||
type_is_integer :: ($$T: Type) -> bool, *Type_Info_Integer {
|
||||
ok, info := check_type_tag(T, .INTEGER);
|
||||
return ok, info.(*Type_Info_Integer);
|
||||
}
|
||||
|
||||
type_is_float :: ($$T: Type) -> bool, *Type_Info_Float {
|
||||
ok, info := check_type_tag(T, .FLOAT);
|
||||
return ok, info.(*Type_Info_Float);
|
||||
}
|
||||
|
||||
type_is_scalar :: (t: Type) -> bool {
|
||||
return type_is_integer(t) || type_is_float(t);
|
||||
}
|
||||
|
||||
type_is_array :: ($$T: Type) -> bool, *Type_Info_Array {
|
||||
ok, info := check_type_tag(T, .ARRAY);
|
||||
return ok, info.(*Type_Info_Array);
|
||||
}
|
||||
|
||||
type_is_struct :: ($$T: Type) -> bool, *Type_Info_Struct {
|
||||
ok, info := check_type_tag(T, .STRUCT);
|
||||
return ok, info.(*Type_Info_Struct);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// These return the bool first so you can check in a conditional,
|
||||
// rather than having to do '_, ok := ...'
|
||||
|
||||
check_tag :: ($$T: Type, tag: Type_Info_Tag) -> bool, *Type_Info {
|
||||
#if is_constant(T) {
|
||||
info :: type_info(T);
|
||||
if info.type == tag return true, info;
|
||||
}
|
||||
else {
|
||||
info := T.(*Type_Info);
|
||||
if info.type == tag return true, info;
|
||||
}
|
||||
|
||||
return false, null;
|
||||
}
|
||||
|
||||
is_integer :: ($$T: Type) -> bool, *Type_Info_Integer {
|
||||
ok, info := check_tag(T, .INTEGER);
|
||||
return ok, info.(*Type_Info_Integer);
|
||||
}
|
||||
|
||||
is_float :: ($$T: Type) -> bool, *Type_Info_Float {
|
||||
ok, info := check_tag(T, .FLOAT);
|
||||
return ok, info.(*Type_Info_Float);
|
||||
}
|
||||
|
||||
is_scalar :: (t: Type) -> bool {
|
||||
return is_integer(t) || is_float(t);
|
||||
}
|
||||
|
||||
is_array :: ($$T: Type) -> bool, *Type_Info_Array {
|
||||
ok, info := check_tag(T, .ARRAY);
|
||||
return ok, info.(*Type_Info_Array);
|
||||
}
|
||||
|
||||
is_struct :: ($$T: Type) -> bool, *Type_Info_Struct {
|
||||
ok, info := check_tag(T, .STRUCT);
|
||||
return ok, info.(*Type_Info_Struct);
|
||||
}
|
||||
Loading…
Reference in a new issue