import { AstListMixin , AstNode , AstNodeList , astList , child } from './base' ; import * as expr from './expr' ; import { Expression , Name } from './expr' ; export class Statements extends AstNodeList < Statement > { scope : unknown ; constructor ( ) { super ( ) ; this . scope = null ; } } export class Statement extends AstNode { eliminateDeadCode ( ) { return false ; } } export class PlainStatement extends Statement { @ child expression : Expression ; constructor ( expression ) { super ( ) ; this . expression = expression ; } } export class Assign extends Statement { @ child lvalue : AstNode ; @ child rvalue : Expression ; isDeclaration : boolean ; constructor ( lvalue , rvalue ) { super ( ) ; this . lvalue = lvalue ; this . rvalue = rvalue ; this . isDeclaration = false ; } } export class Outside extends Statement { @ child name : Name ; constructor ( name ) { super ( ) ; this . name = name ; } } export abstract class Condition extends Statement { } export class If extends Condition { @ child condition : Expression ; @ child ifBlock : Statements ; @ child elseBlock : Statements | null ; constructor ( condition , ifBlock , elseBlock = null ) { super ( ) ; this . condition = condition ; this . ifBlock = ifBlock ; this . elseBlock = elseBlock ; } eliminateDeadCode ( ) { let bool = this . condition . fold ( ) ; if ( bool instanceof expr . Boolean ) { return ( bool . value ? this . ifBlock : this . elseBlock ) || true ; } return false ; } } export class IfNot extends Condition { @ child condition : Expression ; @ child ifBlock : Statements ; @ child elseBlock : Statements | null ; constructor ( condition , ifBlock , elseBlock = null ) { super ( ) ; this . condition = condition ; this . ifBlock = ifBlock ; this . elseBlock = elseBlock ; } eliminateDeadCode ( ) { let bool = this . condition . fold ( ) ; if ( bool instanceof expr . Boolean ) { return ( bool . value ? this . ifBlock : this . elseBlock ) || true ; } return false ; } } export class Loop extends Statement { @ child block : Statements ; constructor ( block ) { super ( ) ; this . block = block ; } } export class Iterate extends Statement { @ child iterator : AstNode ; @ child iteratee : AstNode ; @ child block : Statements ; constructor ( iterator , iteratee , block ) { super ( ) ; this . iterator = iterator ; this . iteratee = iteratee ; this . block = block ; } } export class LoopEnd extends Statement { } export class YaksokEnd extends Statement { }