Skip to content

Commit 6a616d0

Browse files
committed
Add a few helpers to ListValue and HashValue.
1 parent b2c4a21 commit 6a616d0

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

mustang/Value.ooc

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import structs/[HashMap, List]
1+
import structs/[HashMap, List, LinkedList]
22

33

44
Value: abstract class {
@@ -30,12 +30,33 @@ BoolValue: class extends Value {
3030
ListValue: class extends Value {
3131
list: List<Value>
3232

33-
init: func(=list) {}
33+
init: func ~withList(=list) {}
34+
init: func ~empty { list = LinkedList<Value> new() }
3435

3536
emit: func -> String {
3637
"List(size=%d)" format(list size())
3738
}
3839

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+
3960
list: func -> List<Value> { list }
4061
}
4162

@@ -47,10 +68,26 @@ HashValue: class extends Value {
4768

4869
emit: func -> String { "Hash" }
4970

50-
addValue: func(name: String, value: Value) {
71+
setValue: func(name: String, value: Value) {
5172
hash add(name, value)
5273
}
5374

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+
5491
getValue: func(name: String) -> Value {
5592
hash get(name)
5693
}

0 commit comments

Comments
 (0)