Skip to content

Commit

Permalink
Merge pull request #7 from arhik/upStreamSync
Browse files Browse the repository at this point in the history
Up stream sync
  • Loading branch information
arhik authored Feb 20, 2024
2 parents dac63eb + e217b52 commit 8fe7908
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 417 deletions.
275 changes: 0 additions & 275 deletions Manifest.toml

This file was deleted.

4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ authors = ["arhik <[email protected]>"]
version = "0.1.1"

[deps]
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
GeometryBasics = "^0.4"
Lazy = "^0.15"
MacroTools = "^0.5"
Reexport = "^1.2"
Expand Down
12 changes: 12 additions & 0 deletions src/WGSLTypes.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
module WGSLTypes

using MacroTools
using StaticArrays
using DataStructures

const Vec2{T} = SVector{2, T}
const Vec3{T} = SVector{3, T}
const Vec4{T} = SVector{4, T}
const Mat2{T} = SMatrix{2, 2, T, 4}
const Mat3{T} = SMatrix{3, 3, T, 9}
const Mat4{T} = SMatrix{4, 4, T, 16}
const Vec{N, T} = SVector{N, T}

include("functions.jl")
include("builtins.jl")
include("locations.jl")
Expand Down
40 changes: 7 additions & 33 deletions src/builtins.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using GeometryBasics
using GeometryBasics: Vec2, Vec3, Vec4, Mat2, Mat3, Mat4

export BuiltinValue, getEnumBuiltinValue, BuiltIn, @builtin, BuiltInDataType


@enum BuiltinValue begin
vertex_index
instance_index
Expand All @@ -19,7 +16,6 @@ export BuiltinValue, getEnumBuiltinValue, BuiltIn, @builtin, BuiltInDataType
sample_mask
end


function getEnumBuiltinValue(s::Symbol)
ins = instances(BuiltinValue)
for i in ins
Expand All @@ -30,51 +26,24 @@ function getEnumBuiltinValue(s::Symbol)
@error "$s is not in builtin types"
end


struct BuiltIn{B, S, D} end


function BuiltIn(btype::Symbol, pair::Pair{Symbol, DataType})
bVal = getEnumBuiltinValue(btype) |> Val
sVal = pair.first |> Val
sVal = pair.first
dVal = pair.second |> Val
return BuiltIn{bVal, sVal, dVal}
end


macro builtin(exp)
@assert typeof(exp) == Expr """\n
Expecting expression, found typeof(exp) instead
builtin can be defined as
@builtin (builtinValue) => sym::DataType
"""
@assert exp.head == :call "Expecting (builtinValue) => sym::DataType"
@assert typeof(exp.args) == Vector{Any} "E $(typeof(exp.args))"
@assert exp.args[1] == :(=>) "Should check"
@assert exp.args[2] in Symbol.(instances(BuiltinValue)) "$(exp.args[2]) is not in BuiltinValue Enum"
b = exp.args[2]
@assert typeof(exp.args[3]) == Expr """
This expression should be of format sym::Float32
"""
exp2 = exp.args[3]
@assert exp2.head == :(::) "Expecting a seperator :: "
s = exp2.args[1]
d = exp2.args[2]
return BuiltIn(b, s=>eval(d))
end


struct BuiltInDataType{B, D} end


function BuiltInDataType(btype::Symbol, dType::DataType)
bVal = getEnumBuiltinValue(btype) |> Val
dVal = dType |> Val
return BuiltInDataType{bVal, dVal}
end


macro builtin(btype, dtype)
macro builtin(btype, dtype::DataType)
@assert typeof(btype) == Symbol """\n
Expecting expression, found typeof(exp) instead
builtin can be defined as
Expand All @@ -85,6 +54,11 @@ macro builtin(btype, dtype)
return BuiltInDataType(btype, eval(dtype))
end

macro builtin(sym::Symbol, expr::Expr)
@capture(expr, a_::b_) && return BuiltIn(sym, a=>eval(b))
@capture(expr, a_) && return BuiltInDataType(sym, eval(a))
error("BuiltIn didn't follow expected format!!!")
end

function BuiltIn(sVal::Symbol, ::Type{BuiltInDataType{B, D}}) where {B, D}
return BuiltIn{B, sVal, D}
Expand Down
Loading

0 comments on commit 8fe7908

Please sign in to comment.