Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vec4 un-loop design #201

Closed
bvssvni opened this issue May 20, 2016 · 0 comments
Closed

vec4 un-loop design #201

bvssvni opened this issue May 20, 2016 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented May 20, 2016

When you need this:

(x(b[0]), x(b[1]), x(b[2]), x(b[3]))

In Dyon you can just type:

vec4 j x(b[j])

This unrolls the loop in the AST to a vec4, replacing j with numbers 0, 1, 2, 3.

The reason there are no {} brackets is because the loop does not work under composition. Neither can you use continue or break.

It is different from the other loop that do inference but are restricted by items only when indexing. For example, a[i] can be used with the other loops, but not a[(i+1)%3]. The latter works fine with a vec4 un-loop.

s(vec4, f64) for looking up scalar in vector

This is useful in combination with the vec4 un-loop.

vec3 and vec2 un-loops

The vec3 and vec2 un-loops sets the rest of the components to 0:

println(vec3 i i+1) // prints `(1, 2, 3)`
println(vec2 i i+1) // prints `(1, 2)`

Examples

Random values:

vec4 _ random()

Convert array of length 3 into a vec4:

p := [1, 2, 3]
println(vec4 i if i == 3 { 0 } else { p[i] }) // prints `(1, 2, 3, 0)`

Multiply two 4x4 matrices (row major):

multiply_matrix_matrix(a: [vec4], b: [vec4]) =
    sift i { vec4 j a[i] *. vec4 k s(b[k], j) }

Swizzle to (z, x, y, w):

a := (x, y, z, w)
println(vec4 i s(a, if i == 3 { i } else { (i+1)%3 })) // prints `(z, x, y, w)`

Motivation

This is designed for:

  • Flexible initialization of vec4 values
  • Reduce typing
  • Reduce bugs
  • Improve readability
@bvssvni bvssvni self-assigned this May 20, 2016
@bvssvni bvssvni changed the title Add vec4 un-loop vec4 un-loop design May 20, 2016
bvssvni added a commit to bvssvni/dyon that referenced this issue May 20, 2016
See PistonDevelopers#201

- Found a possible bug in “infer_len.rs” that needs closer investigation
- Added `ast::Vec4UnLoop`
- Added `ast::replace` module
- Added `lifetime::Kind::is_decl_un_loop`
@bvssvni bvssvni removed their assignment May 20, 2016
@bvssvni bvssvni removed the draft label May 29, 2016
@bvssvni bvssvni closed this as completed May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant