Commit c57544de authored by Kamil Kisiel's avatar Kamil Kisiel

Implement Tuple1 and Tuple3 opcodes.

parent 63202f0f
......@@ -205,8 +205,12 @@ func (d Decoder) Decode() (interface{}, error) {
err = d.loadSetItem()
case opTuple:
err = d.loadTuple()
case opTuple1:
err = d.loadTuple1()
case opTuple2:
err = d.loadTuple2()
case opTuple3:
err = d.loadTuple3()
case opEmptyTuple:
d.push([]interface{}{})
case opSetitems:
......@@ -609,6 +613,13 @@ func (d *Decoder) loadTuple() error {
return nil
}
func (d *Decoder) loadTuple1() error {
k := len(d.stack) - 1
v := append([]interface{}{}, d.stack[k:]...)
d.stack = append(d.stack[:k], v)
return nil
}
func (d *Decoder) loadTuple2() error {
k := len(d.stack) - 2
v := append([]interface{}{}, d.stack[k:]...)
......@@ -616,6 +627,13 @@ func (d *Decoder) loadTuple2() error {
return nil
}
func (d *Decoder) loadTuple3() error {
k := len(d.stack) - 3
v := append([]interface{}{}, d.stack[k:]...)
d.stack = append(d.stack[:k], v)
return nil
}
func (d *Decoder) obj() error {
return errNotImplemented
}
......
......@@ -41,7 +41,9 @@ 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 1 items from stack", "I0\n\x85.", []interface{}{int64(0)}},
{"tuple with top 2 items from stack", "I0\nI1\n\x86.", []interface{}{int64(0), int64(1)}},
{"tuple with top 3 items from stack", "I0\nI1\nI2\n\x87.", []interface{}{int64(0), int64(1), int64(2)}},
{"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