11using DynamicExpressions
22using Test
33
4- mutable struct MyCustomNode{A,B} <: AbstractNode
4+ mutable struct MyCustomNode{A,B} <: AbstractNode{2}
55 degree:: Int
66 val1:: A
77 val2:: B
8- l:: MyCustomNode{A,B}
9- r:: MyCustomNode{A,B}
8+ children:: NTuple{2,Base.RefValue{MyCustomNode{A,B}}}
109
1110 MyCustomNode (val1, val2) = new {typeof(val1),typeof(val2)} (0 , val1, val2)
12- MyCustomNode (val1, val2, l) = new {typeof(val1),typeof(val2)} (1 , val1, val2, l)
13- MyCustomNode (val1, val2, l, r) = new {typeof(val1),typeof(val2)} (2 , val1, val2, l, r)
11+ function MyCustomNode (val1, val2, l)
12+ return new {typeof(val1),typeof(val2)} (
13+ 1 , val1, val2, (Ref (l), Ref {MyCustomNode{typeof(val1),typeof(val2)}} ())
14+ )
15+ end
16+ function MyCustomNode (val1, val2, l, r)
17+ return new {typeof(val1),typeof(val2)} (2 , val1, val2, (Ref (l), Ref (r)))
18+ end
1419end
1520
1621node1 = MyCustomNode (1.0 , 2 )
@@ -24,7 +29,7 @@ node2 = MyCustomNode(1.5, 3, node1)
2429
2530@test typeof (node2) == MyCustomNode{Float64,Int}
2631@test node2. degree == 1
27- @test node2. l . degree == 0
32+ @test node2. children[ 1 ][] . degree == 0
2833@test count_depth (node2) == 2
2934@test count_nodes (node2) == 2
3035
@@ -37,14 +42,13 @@ node2 = MyCustomNode(1.5, 3, node1, node1)
3742@test count (t -> t. degree == 0 , node2) == 2
3843
3944# If we have a bad definition, it should get caught with a helpful message
40- mutable struct MyCustomNode2{T} <: AbstractExpressionNode{T}
45+ mutable struct MyCustomNode2{T} <: AbstractExpressionNode{T,2 }
4146 degree:: UInt8
4247 constant:: Bool
4348 val:: T
4449 feature:: UInt16
4550 op:: UInt8
46- l:: MyCustomNode2{T}
47- r:: MyCustomNode2{T}
51+ children:: NTuple{2,Base.RefValue{MyCustomNode2{T}}}
4852end
4953
5054@test_throws ErrorException MyCustomNode2 ()
0 commit comments