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
introduce rustpython-compiler-source
  • Loading branch information
qingshi163 committed Oct 7, 2024
commit 38575bd55d82871b4542c14a0261ba8cff57cbbd
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ repository = "https://github.com/RustPython/RustPython"
license = "MIT"

[workspace.dependencies]
rustpython-compiler-source = { path = "compiler/source" }
rustpython-compiler-core = { path = "compiler/core", version = "0.4.0" }
rustpython-compiler = { path = "compiler", version = "0.4.0" }
rustpython-codegen = { path = "compiler/codegen", version = "0.4.0" }
Expand Down
2 changes: 2 additions & 0 deletions compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ license.workspace = true
[dependencies]
rustpython-codegen = { workspace = true }
rustpython-compiler-core = { workspace = true }
rustpython-compiler-source = { workspace = true }
# rustpython-parser = { workspace = true }
ruff_python_parser = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_source_file = { workspace = true }
ruff_text_size = { workspace = true }
thiserror = { workspace = true }

[lints]
Expand Down
1 change: 1 addition & 0 deletions compiler/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license.workspace = true
# rustpython-ast = { workspace = true, features=["unparse", "constant-optimization"] }
# rustpython-parser-core = { workspace = true }
rustpython-compiler-core = { workspace = true }
rustpython-compiler-source = {workspace = true }
ruff_python_parser = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_text_size = { workspace = true }
Expand Down
80 changes: 24 additions & 56 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ruff_python_ast::{
Parameters, Stmt, StmtImport, StmtImportFrom, TypeParam, TypeParamTypeVar, TypeParams, UnaryOp,
WithItem,
};
use ruff_source_file::{LineIndex, OneIndexed, SourceCode};
use ruff_source_file::{LineIndex, OneIndexed};
use ruff_text_size::{Ranged, TextRange};
// use rustpython_ast::located::{self as located_ast, Located};
use rustpython_compiler_core::{
Expand All @@ -33,6 +33,7 @@ use rustpython_compiler_core::{
},
Mode,
};
use rustpython_compiler_source::SourceCode;
// use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
use std::borrow::Cow;

