mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge branch 'master' into coolreader18/update-deps
This commit is contained in:
28 files changed
+276
-394
No files matched your search
Generated
+71
-103
@@ -25,11 +25,6 @@ dependencies = [
|
||||
"scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.4.10"
|
||||
@@ -46,16 +41,6 @@ dependencies = [
|
||||
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.11"
|
||||
@@ -89,21 +74,21 @@ name = "backtrace-sys"
|
||||
version = "0.1.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.4.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-vec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.4.4"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@@ -122,21 +107,31 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.3.3"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "2.2.2"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
version = "0.2.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@@ -155,7 +150,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.31"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@@ -197,10 +192,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.7.6"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -215,14 +210,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "docopt"
|
||||
version = "0.8.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -232,8 +227,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ena"
|
||||
version = "0.5.0"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
@@ -301,7 +299,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.9.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -325,7 +323,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.7.11"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -355,45 +353,23 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop"
|
||||
version = "0.15.2"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-snap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop-snap"
|
||||
version = "0.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -401,7 +377,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop-util"
|
||||
version = "0.15.2"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@@ -466,7 +442,7 @@ version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -526,6 +502,11 @@ name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ordermap"
|
||||
version = "0.3.5"
|
||||
@@ -747,11 +728,6 @@ dependencies = [
|
||||
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.5.6"
|
||||
@@ -816,8 +792,8 @@ dependencies = [
|
||||
name = "rustpython_parser"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -934,13 +910,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.7.1"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1010,11 +986,6 @@ name = "string_cache_shared"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.7.0"
|
||||
@@ -1199,7 +1170,7 @@ name = "wasm-bindgen-backend"
|
||||
version = "0.2.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bumpalo 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bumpalo 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1335,34 +1306,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
|
||||
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
|
||||
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
|
||||
"checksum ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b385d69402821a1c254533a011a312531cbcc0e3e24f19bbb4747a5a2daf37e2"
|
||||
"checksum atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0fd4c0631f06448cc45a6bbb3b710ebb7ff8ccb96a0800c994afe23a70d5df2"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
|
||||
"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4"
|
||||
"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
|
||||
"checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c"
|
||||
"checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f"
|
||||
"checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
|
||||
"checksum bit-vec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb"
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
|
||||
"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
|
||||
"checksum bumpalo 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20bd7761c869bd69b5bd9dbbb1bd84de2f3970b764172efc41e67a06b508c56e"
|
||||
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
|
||||
"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d"
|
||||
"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591"
|
||||
"checksum bumpalo 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6a6bc2ba935b1e2f810787ceba8dfe86cbc164cee55925cae715541186673c4"
|
||||
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
|
||||
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
|
||||
"checksum caseless 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "808dab3318747be122cb31d36de18d4d1c81277a76f8332a02b81a3d73463d7f"
|
||||
"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d"
|
||||
"checksum cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ad0daef304fa0b4238f5f7ed7178774b43b06f6a9b6509f6642bef4ff1f7b9b2"
|
||||
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
|
||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
|
||||
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
|
||||
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
|
||||
"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
"checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a"
|
||||
"checksum docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db2906c2579b5b7207fc1e328796a9a8835dc44e22dbe8e460b1d636f9a7b225"
|
||||
"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac"
|
||||
"checksum ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe5a5078ac8c506d3e4430763b1ba9b609b1286913e7d08e581d1c2de9b7e5"
|
||||
"checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00"
|
||||
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
|
||||
"checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a"
|
||||
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
|
||||
@@ -1371,16 +1341,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
|
||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
|
||||
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
|
||||
"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592"
|
||||
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
|
||||
"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
|
||||
"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum js-sys 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "d4bda84b98977341bb6ba1086ecbd9eab8bc929de0f2923c118baf76c21dd0c8"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba451f7bd819b7afc99d4cf4bdcd5a4861e64955ba9680ac70df3a50625ad6cf"
|
||||
"checksum lalrpop-snap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "60013fd6be14317d43f47658b1440956a9ca48a9ed0257e0e0a59aac13e43a1f"
|
||||
"checksum lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "60c6c48ba857cd700673ce88907cadcdd7e2cd7783ed02378537c5ffd4f6460c"
|
||||
"checksum lalrpop 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2e80bee40b22bca46665b4ef1f3cd88ed0fb043c971407eac17a0712c02572"
|
||||
"checksum lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)" = "33b27d8490dbe1f9704b0088d61e8d46edc10d5673a8829836c6ded26a9912c7"
|
||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||
"checksum lexical 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c106ed999697325a540c43d66a8d5175668cd96d7eb0bdba03a3bd98256cd698"
|
||||
"checksum lexical-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e82e023e062f1d25f807ad182008fba1b46538e999f908a08cc0c29e084462e"
|
||||
@@ -1397,6 +1366,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409"
|
||||
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
||||
"checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662"
|
||||
@@ -1422,7 +1392,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828"
|
||||
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
|
||||
"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f"
|
||||
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
|
||||
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
|
||||
"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
|
||||
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
|
||||
@@ -1436,7 +1405,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
|
||||
"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c"
|
||||
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
|
||||
"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0"
|
||||
"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
|
||||
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
|
||||
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
|
||||
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
||||
@@ -1446,7 +1415,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423"
|
||||
"checksum string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eea1eee654ef80933142157fdad9dd8bc43cf7c74e999e369263496f04ff4da"
|
||||
"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
|
||||
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
|
||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||
"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"
|
||||
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@ build = "build.rs"
|
||||
edition = "2018"
|
||||
|
||||
[build-dependencies]
|
||||
lalrpop="0.15.1"
|
||||
lalrpop="0.16.3"
|
||||
|
||||
[dependencies]
|
||||
lalrpop-util="0.15.1"
|
||||
lalrpop-util="0.16.3"
|
||||
log="0.4.1"
|
||||
regex="0.2.2"
|
||||
num-bigint = "0.2"
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
use lalrpop;
|
||||
|
||||
fn main() {
|
||||
lalrpop::process_root().unwrap();
|
||||
lalrpop::Configuration::new()
|
||||
.generate_in_source_tree()
|
||||
.process()
|
||||
.unwrap();
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
use num_bigint::BigInt;
|
||||
|
||||
/// Python source code can be tokenized in a sequence of these tokens.
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Tok {
|
||||
Name { name: String },
|
||||
Int { value: BigInt },
|
||||
|
||||
@@ -13,6 +13,7 @@ pip install pipenv
|
||||
if [ $CODE_COVERAGE = "true" ]
|
||||
then
|
||||
find . -name '*.gcda' -delete
|
||||
find . -name '*.gcno' -delete
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
|
||||
|
||||
+20
-27
@@ -11,6 +11,7 @@ use num_traits::{Signed, ToPrimitive};
|
||||
use crate::compile;
|
||||
use crate::import::import_module;
|
||||
use crate::obj::objbool;
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objint;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objstr::{self, PyStringRef};
|
||||
@@ -27,14 +28,6 @@ use crate::obj::objcode::PyCodeRef;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::stdlib::io::io_open;
|
||||
|
||||
fn get_locals(vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.get_locals()
|
||||
}
|
||||
|
||||
fn dir_locals(vm: &VirtualMachine) -> PyObjectRef {
|
||||
get_locals(vm)
|
||||
}
|
||||
|
||||
fn builtin_abs(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(x, None)]);
|
||||
match vm.get_method(x.clone(), "__abs__") {
|
||||
@@ -88,7 +81,7 @@ fn builtin_bin(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
fn builtin_callable(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(obj, None)]);
|
||||
let is_callable = objtype::class_has_attr(&obj.type_pyref(), "__call__");
|
||||
let is_callable = objtype::class_has_attr(&obj.class(), "__call__");
|
||||
Ok(vm.new_bool(is_callable))
|
||||
}
|
||||
|
||||
@@ -146,7 +139,7 @@ fn builtin_delattr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
fn builtin_dir(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
if args.args.is_empty() {
|
||||
Ok(dir_locals(vm))
|
||||
Ok(vm.get_locals().into_object())
|
||||
} else {
|
||||
let obj = args.args.into_iter().next().unwrap();
|
||||
let seq = vm.call_method(&obj, "__dir__", vec![])?;
|
||||
@@ -240,7 +233,7 @@ fn make_scope(
|
||||
} else if vm.isinstance(arg, &dict_type)? {
|
||||
Some(arg)
|
||||
} else {
|
||||
let arg_typ = arg.typ();
|
||||
let arg_typ = arg.class();
|
||||
let actual_type = vm.to_pystr(&arg_typ)?;
|
||||
let expected_type_name = vm.to_pystr(&dict_type)?;
|
||||
return Err(vm.new_type_error(format!(
|
||||
@@ -254,11 +247,11 @@ fn make_scope(
|
||||
|
||||
let current_scope = vm.current_scope();
|
||||
let globals = match globals {
|
||||
Some(dict) => dict.clone(),
|
||||
Some(dict) => dict.clone().downcast().unwrap(),
|
||||
None => current_scope.globals.clone(),
|
||||
};
|
||||
let locals = match locals {
|
||||
Some(dict) => Some(dict.clone()),
|
||||
Some(dict) => dict.clone().downcast().ok(),
|
||||
None => current_scope.get_only_locals(),
|
||||
};
|
||||
|
||||
@@ -300,7 +293,7 @@ fn builtin_getattr(
|
||||
}
|
||||
}
|
||||
|
||||
fn builtin_globals(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
|
||||
fn builtin_globals(vm: &VirtualMachine) -> PyResult<PyDictRef> {
|
||||
Ok(vm.current_scope().globals.clone())
|
||||
}
|
||||
|
||||
@@ -368,15 +361,14 @@ fn builtin_len(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
Ok(value) => vm.invoke(value, PyFuncArgs::default()),
|
||||
Err(..) => Err(vm.new_type_error(format!(
|
||||
"object of type '{}' has no method {:?}",
|
||||
objtype::get_type_name(&obj.typ()),
|
||||
obj.class().name,
|
||||
len_method_name
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
fn builtin_locals(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args);
|
||||
Ok(vm.get_locals())
|
||||
fn builtin_locals(vm: &VirtualMachine) -> PyDictRef {
|
||||
vm.get_locals()
|
||||
}
|
||||
|
||||
fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
@@ -605,10 +597,9 @@ fn builtin_reversed(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
match vm.get_method(obj.clone(), "__reversed__") {
|
||||
Ok(value) => vm.invoke(value, PyFuncArgs::default()),
|
||||
// TODO: fallback to using __len__ and __getitem__, if object supports sequence protocol
|
||||
Err(..) => Err(vm.new_type_error(format!(
|
||||
"'{}' object is not reversible",
|
||||
objtype::get_type_name(&obj.typ()),
|
||||
))),
|
||||
Err(..) => {
|
||||
Err(vm.new_type_error(format!("'{}' object is not reversible", obj.class().name)))
|
||||
}
|
||||
}
|
||||
}
|
||||
// builtin_reversed
|
||||
@@ -802,9 +793,9 @@ pub fn builtin_build_class_(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResu
|
||||
};
|
||||
|
||||
for base in bases.clone() {
|
||||
if objtype::issubclass(&base.type_pyref(), &metaclass) {
|
||||
metaclass = base.type_pyref();
|
||||
} else if !objtype::issubclass(&metaclass, &base.type_pyref()) {
|
||||
if objtype::issubclass(&base.class(), &metaclass) {
|
||||
metaclass = base.class();
|
||||
} else if !objtype::issubclass(&metaclass, &base.class()) {
|
||||
return Err(vm.new_type_error("metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases".to_string()));
|
||||
}
|
||||
}
|
||||
@@ -815,13 +806,15 @@ pub fn builtin_build_class_(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResu
|
||||
let prepare = vm.get_attribute(metaclass.clone().into_object(), "__prepare__")?;
|
||||
let namespace = vm.invoke(prepare, vec![name_arg.clone(), bases.clone()])?;
|
||||
|
||||
let namespace: PyDictRef = TryFromObject::try_from_object(vm, namespace)?;
|
||||
|
||||
let cells = vm.ctx.new_dict();
|
||||
|
||||
vm.invoke_with_locals(function, cells.clone().into_object(), namespace.clone())?;
|
||||
vm.invoke_with_locals(function, cells.clone(), namespace.clone())?;
|
||||
let class = vm.call_method(
|
||||
metaclass.as_object(),
|
||||
"__call__",
|
||||
vec![name_arg, bases, namespace],
|
||||
vec![name_arg, bases, namespace.into_object()],
|
||||
)?;
|
||||
cells.set_item(&vm.ctx, "__class__", class.clone());
|
||||
Ok(class)
|
||||
|
||||
@@ -68,7 +68,6 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
args,
|
||||
required = [(exc, Some(vm.ctx.exceptions.exception_type.clone()))]
|
||||
);
|
||||
let type_name = objtype::get_type_name(&exc.typ());
|
||||
let msg = if let Ok(m) = vm.get_attribute(exc.clone(), "msg") {
|
||||
match vm.to_pystr(&m) {
|
||||
Ok(msg) => msg,
|
||||
@@ -77,7 +76,7 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
} else {
|
||||
panic!("Error message must be set");
|
||||
};
|
||||
let s = format!("{}: {}", type_name, msg);
|
||||
let s = format!("{}: {}", exc.class().name, msg);
|
||||
Ok(vm.new_str(s))
|
||||
}
|
||||
|
||||
|
||||
+16
-19
@@ -12,8 +12,7 @@ use crate::function::PyFuncArgs;
|
||||
use crate::obj::objbool;
|
||||
use crate::obj::objbuiltinfunc::PyBuiltinFunction;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objdict;
|
||||
use crate::obj::objdict::PyDict;
|
||||
use crate::obj::objdict::{self, PyDictRef};
|
||||
use crate::obj::objint::PyInt;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objlist;
|
||||
@@ -80,8 +79,8 @@ impl<'a, T> Iterator for Iter<'a, T> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Scope {
|
||||
locals: RcList<PyObjectRef>,
|
||||
pub globals: PyObjectRef,
|
||||
locals: RcList<PyDictRef>,
|
||||
pub globals: PyDictRef,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Scope {
|
||||
@@ -92,7 +91,7 @@ impl fmt::Debug for Scope {
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
pub fn new(locals: Option<PyObjectRef>, globals: PyObjectRef) -> Scope {
|
||||
pub fn new(locals: Option<PyDictRef>, globals: PyDictRef) -> Scope {
|
||||
let locals = match locals {
|
||||
Some(dict) => RcList::new().insert(dict),
|
||||
None => RcList::new(),
|
||||
@@ -100,18 +99,18 @@ impl Scope {
|
||||
Scope { locals, globals }
|
||||
}
|
||||
|
||||
pub fn get_locals(&self) -> PyObjectRef {
|
||||
pub fn get_locals(&self) -> PyDictRef {
|
||||
match self.locals.iter().next() {
|
||||
Some(dict) => dict.clone(),
|
||||
None => self.globals.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_only_locals(&self) -> Option<PyObjectRef> {
|
||||
pub fn get_only_locals(&self) -> Option<PyDictRef> {
|
||||
self.locals.iter().next().cloned()
|
||||
}
|
||||
|
||||
pub fn child_scope_with_locals(&self, locals: PyObjectRef) -> Scope {
|
||||
pub fn child_scope_with_locals(&self, locals: PyDictRef) -> Scope {
|
||||
Scope {
|
||||
locals: self.locals.clone().insert(locals),
|
||||
globals: self.globals.clone(),
|
||||
@@ -119,7 +118,7 @@ impl Scope {
|
||||
}
|
||||
|
||||
pub fn child_scope(&self, ctx: &PyContext) -> Scope {
|
||||
self.child_scope_with_locals(ctx.new_dict().into_object())
|
||||
self.child_scope_with_locals(ctx.new_dict())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,7 +948,7 @@ impl Frame {
|
||||
// let args = PyFuncArgs::default();
|
||||
// TODO: what happens when we got an error during handling exception?
|
||||
let args = if let Some(exc) = exc {
|
||||
let exc_type = exc.typ();
|
||||
let exc_type = exc.class().into_object();
|
||||
let exc_val = exc.clone();
|
||||
let exc_tb = vm.ctx.none(); // TODO: retrieve traceback?
|
||||
vec![exc_type, exc_val, exc_tb]
|
||||
@@ -1093,7 +1092,7 @@ impl Frame {
|
||||
Ok(found) => Ok(found),
|
||||
Err(_) => Err(vm.new_type_error(format!(
|
||||
"{} has no __contains__ method",
|
||||
objtype::get_type_name(&haystack.typ())
|
||||
haystack.class().name
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -1103,7 +1102,7 @@ impl Frame {
|
||||
Ok(found) => Ok(vm.ctx.new_bool(!objbool::get_value(&found))),
|
||||
Err(_) => Err(vm.new_type_error(format!(
|
||||
"{} has no __contains__ method",
|
||||
objtype::get_type_name(&haystack.typ())
|
||||
haystack.class().name
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -1232,13 +1231,11 @@ impl fmt::Debug for Frame {
|
||||
.iter()
|
||||
.map(|elem| format!("\n > {:?}", elem))
|
||||
.collect::<String>();
|
||||
let local_str = match self.scope.get_locals().payload::<PyDict>() {
|
||||
Some(dict) => objdict::get_key_value_pairs_from_content(&dict.entries.borrow())
|
||||
.iter()
|
||||
.map(|elem| format!("\n {:?} = {:?}", elem.0, elem.1))
|
||||
.collect::<String>(),
|
||||
None => panic!("locals unexpectedly not wrapping a dict!",),
|
||||
};
|
||||
let dict = self.scope.get_locals();
|
||||
let local_str = objdict::get_key_value_pairs_from_content(&dict.entries.borrow())
|
||||
.iter()
|
||||
.map(|elem| format!("\n {:?} = {:?}", elem.0, elem.1))
|
||||
.collect::<String>();
|
||||
write!(
|
||||
f,
|
||||
"Frame Object {{ \n Stack:{}\n Blocks:{}\n Locals:{}\n}}",
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ impl PyFuncArgs {
|
||||
Ok(Some(kwarg))
|
||||
} else {
|
||||
let expected_ty_name = vm.to_pystr(&ty)?;
|
||||
let actual_ty_name = vm.to_pystr(&kwarg.typ())?;
|
||||
let actual_ty_name = vm.to_pystr(&kwarg.class())?;
|
||||
Err(vm.new_type_error(format!(
|
||||
"argument of type {} is required for named parameter `{}` (got: {})",
|
||||
expected_ty_name, key, actual_ty_name
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ fn import_uncached_module(vm: &VirtualMachine, current_path: PathBuf, module: &s
|
||||
|
||||
let attrs = vm.ctx.new_dict();
|
||||
attrs.set_item(&vm.ctx, "__name__", vm.new_str(module.to_string()));
|
||||
vm.run_code_obj(code_obj, Scope::new(None, attrs.clone().into_object()))?;
|
||||
vm.run_code_obj(code_obj, Scope::new(None, attrs.clone()))?;
|
||||
Ok(vm.ctx.new_module(module, attrs))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ macro_rules! type_check {
|
||||
let arg = &$args.args[$arg_count];
|
||||
|
||||
if !$crate::obj::objtype::isinstance(arg, &expected_type) {
|
||||
let arg_typ = arg.typ();
|
||||
let arg_typ = arg.class();
|
||||
let expected_type_name = $vm.to_pystr(&expected_type)?;
|
||||
let actual_type = $vm.to_pystr(&arg_typ)?;
|
||||
return Err($vm.new_type_error(format!(
|
||||
|
||||
@@ -190,8 +190,7 @@ impl PyFloatRef {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let type_name = objtype::get_type_name(&arg.typ());
|
||||
return Err(vm.new_type_error(format!("can't convert {} to float", type_name)));
|
||||
return Err(vm.new_type_error(format!("can't convert {} to float", arg.class().name)));
|
||||
};
|
||||
PyFloat { value }.into_ref_with_type(vm, cls)
|
||||
}
|
||||
|
||||
+22
-30
@@ -2,43 +2,35 @@
|
||||
|
||||
*/
|
||||
|
||||
use crate::frame::Frame;
|
||||
use crate::function::PyFuncArgs;
|
||||
use crate::pyobject::{PyContext, PyObjectRef, PyResult, TypeProtocol};
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objdict::PyDictRef;
|
||||
use crate::frame::FrameRef;
|
||||
use crate::pyobject::{PyContext, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
pub fn init(context: &PyContext) {
|
||||
let frame_type = &context.frame_type;
|
||||
extend_class!(context, frame_type, {
|
||||
"__new__" => context.new_rustfunc(frame_new),
|
||||
"__repr__" => context.new_rustfunc(frame_repr),
|
||||
"f_locals" => context.new_property(frame_flocals),
|
||||
"f_code" => context.new_property(frame_fcode)
|
||||
extend_class!(context, &context.frame_type, {
|
||||
"__new__" => context.new_rustfunc(FrameRef::new),
|
||||
"__repr__" => context.new_rustfunc(FrameRef::repr),
|
||||
"f_locals" => context.new_property(FrameRef::flocals),
|
||||
"f_code" => context.new_property(FrameRef::fcode),
|
||||
});
|
||||
}
|
||||
|
||||
fn frame_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(_cls, None)]);
|
||||
Err(vm.new_type_error("Cannot directly create frame object".to_string()))
|
||||
}
|
||||
impl FrameRef {
|
||||
fn new(_class: FrameRef, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("Cannot directly create frame object".to_string()))
|
||||
}
|
||||
|
||||
fn frame_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(_frame, Some(vm.ctx.frame_type()))]);
|
||||
let repr = "<frame object at .. >".to_string();
|
||||
Ok(vm.new_str(repr))
|
||||
}
|
||||
fn repr(self, _vm: &VirtualMachine) -> String {
|
||||
"<frame object at .. >".to_string()
|
||||
}
|
||||
|
||||
fn frame_flocals(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(frame, Some(vm.ctx.frame_type()))]);
|
||||
let frame = get_value(frame);
|
||||
Ok(frame.scope.get_locals().clone())
|
||||
}
|
||||
fn flocals(self, _vm: &VirtualMachine) -> PyDictRef {
|
||||
self.scope.get_locals()
|
||||
}
|
||||
|
||||
fn frame_fcode(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(frame, Some(vm.ctx.frame_type()))]);
|
||||
Ok(vm.ctx.new_code_object(get_value(frame).code.clone()))
|
||||
}
|
||||
|
||||
pub fn get_value(obj: &PyObjectRef) -> &Frame {
|
||||
&obj.payload::<Frame>().unwrap()
|
||||
fn fcode(self, vm: &VirtualMachine) -> PyCodeRef {
|
||||
vm.ctx.new_code_object(self.code.clone())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::frame::Scope;
|
||||
use crate::function::PyFuncArgs;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objtype::PyClassRef;
|
||||
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
|
||||
@@ -69,16 +68,15 @@ pub fn init(context: &PyContext) {
|
||||
});
|
||||
}
|
||||
|
||||
fn bind_method(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(function, None), (obj, None), (cls, None)]
|
||||
);
|
||||
|
||||
if obj.is(&vm.get_none()) && !cls.is(&obj.typ()) {
|
||||
Ok(function.clone())
|
||||
fn bind_method(
|
||||
function: PyObjectRef,
|
||||
obj: PyObjectRef,
|
||||
cls: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
if obj.is(&vm.get_none()) && !cls.is(&obj.class()) {
|
||||
Ok(function)
|
||||
} else {
|
||||
Ok(vm.ctx.new_bound_method(function.clone(), obj.clone()))
|
||||
Ok(vm.ctx.new_bound_method(function, obj))
|
||||
}
|
||||
}
|
||||
+3
-12
@@ -211,11 +211,7 @@ impl PyIntRef {
|
||||
|
||||
fn lshift(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
if !objtype::isinstance(&other, &vm.ctx.int_type()) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"unsupported operand type(s) for << '{}' and '{}'",
|
||||
objtype::get_type_name(&self.as_object().typ()),
|
||||
objtype::get_type_name(&other.typ())
|
||||
)));
|
||||
return Ok(vm.ctx.not_implemented());
|
||||
}
|
||||
|
||||
if let Some(n_bits) = get_value(&other).to_usize() {
|
||||
@@ -234,11 +230,7 @@ impl PyIntRef {
|
||||
|
||||
fn rshift(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
if !objtype::isinstance(&other, &vm.ctx.int_type()) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"unsupported operand type(s) for >> '{}' and '{}'",
|
||||
objtype::get_type_name(&self.as_object().typ()),
|
||||
objtype::get_type_name(&other.typ())
|
||||
)));
|
||||
return Ok(vm.ctx.not_implemented());
|
||||
}
|
||||
|
||||
if let Some(n_bits) = get_value(&other).to_usize() {
|
||||
@@ -420,10 +412,9 @@ pub fn to_int(vm: &VirtualMachine, obj: &PyObjectRef, base: u32) -> PyResult<Big
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let type_name = objtype::get_type_name(&obj.typ());
|
||||
return Err(vm.new_type_error(format!(
|
||||
"int() argument must be a string or a number, not '{}'",
|
||||
type_name
|
||||
obj.class().name
|
||||
)));
|
||||
};
|
||||
Ok(val)
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::obj::objtype::PyClassRef;
|
||||
*/
|
||||
pub fn get_iter(vm: &VirtualMachine, iter_target: &PyObjectRef) -> PyResult {
|
||||
vm.call_method(iter_target, "__iter__", vec![])
|
||||
// let type_str = objstr::get_value(&vm.to_str(iter_target.typ()).unwrap());
|
||||
// let type_str = objstr::get_value(&vm.to_str(iter_target.class()).unwrap());
|
||||
// let type_error = vm.new_type_error(format!("Cannot iterate over {}", type_str));
|
||||
// return Err(type_error);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ pub type PyNoneRef = PyRef<PyNone>;
|
||||
|
||||
impl PyValue for PyNone {
|
||||
fn class(vm: &VirtualMachine) -> PyClassRef {
|
||||
vm.ctx.none().type_pyref()
|
||||
vm.ctx.none().class()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl PyNoneRef {
|
||||
|
||||
fn get_attribute(self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
trace!("None.__getattribute__({:?}, {:?})", self, name);
|
||||
let cls = self.typ();
|
||||
let cls = self.class();
|
||||
|
||||
// Properties use a comparision with None to determine if they are either invoked by am
|
||||
// instance binding or a class binding. But if the object itself is None then this detection
|
||||
@@ -69,7 +69,7 @@ impl PyNoneRef {
|
||||
}
|
||||
|
||||
if let Some(attr) = class_get_attr(&cls, &name.value) {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if class_has_attr(&attr_class, "__set__") {
|
||||
if let Some(get_func) = class_get_attr(&attr_class, "__get__") {
|
||||
return call_descriptor(
|
||||
@@ -88,7 +88,7 @@ impl PyNoneRef {
|
||||
// Ok(obj_attr)
|
||||
// } else
|
||||
if let Some(attr) = class_get_attr(&cls, &name.value) {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if let Some(get_func) = class_get_attr(&attr_class, "__get__") {
|
||||
call_descriptor(attr, get_func, self.into_object(), cls.into_object(), vm)
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ fn none_new(_: PyClassRef, vm: &VirtualMachine) -> PyNoneRef {
|
||||
}
|
||||
|
||||
pub fn init(context: &PyContext) {
|
||||
extend_class!(context, &context.none.typ(), {
|
||||
extend_class!(context, &context.none.class(), {
|
||||
"__new__" => context.new_rustfunc(none_new),
|
||||
"__repr__" => context.new_rustfunc(PyNoneRef::repr),
|
||||
"__bool__" => context.new_rustfunc(PyNoneRef::bool),
|
||||
|
||||
+36
-86
@@ -1,6 +1,6 @@
|
||||
use super::objdict::{self, PyDictRef};
|
||||
use super::objlist::PyList;
|
||||
use super::objstr::{self, PyStringRef};
|
||||
use super::objstr::PyStringRef;
|
||||
use super::objtype;
|
||||
use crate::function::PyFuncArgs;
|
||||
use crate::obj::objproperty::PropertyBuilder;
|
||||
@@ -31,69 +31,31 @@ pub fn new_instance(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResult {
|
||||
Ok(PyObject::new(PyInstance, cls, dict))
|
||||
}
|
||||
|
||||
fn object_eq(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_eq(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_ne(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_ne(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_lt(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_lt(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_le(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_le(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_gt(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_gt(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_ge(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
|
||||
);
|
||||
|
||||
Ok(vm.ctx.not_implemented())
|
||||
fn object_ge(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
|
||||
fn object_hash(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.object()))]);
|
||||
|
||||
// For now default to non hashable
|
||||
fn object_hash(_zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("unhashable type".to_string()))
|
||||
}
|
||||
|
||||
@@ -104,10 +66,10 @@ fn object_setattr(
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
trace!("object.__setattr__({:?}, {}, {:?})", obj, attr_name, value);
|
||||
let cls = obj.type_pyref();
|
||||
let cls = obj.class();
|
||||
|
||||
if let Some(attr) = objtype::class_get_attr(&cls, &attr_name.value) {
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr.type_pyref(), "__set__") {
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr.class(), "__set__") {
|
||||
return vm
|
||||
.invoke(descriptor, vec![attr, obj.clone(), value])
|
||||
.map(|_| ());
|
||||
@@ -118,19 +80,19 @@ fn object_setattr(
|
||||
dict.set_item(&vm.ctx, &attr_name.value, value);
|
||||
Ok(())
|
||||
} else {
|
||||
let type_name = objtype::get_type_name(obj.type_ref());
|
||||
Err(vm.new_attribute_error(format!(
|
||||
"'{}' object has no attribute '{}'",
|
||||
type_name, &attr_name.value
|
||||
obj.class().name,
|
||||
&attr_name.value
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
fn object_delattr(obj: PyObjectRef, attr_name: PyStringRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let cls = obj.type_pyref();
|
||||
let cls = obj.class();
|
||||
|
||||
if let Some(attr) = objtype::class_get_attr(&cls, &attr_name.value) {
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr.type_pyref(), "__delete__") {
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr.class(), "__delete__") {
|
||||
return vm.invoke(descriptor, vec![attr, obj.clone()]).map(|_| ());
|
||||
}
|
||||
}
|
||||
@@ -139,24 +101,20 @@ fn object_delattr(obj: PyObjectRef, attr_name: PyStringRef, vm: &VirtualMachine)
|
||||
dict.del_item(&attr_name.value);
|
||||
Ok(())
|
||||
} else {
|
||||
let type_name = objtype::get_type_name(obj.type_ref());
|
||||
Err(vm.new_attribute_error(format!(
|
||||
"'{}' object has no attribute '{}'",
|
||||
type_name, &attr_name.value
|
||||
obj.class().name,
|
||||
&attr_name.value
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
fn object_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(zelf, Some(vm.ctx.object()))]);
|
||||
vm.call_method(zelf, "__repr__", vec![])
|
||||
fn object_str(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm.call_method(&zelf, "__repr__", vec![])
|
||||
}
|
||||
|
||||
fn object_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(obj, Some(vm.ctx.object()))]);
|
||||
let type_name = objtype::get_type_name(&obj.typ());
|
||||
let address = obj.get_id();
|
||||
Ok(vm.new_str(format!("<{} object at 0x{:x}>", type_name, address)))
|
||||
fn object_repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String {
|
||||
format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id())
|
||||
}
|
||||
|
||||
pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyList {
|
||||
@@ -216,7 +174,7 @@ fn object_init(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
|
||||
}
|
||||
|
||||
fn object_class(obj: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
obj.typ()
|
||||
obj.class().into_object()
|
||||
}
|
||||
|
||||
fn object_class_setter(
|
||||
@@ -224,7 +182,7 @@ fn object_class_setter(
|
||||
_value: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let type_repr = vm.to_pystr(&instance.typ())?;
|
||||
let type_repr = vm.to_pystr(&instance.class())?;
|
||||
Err(vm.new_type_error(format!("can't change class of type '{}'", type_repr)))
|
||||
}
|
||||
|
||||
@@ -236,24 +194,16 @@ fn object_dict(object: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDictRef>
|
||||
}
|
||||
}
|
||||
|
||||
fn object_getattribute(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
required = [
|
||||
(obj, Some(vm.ctx.object())),
|
||||
(name_str, Some(vm.ctx.str_type()))
|
||||
]
|
||||
);
|
||||
let name = objstr::get_value(&name_str);
|
||||
fn object_getattribute(obj: PyObjectRef, name_str: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
let name = &name_str.value;
|
||||
trace!("object.__getattribute__({:?}, {:?})", obj, name);
|
||||
let cls = obj.type_pyref();
|
||||
let cls = obj.class();
|
||||
|
||||
if let Some(attr) = objtype::class_get_attr(&cls, &name) {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if objtype::class_has_attr(&attr_class, "__set__") {
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr_class, "__get__") {
|
||||
return vm.invoke(descriptor, vec![attr, obj.clone(), cls.into_object()]);
|
||||
return vm.invoke(descriptor, vec![attr, obj, cls.into_object()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,9 +211,9 @@ fn object_getattribute(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
if let Some(obj_attr) = object_getattr(&obj, &name) {
|
||||
Ok(obj_attr)
|
||||
} else if let Some(attr) = objtype::class_get_attr(&cls, &name) {
|
||||
vm.call_get_descriptor(attr, obj.clone())
|
||||
vm.call_get_descriptor(attr, obj)
|
||||
} else if let Some(getter) = objtype::class_get_attr(&cls, "__getattr__") {
|
||||
vm.invoke(getter, vec![obj.clone(), name_str.clone()])
|
||||
vm.invoke(getter, vec![obj, name_str.into_object()])
|
||||
} else {
|
||||
Err(vm.new_attribute_error(format!("{} has no attribute '{}'", obj, name)))
|
||||
}
|
||||
@@ -279,7 +229,7 @@ fn object_getattr(obj: &PyObjectRef, attr_name: &str) -> Option<PyObjectRef> {
|
||||
|
||||
pub fn get_attributes(obj: &PyObjectRef) -> PyAttributes {
|
||||
// Get class attributes:
|
||||
let mut attributes = objtype::get_attributes(obj.type_pyref());
|
||||
let mut attributes = objtype::get_attributes(obj.class());
|
||||
|
||||
// Get instance attributes:
|
||||
if let Some(dict) = &obj.dict {
|
||||
|
||||
@@ -6,7 +6,9 @@ use crate::function::IntoPyNativeFunc;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objstr::PyStringRef;
|
||||
use crate::obj::objtype::PyClassRef;
|
||||
use crate::pyobject::{IdProtocol, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::pyobject::{
|
||||
IdProtocol, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
/// Read-only property, doesn't have __set__ or __delete__
|
||||
@@ -137,7 +139,7 @@ impl PyPropertyRef {
|
||||
setter: self.setter.clone(),
|
||||
deleter: self.deleter.clone(),
|
||||
}
|
||||
.into_ref_with_type(vm, self.typ())
|
||||
.into_ref_with_type(vm, TypeProtocol::class(&self))
|
||||
}
|
||||
|
||||
fn setter(self, setter: Option<PyObjectRef>, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
@@ -146,7 +148,7 @@ impl PyPropertyRef {
|
||||
setter: setter.or_else(|| self.setter.clone()),
|
||||
deleter: self.deleter.clone(),
|
||||
}
|
||||
.into_ref_with_type(vm, self.typ())
|
||||
.into_ref_with_type(vm, TypeProtocol::class(&self))
|
||||
}
|
||||
|
||||
fn deleter(self, deleter: Option<PyObjectRef>, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
@@ -155,7 +157,7 @@ impl PyPropertyRef {
|
||||
setter: self.setter.clone(),
|
||||
deleter: deleter.or_else(|| self.deleter.clone()),
|
||||
}
|
||||
.into_ref_with_type(vm, self.typ())
|
||||
.into_ref_with_type(vm, TypeProtocol::class(&self))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,13 +163,13 @@ pub fn get_item(
|
||||
if sequence.payload::<PyList>().is_some() {
|
||||
Ok(PyObject::new(
|
||||
PyList::from(elements.to_vec().get_slice_items(vm, &subscript)?),
|
||||
sequence.type_pyref(),
|
||||
sequence.class(),
|
||||
None,
|
||||
))
|
||||
} else if sequence.payload::<PyTuple>().is_some() {
|
||||
Ok(PyObject::new(
|
||||
PyTuple::from(elements.to_vec().get_slice_items(vm, &subscript)?),
|
||||
sequence.type_pyref(),
|
||||
sequence.class(),
|
||||
None,
|
||||
))
|
||||
} else {
|
||||
|
||||
+15
-15
@@ -231,16 +231,16 @@ fn set_new(cls: PyClassRef, iterable: OptionalArg<PyObjectRef>, vm: &VirtualMach
|
||||
fn set_len(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
trace!("set.len called with: {:?}", args);
|
||||
arg_check!(vm, args, required = [(s, None)]);
|
||||
validate_set_or_frozenset(vm, s.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, s.class())?;
|
||||
let elements = get_elements(s);
|
||||
Ok(vm.context().new_int(elements.len()))
|
||||
}
|
||||
|
||||
fn set_copy(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
trace!("set.copy called with: {:?}", obj);
|
||||
validate_set_or_frozenset(vm, obj.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, obj.class())?;
|
||||
let elements = get_elements(&obj).clone();
|
||||
create_set(vm, elements, obj.type_pyref())
|
||||
create_set(vm, elements, obj.class())
|
||||
}
|
||||
|
||||
fn set_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
@@ -265,7 +265,7 @@ fn set_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
pub fn set_contains(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(set, None), (needle, None)]);
|
||||
validate_set_or_frozenset(vm, set.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, set.class())?;
|
||||
for element in get_elements(set).iter() {
|
||||
match vm._eq(needle.clone(), element.1.clone()) {
|
||||
Ok(value) => {
|
||||
@@ -333,8 +333,8 @@ fn set_compare_inner(
|
||||
) -> PyResult {
|
||||
arg_check!(vm, args, required = [(zelf, None), (other, None)]);
|
||||
|
||||
validate_set_or_frozenset(vm, zelf.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, other.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, zelf.class())?;
|
||||
validate_set_or_frozenset(vm, other.class())?;
|
||||
|
||||
let get_zelf = |swap: bool| -> &PyObjectRef {
|
||||
if swap {
|
||||
@@ -370,13 +370,13 @@ fn set_compare_inner(
|
||||
}
|
||||
|
||||
fn set_union(zelf: PyObjectRef, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
validate_set_or_frozenset(vm, zelf.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, other.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, zelf.class())?;
|
||||
validate_set_or_frozenset(vm, other.class())?;
|
||||
|
||||
let mut elements = get_elements(&zelf).clone();
|
||||
elements.extend(get_elements(&other).clone());
|
||||
|
||||
create_set(vm, elements, zelf.type_pyref())
|
||||
create_set(vm, elements, zelf.class())
|
||||
}
|
||||
|
||||
fn set_intersection(zelf: PyObjectRef, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -392,8 +392,8 @@ fn set_symmetric_difference(
|
||||
other: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
validate_set_or_frozenset(vm, zelf.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, other.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, zelf.class())?;
|
||||
validate_set_or_frozenset(vm, other.class())?;
|
||||
let mut elements = HashMap::new();
|
||||
|
||||
for element in get_elements(&zelf).iter() {
|
||||
@@ -410,7 +410,7 @@ fn set_symmetric_difference(
|
||||
}
|
||||
}
|
||||
|
||||
create_set(vm, elements, zelf.type_pyref())
|
||||
create_set(vm, elements, zelf.class())
|
||||
}
|
||||
|
||||
enum SetCombineOperation {
|
||||
@@ -424,8 +424,8 @@ fn set_combine_inner(
|
||||
vm: &VirtualMachine,
|
||||
op: SetCombineOperation,
|
||||
) -> PyResult {
|
||||
validate_set_or_frozenset(vm, zelf.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, other.type_pyref())?;
|
||||
validate_set_or_frozenset(vm, zelf.class())?;
|
||||
validate_set_or_frozenset(vm, other.class())?;
|
||||
let mut elements = HashMap::new();
|
||||
|
||||
for element in get_elements(&zelf).iter() {
|
||||
@@ -439,7 +439,7 @@ fn set_combine_inner(
|
||||
}
|
||||
}
|
||||
|
||||
create_set(vm, elements, zelf.type_pyref())
|
||||
create_set(vm, elements, zelf.class())
|
||||
}
|
||||
|
||||
fn set_pop(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
@@ -715,7 +715,7 @@ fn str_format(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
let zelf = &args.args[0];
|
||||
if !objtype::isinstance(&zelf, &vm.ctx.str_type()) {
|
||||
let zelf_typ = zelf.typ();
|
||||
let zelf_typ = zelf.class();
|
||||
let actual_type = vm.to_pystr(&zelf_typ)?;
|
||||
return Err(vm.new_type_error(format!(
|
||||
"descriptor 'format' requires a 'str' object but received a '{}'",
|
||||
@@ -738,7 +738,7 @@ fn call_object_format(vm: &VirtualMachine, argument: PyObjectRef, format_spec: &
|
||||
let returned_type = vm.ctx.new_str(format_spec.to_string());
|
||||
let result = vm.call_method(&argument, "__format__", vec![returned_type])?;
|
||||
if !objtype::isinstance(&result, &vm.ctx.str_type()) {
|
||||
let result_type = result.typ();
|
||||
let result_type = result.class();
|
||||
let actual_type = vm.to_pystr(&result_type)?;
|
||||
return Err(vm.new_type_error(format!("__format__ must return a str, not {}", actual_type)));
|
||||
}
|
||||
@@ -809,7 +809,7 @@ fn str_new(
|
||||
OptionalArg::Present(ref input) => vm.to_str(input)?.into_object(),
|
||||
OptionalArg::Missing => vm.new_str("".to_string()),
|
||||
};
|
||||
if string.typ().is(&cls) {
|
||||
if string.class().is(&cls) {
|
||||
TryFromObject::try_from_object(vm, string)
|
||||
} else {
|
||||
let payload = string.payload::<PyString>().unwrap();
|
||||
|
||||
@@ -112,10 +112,9 @@ fn super_new(
|
||||
|
||||
// Check type argument:
|
||||
if !objtype::isinstance(py_type.as_object(), &vm.get_type()) {
|
||||
let type_name = objtype::get_type_name(py_type.as_object().type_ref());
|
||||
return Err(vm.new_type_error(format!(
|
||||
"super() argument 1 must be type, not {}",
|
||||
type_name
|
||||
py_type.class().name
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
+7
-21
@@ -39,12 +39,6 @@ impl PyValue for PyClass {
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeProtocol for PyClassRef {
|
||||
fn type_ref(&self) -> &PyObjectRef {
|
||||
&self.as_object().type_ref()
|
||||
}
|
||||
}
|
||||
|
||||
struct IterMro<'a> {
|
||||
cls: &'a PyClassRef,
|
||||
offset: Option<usize>,
|
||||
@@ -117,10 +111,10 @@ impl PyClassRef {
|
||||
fn getattribute(self, name_ref: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
let name = &name_ref.value;
|
||||
trace!("type.__getattribute__({:?}, {:?})", self, name);
|
||||
let mcl = self.type_pyref();
|
||||
let mcl = self.class();
|
||||
|
||||
if let Some(attr) = class_get_attr(&mcl, &name) {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if class_has_attr(&attr_class, "__set__") {
|
||||
if let Some(descriptor) = class_get_attr(&attr_class, "__get__") {
|
||||
return vm.invoke(
|
||||
@@ -132,7 +126,7 @@ impl PyClassRef {
|
||||
}
|
||||
|
||||
if let Some(attr) = class_get_attr(&self, &name) {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if let Some(descriptor) = class_get_attr(&attr_class, "__get__") {
|
||||
let none = vm.get_none();
|
||||
return vm.invoke(descriptor, vec![attr, none, self.into_object()]);
|
||||
@@ -156,8 +150,8 @@ impl PyClassRef {
|
||||
value: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if let Some(attr) = class_get_attr(&self.type_pyref(), &attr_name.value) {
|
||||
if let Some(descriptor) = class_get_attr(&attr.type_pyref(), "__set__") {
|
||||
if let Some(attr) = class_get_attr(&self.class(), &attr_name.value) {
|
||||
if let Some(descriptor) = class_get_attr(&attr.class(), "__set__") {
|
||||
vm.invoke(descriptor, vec![attr, self.into_object(), value])?;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -218,7 +212,7 @@ fn _mro(cls: &PyClassRef) -> Vec<PyClassRef> {
|
||||
/// Determines if `obj` actually an instance of `cls`, this doesn't call __instancecheck__, so only
|
||||
/// use this if `cls` is known to have not overridden the base __instancecheck__ magic method.
|
||||
pub fn isinstance(obj: &PyObjectRef, cls: &PyClassRef) -> bool {
|
||||
issubclass(&obj.type_pyref(), &cls)
|
||||
issubclass(&obj.class(), &cls)
|
||||
}
|
||||
|
||||
/// Determines if `subclass` is actually a subclass of `cls`, this doesn't call __subclasscheck__,
|
||||
@@ -229,18 +223,10 @@ pub fn issubclass(subclass: &PyClassRef, cls: &PyClassRef) -> bool {
|
||||
subclass.is(cls) || mro.iter().any(|c| c.is(cls.as_object()))
|
||||
}
|
||||
|
||||
pub fn get_type_name(typ: &PyObjectRef) -> String {
|
||||
if let Some(PyClass { name, .. }) = &typ.payload::<PyClass>() {
|
||||
name.clone()
|
||||
} else {
|
||||
panic!("Cannot get type_name of non-type type {:?}", typ);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn type_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
debug!("type.__new__ {:?}", args);
|
||||
if args.args.len() == 2 {
|
||||
Ok(args.args[1].typ())
|
||||
Ok(args.args[1].class().into_object())
|
||||
} else if args.args.len() == 4 {
|
||||
let (typ, name, bases, dict) = args.bind(vm)?;
|
||||
type_new_class(vm, typ, name, bases, dict).map(|x| x.into_object())
|
||||
|
||||
+25
-21
@@ -88,7 +88,7 @@ impl fmt::Display for PyObject<dyn PyObjectPayload> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::TypeProtocol;
|
||||
if let Some(PyClass { ref name, .. }) = self.payload::<PyClass>() {
|
||||
let type_name = objtype::get_type_name(&self.typ());
|
||||
let type_name = self.class().name.clone();
|
||||
// We don't have access to a vm, so just assume that if its parent's name
|
||||
// is type, it's a type
|
||||
if type_name == "type" {
|
||||
@@ -101,7 +101,7 @@ impl fmt::Display for PyObject<dyn PyObjectPayload> {
|
||||
if let Some(PyModule { ref name, .. }) = self.payload::<PyModule>() {
|
||||
return write!(f, "module '{}'", name);
|
||||
}
|
||||
write!(f, "'{}' object", objtype::get_type_name(&self.typ()))
|
||||
write!(f, "'{}' object", self.class().name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ pub struct PyNotImplemented;
|
||||
|
||||
impl PyValue for PyNotImplemented {
|
||||
fn class(vm: &VirtualMachine) -> PyClassRef {
|
||||
vm.ctx.not_implemented().type_pyref()
|
||||
vm.ctx.not_implemented().class()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,7 +582,7 @@ impl PyContext {
|
||||
}
|
||||
|
||||
pub fn new_scope(&self) -> Scope {
|
||||
Scope::new(None, self.new_dict().into_object())
|
||||
Scope::new(None, self.new_dict())
|
||||
}
|
||||
|
||||
pub fn new_module(&self, name: &str, dict: PyDictRef) -> PyObjectRef {
|
||||
@@ -613,8 +613,10 @@ impl PyContext {
|
||||
PropertyBuilder::new(self).add_getter(f).create()
|
||||
}
|
||||
|
||||
pub fn new_code_object(&self, code: bytecode::CodeObject) -> PyObjectRef {
|
||||
pub fn new_code_object(&self, code: bytecode::CodeObject) -> PyCodeRef {
|
||||
PyObject::new(objcode::PyCode::new(code), self.code_type(), None)
|
||||
.downcast()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn new_function(
|
||||
@@ -683,7 +685,9 @@ impl PyContext {
|
||||
bytecode::Constant::String { ref value } => self.new_str(value.clone()),
|
||||
bytecode::Constant::Bytes { ref value } => self.new_bytes(value.clone()),
|
||||
bytecode::Constant::Boolean { ref value } => self.new_bool(value.clone()),
|
||||
bytecode::Constant::Code { ref code } => self.new_code_object(*code.clone()),
|
||||
bytecode::Constant::Code { ref code } => {
|
||||
self.new_code_object(*code.clone()).into_object()
|
||||
}
|
||||
bytecode::Constant::Tuple { ref elements } => {
|
||||
let elements = elements
|
||||
.iter()
|
||||
@@ -772,7 +776,7 @@ impl<T: PyValue> PyRef<T> {
|
||||
|
||||
pub fn typ(&self) -> PyClassRef {
|
||||
PyRef {
|
||||
obj: self.obj.typ(),
|
||||
obj: self.obj.class().into_object(),
|
||||
_payload: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -802,7 +806,7 @@ where
|
||||
} else {
|
||||
let class = T::class(vm);
|
||||
let expected_type = vm.to_pystr(&class)?;
|
||||
let actual_type = vm.to_pystr(&obj.typ())?;
|
||||
let actual_type = vm.to_pystr(&obj.class())?;
|
||||
Err(vm.new_type_error(format!(
|
||||
"Expected type {}, not {}",
|
||||
expected_type, actual_type,
|
||||
@@ -877,18 +881,12 @@ impl<T: PyObjectPayload> IdProtocol for PyRef<T> {
|
||||
}
|
||||
|
||||
pub trait TypeProtocol {
|
||||
fn typ(&self) -> PyObjectRef {
|
||||
self.type_ref().clone()
|
||||
}
|
||||
fn type_pyref(&self) -> PyClassRef {
|
||||
self.typ().downcast().unwrap()
|
||||
}
|
||||
fn type_ref(&self) -> &PyObjectRef;
|
||||
fn class(&self) -> PyClassRef;
|
||||
}
|
||||
|
||||
impl TypeProtocol for PyObjectRef {
|
||||
fn type_ref(&self) -> &PyObjectRef {
|
||||
(**self).type_ref()
|
||||
fn class(&self) -> PyClassRef {
|
||||
(**self).class()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,8 +894,14 @@ impl<T> TypeProtocol for PyObject<T>
|
||||
where
|
||||
T: ?Sized + PyObjectPayload,
|
||||
{
|
||||
fn type_ref(&self) -> &PyObjectRef {
|
||||
self.typ.as_object()
|
||||
fn class(&self) -> PyClassRef {
|
||||
self.typ.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TypeProtocol for PyRef<T> {
|
||||
fn class(&self) -> PyClassRef {
|
||||
self.obj.typ.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -956,7 +960,7 @@ pub trait BufferProtocol {
|
||||
|
||||
impl BufferProtocol for PyObjectRef {
|
||||
fn readonly(&self) -> bool {
|
||||
match objtype::get_type_name(&self.typ()).as_ref() {
|
||||
match self.class().name.as_str() {
|
||||
"bytes" => false,
|
||||
"bytearray" | "memoryview" => true,
|
||||
_ => panic!("Bytes-Like type expected not {:?}", self),
|
||||
@@ -1249,7 +1253,7 @@ where
|
||||
"must be {} or {}, not {}",
|
||||
A::class(vm),
|
||||
B::class(vm),
|
||||
obj.type_pyref()
|
||||
obj.class()
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
} else {
|
||||
Err(serde::ser::Error::custom(format!(
|
||||
"Object of type '{:?}' is not serializable",
|
||||
self.pyobject.typ()
|
||||
self.pyobject.class()
|
||||
)))
|
||||
}
|
||||
}
|
||||
@@ -199,8 +199,7 @@ pub fn de_pyobject(vm: &VirtualMachine, s: &str) -> PyResult {
|
||||
de.deserialize(&mut serde_json::Deserializer::from_str(s))
|
||||
.map_err(|err| {
|
||||
let json_decode_error = vm
|
||||
.sys_module
|
||||
.get_item("modules")
|
||||
.get_attribute(vm.sys_module.clone(), "modules")
|
||||
.unwrap()
|
||||
.get_item("json")
|
||||
.unwrap()
|
||||
|
||||
+17
-16
@@ -19,6 +19,7 @@ use crate::function::PyFuncArgs;
|
||||
use crate::obj::objbool;
|
||||
use crate::obj::objbuiltinfunc::PyBuiltinFunction;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objfunction::{PyFunction, PyMethod};
|
||||
use crate::obj::objgenerator::PyGeneratorRef;
|
||||
use crate::obj::objiter;
|
||||
@@ -174,11 +175,11 @@ impl VirtualMachine {
|
||||
b: PyObjectRef,
|
||||
op: &str,
|
||||
) -> PyObjectRef {
|
||||
let a_type_name = objtype::get_type_name(&a.typ());
|
||||
let b_type_name = objtype::get_type_name(&b.typ());
|
||||
self.new_type_error(format!(
|
||||
"Unsupported operand types for '{}': '{}' and '{}'",
|
||||
op, a_type_name, b_type_name
|
||||
op,
|
||||
a.class().name,
|
||||
b.class().name
|
||||
))
|
||||
}
|
||||
|
||||
@@ -231,7 +232,7 @@ impl VirtualMachine {
|
||||
self.ctx.object()
|
||||
}
|
||||
|
||||
pub fn get_locals(&self) -> PyObjectRef {
|
||||
pub fn get_locals(&self) -> PyDictRef {
|
||||
self.current_scope().get_locals().clone()
|
||||
}
|
||||
|
||||
@@ -270,7 +271,7 @@ impl VirtualMachine {
|
||||
pub fn isinstance(&self, obj: &PyObjectRef, cls: &PyClassRef) -> PyResult<bool> {
|
||||
// cpython first does an exact check on the type, although documentation doesn't state that
|
||||
// https://github.com/python/cpython/blob/a24107b04c1277e3c1105f98aff5bfa3a98b33a0/Objects/abstract.c#L2408
|
||||
if Rc::ptr_eq(&obj.typ(), cls.as_object()) {
|
||||
if Rc::ptr_eq(&obj.class().into_object(), cls.as_object()) {
|
||||
Ok(true)
|
||||
} else {
|
||||
let ret = self.call_method(cls.as_object(), "__instancecheck__", vec![obj.clone()])?;
|
||||
@@ -286,10 +287,10 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn call_get_descriptor(&self, attr: PyObjectRef, obj: PyObjectRef) -> PyResult {
|
||||
let attr_class = attr.type_pyref();
|
||||
let attr_class = attr.class();
|
||||
if let Some(descriptor) = objtype::class_get_attr(&attr_class, "__get__") {
|
||||
let cls = obj.typ();
|
||||
self.invoke(descriptor, vec![attr, obj.clone(), cls])
|
||||
let cls = obj.class();
|
||||
self.invoke(descriptor, vec![attr, obj.clone(), cls.into_object()])
|
||||
} else {
|
||||
Ok(attr)
|
||||
}
|
||||
@@ -300,7 +301,7 @@ impl VirtualMachine {
|
||||
T: Into<PyFuncArgs>,
|
||||
{
|
||||
// This is only used in the vm for magic methods, which use a greatly simplified attribute lookup.
|
||||
let cls = obj.type_pyref();
|
||||
let cls = obj.class();
|
||||
match objtype::class_get_attr(&cls, method_name) {
|
||||
Some(func) => {
|
||||
trace!(
|
||||
@@ -371,8 +372,8 @@ impl VirtualMachine {
|
||||
pub fn invoke_with_locals(
|
||||
&self,
|
||||
function: PyObjectRef,
|
||||
cells: PyObjectRef,
|
||||
locals: PyObjectRef,
|
||||
cells: PyDictRef,
|
||||
locals: PyDictRef,
|
||||
) -> PyResult {
|
||||
if let Some(PyFunction {
|
||||
code,
|
||||
@@ -395,7 +396,7 @@ impl VirtualMachine {
|
||||
fn fill_locals_from_args(
|
||||
&self,
|
||||
code_object: &bytecode::CodeObject,
|
||||
locals: &PyObjectRef,
|
||||
locals: &PyDictRef,
|
||||
args: PyFuncArgs,
|
||||
defaults: &PyObjectRef,
|
||||
) -> PyResult<()> {
|
||||
@@ -450,11 +451,11 @@ impl VirtualMachine {
|
||||
// Do we support `**kwargs` ?
|
||||
let kwargs = match code_object.varkeywords {
|
||||
bytecode::Varargs::Named(ref kwargs_name) => {
|
||||
let d = self.ctx.new_dict().into_object();
|
||||
locals.set_item(&self.ctx, kwargs_name, d.clone());
|
||||
let d = self.ctx.new_dict();
|
||||
locals.set_item(&self.ctx, kwargs_name, d.as_object().clone());
|
||||
Some(d)
|
||||
}
|
||||
bytecode::Varargs::Unnamed => Some(self.ctx.new_dict().into_object()),
|
||||
bytecode::Varargs::Unnamed => Some(self.ctx.new_dict()),
|
||||
bytecode::Varargs::None => None,
|
||||
};
|
||||
|
||||
@@ -583,7 +584,7 @@ impl VirtualMachine {
|
||||
// get_method should be used for internal access to magic methods (by-passing
|
||||
// the full getattribute look-up.
|
||||
pub fn get_method(&self, obj: PyObjectRef, method_name: &str) -> PyResult {
|
||||
let cls = obj.type_pyref();
|
||||
let cls = obj.class();
|
||||
match objtype::class_get_attr(&cls, method_name) {
|
||||
Some(method) => self.call_get_descriptor(method, obj.clone()),
|
||||
None => Err(self.new_type_error(format!("{} has no method {:?}", obj, method_name))),
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> Result<String
|
||||
if !objtype::isinstance(obj, &vm.ctx.str_type()) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"sep must be None or a string, not {}",
|
||||
objtype::get_type_name(&obj.typ())
|
||||
obj.class().name
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> Result<String
|
||||
if !objtype::isinstance(obj, &vm.ctx.str_type()) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"end must be None or a string, not {}",
|
||||
objtype::get_type_name(&obj.typ())
|
||||
obj.class().name
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user