-
Notifications
You must be signed in to change notification settings - Fork 95
Multi-context execution (py.Context) #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
fc66b7f
py.CompileMode now a string enum
d10c35f
addressed benign Go warnings
2161b71
make Float implement M__index__
247ec42
added string helper functions
9a75271
updated to 1.15
90a8988
new Ctx-aware module model
c51644e
py.Ctx model allows concurrent execution
7f7d213
repl.New() now accepts an existing py.Ctx
708bb7e
fixed typo in callInternal()
a244256
unbroke test compatibilty
75d8743
cleaned up py.Ctx initialization wrt sys and DefaultCtxOpts()
d5fb8e8
added multi Ctx benchmark
269bdc0
WIP
4db9c65
fixed py.NewCtx not being set
53d05db
fixed List.sort() detection of instance invocation
7fd1c29
separated path resolution from path evaluation
8f3a104
removed cruft
5ebaf66
place ctx at top
d423190
err msg tweak
drew-512 b33c266
typo fix
drew-512 efca761
for loops we can all agree on
drew-512 1569475
removed outdated comments
a9c5f1f
Merge branch 'master' of https://github.com/drew-512/gpython
6372aee
added info for Frame.Ctx
4af4f90
removed unnecessary assignment
aec59f8
copyright and formatting
74f1a19
Ctx and NewCtx docs
8fa6622
switch cleanup
26fb9aa
leaner ModuleImpl schema
8614aeb
added GetDict() impl
86531c6
Compile() now returns py.Code (vs py.Object)
f71b961
tighter py.Ctx invocation patterns
77a7954
WIP
6bba7da
reverted to 644
46d1052
chmod 644
66fad23
enhanced RunFile() to enclose RunInNewModule()
95afd7b
Update examples/multi-ctx/main.go
drew-512 319edb7
Update modules/runtime.go
drew-512 06a2eae
Update modules/runtime.go
drew-512 8d4d586
Update modules/runtime.go
drew-512 d475e67
Update vm/eval.go
drew-512 6afac99
Update py/run.go
drew-512 931c346
Update modules/runtime.go
drew-512 a7ce4bb
Update modules/runtime.go
drew-512 c1f8809
Update modules/runtime.go
drew-512 9f02cf1
Update modules/runtime.go
drew-512 85e3a4a
Update modules/runtime.go
drew-512 fbec34e
Update modules/runtime.go
drew-512 dbd54d8
code cleanuo
71a5604
Module doc str
634823c
consistent arg order of NewFunction
6a0c11e
license and formatting
6242836
comment and cruft cleanup
61c7830
renamed Store to ModuleStore + docs
bb98aa8
added import docs
36b1018
shadowing cleanup
f2602bc
docs tweaks
e25e3bb
code cleanup
9421b6b
synced with gpython
92aed8a
Merge branch 'go-python:master' into master
drew-512 96515ea
Update modules/runtime.go
drew-512 f62f2b7
Update modules/runtime.go
drew-512 3bdba62
reverted from %w to %v (linux CI compile failure)
8033615
renamed py.Ctx to py.Context
681abf2
added Context.Close() and ModuleImpl.OnContextClosed()
7508556
docs and LoadIntsFromList
99bcb40
rename edits
0cc7650
push/popBusy now private
9afb2d3
doc edits
7d2a8d9
fixed kwarg issues in ParseTupleAndKeywords() and builtin_print test
ba7db80
added Flush kwarg to print test
61e42c8
added embedding example
168c337
main README makeover
2b7e1ab
fixed type conversion
3821b4b
Update README.md
drew-512 170f0d2
Update README.md
drew-512 b68b9f6
Update py/util.go
drew-512 759023b
Update py/util.go
drew-512 0c77716
Update py/util.go
drew-512 505755d
LoadIntsFromList cleanup
02d6b3e
comment edits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs and LoadIntsFromList
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,6 +13,7 @@ var ( | |||||
ErrUnsupportedObjType = errors.New("unsupported obj type") | ||||||
) | ||||||
|
||||||
// GetInt is a high-level convenience function that gets the length of the given Object. | ||||||
func GetLen(obj Object) (Int, error) { | ||||||
getlen, ok := obj.(I__len__) | ||||||
if !ok { | ||||||
|
@@ -27,6 +28,7 @@ func GetLen(obj Object) (Int, error) { | |||||
return GetInt(lenObj) | ||||||
} | ||||||
|
||||||
// GetInt is a high-level convenience function that converts the given value to an int. | ||||||
func GetInt(obj Object) (Int, error) { | ||||||
toIdx, ok := obj.(I__index__) | ||||||
if !ok { | ||||||
|
@@ -37,6 +39,7 @@ func GetInt(obj Object) (Int, error) { | |||||
return toIdx.M__index__() | ||||||
} | ||||||
|
||||||
// LoadTuple attempts to convert each element of the given list and store into each destination value (based on its type). | ||||||
func LoadTuple(args Tuple, vars []interface{}) error { | ||||||
|
||||||
if len(args) > len(vars) { | ||||||
|
@@ -57,18 +60,54 @@ func LoadTuple(args Tuple, vars []interface{}) error { | |||||
return nil | ||||||
} | ||||||
|
||||||
func LoadAttr(obj Object, attrName string, data interface{}) error { | ||||||
// LoadAttr gets the named attrib and attempts to store it into the given destination value (based on its type). | ||||||
drew-512 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
func LoadAttr(obj Object, attrName string, dst interface{}) error { | ||||||
attr, err := GetAttrString(obj, attrName) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
err = loadValue(attr, data) | ||||||
err = loadValue(attr, dst) | ||||||
if err == ErrUnsupportedObjType { | ||||||
return ExceptionNewf(TypeError, "attribute \"%s\" has unsupported object type: %s", attrName, attr.Type().Name) | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
// LoadIntsFromList extracts a list of ints contained given a py.List or py.Tuple | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
func LoadIntsFromList(list Object) ([]int64, error) { | ||||||
N, err := GetLen(list) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
getter, ok := list.(I__getitem__) | ||||||
if !ok { | ||||||
return nil, nil | ||||||
} | ||||||
|
||||||
var intList []int64 | ||||||
if ok && N > 0 { | ||||||
drew-512 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
intList = make([]int64, N) | ||||||
|
||||||
var intVal Int | ||||||
for i := Int(0); i < N; i++ { | ||||||
item, err := getter.M__getitem__(i) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
intVal, err = GetInt(item) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
intList[i] = int64(intVal) | ||||||
} | ||||||
} | ||||||
|
||||||
return intList, nil | ||||||
} | ||||||
|
||||||
func loadValue(src Object, data interface{}) error { | ||||||
var ( | ||||||
v_str string | ||||||
|
@@ -104,6 +143,8 @@ func loadValue(src Object, data interface{}) error { | |||||
} | ||||||
|
||||||
switch dst := data.(type) { | ||||||
case *Int: | ||||||
*dst = Int(v_int) | ||||||
case *bool: | ||||||
*dst = v_int != 0 | ||||||
case *int8: | ||||||
|
@@ -136,9 +177,15 @@ func loadValue(src Object, data interface{}) error { | |||||
v_float, _ = strconv.ParseFloat(v_str, 64) | ||||||
} | ||||||
*dst = v_float | ||||||
case *Float: | ||||||
if haveStr { | ||||||
v_float, _ = strconv.ParseFloat(v_str, 64) | ||||||
} | ||||||
*dst = Float(v_float) | ||||||
case *string: | ||||||
*dst = v_str | ||||||
|
||||||
case *String: | ||||||
*dst = String(v_str) | ||||||
// case []uint64: | ||||||
// for i := range data { | ||||||
// dst[i] = order.Uint64(bs[8*i:]) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.