Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a3fb40
Implement `random` module
malkoG Oct 26, 2019
908abef
Apply code review for test snippet
malkoG Dec 14, 2019
a20b6bf
Implement _random using the MT19937 algorithm
coolreader18 Feb 1, 2020
2fd9eb9
Add random.py from CPython 3.6
coolreader18 Feb 1, 2020
b40dcb7
Use random.Random in tempfile
coolreader18 Feb 1, 2020
a762bf8
Move gen_res53 to mersenne.rs
coolreader18 Feb 4, 2020
9abb258
Fix clippy warnings
coolreader18 Feb 4, 2020
c44f04b
Fallback exit code to 0 in case of overflow
arnavb Feb 4, 2020
4c49185
Have wasm/demo's "test" npm script build the demo in release mode
coolreader18 Feb 5, 2020
60037a2
Cache WASM dependencies
coolreader18 Feb 5, 2020
3960fb8
Merge pull request #1745 from arnavb/fix-exit-code
youknowone Feb 5, 2020
c435ba0
Merge pull request #1731 from RustPython/feature/implement-random
coolreader18 Feb 5, 2020
1bac582
&str::to_string -> &str::to_owned for literals
youknowone Feb 5, 2020
7d0d313
&str::to_string -> &str::to_owned for variables
youknowone Feb 5, 2020
78180ff
Merge pull request #1734 from youknowone/to-owned
youknowone Feb 5, 2020
9f5cd17
Add getset_descriptor
youknowone Feb 2, 2020
c3d5f6c
IntoPyGetterFunc, IntoPySetterFunc
youknowone Feb 2, 2020
ca55778
`&self` support for getter/setter
youknowone Feb 3, 2020
d1f9cb4
PySetResult and IntoPySetResult
youknowone Feb 3, 2020
226a2a6
VM polymorphism for getter and setter
youknowone Feb 3, 2020
23381b9
compatiibility for CPytthon descr_check
youknowone Feb 4, 2020
0aee78d
pyproperty generates PyGetSet instead of PyProperty
youknowone Feb 3, 2020
facabfe
Remove PropertyBuilder and add new_getset
youknowone Feb 5, 2020
58744df
Revert 08e66b5002f3a3a30db72b350b18c61d367ef1fc
youknowone Feb 1, 2020
c0b235e
cleanup property and get descriptor codes
youknowone Feb 2, 2020
429a276
Bump up to python 3.8 for Azure Pipelines
youknowone Jan 25, 2020
0f12db1
Merge pull request #1705 from youknowone/azure-38
youknowone Feb 5, 2020
e7ea486
Merge pull request #1738 from youknowone/getset
coolreader18 Feb 6, 2020
844b639
Fix SyntaxError initial value
youknowone Feb 5, 2020
6ddb690
Remove `_vm` parameter when it is not required
youknowone Feb 5, 2020
92cb58b
Remove `_vm` parameter - remove unused functions
youknowone Feb 6, 2020
7312e18
Merge pull request #1748 from youknowone/syntax-error
youknowone Feb 6, 2020
67f072d
Merge pull request #1749 from youknowone/_vm
youknowone Feb 6, 2020
f873c0e
Merge pull request #1746 from RustPython/coolreader18/wasm-test-produ…
coolreader18 Feb 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn bench_rustpy_nbody(b: &mut test::Bencher) {

let vm = VirtualMachine::default();

let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_string()) {
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_owned()) {
Ok(code) => code,
Err(e) => panic!("{:?}", e),
};
Expand All @@ -113,7 +113,7 @@ fn bench_rustpy_mandelbrot(b: &mut test::Bencher) {

let vm = VirtualMachine::default();

let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_string()) {
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_owned()) {
Ok(code) => code,
Err(e) => panic!("{:?}", e),
};
Expand Down
58 changes: 29 additions & 29 deletions compiler/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn with_compiler(
) -> Result<CodeObject, CompileError> {
let mut compiler = Compiler::new(optimize);
compiler.source_path = Some(source_path);
compiler.push_new_code_object("<module>".to_string());
compiler.push_new_code_object("<module>".to_owned());
f(&mut compiler)?;
let code = compiler.pop_code_object();
trace!("Compilation completed: {:?}", code);
Expand Down Expand Up @@ -290,15 +290,15 @@ impl<O: OutputStream> Compiler<O> {
fn load_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::LoadName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}

fn store_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::StoreName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<O: OutputStream> Compiler<O> {
for name in names {
// import symbol from module:
self.emit(Instruction::ImportFrom {
name: name.symbol.to_string(),
name: name.symbol.to_owned(),
});

// Store module under proper name:
Expand Down Expand Up @@ -619,13 +619,13 @@ impl<O: OutputStream> Compiler<O> {
match &expression.node {
ast::ExpressionType::Identifier { name } => {
self.emit(Instruction::DeleteName {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::DeleteAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Subscript { a, b } => {
Expand Down Expand Up @@ -701,7 +701,7 @@ impl<O: OutputStream> Compiler<O> {
compile_varargs(&args.kwarg),
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();

Expand Down Expand Up @@ -897,7 +897,7 @@ impl<O: OutputStream> Compiler<O> {
// key:
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: "return".to_string(),
value: "return".to_owned(),
},
});
// value:
Expand All @@ -909,7 +909,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(annotation) = &arg.annotation {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: arg.arg.to_string(),
value: arg.arg.to_owned(),
},
});
self.compile_expression(&annotation)?;
Expand Down Expand Up @@ -982,18 +982,18 @@ impl<O: OutputStream> Compiler<O> {
Varargs::None,
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();

let (new_body, doc_str) = get_doc(body);

self.emit(Instruction::LoadName {
name: "__name__".to_string(),
name: "__name__".to_owned(),
scope: bytecode::NameScope::Global,
});
self.emit(Instruction::StoreName {
name: "__module__".to_string(),
name: "__module__".to_owned(),
scope: bytecode::NameScope::Free,
});
self.emit(Instruction::LoadConst {
Expand All @@ -1002,7 +1002,7 @@ impl<O: OutputStream> Compiler<O> {
},
});
self.emit(Instruction::StoreName {
name: "__qualname__".to_string(),
name: "__qualname__".to_owned(),
scope: bytecode::NameScope::Free,
});
self.compile_statements(new_body)?;
Expand All @@ -1022,7 +1022,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});

Expand All @@ -1044,7 +1044,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
Expand Down Expand Up @@ -1090,7 +1090,7 @@ impl<O: OutputStream> Compiler<O> {

self.emit(Instruction::Rotate { amount: 2 });
self.emit(Instruction::StoreAttr {
name: "__doc__".to_string(),
name: "__doc__".to_owned(),
});
}

Expand Down Expand Up @@ -1171,7 +1171,7 @@ impl<O: OutputStream> Compiler<O> {
self.set_label(check_asynciter_label);
self.emit(Instruction::Duplicate);
self.emit(Instruction::LoadName {
name: "StopAsyncIteration".to_string(),
name: "StopAsyncIteration".to_owned(),
scope: bytecode::NameScope::Global,
});
self.emit(Instruction::CompareOperation {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.emit(Instruction::StoreSubscript);
Expand All @@ -1332,7 +1332,7 @@ impl<O: OutputStream> Compiler<O> {
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::StoreAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
Expand Down Expand Up @@ -1605,7 +1605,7 @@ impl<O: OutputStream> Compiler<O> {
Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::LoadAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
Compare { vals, ops } => {
Expand Down Expand Up @@ -1732,7 +1732,7 @@ impl<O: OutputStream> Compiler<O> {
func: FunctionContext::Function,
};

let name = "<lambda>".to_string();
let name = "<lambda>".to_owned();
self.enter_function(&name, args)?;
self.compile_expression(body)?;
self.emit(Instruction::ReturnValue);
Expand Down Expand Up @@ -1795,7 +1795,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(name) = &keyword.name {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.compile_expression(&keyword.value)?;
Expand Down Expand Up @@ -1858,7 +1858,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
Expand Down Expand Up @@ -1927,13 +1927,13 @@ impl<O: OutputStream> Compiler<O> {
ast::ComprehensionKind::Set { .. } => "<setcomp>",
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
}
.to_string();
.to_owned();

let line_number = self.get_source_line_number();
// Create magnificent function <listcomp>:
self.push_output(CodeObject::new(
Default::default(),
vec![".0".to_string()],
vec![".0".to_owned()],
Varargs::None,
vec![],
Varargs::None,
Expand Down Expand Up @@ -2099,7 +2099,7 @@ impl<O: OutputStream> Compiler<O> {
ast::StringGroup::Constant { value } => {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: value.to_string(),
value: value.to_owned(),
},
});
}
Expand Down Expand Up @@ -2264,9 +2264,9 @@ mod tests {

fn compile_exec(source: &str) -> CodeObject {
let mut compiler: Compiler = Default::default();
compiler.source_path = Some("source_path".to_string());
compiler.push_new_code_object("<module>".to_string());
let ast = parser::parse_program(&source.to_string()).unwrap();
compiler.source_path = Some("source_path".to_owned());
compiler.push_new_code_object("<module>".to_owned());
let ast = parser::parse_program(source).unwrap();
let symbol_scope = make_symbol_table(&ast).unwrap();
compiler.compile_program(&ast, symbol_scope).unwrap();
compiler.pop_code_object()
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl CompileError {
match parse {
ParseErrorType::Lexical(LexicalErrorType::IndentationError) => true,
ParseErrorType::UnrecognizedToken(token, expected) => {
*token == Tok::Indent || expected.clone() == Some("Indent".to_string())
*token == Tok::Indent || expected.clone() == Some("Indent".to_owned())
}
_ => false,
}
Expand All @@ -88,14 +88,14 @@ impl fmt::Display for CompileError {
let error_desc = match &self.error {
CompileErrorType::Assign(target) => format!("can't assign to {}", target),
CompileErrorType::Delete(target) => format!("can't delete {}", target),
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_string(),
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
CompileErrorType::Parse(err) => err.to_string(),
CompileErrorType::SyntaxError(err) => err.to_string(),
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_string(),
CompileErrorType::InvalidBreak => "'break' outside loop".to_string(),
CompileErrorType::InvalidContinue => "'continue' outside loop".to_string(),
CompileErrorType::InvalidReturn => "'return' outside function".to_string(),
CompileErrorType::InvalidYield => "'yield' outside function".to_string(),
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(),
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),
CompileErrorType::InvalidYield => "'yield' outside function".to_owned(),
};

if let Some(statement) = &self.statement {
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Symbol {
impl Symbol {
fn new(name: &str) -> Self {
Symbol {
name: name.to_string(),
name: name.to_owned(),
// table,
scope: SymbolScope::Unknown,
is_param: false,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl SymbolTableBuilder {
}

fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
let table = SymbolTable::new(name.to_string(), typ, line_number);
let table = SymbolTable::new(name.to_owned(), typ, line_number);
self.tables.push(table);
}

Expand Down Expand Up @@ -793,7 +793,7 @@ impl SymbolTableBuilder {
// Insert symbol when required:
if !containing {
let symbol = Symbol::new(name);
table.symbols.insert(name.to_string(), symbol);
table.symbols.insert(name.to_owned(), symbol);
}

// Set proper flags on symbol:
Expand Down
4 changes: 2 additions & 2 deletions derive/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CompilationSource {
let module_name = if is_init {
parent.clone()
} else if parent.is_empty() {
stem.to_string()
stem.to_owned()
} else {
format!("{}.{}", parent, stem)
};
Expand Down Expand Up @@ -235,7 +235,7 @@ impl PyCompileInput {
})?
.compile(
mode.unwrap_or(compile::Mode::Exec),
module_name.unwrap_or_else(|| "frozen".to_string()),
module_name.unwrap_or_else(|| "frozen".to_owned()),
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Class {
} else {
Err(Diagnostic::span_error(
span,
"Duplicate #[py*] attribute on pyimpl".to_string(),
"Duplicate #[py*] attribute on pyimpl".to_owned(),
))
}
}
Expand Down Expand Up @@ -620,7 +620,7 @@ fn generate_class_def(
let meta = attr.parse_meta().expect("expected doc attr to be a meta");
if let Meta::NameValue(name_value) = meta {
if let Lit::Str(s) = name_value.lit {
let val = s.value().trim().to_string();
let val = s.value().trim().to_owned();
match doc {
Some(ref mut doc) => doc.push(val),
None => doc = Some(vec![val]),
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() -> vm::pyobject::PyResult<()> {
.compile(
r#"print("Hello World!")"#,
compiler::compile::Mode::Exec,
"<embedded>".to_string(),
"<embedded>".to_owned(),
)
.map_err(|err| vm.new_syntax_error(&err))?;

Expand Down
2 changes: 1 addition & 1 deletion examples/mini_repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn main() -> vm::pyobject::PyResult<()> {
.compile(
&input,
compiler::compile::Mode::Single,
"<embedded>".to_string(),
"<embedded>".to_owned(),
)
.map_err(|err| vm.new_syntax_error(&err))
.and_then(|code_obj| vm.run_code_obj(code_obj, scope.clone()))
Expand Down
2 changes: 1 addition & 1 deletion examples/parse_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn parse_python_file(filename: &Path) -> ParsedFile {
match std::fs::read_to_string(filename) {
Err(e) => ParsedFile {
// filename: Box::new(filename.to_path_buf()),
// code: "".to_string(),
// code: "".to_owned(),
num_lines: 0,
result: Err(e.to_string()),
},
Expand Down
2 changes: 1 addition & 1 deletion parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl fmt::Display for ParseErrorType {
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {
if *tok == Tok::Indent {
write!(f, "unexpected indent")
} else if expected.clone() == Some("Indent".to_string()) {
} else if expected.clone() == Some("Indent".to_owned()) {
write!(f, "expected an indented block")
} else {
write!(f, "Got unexpected token {}", tok)
Expand Down
Loading