From c8a0500b2fc78101e1a7f3b2c99939f88a33aa4d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 5 Jun 2012 22:39:30 -0700 Subject: [PATCH] New syntax: let declarations, initialised arguments. --- Cycript.l.in | 2 + Cycript.yy.in | 146 ++++++++++++++++++++++++++++++----------- ObjectiveC/Replace.cpp | 10 +-- Output.cpp | 32 ++++----- Parser.hpp | 44 ++++++------- Replace.cpp | 56 +++++++--------- Replace.hpp | 16 ++--- 7 files changed, 185 insertions(+), 121 deletions(-) diff --git a/Cycript.l.in b/Cycript.l.in index f97158e..dca452a 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -172,6 +172,8 @@ XMLName {XMLNameStart}{XMLNamePart}* " AssignmentExpression_ %type AssignmentExpressionNoBF %type AssignmentExpressionNoIn +%type BindingIdentifier %type BitwiseANDExpression %type BitwiseANDExpressionNoBF %type BitwiseANDExpressionNoIn %type Block %type Block_ %type BooleanLiteral +%type BindingElement %type BitwiseORExpression %type BitwiseORExpressionNoBF %type BitwiseORExpressionNoIn @@ -342,6 +345,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type BitwiseXORExpressionNoBF %type BitwiseXORExpressionNoIn %type BreakStatement +%type BreakableStatement %type CallExpression %type CallExpressionNoBF %type CaseBlock @@ -354,6 +358,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn %type ContinueStatement +%type DebuggerStatement +%type Declaration %type DefaultClause %type DoWhileStatement %type Element @@ -379,8 +385,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ForStatementInitialiser %type ForInStatement %type ForInStatementInitialiser +%type FormalParameter %type FormalParameterList %type FormalParameterList_ +%type FormalParameterListOpt %type FunctionBody %type FunctionDeclaration %type FunctionExpression @@ -396,7 +404,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF +//%type LetExpression %type LetStatement +%type LexicalDeclaration %type Literal %type LiteralNoRE %type LiteralRE @@ -425,6 +435,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type PrimaryExpressionNoRE %type PrimaryExpressionBF %type Program +%type ProgramBody +%type ProgramBodyOpt %type PropertyName %type PropertyName_ %type PropertyNameAndValueList @@ -444,13 +456,12 @@ int cylex(YYSTYPE *, cy::location *, void *); %type RubyProcParametersOpt %type ShiftExpression %type ShiftExpressionNoBF -%type SourceElement -%type SourceElement_ -%type SourceElements +%type SingleNameBinding %type Statement %type Statement_ %type StatementList %type StatementListOpt +%type StatementListItem %type SwitchStatement %type ThrowStatement %type TryStatement @@ -678,7 +689,7 @@ Identifier | "transient" { $$ = $1; } | "volatile" { $$ = $1; } - | "let" { $$ = $1; } + // XXX: is this allowed?! | "let" { $$ = $1; } | "yield" { $$ = $1; } | "each" { $$ = $1; } @@ -1251,20 +1262,30 @@ Statement_ | EmptyStatement { $$ = $1; } | ExpressionStatement { $$ = $1; } | IfStatement { $$ = $1; } - | IterationStatement { $$ = $1; } + | BreakableStatement { $$ = $1; } | ContinueStatement { $$ = $1; } | BreakStatement { $$ = $1; } | ReturnStatement { $$ = $1; } | WithStatement { $$ = $1; } | LabelledStatement { $$ = $1; } - | SwitchStatement { $$ = $1; } | ThrowStatement { $$ = $1; } | TryStatement { $$ = $1; } + | DebuggerStatement { $$ = $1; } ; Statement : LexSetRegExp Statement_ { $$ = $2; } ; + +Declaration + : FunctionDeclaration { $$ = $1; } + | LexicalDeclaration { $$ = $1; } + ; + +BreakableStatement + : IterationStatement { $$ = $1; } + | SwitchStatement { $$ = $1; } + ; /* }}} */ /* 12.1 Block {{{ */ Block_ @@ -1276,15 +1297,37 @@ Block ; StatementList - : Statement StatementListOpt { $1->SetNext($2); $$ = $1; } + : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; } ; StatementListOpt : StatementList { $$ = $1; } | LexSetRegExp { $$ = NULL; } ; + +StatementListItem + : Statement { $$ = $1; } + | LexSetRegExp Declaration { $$ = $2; } + ; +/* }}} */ +/* 12.2 Declarations {{{ */ +BindingIdentifier + : Identifier { $$ = $1; } + ; + +// XXX: BindingPattern +/* }}} */ +/* 12.2.1 Let and Const Declarations {{{ */ +LexicalDeclaration + : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } + ; + +LetOrConst + : "let" + | "const" + ; /* }}} */ -/* 12.2 Variable Statement {{{ */ +/* 12.2.2 Variable Statement {{{ */ VariableStatement : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } ; @@ -1308,11 +1351,13 @@ VariableDeclarationListNoIn ; VariableDeclaration - : Identifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } + : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } + // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); } ; VariableDeclarationNoIn - : Identifier InitialiserNoInOpt { $$ = CYNew CYDeclaration($1, $2); } + : BindingIdentifier InitialiserNoInOpt { $$ = CYNew CYDeclaration($1, $2); } + // XXX: | BindingPattern InitialiserNoIn { $$ = CYNew CYDeclaration($1, $2); } ; InitialiserOpt @@ -1333,6 +1378,17 @@ InitialiserNoIn : "=" AssignmentExpressionNoIn { $$ = $2; } ; /* }}} */ +/* 12.2.4 Destructuring Binding Patterns {{{ */ +// XXX: * + +BindingElement + : SingleNameBinding { $$ = $1; } + ; + +SingleNameBinding + : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } + ; +/* }}} */ /* 12.3 Empty Statement {{{ */ EmptyStatement : ";" { $$ = CYNew CYEmpty(); } @@ -1462,14 +1518,19 @@ FinallyOpt | { $$ = NULL; } ; /* }}} */ +/* 12.14 The debugger Statement {{{ */ +DebuggerStatement + : "debugger" Terminator { $$ = CYNew CYDebugger(); } + ; +/* }}} */ /* 13 Function Definition {{{ */ FunctionDeclaration - : "function" Identifier "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } + : "function" Identifier "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } ; FunctionExpression - : "function" IdentifierOpt "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionExpression($2, $4, $7); } + : "function" IdentifierOpt "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionExpression($2, $4, $7); } ; FormalParameterList_ @@ -1477,32 +1538,40 @@ FormalParameterList_ | { $$ = NULL; } ; -FormalParameterList - : Identifier FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } +FormalParameterListOpt + : FormalParameterList | { $$ = NULL; } ; +FormalParameterList + // XXX: : FunctionRestParameter { $$ = $1; } + : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } + ; + +/* XXX: FunctionRestParameter + : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); } + ;*/ + +FormalParameter + : BindingElement { $$ = $1; } + ; + FunctionBody - : SourceElements { $$ = $1; } + : StatementListOpt { $$ = $1; } ; /* }}} */ /* 14 Program {{{ */ Program - : SourceElements { driver.program_ = CYNew CYProgram($1); } - ; - -SourceElements - : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } - | LexSetRegExp { $$ = NULL; } + : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); } ; -SourceElement_ - : Statement_ { $$ = $1; } - | FunctionDeclaration { $$ = $1; } +ProgramBodyOpt + : ProgramBody { $$ = $1; } + | { $$ = NULL; } ; -SourceElement - : LexSetRegExp SourceElement_ { $$ = $2; } +ProgramBody + : StatementList { $$ = $1; } ; /* }}} */ @@ -1678,7 +1747,7 @@ ImportPath | StringLiteral ; -SourceElement_ +StatementListItem : "@import" ImportPath { $$ = CYNew CYImport(); } ; /* }}} */ @@ -1914,9 +1983,18 @@ ForInStatement : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = CYNew CYForEachIn($4, $6, $8); } ; /* }}} */ +/* JavaScript 1.7: let Expressions {{{ */ +/*LetExpression + : "let" "(" VariableDeclarationList ")" Expression { $$ = CYNew CYLetExpression($3, $5); } + ; + +MemberExpression + : LexSetRegExp LetExpression { $$ = $2; } + ;*/ +/* }}} */ /* JavaScript 1.7: let Statements {{{ */ LetStatement - : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLet($3, $5); } + : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } ; Statement_ @@ -1924,16 +2002,6 @@ Statement_ ; /* }}} */ -/* JavaScript FTW: Function Statements {{{ */ -Statement - : LexSetRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; } - ; -/* }}} */ -/* JavaScript FTW: Optional Arguments {{{ */ -FormalParameterList - : Identifier "=" AssignmentExpression FormalParameterList_ { $$ = CYNew CYOptionalFunctionParameter($1, $3, $4); } - ; -/* }}} */ /* JavaScript FTW: Ruby Blocks {{{ */ RubyProcParameterList_ : "," RubyProcParameterList { $$ = $2; } @@ -1941,7 +2009,7 @@ RubyProcParameterList_ ; RubyProcParameterList - : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } + : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); } | { $$ = NULL; } ; diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 748fc6f..4271d40 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -27,7 +27,7 @@ CYStatement *CYCategory::Replace(CYContext &context) { CYVariable *cyc($V("$cyc")), *cys($V("$cys")); - return $E($C1($F(NULL, $P5("$cys", "$cyp", "$cyc", "$cyn", "$cyt"), $$->* + return $E($C1($F(NULL, $P5($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt")), $$->* $E($ CYAssign($V("$cyp"), $C1($V("object_getClass"), cys)))->* $E($ CYAssign(cyc, cys))->* $E($ CYAssign($V("$cym"), $C1($V("object_getClass"), cyc)))->* @@ -40,7 +40,7 @@ CYExpression *CYClass::Replace_(CYContext &context) { CYExpression *name(name_ != NULL ? name_->ClassName(context, false) : $C1($V("$cyq"), $S("CY$"))); - return $C1($F(NULL, $P6("$cys", "$cyp", "$cyc", "$cyn", "$cyt", "$cym"), $$->* + return $C1($F(NULL, $P6($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt"), $L("$cym")), $$->* $E($ CYAssign($V("$cyp"), $C1($V("object_getClass"), cys)))->* $E($ CYAssign(cyc, $C3($V("objc_allocateClassPair"), cys, name, $D(0))))->* $E($ CYAssign($V("$cym"), $C1($V("object_getClass"), cyc)))->* @@ -81,8 +81,8 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL $E($C4($V(replace ? "class_replaceMethod" : "class_addMethod"), $V(instance_ ? "$cyc" : "$cym"), cyn, - $N2($V("Functor"), $F(NULL, $P2("self", "_cmd", parameters_->Parameters(context)), $$->* - $ CYVar($L1($L($I("$cyr"), $N2($V("Super"), self, _class))))->* + $N2($V("Functor"), $F(NULL, $P2($L("self"), $L("_cmd"), parameters_->Parameters(context)), $$->* + $ CYVar($L1($L("$cyr", $N2($V("Super"), self, _class))))->* $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), self)) ), cyt), cyt @@ -92,7 +92,7 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); - return name_ == NULL ? next : $ CYFunctionParameter(name_, next); + return name_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(name_), next); } CYSelector *CYMessageParameter::Selector(CYContext &context) const { diff --git a/Output.cpp b/Output.cpp index 8d3ddaa..752d8a9 100644 --- a/Output.cpp +++ b/Output.cpp @@ -236,6 +236,10 @@ void CYClause::Output(CYOutput &out) const { out << next_; } +void CYDebugger::Output(CYOutput &out, CYFlags flags) const { + out << "debugger" << ';'; +} + void CYDeclaration::ForIn(CYOutput &out, CYFlags flags) const { out << "var"; Output(out, CYRight(flags)); @@ -262,16 +266,19 @@ void CYDeclarations::Output(CYOutput &out) const { void CYDeclarations::Output(CYOutput &out, CYFlags flags) const { const CYDeclarations *declaration(this); bool first(true); - output: - CYDeclarations *next(declaration->next_); - CYFlags jacks(first ? CYLeft(flags) : next == NULL ? CYRight(flags) : CYCenter(flags)); - first = false; - declaration->declaration_->Output(out, jacks); - if (next != NULL) { + for (;;) { + CYDeclarations *next(declaration->next_); + + CYFlags jacks(first ? CYLeft(flags) : next == NULL ? CYRight(flags) : CYCenter(flags)); + first = false; + declaration->declaration_->Output(out, jacks); + + if (next == NULL) + break; + out << ',' << ' '; declaration = next; - goto output; } } @@ -395,7 +402,7 @@ void CYFunctionStatement::Output(CYOutput &out, CYFlags flags) const { } void CYFunctionParameter::Output(CYOutput &out) const { - out << *name_; + initialiser_->Output(out, CYNoFlags); if (next_ != NULL) out << ',' << ' ' << *next_; } @@ -463,7 +470,7 @@ void CYLabel::Output(CYOutput &out, CYFlags flags) const { statement_->Single(out, CYRight(flags)); } -void CYLet::Output(CYOutput &out, CYFlags flags) const { +void CYLetStatement::Output(CYOutput &out, CYFlags flags) const { out << "let" << ' ' << '(' << *declarations_ << ')'; code_->Single(out, CYRight(flags)); } @@ -512,13 +519,6 @@ void CYObject::Output(CYOutput &out, CYFlags flags) const { out << ')'; } -void CYOptionalFunctionParameter::Output(CYOutput &out) const { - out << *name_ << '='; - initializer_->Output(out, CYAssign::Precedence_, CYNoFlags); - if (next_ != NULL) - out << ',' << ' ' << *next_; -} - void CYPostfix::Output(CYOutput &out, CYFlags flags) const { lhs_->Output(out, Precedence(), CYLeft(flags)); out << Operator(); diff --git a/Parser.hpp b/Parser.hpp index 3860caa..a5d1148 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -536,6 +536,8 @@ struct CYForInInitialiser { virtual CYExpression *Replace(CYContext &context) = 0; virtual CYAssignment *Assignment(CYContext &context) = 0; + + virtual void Output(CYOutput &out, CYFlags flags) const = 0; }; struct CYNumber; @@ -623,35 +625,22 @@ struct CYCompound : void Output(CYOutput &out, CYFlags flags) const; }; +struct CYDeclaration; + struct CYFunctionParameter : CYNext, CYThing { - CYIdentifier *name_; + CYForInInitialiser *initialiser_; - CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) : + CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) : CYNext(next), - name_(name) - { - } - - virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code); - virtual void Output(CYOutput &out) const; -}; - -struct CYOptionalFunctionParameter : - CYFunctionParameter -{ - CYExpression *initializer_; - - CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) : - CYFunctionParameter(name, next), - initializer_(initializer) + initialiser_(initialiser) { } - virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code); - virtual void Output(CYOutput &out) const; + void Replace(CYContext &context, CYBlock &code); + void Output(CYOutput &out) const; }; struct CYComprehension : @@ -1221,13 +1210,13 @@ struct CYVar : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYLet : +struct CYLetStatement : CYStatement { CYDeclarations *declarations_; CYStatement *code_; - CYLet(CYDeclarations *declarations, CYStatement *code) : + CYLetStatement(CYDeclarations *declarations, CYStatement *code) : declarations_(declarations), code_(code) { @@ -1706,6 +1695,17 @@ struct CYSwitch : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYDebugger : + CYStatement +{ + CYDebugger() + { + } + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYCondition : CYExpression { diff --git a/Replace.cpp b/Replace.cpp index 5be4e01..d4037f8 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -85,7 +85,7 @@ CYExpression *CYArray::Replace(CYContext &context) { CYExpression *CYArrayComprehension::Replace(CYContext &context) { CYVariable *cyv($V("$cyv")); - return $C0($F(NULL, $P1("$cyv", comprehensions_->Parameters(context)), $$->* + return $C0($F(NULL, $P1($L("$cyv"), comprehensions_->Parameters(context)), $$->* $E($ CYAssign(cyv, $ CYArray()))->* comprehensions_->Replace(context, $E($C1($M(cyv, $S("push")), expression_)))->* $ CYReturn(cyv) @@ -183,7 +183,7 @@ void CYContext::NonLocal(CYStatement *&statements) { CYIdentifier *unique(nextlocal_->identifier_->Replace(context)); CYStatement *declare( - $ CYVar($L1($L(unique, $ CYObject())))); + $ CYVar($L1($ CYDeclaration(unique, $ CYObject())))); cy::Syntax::Catch *rescue( $ cy::Syntax::Catch(cye, $$->* @@ -208,6 +208,10 @@ CYStatement *CYContinue::Replace(CYContext &context) { return this; } +CYStatement *CYDebugger::Replace(CYContext &context) { + return this; +} + CYAssignment *CYDeclaration::Assignment(CYContext &context) { if (initialiser_ == NULL) return NULL; @@ -222,7 +226,7 @@ CYVariable *CYDeclaration::Variable(CYContext &context) { } CYStatement *CYDeclaration::ForEachIn(CYContext &context, CYExpression *value) { - return $ CYVar($L1($L(identifier_, value))); + return $ CYVar($L1($ CYDeclaration(identifier_, value))); } CYExpression *CYDeclaration::Replace(CYContext &context) { @@ -241,7 +245,7 @@ CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL) } CYFunctionParameter *CYDeclarations::Parameter(CYContext &context) { $T(NULL) - return $ CYFunctionParameter(declaration_->identifier_, next_->Parameter(context)); + return $ CYFunctionParameter($ CYDeclaration(declaration_->identifier_), next_->Parameter(context)); } CYArgument *CYDeclarations::Argument(CYContext &context) { $T(NULL) @@ -349,7 +353,7 @@ CYStatement *CYForIn::Replace(CYContext &context) { } CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const { - return $ CYFunctionParameter(name_); + return $ CYFunctionParameter($ CYDeclaration(name_)); } CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *statement) const { @@ -365,7 +369,7 @@ CYStatement *CYForEachIn::Replace(CYContext &context) { CYIdentifier *cys($I("$cys")), *cyt($I("$cyt")); - return $ CYLet($L2($L(cys, set_), $L(cyt)), $$->* + return $ CYLetStatement($L2($ CYDeclaration(cys, set_), $ CYDeclaration(cyt)), $$->* $ CYForIn($V(cyt), $V(cys), $ CYBlock($$->* initialiser_->ForEachIn(context, $M($V(cys), $V(cyt)))->* code_ @@ -374,13 +378,13 @@ CYStatement *CYForEachIn::Replace(CYContext &context) { } CYFunctionParameter *CYForEachInComprehension::Parameter(CYContext &context) const { - return $ CYFunctionParameter(name_); + return $ CYFunctionParameter($ CYDeclaration(name_)); } CYStatement *CYForEachInComprehension::Replace(CYContext &context, CYStatement *statement) const { CYIdentifier *cys($I("cys")); - return $E($C0($F(NULL, $P1("$cys"), $$->* + return $E($C0($F(NULL, $P1($L("$cys")), $$->* $E($ CYAssign($V(cys), set_))->* $ CYForIn($V(name_), $V(cys), $ CYBlock($$->* $E($ CYAssign($V(name_), $M($V(cys), $V(name_))))->* @@ -416,9 +420,7 @@ void CYFunction::Replace_(CYContext &context, bool outer) { if (!outer && name_ != NULL) Inject(context); - if (parameters_ != NULL) - parameters_ = parameters_->Replace(context, code_); - + parameters_->Replace(context, code_); code_.Replace(context); if (localize) @@ -435,12 +437,17 @@ CYExpression *CYFunctionExpression::Replace(CYContext &context) { return this; } -CYFunctionParameter *CYFunctionParameter::Replace(CYContext &context, CYBlock &code) { - context.Replace(name_); - context.scope_->Declare(context, name_, CYIdentifierArgument); - if (next_ != NULL) - next_ = next_->Replace(context, code); - return this; +void CYFunctionParameter::Replace(CYContext &context, CYBlock &code) { $T() + CYAssignment *assignment(initialiser_->Assignment(context)); + context.Replace(initialiser_); + + next_->Replace(context, code); + + if (assignment != NULL) + // XXX: this cast is quite incorrect + code.AddPrev($ CYIf($ CYIdentical($ CYTypeOf(dynamic_cast(initialiser_)), $S("undefined")), $$->* + $E(assignment) + )); } CYStatement *CYFunctionStatement::Replace(CYContext &context) { @@ -489,7 +496,7 @@ CYStatement *CYLabel::Replace(CYContext &context) { return this; } -CYStatement *CYLet::Replace(CYContext &context) { +CYStatement *CYLetStatement::Replace(CYContext &context) { return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context))); } @@ -531,19 +538,6 @@ CYExpression *CYObject::Replace(CYContext &context) { return this; } -CYFunctionParameter *CYOptionalFunctionParameter::Replace(CYContext &context, CYBlock &code) { - CYFunctionParameter *parameter($ CYFunctionParameter(name_, next_)); - parameter = parameter->Replace(context, code); - context.Replace(initializer_); - - CYVariable *name($V(name_)); - code.AddPrev($ CYIf($ CYIdentical($ CYTypeOf(name), $S("undefined")), $$->* - $E($ CYAssign(name, initializer_)) - )); - - return parameter; -} - CYExpression *CYPostfix::Replace(CYContext &context) { context.Replace(lhs_); return this; diff --git a/Replace.hpp b/Replace.hpp index a032902..c1d0c27 100644 --- a/Replace.hpp +++ b/Replace.hpp @@ -52,17 +52,17 @@ CYStatements() #define $P1(arg0, args...) \ - $P($I(arg0), ##args) + $P(arg0, ##args) #define $P2(arg0, arg1, args...) \ - $P($I(arg0), $P1(arg1, ##args)) + $P(arg0, $P1(arg1, ##args)) #define $P3(arg0, arg1, arg2, args...) \ - $P($I(arg0), $P2(arg1, arg2, ##args)) + $P(arg0, $P2(arg1, arg2, ##args)) #define $P4(arg0, arg1, arg2, arg3, args...) \ - $P($I(arg0), $P3(arg1, arg2, arg3, ##args)) + $P(arg0, $P3(arg1, arg2, arg3, ##args)) #define $P5(arg0, arg1, arg2, arg3, arg4, args...) \ - $P($I(arg0), $P4(arg1, arg2, arg3, arg4, ##args)) + $P(arg0, $P4(arg1, arg2, arg3, arg4, ##args)) #define $P6(arg0, arg1, arg2, arg3, arg4, arg5, args...) \ - $P($I(arg0), $P5(arg1, arg2, arg3, arg4, arg5, ##args)) + $P(arg0, $P5(arg1, arg2, arg3, arg4, arg5, ##args)) #define $C(args...) \ ($ CYCall(args)) @@ -110,8 +110,8 @@ #define $N5(func, args...) \ $N(func, $C5_(args)) -#define $L(args...) \ - $ CYDeclaration(args) +#define $L(arg0, args...) \ + $ CYDeclaration($I(arg0), ##args) #define $L1(arg0) \ $ CYDeclarations(arg0) #define $L2(arg0, args...) \ -- 2.45.2