Expand Down Expand Up @@ -62,9 +63,7 @@ fn is_forbidden_name(name: &str) -> bool {
struct Compiler<'src> {
code_stack: Vec<ir::CodeInfo>,
symbol_table_stack: Vec<SymbolTable>,
source_path: String,
source_text: &'src str,
source_index: LineIndex,
source_code: SourceCode<'src>,
// current_source_location: SourceLocation,
current_source_range: TextRange,
qualified_path: Vec<String>,
Expand Down Expand Up @@ -113,18 +112,13 @@ enum ComprehensionType {
/// Compile an Mod produced from rustpython_parser::parse()
pub fn compile_top(
ast: ruff_python_ast::Mod,
source_path: String,
source_text: &str,
source_code: SourceCode,
mode: Mode,
opts: CompileOpts,
) -> CompileResult<CodeObject> {
match ast {
ruff_python_ast::Mod::Module(module) => {
compile_program(&module, source_path, source_text, opts)
}
ruff_python_ast::Mod::Expression(expr) => {
compile_expression(&expr, source_path, source_text, opts)
}
ruff_python_ast::Mod::Module(module) => compile_program(&module, source_code, opts),
ruff_python_ast::Mod::Expression(expr) => compile_expression(&expr, source_code, opts),
}
// match ast {
// Mod::Module(ModModule { body, .. }) => {
Expand Down Expand Up @@ -169,21 +163,12 @@ pub fn compile_top(
/// Compile a standard Python program to bytecode
pub fn compile_program(
ast: &ModModule,
source_path: String,
source_text: &str,
source_code: SourceCode,
opts: CompileOpts,
) -> CompileResult<CodeObject> {
let source_index = LineIndex::from_source_text(source_text);
let source_code = SourceCode::new(source_text, &source_index);
let symbol_table = SymbolTable::scan_program(ast, source_code)
.map_err(|e| e.into_codegen_error(source_path.clone()))?;
let mut compiler = Compiler::new(
opts,
source_path,
source_text,
source_index,
"<module>".to_owned(),
);
let symbol_table = SymbolTable::scan_program(ast, source_code.clone())
.map_err(|e| e.into_codegen_error(source_code.path.to_owned()))?;
let mut compiler = Compiler::new(opts, source_code, "<module>".to_owned());
compiler.compile_program(ast, symbol_table)?;
let code = compiler.pop_code_object();
Ok(code)
Expand Down Expand Up @@ -230,21 +215,12 @@ pub fn compile_program(

pub fn compile_expression(
ast: &ModExpression,
source_path: String,
source_text: &str,
source_code: SourceCode,
opts: CompileOpts,
) -> CompileResult<CodeObject> {
let source_index = LineIndex::from_source_text(source_text);
let source_code = SourceCode::new(source_text, &source_index);
let symbol_table = SymbolTable::scan_expr(ast, source_code)
.map_err(|e| e.into_codegen_error(source_path.clone()))?;
let mut compiler = Compiler::new(
opts,
source_path,
source_text,
source_index,
"<module>".to_owned(),
);
let symbol_table = SymbolTable::scan_expr(ast, source_code.clone())
.map_err(|e| e.into_codegen_error(source_code.path.to_owned()))?;
let mut compiler = Compiler::new(opts, source_code, "<module>".to_owned());
compiler.compile_eval(ast, symbol_table)?;
let code = compiler.pop_code_object();
Ok(code)
Expand All @@ -266,19 +242,13 @@ macro_rules! emit {
}

impl<'src> Compiler<'src> {
fn new(
opts: CompileOpts,
source_path: String,
source_text: &'src str,
source_index: LineIndex,
code_name: String,
) -> Self {
fn new(opts: CompileOpts, source_code: SourceCode<'src>, code_name: String) -> Self {
let module_code = ir::CodeInfo {
flags: bytecode::CodeFlags::NEW_LOCALS,
posonlyarg_count: 0,
arg_count: 0,
kwonlyarg_count: 0,
source_path: source_path.clone(),
source_path: source_code.path.to_owned(),
first_line_number: OneIndexed::MIN,
obj_name: code_name,

Expand All @@ -293,9 +263,7 @@ impl<'src> Compiler<'src> {
Compiler {
code_stack: vec![module_code],
symbol_table_stack: Vec::new(),
source_path,
source_text,
source_index,
source_code,
// current_source_location: SourceLocation::default(),
current_source_range: TextRange::default(),
qualified_path: Vec::new(),
Expand All @@ -317,11 +285,11 @@ impl Compiler<'_> {
self.error_ranged(error, self.current_source_range)
}
fn error_ranged(&mut self, error: CodegenErrorType, range: TextRange) -> CodegenError {
let location = self.source_index.source_location(range.start(), self.source_text);
let location = self.source_code.source_location(range.start());
CodegenError {
error,
location: Some(location),
source_path: self.source_path.clone(),
source_path: self.source_code.path.to_owned(),
}
}

Expand Down Expand Up @@ -353,7 +321,7 @@ impl Compiler<'_> {
kwonlyarg_count: u32,
obj_name: String,
) {
let source_path = self.source_path.clone();
let source_path = self.source_code.path.to_owned();
let first_line_number = self.get_source_line_number();

let table = self.push_symbol_table();
Expand Down Expand Up @@ -1470,7 +1438,7 @@ impl Compiler<'_> {
let symbol = table.lookup(var).unwrap_or_else(|| {
panic!(
"couldn't look up var {} in {} in {}",
var, code.obj_name, self.source_path
var, code.obj_name, self.source_code.path
)
});
let parent_code = self.code_stack.last().unwrap();
Expand Down Expand Up @@ -3018,7 +2986,7 @@ impl Compiler<'_> {
// Low level helper functions:
fn _emit(&mut self, instr: Instruction, arg: OpArg, target: ir::BlockIdx) {
let range = self.current_source_range;
let location = self.source_index.source_location(range.start(), self.source_text);
let location = self.source_code.source_location(range.start());
// TODO: insert source filename
self.current_block().instructions.push(ir::InstructionInfo {
instr,
Expand Down Expand Up @@ -3108,7 +3076,7 @@ impl Compiler<'_> {
}

fn get_source_line_number(&mut self) -> OneIndexed {
self.source_index
self.source_code
.line_index(self.current_source_range.start())
}

Expand Down Expand Up @@ -3410,4 +3378,4 @@ for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):
));
}
}
*/
*/
5 changes: 1 addition & 4 deletions compiler/codegen/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::fmt;

use ruff_python_ast::Expr;
use ruff_source_file::SourceLocation;
use ruff_text_size::TextRange;
use thiserror::Error;

// pub type CodegenError = rustpython_parser_core::source_code::LocatedError<CodegenErrorType>;
Expand All @@ -15,7 +12,7 @@ pub struct CodegenError {
pub source_path: String,
}

impl std::fmt::Display for CodegenError {
impl fmt::Display for CodegenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO:
self.error.fmt(f)
Expand Down
12 changes: 6 additions & 6 deletions compiler/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use ruff_python_ast::{
self as ast, Comprehension, Decorator, Expr, ModExpression, ModModule, Parameter,
ParameterWithDefault, Parameters, Stmt, TypeParam, TypeParamTypeVar, TypeParams,
};
use ruff_source_file::{SourceCode, SourceLocation};
use ruff_text_size::{Ranged, TextRange};
use rustpython_compiler_source::{SourceCode, SourceLocation};
// use rustpython_ast::{self as ast, located::Located};
// use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
use std::{borrow::Cow, fmt, thread::LocalKey};
Expand Down Expand Up @@ -551,12 +551,12 @@ enum SymbolUsage {
Iter,
}

struct SymbolTableBuilder<'src, 'index> {
struct SymbolTableBuilder<'src> {
class_name: Option<String>,
// Scope stack.
tables: Vec<SymbolTable>,
future_annotations: bool,
source_code: SourceCode<'src, 'index>,
source_code: SourceCode<'src>,
}

/// Enum to indicate in what mode an expression
Expand All @@ -572,8 +572,8 @@ enum ExpressionContext {
IterDefinitionExp,
}

impl<'src, 'index> SymbolTableBuilder<'src, 'index> {
fn new(source_code: SourceCode<'src, 'index>) -> Self {
impl<'src> SymbolTableBuilder<'src> {
fn new(source_code: SourceCode<'src>) -> Self {
let mut this = Self {
class_name: None,
tables: vec![],
Expand All @@ -585,7 +585,7 @@ impl<'src, 'index> SymbolTableBuilder<'src, 'index> {
}
}

impl SymbolTableBuilder<'_, '_> {
impl SymbolTableBuilder<'_> {
fn finish(mut self) -> Result<SymbolTable, SymbolTableError> {
assert_eq!(self.tables.len(), 1);
let mut symbol_table = self.tables.pop().unwrap();
Expand Down
16 changes: 16 additions & 0 deletions compiler/source/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "rustpython-compiler-source"
description = "RustPython Source and Index"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
ruff_source_file = { workspace = true }
ruff_text_size = { workspace = true }

[lints]
workspace = true
24 changes: 24 additions & 0 deletions compiler/source/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub use ruff_source_file::{LineIndex, OneIndexed as LineNumber, SourceLocation};
pub use ruff_text_size::TextSize;

#[derive(Clone)]
pub struct SourceCode<'src> {
pub path: &'src str,
pub text: &'src str,
pub index: LineIndex,
}

impl<'src> SourceCode<'src> {
pub fn new(path: &'src str, text: &'src str) -> Self {
let index = LineIndex::from_source_text(text);
Self { path, text, index }
}

pub fn line_index(&self, offset: TextSize) -> LineNumber {
self.index.line_index(offset)
}

pub fn source_location(&self, offset: TextSize) -> SourceLocation {
self.index.source_location(offset, self.text)
}
}
Loading