-
Notifications
You must be signed in to change notification settings - Fork 1
/
JulTran.jl
52 lines (40 loc) · 1.15 KB
/
JulTran.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# JulTran.jl
struct NONALLOCATO
DT::DataType
end
macro declare(A, T, NX)
return :( $(esc(A)) = NONALLOCATO(Array{$(esc(T)),$(esc(NX))}) )
end
macro Ndeclare(A, T)
return :( $(esc(A)) = NONALLOCATO($(esc(T))) )
end
#https://stackoverflow.com/questions/39931112/quote-unquote-idiom-in-julia-concatenating-expr-objects
import Base.zero
zero(::Type{T}) where{T<:AbstractString} = string("")
macro declareNtimes(vars...)
ex = Expr(:block)
t = vars[1]
ex.args = [:($(esc(n)) = Base.zero($(esc(t)))) for n in vars[2:end]]
ex
end
#@declareNtimes Bool a b c
macro Ninit(A, T, V)
return :( $(esc(A)) = Base.convert($(esc(T)),$(esc(V))) )
end
macro NinitNtimes(vars...)
ex = Expr(:block)
t = vars[1]
ex.args = [:( $(esc(c.args[1])) = Base.convert($(esc(t)), $(esc(c.args[2]))) ) for c in vars[2:end]]
ex
end
#@NinitNtimes Bool (a,false) (b,true)
#@assert !a && b
macro allocate(A, T, S)
return :( $(esc(A)) = Base.fill(Base.zero($(esc(T))),$(esc(S))) )
end
macro deallocate(a)
return :( $(esc(a)) = NONALLOCATO(Base.typeof($(esc(a)))) )
end
macro isallocated(a)
return :( ! Base.isa($(esc(a)), NONALLOCATO) )
end