mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Increase precedence of (Foo) { 1, 2 }
- Add `--enable-new-generics` to enable `Foo{int}` generic syntax.
This commit is contained in:
committed by
Christoffer Lerno
parent
c41d551ead
commit
e77d1fb646
@@ -11,21 +11,21 @@ union Complex
|
||||
|
||||
const Complex IDENTITY = { 1, 0 };
|
||||
const Complex IMAGINARY = { 0, 1 };
|
||||
macro Complex Complex.add(self, Complex b) => Complex { .v = self.v + b.v };
|
||||
macro Complex Complex.add_each(self, Real b) => Complex { .v = self.v + b };
|
||||
macro Complex Complex.sub(self, Complex b) => Complex { .v = self.v - b.v };
|
||||
macro Complex Complex.sub_each(self, Real b) => Complex { .v = self.v - b };
|
||||
macro Complex Complex.scale(self, Real s) => Complex { .v = self.v * s };
|
||||
macro Complex Complex.add(self, Complex b) => { .v = self.v + b.v };
|
||||
macro Complex Complex.add_each(self, Real b) => { .v = self.v + b };
|
||||
macro Complex Complex.sub(self, Complex b) => { .v = self.v - b.v };
|
||||
macro Complex Complex.sub_each(self, Real b) => { .v = self.v - b };
|
||||
macro Complex Complex.scale(self, Real s) => { .v = self.v * s };
|
||||
macro Complex Complex.mul(self, Complex b) => { self.r * b.r - self.c * b.c, self.r * b.c + b.r * self.c };
|
||||
macro Complex Complex.div(self, Complex b)
|
||||
{
|
||||
Real div = b.v.dot(b.v);
|
||||
return Complex{ (self.r * b.r + self.c * b.c) / div, (self.c * b.r - self.r * b.c) / div };
|
||||
return { (self.r * b.r + self.c * b.c) / div, (self.c * b.r - self.r * b.c) / div };
|
||||
}
|
||||
macro Complex Complex.inverse(self)
|
||||
{
|
||||
Real sqr = self.v.dot(self.v);
|
||||
return Complex{ self.r / sqr, -self.c / sqr };
|
||||
return { self.r / sqr, -self.c / sqr };
|
||||
}
|
||||
macro Complex Complex.conjugate(self) => Complex { .r = self.r, .c = -self.c };
|
||||
macro Complex Complex.conjugate(self) => { .r = self.r, .c = -self.c };
|
||||
macro bool Complex.equals(self, Complex b) => self.v == b.v;
|
||||
|
||||
@@ -420,19 +420,19 @@ const Matrix4x4 IDENTITY4 = { .m = { [0] = 1, [5] = 1, [10] = 1, [15] = 1 } };
|
||||
macro matrix_component_mul(mat, val) @private
|
||||
{
|
||||
var $Type = Real[<$typeof(mat.m).len>];
|
||||
return $typeof(*mat) { .m = val * ($Type)mat.m };
|
||||
return ($typeof(*mat)) { .m = val * ($Type)mat.m };
|
||||
}
|
||||
|
||||
macro matrix_add(mat, mat2) @private
|
||||
{
|
||||
var $Type = Real[<$typeof(mat.m).len>];
|
||||
return $typeof(*mat) { .m = ($Type)mat.m + ($Type)mat2.m };
|
||||
return ($typeof(*mat)) { .m = ($Type)mat.m + ($Type)mat2.m };
|
||||
}
|
||||
|
||||
macro matrix_sub(mat, mat2) @private
|
||||
{
|
||||
var $Type = Real[<$typeof(mat.m).len>];
|
||||
return $typeof(*mat) { .m = ($Type)mat.m - ($Type)mat2.m };
|
||||
return ($typeof(*mat)) { .m = ($Type)mat.m - ($Type)mat2.m };
|
||||
}
|
||||
|
||||
macro matrix_look_at($Type, eye, target, up) @private
|
||||
@@ -441,7 +441,7 @@ macro matrix_look_at($Type, eye, target, up) @private
|
||||
var vx = up.cross(vz).normalize();
|
||||
var vy = vz.cross(vx);
|
||||
|
||||
return $Type {
|
||||
return ($Type){
|
||||
vx[0], vx[1], vx[2], - (Real)vx.dot(eye),
|
||||
vy[0], vy[1], vy[2], - (Real)vy.dot(eye),
|
||||
vz[0], vz[1], vz[2], - (Real)vz.dot(eye),
|
||||
|
||||
@@ -11,11 +11,11 @@ union Quaternion
|
||||
|
||||
const Quaternion IDENTITY = { 0, 0, 0, 1 };
|
||||
|
||||
macro Quaternion Quaternion.add(Quaternion a, Quaternion b) => Quaternion { .v = a.v + b.v };
|
||||
macro Quaternion Quaternion.add_each(Quaternion a, Real b) => Quaternion { .v = a.v + b };
|
||||
macro Quaternion Quaternion.sub(Quaternion a, Quaternion b) => Quaternion { .v = a.v - b.v };
|
||||
macro Quaternion Quaternion.sub_each(Quaternion a, Real b) => Quaternion { .v = a.v - b };
|
||||
macro Quaternion Quaternion.scale(Quaternion a, Real s) => Quaternion { .v = a.v * s };
|
||||
macro Quaternion Quaternion.add(Quaternion a, Quaternion b) => { .v = a.v + b.v };
|
||||
macro Quaternion Quaternion.add_each(Quaternion a, Real b) => { .v = a.v + b };
|
||||
macro Quaternion Quaternion.sub(Quaternion a, Quaternion b) => { .v = a.v - b.v };
|
||||
macro Quaternion Quaternion.sub_each(Quaternion a, Real b) => { .v = a.v - b };
|
||||
macro Quaternion Quaternion.scale(Quaternion a, Real s) => { .v = a.v * s };
|
||||
macro Quaternion Quaternion.normalize(Quaternion q) => { .v = q.v.normalize() };
|
||||
macro Real Quaternion.length(Quaternion q) => q.v.length();
|
||||
macro Quaternion Quaternion.lerp(Quaternion q1, Quaternion q2, Real amount) => { .v = q1.v.lerp(q2.v, amount) };
|
||||
@@ -76,7 +76,7 @@ macro into_matrix(Quaternion* q, $Type) @private
|
||||
var z = rotation.k;
|
||||
var w = rotation.l;
|
||||
|
||||
return $Type {
|
||||
return ($Type) {
|
||||
1 - 2*y*y - 2*z*z, 2*x*y - 2*z*w, 2*x*z + 2*y*w, 0,
|
||||
2*x*y + 2*z*w, 1 - 2*x*x - 2*z*z, 2*y*z - 2*x*w, 0,
|
||||
2*x*z - 2*y*w, 2*y*z + 2*x*w , 1 - 2*x*x - 2*y*y, 0,
|
||||
|
||||
@@ -145,7 +145,7 @@ macro transform2(v, mat) @private
|
||||
|
||||
macro transform3(v, mat) @private
|
||||
{
|
||||
return $typeof(v) {
|
||||
return ($typeof(v)){
|
||||
mat.m00 * v[0] + mat.m10 * v[1] + mat.m20 * v[2] + mat.m30,
|
||||
mat.m01 * v[0] + mat.m11 * v[1] + mat.m21 * v[2] + mat.m31,
|
||||
mat.m02 * v[0] + mat.m12 * v[1] + mat.m22 * v[2] + mat.m32
|
||||
@@ -169,7 +169,7 @@ macro void ortho_normalize3(v1, v2) @private
|
||||
|
||||
macro rotate_by_quat3(v, q) @private
|
||||
{
|
||||
return $typeof(v) {
|
||||
return ($typeof(v)){
|
||||
v[0] * (q.i * q.i + q.l * q.l - q.j * q.j - q.k * q.k)
|
||||
+ v[1] * (2 * q.i * q.j - 2 * q.l * q.k)
|
||||
+ v[2] * (2 * q.i * q.k - 2 * q.l * q.j),
|
||||
@@ -233,7 +233,7 @@ macro barycenter3(p, a, b, c) @private
|
||||
var denom = d00 * d11 - d01 * d01;
|
||||
var y = (d11 * d20 - d01 * d21) / denom;
|
||||
var z = (d00 * d21 - d01 * d20) / denom;
|
||||
return $typeof(p) { 1 - y - z, y, z };
|
||||
return ($typeof(p)){ 1 - y - z, y, z };
|
||||
}
|
||||
|
||||
macro refract3(v, n, r) @private
|
||||
|
||||
Reference in New Issue
Block a user