mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Removal of Clone trait on ast nodes. Should reduce codesize somewhat.
This commit is contained in:
1 parent
5707548436
commit
e334941728
5 files changed
+44
-21
No files matched your search
+9
-9
@@ -116,7 +116,7 @@ pub struct WithItem {
|
||||
pub optional_vars: Option<Expression>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Expression {
|
||||
BoolOp {
|
||||
a: Box<Expression>,
|
||||
@@ -195,21 +195,21 @@ pub enum Expression {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ComprehensionKind {
|
||||
List { element: Expression },
|
||||
Set { element: Expression },
|
||||
Dict { key: Expression, value: Expression },
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Comprehension {
|
||||
pub target: Expression,
|
||||
pub iter: Expression,
|
||||
pub ifs: Vec<Expression>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Keyword {
|
||||
pub name: Option<String>,
|
||||
pub value: Expression,
|
||||
@@ -222,7 +222,7 @@ pub struct ExceptHandler {
|
||||
pub body: Vec<LocatedStatement>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Operator {
|
||||
Add,
|
||||
Sub,
|
||||
@@ -239,19 +239,19 @@ pub enum Operator {
|
||||
FloorDiv,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BooleanOperator {
|
||||
And,
|
||||
Or,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum UnaryOperator {
|
||||
Neg,
|
||||
Not,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Comparison {
|
||||
Equal,
|
||||
NotEqual,
|
||||
@@ -265,7 +265,7 @@ pub enum Comparison {
|
||||
IsNot,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Number {
|
||||
Integer { value: i32 },
|
||||
Float { value: f64 },
|
||||
|
||||
@@ -62,22 +62,31 @@ ExpressionStatement: ast::LocatedStatement = {
|
||||
} else {
|
||||
ast::LocatedStatement {
|
||||
location: loc.clone(),
|
||||
node: ast::Statement::Expression { expression: expr[0].clone() },
|
||||
node: ast::Statement::Expression { expression: expr.into_iter().next().unwrap() },
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut targets = vec![if expr.len() > 1 {
|
||||
ast::Expression::Tuple { elements: expr }
|
||||
} else {
|
||||
expr[0].clone()
|
||||
expr.into_iter().next().unwrap()
|
||||
}];
|
||||
let mut values : Vec<ast::Expression> = suffix.into_iter().map(|test_list| if test_list.len() > 1 { ast::Expression::Tuple { elements: test_list }} else { test_list[0].clone() }).collect();
|
||||
let mut values : Vec<ast::Expression> = suffix
|
||||
.into_iter()
|
||||
.map(|test_list| if test_list.len() > 1 {
|
||||
ast::Expression::Tuple {
|
||||
elements: test_list
|
||||
}
|
||||
} else {
|
||||
test_list.into_iter().next().unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
while values.len() > 1 {
|
||||
targets.push(values.remove(0));
|
||||
}
|
||||
|
||||
let value = values[0].clone();
|
||||
let value = values.into_iter().next().unwrap();
|
||||
|
||||
ast::LocatedStatement {
|
||||
location: loc.clone(),
|
||||
@@ -395,7 +404,7 @@ TypedArgsList: Vec<(String, Option<ast::Expression>)> = {
|
||||
|
||||
Parameter: (String, Option<ast::Expression>) = {
|
||||
<i:Identifier> => (i.clone(), None),
|
||||
<i:Identifier> "=" <e:Expression> => (i.clone(), Some(e.clone())),
|
||||
<i:Identifier> "=" <e:Expression> => (i.clone(), Some(e)),
|
||||
};
|
||||
|
||||
ClassDef: ast::LocatedStatement = {
|
||||
@@ -738,8 +747,8 @@ ArgumentList: (Vec<ast::Expression>, Vec<ast::Keyword>) = {
|
||||
};
|
||||
|
||||
FunctionArgument: (Option<String>, ast::Expression) = {
|
||||
<e:Expression> => (None, e.clone()),
|
||||
<i:Identifier> "=" <e:Expression> => (Some(i.clone()), e.clone()),
|
||||
<e:Expression> => (None, e),
|
||||
<i:Identifier> "=" <e:Expression> => (Some(i.clone()), e),
|
||||
};
|
||||
|
||||
Comma<T>: Vec<T> = {
|
||||
|
||||
@@ -111,6 +111,7 @@ pub enum Instruction {
|
||||
},
|
||||
ForIter,
|
||||
ReturnValue,
|
||||
YieldValue,
|
||||
SetupLoop {
|
||||
start: Label,
|
||||
end: Label,
|
||||
|
||||
+14
-5
@@ -393,9 +393,12 @@ impl Compiler {
|
||||
|
||||
let have_kwargs = default_elements.len() > 0;
|
||||
if have_kwargs {
|
||||
self.compile_expression(&ast::Expression::Tuple {
|
||||
elements: default_elements,
|
||||
});
|
||||
// Construct a tuple:
|
||||
let size = default_elements.len();
|
||||
for element in default_elements {
|
||||
self.compile_expression(element);
|
||||
}
|
||||
self.emit(Instruction::BuildTuple { size });
|
||||
}
|
||||
|
||||
self.code_object_stack.push(CodeObject::new(
|
||||
@@ -828,8 +831,14 @@ impl Compiler {
|
||||
}
|
||||
self.emit(Instruction::BuildSlice { size: size });
|
||||
}
|
||||
ast::Expression::Yield { .. } => {
|
||||
unimplemented!("TODO: implement generators");
|
||||
ast::Expression::Yield { expression } => {
|
||||
match expression {
|
||||
Some(expression) => self.compile_expression(expression),
|
||||
None => self.emit(Instruction::LoadConst {
|
||||
value: bytecode::Constant::None,
|
||||
}),
|
||||
};
|
||||
self.emit(Instruction::YieldValue);
|
||||
}
|
||||
ast::Expression::True => {
|
||||
self.emit(Instruction::LoadConst {
|
||||
|
||||
@@ -967,6 +967,10 @@ impl VirtualMachine {
|
||||
Some(Ok(value))
|
||||
}
|
||||
}
|
||||
bytecode::Instruction::YieldValue => {
|
||||
let value = self.pop_value();
|
||||
unimplemented!("TODO: implement generators: {:?}", value);
|
||||
}
|
||||
bytecode::Instruction::SetupLoop { start, end } => {
|
||||
self.push_block(Block::Loop {
|
||||
start: *start,
|
||||
|
||||
Reference in new issue
Block a user