Add support for defaults to bytecode, compiler and VM

This commit is contained in:
Daniel Watkins
2018-08-27 22:16:51 -04:00
parent 0787115d07
commit 2cecd362fe
9 changed files with 113 additions and 25 deletions

View File

@@ -95,12 +95,12 @@ pub enum Statement {
ClassDef {
name: String,
body: Vec<LocatedStatement>,
args: Vec<String>,
args: Vec<(String, Option<Expression>)>,
// TODO: docstring: String,
},
FunctionDef {
name: String,
args: Vec<String>,
args: Vec<(String, Option<Expression>)>,
// docstring: String,
body: Vec<LocatedStatement>,
},
@@ -161,7 +161,7 @@ pub enum Expression {
name: String,
},
Lambda {
args: Vec<String>,
args: Vec<(String, Option<Expression>)>,
body: Box<Expression>,
},
True,

View File

@@ -308,12 +308,16 @@ FuncDef: ast::LocatedStatement = {
},
};
Parameters: Vec<String> = {
Parameters: Vec<(String, Option<ast::Expression>)> = {
"(" <a: TypedArgsList> ")" => a,
};
TypedArgsList: Vec<String> = {
<a: Comma<Identifier>> => a,
// parameters are (String, None), kwargs are (String, Some(Test)) where Test is
// the default
TypedArgsList: Vec<(String, Option<ast::Expression>)> = {
<a: Comma<Identifier>> => {
a.iter().map(|param| (param.clone(), None)).collect()
},
};
ClassDef: ast::LocatedStatement = {