Skip to content

Commit 6d1f298

Browse files
committed
Custom marshal enc/decoding impl
1 parent 166959d commit 6d1f298

29 files changed

+1190
-616
lines changed

Cargo.lock

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ edition = "2021"
99
rustpython-compiler-core = { path = "core" }
1010
rustpython-codegen = { path = "codegen" }
1111
rustpython-parser = { path = "parser" }
12-
13-
thiserror = { workspace = true }

compiler/codegen/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ bitflags = { workspace = true }
1616
indexmap = { workspace = true }
1717
itertools = { workspace = true }
1818
log = { workspace = true }
19-
num-complex = { workspace = true, features = ["serde"] }
19+
num-complex = { workspace = true }
2020
num-traits = { workspace = true }
21-
thiserror = { workspace = true }
2221

2322
[dev-dependencies]
2423
rustpython-parser = { path = "../parser" }

compiler/codegen/src/compile.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ impl Compiler {
249249
fn push_output(
250250
&mut self,
251251
flags: bytecode::CodeFlags,
252-
posonlyarg_count: usize,
253-
arg_count: usize,
254-
kwonlyarg_count: usize,
252+
posonlyarg_count: u32,
253+
arg_count: u32,
254+
kwonlyarg_count: u32,
255255
obj_name: String,
256256
) {
257257
let source_path = self.source_path.clone();
@@ -936,9 +936,11 @@ impl Compiler {
936936

937937
self.push_output(
938938
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
939-
args.posonlyargs.len(),
940-
args.posonlyargs.len() + args.args.len(),
941-
args.kwonlyargs.len(),
939+
args.posonlyargs.len().try_into().unwrap(),
940+
(args.posonlyargs.len() + args.args.len())
941+
.try_into()
942+
.unwrap(),
943+
args.kwonlyargs.len().try_into().unwrap(),
942944
name.to_owned(),
943945
);
944946

@@ -2750,8 +2752,8 @@ impl Compiler {
27502752
self.current_source_location = location;
27512753
}
27522754

2753-
fn get_source_line_number(&self) -> usize {
2754-
self.current_source_location.row()
2755+
fn get_source_line_number(&self) -> u32 {
2756+
self.current_source_location.row() as u32
27552757
}
27562758

27572759
fn push_qualified_path(&mut self, name: &str) {

compiler/codegen/src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
pub type CodegenError = rustpython_compiler_core::BaseError<CodegenErrorType>;
44

5-
#[derive(Debug, thiserror::Error)]
5+
#[derive(Debug)]
66
#[non_exhaustive]
77
pub enum CodegenErrorType {
88
/// Invalid assignment, cannot store value in target.
@@ -33,6 +33,8 @@ pub enum CodegenErrorType {
3333
NotImplementedYet, // RustPython marker for unimplemented features
3434
}
3535

36+
impl std::error::Error for CodegenErrorType {}
37+
3638
impl fmt::Display for CodegenErrorType {
3739
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3840
use CodegenErrorType::*;

compiler/codegen/src/ir.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ impl Default for Block {
6363

6464
pub struct CodeInfo {
6565
pub flags: CodeFlags,
66-
pub posonlyarg_count: usize, // Number of positional-only arguments
67-
pub arg_count: usize,
68-
pub kwonlyarg_count: usize,
66+
pub posonlyarg_count: u32, // Number of positional-only arguments
67+
pub arg_count: u32,
68+
pub kwonlyarg_count: u32,
6969
pub source_path: String,
70-
pub first_line_number: usize,
70+
pub first_line_number: u32,
7171
pub obj_name: String, // Name of the object that created this code object
7272

7373
pub blocks: Vec<Block>,
@@ -172,15 +172,15 @@ impl CodeInfo {
172172
}
173173
}
174174

175-
fn cell2arg(&self) -> Option<Box<[isize]>> {
175+
fn cell2arg(&self) -> Option<Box<[i32]>> {
176176
if self.cellvar_cache.is_empty() {
177177
return None;
178178
}
179179

180180
let total_args = self.arg_count
181181
+ self.kwonlyarg_count
182-
+ self.flags.contains(CodeFlags::HAS_VARARGS) as usize
183-
+ self.flags.contains(CodeFlags::HAS_VARKEYWORDS) as usize;
182+
+ self.flags.contains(CodeFlags::HAS_VARARGS) as u32
183+
+ self.flags.contains(CodeFlags::HAS_VARKEYWORDS) as u32;
184184

185185
let mut found_cellarg = false;
186186
let cell2arg = self
@@ -190,10 +190,10 @@ impl CodeInfo {
190190
self.varname_cache
191191
.get_index_of(var)
192192
// check that it's actually an arg
193-
.filter(|i| *i < total_args)
193+
.filter(|i| *i < total_args as usize)
194194
.map_or(-1, |i| {
195195
found_cellarg = true;
196-
i as isize
196+
i as i32
197197
})
198198
})
199199
.collect::<Box<[_]>>();

compiler/core/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ repository = "https://github.com/RustPython/RustPython"
88
license = "MIT"
99

1010
[dependencies]
11-
bincode = { workspace = true }
1211
bitflags = { workspace = true }
1312
bstr = { workspace = true }
1413
itertools = { workspace = true }
15-
num-bigint = { workspace = true, features = ["serde"] }
16-
num-complex = { workspace = true, features = ["serde"] }
17-
num_enum = { workspace = true }
18-
serde = { workspace = true, features = ["derive"] }
19-
thiserror = { workspace = true }
14+
num-bigint = { workspace = true }
15+
num-complex = { workspace = true }
2016

2117
lz4_flex = "0.9.2"

0 commit comments

Comments
 (0)