FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix PyCode constructor/replace by youknowone · Pull Request #6193 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rs  (4) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 0 additions & 6 deletions Lib/test/test_code.py
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
Expand Up @@ -222,8 +222,6 @@ class List(list):
obj = List([1, 2, 3])
self.assertEqual(obj[0], "Foreign getitem: 1")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_constructor(self):
def func(): pass
co = func.__code__
Expand Down Expand Up @@ -255,8 +253,6 @@ def test_qualname(self):
CodeTest.test_qualname.__qualname__
)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_replace(self):
def func():
x = 1
Expand Down Expand Up @@ -297,8 +293,6 @@ def func2():
self.assertEqual(new_code.co_varnames, code2.co_varnames)
self.assertEqual(new_code.co_nlocals, code2.co_nlocals)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nlocals_mismatch(self):
def func():
x = 1
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_funcattrs.py
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
Expand Up @@ -65,8 +65,6 @@ def duplicate():
return 3
self.assertNotEqual(self.b, duplicate)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_copying___code__(self):
def test(): pass
self.assertEqual(test(), None)
Expand Down
22 changes: 14 additions & 8 deletions compiler/core/src/marshal.rs
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
Expand Up @@ -165,6 +165,19 @@ impl<'a> ReadBorrowed<'a> for &'a [u8] {
}
}

/// Parses bytecode bytes into CodeUnit instructions.
/// Each instruction is 2 bytes: opcode and argument.
pub fn parse_instructions_from_bytes(bytes: &[u8]) -> Result<Box<[CodeUnit]>> {
bytes
.chunks_exact(2)
.map(|cu| {
let op = Instruction::try_from(cu[0])?;
let arg = OpArgByte(cu[1]);
Ok(CodeUnit { op, arg })
})
.collect()
}

pub struct Cursor<B> {
pub data: B,
pub position: usize,
Expand All @@ -185,14 +198,7 @@ pub fn deserialize_code<R: Read, Bag: ConstantBag>(
) -> Result<CodeObject<Bag::Constant>> {
let len = rdr.read_u32()?;
let instructions = rdr.read_slice(len * 2)?;
let instructions = instructions
.chunks_exact(2)
.map(|cu| {
let op = Instruction::try_from(cu[0])?;
let arg = OpArgByte(cu[1]);
Ok(CodeUnit { op, arg })
})
.collect::<Result<Box<[CodeUnit]>>>()?;
let instructions = parse_instructions_from_bytes(instructions)?;

let len = rdr.read_u32()?;
let locations = (0..len)
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL