Added constant folding for default arguments in function declarations
This commit is contained in:
parent
13efaa5e17
commit
31c6f300fa
|
@ -519,7 +519,7 @@ proc `$`*(self: ASTNode): string =
|
|||
result &= &"Var(name={self.name}, value={self.value}, const={self.isConst}, let={self.isLet}, static={self.isStatic}, private={self.isPrivate})"
|
||||
of funDecl:
|
||||
var self = FunDecl(self)
|
||||
result &= &"FunDecl(name={self.name}, body={self.body}, arguments=[{self.arguments.join(\", \")}], async={self.isAsync}, generator={self.isGenerator}, static={self.isStatic}, private={self.isPrivate})"
|
||||
result &= &"FunDecl(name={self.name}, body={self.body}, arguments=[{self.arguments.join(\", \")}], defaults=[{self.defaults.join(\", \")}], async={self.isAsync}, generator={self.isGenerator}, static={self.isStatic}, private={self.isPrivate})"
|
||||
of classDecl:
|
||||
var self = ClassDecl(self)
|
||||
result &= &"Class(name={self.name}, body={self.body}, parents=[{self.parents.join(\", \")}], static={self.isStatic}, private={self.isPrivate})"
|
||||
|
|
|
@ -290,6 +290,11 @@ proc optimizeNode(self: Optimizer, node: ASTNode): ASTNode =
|
|||
for keyword in node.arguments.keyword:
|
||||
newArgs.keyword.add((name: keyword.name, value: self.optimizeNode(keyword.value)))
|
||||
result = CallExpr(kind: callExpr, callee: node.callee, arguments: newArgs)
|
||||
of funDecl:
|
||||
var decl = FunDecl(node)
|
||||
for i, node in decl.defaults:
|
||||
decl.defaults[i] = self.optimizeNode(node)
|
||||
result = decl
|
||||
of blockStmt:
|
||||
var newBlock = newBlockStmt(@[])
|
||||
for node in BlockStmt(node).code:
|
||||
|
|
Loading…
Reference in New Issue