Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6a88cc

Browse files
committed
Add test script for bytearray
1 parent810ef7d commitb6a88cc

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

‎tests/snippets/basic_types.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
exceptTypeError:
3737
pass
3838

39+
a=bytearray([1,2,3])
40+
# assert a[1] == 2
41+
3942
assertint()==0
4043

4144
a=complex(2,4)

‎vm/src/obj/objbytearray.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ fn bytearray_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6565
Ok(vm.ctx.new_bool(result))
6666
}
6767

68+
/*
69+
fn bytearray_getitem(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
70+
arg_check!(
71+
vm,
72+
args,
73+
required = [(obj, Some(vm.ctx.bytearray_type())), (needle, None)]
74+
);
75+
let elements = get_elements(obj);
76+
get_item(vm, list, &, needle.clone())
77+
}
78+
*/
6879
/*
6980
fn set_value(obj: &PyObjectRef, value: Vec<u8>) {
7081
obj.borrow_mut().kind = PyObjectKind::Bytes { value };

‎vm/src/obj/objlist.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use super::super::pyobject::{
55
usesuper::super::vm::VirtualMachine;
66
usesuper::objbool;
77
usesuper::objint;
8-
usesuper::objiter;
98
usesuper::objsequence::{get_item, seq_equal,PySliceableSequence};
109
usesuper::objstr;
1110
usesuper::objtype;

‎vm/src/pyobject.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ The PyRef type implements
4545
https://doc.rust-lang.org/std/cell/index.html#introducing-mutability-inside-of-something-immutable
4646
*/
4747
pubtypePyRef<T> =Rc<RefCell<T>>;
48+
49+
/// The `PyObjectRef` is one of the most used types. It is a reference to a
50+
/// python object. A single python object can have multiple references, and
51+
/// this reference counting is accounted for by this type. Use the `.clone()`
52+
/// method to create a new reference and increment the amount of references
53+
/// to the python object by 1.
4854
pubtypePyObjectRef =PyRef<PyObject>;
55+
56+
/// Use this type for function which return a python object or and exception.
57+
/// Both the python object and the python exception are `PyObjectRef` types
58+
/// since exceptions are also python objects.
4959
pubtypePyResult =Result<PyObjectRef,PyObjectRef>;// A valid value, or an exception
5060

5161
/*
@@ -407,6 +417,9 @@ impl PyContext {
407417
}
408418
}
409419

420+
/// This is an actual python object. It consists of a `typ` which is the
421+
/// python class, and carries some rust payload optionally. This rust
422+
/// payload can be a rust float or rust int in case of float and int objects.
410423
pubstructPyObject{
411424
pubkind:PyObjectKind,
412425
pubtyp:Option<PyObjectRef>,
@@ -594,6 +607,9 @@ impl fmt::Debug for PyObject {
594607
}
595608
}
596609

610+
/// The `PyFuncArgs` struct is one of the most used structs then creating
611+
/// a rust function that can be called from python. It holds both positional
612+
/// arguments, as well as keyword arguments passed to the function.
597613
#[derive(Debug,Default,Clone)]
598614
pubstructPyFuncArgs{
599615
pubargs:Vec<PyObjectRef>,
@@ -637,6 +653,10 @@ impl PyFuncArgs {
637653

638654
typeRustPyFunc =fn(vm:&mutVirtualMachine,PyFuncArgs) ->PyResult;
639655

656+
/// Rather than determining the type of a python object, this enum is more
657+
/// a holder for the rust payload of a python object. It is more a carrier
658+
/// of rust data for a particular python object. Determine the python type
659+
/// by using for example the `.typ()` method on a python object.
640660
pubenumPyObjectKind{
641661
String{
642662
value:String,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp