mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
1 parent
07e339a7fb
commit
55061c7b6a
24 files changed
+147
-173
No files matched your search
+5
-6
@@ -13,8 +13,7 @@ extern crate env_logger;
|
||||
extern crate log;
|
||||
|
||||
use clap::{App, Arg};
|
||||
|
||||
use rustpython_compiler as compile;
|
||||
use rustpython_compiler as compiler;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
@@ -62,7 +61,7 @@ fn main() {
|
||||
let optimize = matches.occurrences_of("optimize") as u8;
|
||||
let scripts = matches.values_of_os("scripts").unwrap();
|
||||
|
||||
let opts = compile::CompileOpts {
|
||||
let opts = compiler::CompileOpts {
|
||||
optimize,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -81,12 +80,12 @@ fn main() {
|
||||
|
||||
fn display_script(
|
||||
path: &Path,
|
||||
mode: compile::Mode,
|
||||
opts: compile::CompileOpts,
|
||||
mode: compiler::Mode,
|
||||
opts: compiler::CompileOpts,
|
||||
expand_codeobjects: bool,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let source = fs::read_to_string(path)?;
|
||||
let code = compile::compile(&source, mode, path.to_string_lossy().into_owned(), opts)?;
|
||||
let code = compiler::compile(&source, mode, path.to_string_lossy().into_owned(), opts)?;
|
||||
println!("{}:", path.display());
|
||||
if expand_codeobjects {
|
||||
println!("{}", code.display_expand_codeobjects());
|
||||
|
||||
@@ -7,7 +7,7 @@ fn main() -> vm::PyResult<()> {
|
||||
let code_obj = vm
|
||||
.compile(
|
||||
r#"print("Hello World!")"#,
|
||||
vm::compile::Mode::Exec,
|
||||
vm::compiler::Mode::Exec,
|
||||
"<embedded>".to_owned(),
|
||||
)
|
||||
.map_err(|err| vm.new_syntax_error(&err))?;
|
||||
|
||||
@@ -62,9 +62,9 @@ def fib(n):
|
||||
.expect("Failed to read line of input");
|
||||
|
||||
// this line also automatically prints the output
|
||||
// (note that this is only the case when compile::Mode::Single is passed to vm.compile)
|
||||
// (note that this is only the case when compiler::Mode::Single is passed to vm.compile)
|
||||
match vm
|
||||
.compile(&input, vm::compile::Mode::Single, "<embedded>".to_owned())
|
||||
.compile(&input, vm::compiler::Mode::Single, "<embedded>".to_owned())
|
||||
.map_err(|err| vm.new_syntax_error(&err))
|
||||
.and_then(|code_obj| vm.run_code_obj(code_obj, scope.clone()))
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user