Commit 63202f0f authored by Kamil Kisiel's avatar Kamil Kisiel

Merge pull request #8 from Sean-Der/implement-tuple2-decode

Implement the TUPLE2 Opcode
parents eb26998f 1b113b59
......@@ -205,6 +205,8 @@ func (d Decoder) Decode() (interface{}, error) {
err = d.loadSetItem()
case opTuple:
err = d.loadTuple()
case opTuple2:
err = d.loadTuple2()
case opEmptyTuple:
d.push([]interface{}{})
case opSetitems:
......@@ -607,6 +609,13 @@ func (d *Decoder) loadTuple() error {
return nil
}
func (d *Decoder) loadTuple2() error {
k := len(d.stack) - 2
v := append([]interface{}{}, d.stack[k:]...)
d.stack = append(d.stack[:k], v)
return nil
}
func (d *Decoder) obj() error {
return errNotImplemented
}
......
......@@ -41,6 +41,7 @@ func TestDecode(t *testing.T) {
{"tuple of two ints", "(I1\nI2\ntp0\n.", []interface{}{int64(1), int64(2)}},
{"nested tuples", "((I1\nI2\ntp0\n(I3\nI4\ntp1\ntp2\n.",
[]interface{}{[]interface{}{int64(1), int64(2)}, []interface{}{int64(3), int64(4)}}},
{"tuple with top 2 items from stack", "I0\nI1\n\x86.", []interface{}{int64(0), int64(1)}},
{"empty list", "(lp0\n.", []interface{}{}},
{"list of numbers", "(lp0\nI1\naI2\naI3\naI4\na.", []interface{}{int64(1), int64(2), int64(3), int64(4)}},
{"string", "S'abc'\np0\n.", string("abc")},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment