Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
93b7d6b
stage1
qingshi163 Sep 10, 2024
e0a3f26
compiler pass build
qingshi163 Oct 7, 2024
38575bd
introduce rustpython-compiler-source
qingshi163 Oct 7, 2024
dce0d94
stage2
qingshi163 Oct 15, 2024
3162b9b
fixup
qingshi163 Oct 15, 2024
1f7024a
pass compile
qingshi163 Oct 28, 2024
e189ecf
Fix hello world compiler test
etaloof Dec 2, 2024
0f100e9
Fix code generation for if-elif-else statement
etaloof Dec 2, 2024
b42f88f
Fix code generation for lambda expression
etaloof Dec 2, 2024
7c53857
Fix code generation for integers
etaloof Dec 2, 2024
424e05a
Fix code generation for fstrings
etaloof Dec 2, 2024
2691cbe
Fix code generation for if statement
etaloof Dec 2, 2024
a98a623
Fix code generation for if statement
etaloof Dec 2, 2024
168aa01
Fix code generation for if statement
etaloof Dec 2, 2024
c25d958
Fix code generation for fstring
etaloof Dec 2, 2024
4e29dd4
Fix code generation for class definition
etaloof Dec 2, 2024
89afad2
Replace feature flags
etaloof Dec 2, 2024
e760ac7
Initialize frozen core modules
etaloof Dec 2, 2024
2987cbe
Allow __future__ import after module doc comment
etaloof Dec 2, 2024
c10df16
Disable ast module
etaloof Dec 2, 2024
bcfbf88
Commit remaining fixes for compile errors in examples
etaloof Dec 2, 2024
def0e42
Fix some warnings
etaloof Dec 6, 2024
4bef13b
Update ast stdlib module
etaloof Jan 3, 2025
1fd48c7
Update ast stdlib module
etaloof Jan 3, 2025
ca2b302
Update ast stdlib module
etaloof Jan 4, 2025
e9bc377
Update ast stdlib module
etaloof Jan 6, 2025
c6ece03
Update ast stdlib module
etaloof Jan 6, 2025
5c22c39
Split ast stdlib module into files
etaloof Jan 6, 2025
6b49cfb
Fix codegen for positional arguments with defaults
etaloof Jan 6, 2025
4cdd4ae
Update ast stdlib module
etaloof Jan 7, 2025
f03d43f
Update ast stdlib module
etaloof Jan 8, 2025
60dc970
Extract string and constant handling from expression.rs
etaloof Jan 8, 2025
5bd4d5b
Always add required fields to AST nodes
etaloof Jan 12, 2025
85edb25
Compile doc strings correctly again
etaloof Jan 12, 2025
f4154a0
Enable "ast" Cargo feature by default
etaloof Jan 12, 2025
1bff3dc
Refactor compilation of big integer literal
etaloof Jan 12, 2025
a669803
Update ast stdlib module
etaloof Jan 13, 2025
1bd4078
Update ast stdlib module
etaloof Jan 18, 2025
a054ca6
Update ast stdlib module
etaloof Jan 23, 2025
1476b49
Reset barebones example
etaloof Jan 23, 2025
1a3c5bb
Merge remote-tracking branch 'refs/remotes/origin/main' into ruff-parser
etaloof Jan 25, 2025
595622b
Fix some left-over warnings
etaloof Jan 25, 2025
c00d58f
Undo accidential change
etaloof Jan 25, 2025
d08716f
Adapt shell to ruff parser
etaloof Jan 25, 2025
c8acbf8
Pin parser to v0.4.10
youknowone Jan 27, 2025
c04f702
fix clippy
youknowone Jan 27, 2025
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
Prev Previous commit
Next Next commit
Fix codegen for positional arguments with defaults
  • Loading branch information
etaloof committed Jan 7, 2025
commit 6b49cfb77572b2d50aa20bedecf148958da8f639
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ssl-vendor = ["ssl", "rustpython-stdlib/ssl-vendor"]
rustpython-compiler = { workspace = true }
rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler", "ast"] }
ruff_python_parser = { workspace = true }

atty = { workspace = true }
Expand Down
13 changes: 6 additions & 7 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,10 @@ impl Compiler<'_> {
name: &str,
parameters: &Parameters,
) -> CompileResult<bytecode::MakeFunctionFlags> {
// let defaults: Vec<_> = args.defaults().collect();
let defaults: Vec<_> = parameters
.iter_non_variadic_params()
// FIXME: clone?
.filter_map(|x| x.default.clone())
let defaults: Vec<_> = std::iter::empty()
.chain(&parameters.posonlyargs)
.chain(&parameters.args)
.filter_map(|x| x.default.as_deref())
.collect();
let have_defaults = !defaults.is_empty();
if have_defaults {
Expand Down Expand Up @@ -1525,8 +1524,6 @@ impl Compiler<'_> {
) -> CompileResult<()> {
self.prepare_decorators(decorator_list)?;

emit!(self, Instruction::LoadBuildClass);

let prev_ctx = self.ctx;
self.ctx = CompileContext {
func: FunctionContext::NoFunction,
Expand Down Expand Up @@ -1601,6 +1598,8 @@ impl Compiler<'_> {
self.qualified_path.append(global_path_prefix.as_mut());
self.ctx = prev_ctx;

emit!(self, Instruction::LoadBuildClass);

let mut func_flags = bytecode::MakeFunctionFlags::empty();

// Prepare generic type parameters:
Expand Down
16 changes: 15 additions & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn _compile_symtable(
fn test_compile() {
let code = "x = 'abc'";
let compiled = compile(&code, Mode::Single, "<>", CompileOpts::default());
dbg!(compiled);
dbg!(compiled.expect("compile error"));
}

#[test]
Expand Down Expand Up @@ -288,3 +288,17 @@ assert f"{{{(lambda x: f'hello, {x}')('world}')}" == '{hello, world}'
let compiled = compile(&code6, Mode::Exec, "<>", CompileOpts::default());
dbg!(compiled.expect("compile error"));
}

#[test]
fn test_simple_enum() {
let code = r#"
import enum
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
class RegexFlag:
NOFLAG = 0
DEBUG = 1
print(RegexFlag.NOFLAG & RegexFlag.DEBUG)
"#;
let compiled = compile(&code, Mode::Exec, "<string>", CompileOpts::default());
dbg!(compiled.expect("compile error"));
}
2 changes: 2 additions & 0 deletions example_projects/barebone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ edition = "2021"
[dependencies]
# FIXME: Remove unnessary features
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler", "ast"] }
rustpython = { path = "../.." }
env_logger = "0.11.6"

[workspace]
55 changes: 48 additions & 7 deletions example_projects/barebone/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
use rustpython_vm::Interpreter;
use rustpython::InterpreterConfig;
use rustpython_vm::stdlib::get_module_inits;
use rustpython_vm::{Interpreter, PyResult, Settings, VirtualMachine};
use std::env;
use std::env::split_paths;

pub fn main() {
let interp = Interpreter::without_stdlib(Default::default());
env_logger::init();
// let mut stdlib = get_module_inits();
// let interp = Interpreter::with_init(Default::default(), |vm: &mut VirtualMachine| {
// vm.add_native_module("_ast", stdlib.remove("_ast").unwrap())
//
// });
let mut settings = Settings::default();
settings.path_list.extend(get_paths("RUSTPYTHONPATH"));
let mut config = InterpreterConfig::new().init_stdlib().settings(settings);

let interp = config.interpreter();
let value = interp.enter(|vm| {
let max = vm.builtins.get_attr("max", vm)?;
let value = max.call((vm.ctx.new_int(5), vm.ctx.new_int(10)), vm)?;
vm.print((vm.ctx.new_str("python print"), value.clone()))?;
Ok(value)
// import ast
// let module = vm.import("ast", 0);
// module

vm.run_code_string(
vm.new_scope_with_builtins(),
"
import enum
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
class RegexFlag:
NOFLAG = 0
DEBUG = 1
RegexFlag.NOFLAG & RegexFlag.DEBUG
",
"<string>".to_string(),
)
});
match value {
Ok(value) => println!("Rust repr: {:?}", value),
Err(err) => {
interp.finalize(err);
interp.finalize(Some(err));
}
}
}

/// Helper function to retrieve a sequence of paths from an environment variable.
fn get_paths(env_variable_name: &str) -> impl Iterator<Item = String> + '_ {
env::var_os(env_variable_name)
.into_iter()
.flat_map(move |paths| {
split_paths(&paths)
.map(|path| {
path.into_os_string()
.into_string()
.unwrap_or_else(|_| panic!("{env_variable_name} isn't valid unicode"))
})
.collect::<Vec<_>>()
})
}
49 changes: 47 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
pub fn main() -> std::process::ExitCode {
rustpython::run(|_vm| {})
use rustpython::InterpreterConfig;
use rustpython_vm::Settings;
use std::env;
use std::env::split_paths;
use std::process::ExitCode;

pub fn main() -> ExitCode {
let mut settings = Settings::default();
settings.write_bytecode = false;
settings.path_list.extend(get_paths("RUSTPYTHONPATH"));
let mut config = InterpreterConfig::new().init_stdlib().settings(settings);
let interp = config.interpreter();
let exitcode = interp.run(move |vm| {
let scope = vm.new_scope_with_builtins();
vm.run_code_string(
scope,
r#"
import enum
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
class RegexFlag:
NOFLAG = 0
DEBUG = 1
print(RegexFlag.NOFLAG & RegexFlag.DEBUG)
#import ast
#print(dir(ast))
"#,
"<main>".to_string(),
)
.map(|_| ())
});

ExitCode::from(exitcode)
}

/// Helper function to retrieve a sequence of paths from an environment variable.
fn get_paths(env_variable_name: &str) -> impl Iterator<Item = String> + '_ {
env::var_os(env_variable_name)
.into_iter()
.flat_map(move |paths| {
split_paths(&paths)
.map(|path| {
path.into_os_string()
.into_string()
.unwrap_or_else(|_| panic!("{env_variable_name} isn't valid unicode"))
})
.collect::<Vec<_>>()
})
}