Skip to content

Commit

Permalink
Parametric types by default. Experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRT committed Jul 2, 2021
1 parent 42bf36f commit bbade82
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/union.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ They can be used in that way with match.jl
# i
# end
=#

#=
TODO: Sometimes when people use type aliasing @Uniontype will not know about the specific type during compilation time
TODO: Sometimes when people use type aliasing @Uniontype will not know about the specific type during compilation time
=#
module UniontypeDef

include("metaModelicaTypes.jl")
import .MetaModelicaTypes
using MacroTools

function makeRecord(recordExpr::Expr)
local arr = []
Expand Down Expand Up @@ -69,15 +71,37 @@ function replaceLineNum(a::Expr, lines::LineNumberNode)
replaceLineNum(n, lines)
end
end

function replaceLineNum(a::Any, lines::LineNumberNode) end

function makeUniontypes(name, records, lineNode::LineNumberNode)
recordsArray1 = Array.(records)
recordsArray2 = recordsArray1[1]
constructedRecords = []
for r in recordsArray2
local block = r[2] #= Get the block. That is r[2]=#
blckExprs = block.args
varToDecl = Dict()
local i::Int = 0
local exprCounter::Int = 1
for expr in blckExprs
if typeof(expr) === LineNumberNode #= Ignore comment lines =#
continue
end
#= Check if we have a uniontype type declaration. =#
if (@capture(expr, T_::TYPE_))
parametricType::Symbol = Symbol("T", i)
varToDecl[T] = [parametricType, TYPE]
i += 1
newExpr = expr
newExpr.args[2] = parametricType
end
exprCounter += 1
end
local structName = r[1]
parametricTypes::Vector{Expr} = [ :($(varToDecl[i][1]) <: $(varToDecl[i][2])) for i in keys(varToDecl)]
recordNode = quote
struct $(r[1]) <: $name
struct $(structName){$(parametricTypes...)} <: $name
$(r[2])
end
end
Expand Down

0 comments on commit bbade82

Please sign in to comment.