forked from flosch/GoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyobj.go
63 lines (54 loc) · 1.41 KB
/
pyobj.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
63
package vm
import (
"fmt"
)
type PyObject interface {
getValue() interface{}
isTrue() bool
asString() *string
getattr(name, standard PyObject) PyObject
operation(op int, obj2 PyObject, inplace bool) (PyObject, PyObject)
setItem(key, value PyObject) PyObject
getItem(key PyObject) PyObject
}
type PyObjectData struct {
attributes map[string]PyObject
}
func (obj *PyObjectData) pyObjInit() {
obj.attributes = make(map[string]PyObject)
}
func (obj *PyObjectData) operation(op int, obj2 PyObject, inplace bool) (PyObject, PyObject) {
return PyTypeError, nil
}
func (obj *PyObjectData) getattr(name, standard PyObject) PyObject {
name_string, ok := name.(*PyString)
if !ok {
panic(fmt.Sprintf("getattr(_, name [%v]) is no PyString", name))
}
value, found := obj.attributes[*name_string.asString()]
if !found {
if standard != PyNil {
return standard
} else {
return PyAttributeError
}
}
return value
}
// Returns nil or exception object
func (obj *PyObjectData) setItem(key, value PyObject) PyObject {
if _, ok := obj.attributes["__setitem__"]; ok { // set_func
// found setattr, call it!
panic("not implemented yet")
}
panic("stop")
return PyTypeError
}
// Returns actual object or exception object
func (obj *PyObjectData) getItem(key PyObject) PyObject {
if _, ok := obj.attributes["__getitem__"]; ok { // set_func
// found setattr, call it!
panic("not implemented yet")
}
return PyTypeError
}