Changeset fd54fef for libcfa/src/vec


Ignore:
Timestamp:
Jan 19, 2021, 8:44:29 PM (11 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
dafbde8
Parents:
2f47ea4
Message:

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

Location:
libcfa/src/vec
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vec/vec.hfa

    r2f47ea4 rfd54fef  
    1818#include <math.hfa>
    1919
    20 trait fromint(otype T) {
     20trait fromint(T) {
    2121    void ?{}(T&, int);
    2222};
    23 trait zeroinit(otype T) {
     23trait zeroinit(T) {
    2424    void ?{}(T&, zero_t);
    2525};
    26 trait zero_assign(otype T) {
     26trait zero_assign(T) {
    2727    T ?=?(T&, zero_t);
    2828};
    29 trait subtract(otype T) {
     29trait subtract(T) {
    3030    T ?-?(T, T);
    3131};
    32 trait negate(otype T) {
     32trait negate(T) {
    3333    T -?(T);
    3434};
    35 trait add(otype T) {
     35trait add(T) {
    3636    T ?+?(T, T);
    3737};
    38 trait multiply(otype T) {
     38trait multiply(T) {
    3939    T ?*?(T, T);
    4040};
    41 trait divide(otype T) {
     41trait divide(T) {
    4242    T ?/?(T, T);
    4343};
    44 trait lessthan(otype T) {
     44trait lessthan(T) {
    4545    int ?<?(T, T);
    4646};
    47 trait equality(otype T) {
     47trait equality(T) {
    4848    int ?==?(T, T);
    4949};
    50 trait sqrt(otype T) {
     50trait sqrt(T) {
    5151    T sqrt(T);
    5252};
     
    6868}
    6969
    70 trait dottable(otype V, otype T) {
     70trait dottable(V, T) {
    7171    T dot(V, V);
    7272};
     
    7474static inline {
    7575
    76 forall(otype T | sqrt(T), otype V | dottable(V, T))
     76forall(T | sqrt(T), V | dottable(V, T))
    7777T length(V v) {
    7878   return sqrt(dot(v, v));
    7979}
    8080
    81 forall(otype T, otype V | dottable(V, T))
     81forall(T, V | dottable(V, T))
    8282T length_squared(V v) {
    8383   return dot(v, v);
    8484}
    8585
    86 forall(otype T, otype V | { T length(V); } | subtract(V))
     86forall(T, V | { T length(V); } | subtract(V))
    8787T distance(V v1, V v2) {
    8888    return length(v1 - v2);
    8989}
    9090
    91 forall(otype T, otype V | { T length(V); V ?/?(V, T); })
     91forall(T, V | { T length(V); V ?/?(V, T); })
    9292V normalize(V v) {
    9393    return v / length(v);
     
    9595
    9696// Project vector u onto vector v
    97 forall(otype T, otype V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
     97forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
    9898V project(V u, V v) {
    9999    V v_norm = normalize(v);
     
    102102
    103103// Reflect incident vector v with respect to surface with normal n
    104 forall(otype T | fromint(T), otype V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
     104forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
    105105V reflect(V v, V n) {
    106106    return v - (T){2} * project(v, n);
     
    111111// entering material (i.e., from air to water, eta = 1/1.33)
    112112// v and n must already be normalized
    113 forall(otype T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
    114        otype V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
     113forall(T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
     114       V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
    115115V refract(V v, V n, T eta) {
    116116    T dotValue = dot(n, v);
     
    128128// i is the incident vector
    129129// ng is the geometric normal of the surface
    130 forall(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
     130forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V))
    131131V faceforward(V n, V i, V ng) {
    132132    return dot(ng, i) < (T){0} ? n : -n;
  • libcfa/src/vec/vec2.hfa

    r2f47ea4 rfd54fef  
    1919#include "vec.hfa"
    2020
    21 forall (otype T) {
     21forall (T) {
    2222    struct vec2 {
    2323        T x, y;
     
    2525}
    2626
    27 forall (otype T) {
     27forall (T) {
    2828    static inline {
    2929
     
    279279}
    280280
    281 forall(dtype ostype, otype T | writeable(T, ostype)) {
     281forall(ostype &, T | writeable(T, ostype)) {
    282282    ostype & ?|?(ostype & os, vec2(T) v) with (v) {
    283283        return os | '<' | x | ',' | y | '>';
  • libcfa/src/vec/vec3.hfa

    r2f47ea4 rfd54fef  
    1919#include "vec.hfa"
    2020
    21 forall (otype T) {
     21forall (T) {
    2222    struct vec3 {
    2323        T x, y, z;
     
    2525}
    2626
    27 forall (otype T) {
     27forall (T) {
    2828    static inline {
    2929
     
    288288}
    289289
    290 forall(dtype ostype, otype T | writeable(T, ostype)) {
     290forall(ostype &, T | writeable(T, ostype)) {
    291291    ostype & ?|?(ostype & os, vec3(T) v) with (v) {
    292292        return os | '<' | x | ',' | y | ',' | z | '>';
  • libcfa/src/vec/vec4.hfa

    r2f47ea4 rfd54fef  
    1919#include "vec.hfa"
    2020
    21 forall (otype T) {
     21forall (T) {
    2222    struct vec4 {
    2323        T x, y, z, w;
     
    2525}
    2626
    27 forall (otype T) {
     27forall (T) {
    2828    static inline {
    2929
     
    283283}
    284284
    285 forall(dtype ostype, otype T | writeable(T, ostype)) {
     285forall(ostype &, T | writeable(T, ostype)) {
    286286    ostype & ?|?(ostype & os, vec4(T) v) with (v) {
    287287        return os | '<' | x | ',' | y | ',' | z | ',' | w | '>';
Note: See TracChangeset for help on using the changeset viewer.