forked from flosch/GoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylist.go
62 lines (51 loc) · 1.09 KB
/
pylist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package vm
import (
"fmt"
)
type PyList struct {
PyTuple
}
func (pl *PyList) asString() *string {
str := fmt.Sprintf("[%s]", *pl.buildItemString())
return &str
}
// Returns nil or exception object
func (pl *PyList) setItem(key, value PyObject) PyObject {
if _, ok := pl.attributes["__setitem__"]; ok { // set_func
// found setattr, call it!
panic("not implemented yet")
}
idxobj, isInt := key.(*PyInt)
if !isInt {
fmt.Sprintf("joo\n")
return PyTypeError
}
if int(idxobj.value) > len(pl.items) {
return PyIndexError
}
pl.items[idxobj.value] = value
return nil
}
// Returns actual object or exception object
func (pl *PyList) getItem(key PyObject) PyObject {
if _, ok := pl.attributes["__getitem__"]; ok { // set_func
// found setattr, call it!
panic("not implemented yet")
}
idxobj, isInt := key.(*PyInt)
if !isInt {
fmt.Sprintf("joo\n")
return PyTypeError
}
if int(idxobj.value) > len(pl.items) {
return PyIndexError
}
return pl.items[idxobj.value]
}
func NewPyList(items []PyObject) PyObject {
pl := &PyList{
PyTuple{items: items},
}
pl.pyObjInit()
return pl
}