1
- import structs/[HashMap, List]
1
+ import structs/[HashMap, List, LinkedList ]
2
2
3
3
4
4
Value : abstract class {
@@ -30,12 +30,33 @@ BoolValue: class extends Value {
30
30
ListValue : class extends Value {
31
31
list : List <Value >
32
32
33
- init : func (= list ) {}
33
+ init : func ~withList (= list ) {}
34
+ init : func ~empty { list = LinkedList< Value> new () }
34
35
35
36
emit : func -> String {
36
37
"List(size=%d)" format (list size ())
37
38
}
38
39
40
+ appendValue : func (value : Value ) {
41
+ list add (value)
42
+ }
43
+
44
+ appendString : func (value : String ) {
45
+ list add (StringValue new (value))
46
+ }
47
+
48
+ appendBool : func (value : Bool ) {
49
+ list add (BoolValue new (value))
50
+ }
51
+
52
+ appendList : func (list : List < Value > ) {
53
+ list add (ListValue new (list))
54
+ }
55
+
56
+ appendHashMap : func (hash : HashMap < Value > ) {
57
+ list add (HashValue new (hash))
58
+ }
59
+
39
60
list : func -> List < Value> { list }
40
61
}
41
62
@@ -47,10 +68,26 @@ HashValue: class extends Value {
47
68
48
69
emit : func -> String { "Hash" }
49
70
50
- addValue : func (name : String , value : Value ) {
71
+ setValue : func (name : String , value : Value ) {
51
72
hash add (name, value)
52
73
}
53
74
75
+ setString : func (name : String , value : String ) {
76
+ addValue (name, StringValue new (value))
77
+ }
78
+
79
+ setBool : func (name : String , value : Bool ) {
80
+ addValue (name, BoolValue new (value))
81
+ }
82
+
83
+ setList : func (name : String , list : List < Value > ) {
84
+ addValue (name, ListValue new (list))
85
+ }
86
+
87
+ setHashMap : func (name : String , hash : HashMap < Value > ) {
88
+ addValue (name, HashValue new (hash))
89
+ }
90
+
54
91
getValue : func (name : String ) -> Value {
55
92
hash get (name)
56
93
}
0 commit comments