expect(",") if !matches("]")
end
expect("]")
- exprs
IR::Const.new(loc, nil, exprs)
end
def hash_literal()
- exprs = {}
+ dict = {}
expect("{")
-# while !matches("}")
-# exprs << expression()
-# expect(",") if !matches("}")
-# end
+ loc = location()
+ while !matches("}")
+ key = string_or_ident()
+ expect(":")
+ val = expression()
+ dict[key] = val
+ expect(",") if !matches("}")
+ end
expect("}")
- exprs
+ IR::Const.new(loc, nil, dict)
+ end
+
+ def string_or_ident()
+ tok = consume()
+ if tok.type == :string
+ IR::Const.new(tok.pos, Value::String, tok.text)
+ elsif tok.type == :ident
+ IR::Const.new(tok.pos, Value::String, "\"#{tok.text}\"")
+ else
+ error("not a string or identifier: #{tok}")
+ end
end
end
end
elsif v.value.is_a? Hash
- putln state, "Value #{var} = MakeHash(#{v.value});"
+# putln state, "Value #{var} = MakeHash(#{v.value});"
+
+ putln state, "Value #{var} = MakeHashOfLength(#{v.value.length});"
+ v.value.each do |k, v|
+ val = emit(state, v)
+ putln state, "Hash_SetIndex(#{var}, MakeString(#{k.value}), #{val});"
+#
+#
+# pp k
+# val = emit(state, e)
+# putln state, "Array_SetIndex(#{var}, #{i}, #{val});"
+#
+ end
+
+
else
raise "code emitting constants of this type not implemented"
end