@@ -550,6 +550,9 @@ const codeGenerators: { [type: string]: (node: Node, cg: CodeGenerator) => Compi
550550
551551 ExpressionStatement : ( node : Node , cg : CodeGenerator ) => {
552552 const { stmtExp } = node as ExpressionStatement
553+ if ( stmtExp . kind === 'PrefixExpression' || stmtExp . kind === 'PostfixExpression' ) {
554+ return codeGenerators [ 'IncrementDecrementExpression' ] ( stmtExp , cg )
555+ }
553556 return compile ( stmtExp , cg )
554557 } ,
555558
@@ -708,6 +711,18 @@ const codeGenerators: { [type: string]: (node: Node, cg: CodeGenerator) => Compi
708711 }
709712 } ,
710713
714+ IncrementDecrementExpression : ( node : Node , cg : CodeGenerator ) => {
715+ // handle cases of ++x, x++, x--, --x that do not add object to operand stack
716+ if ( node . kind === 'PrefixExpression' || node . kind === 'PostfixExpression' ) {
717+ const { name } = node . expression as ExpressionName
718+ const info = cg . symbolTable . queryVariable ( name )
719+ if ( ! Array . isArray ( info ) ) {
720+ cg . code . push ( OPCODE . IINC , info . index , node . operator === '++' ? 1 : - 1 )
721+ }
722+ }
723+ return { stackSize : 0 , resultType : EMPTY_TYPE }
724+ } ,
725+
711726 PrefixExpression : ( node : Node , cg : CodeGenerator ) => {
712727 const { operator : op , expression : expr } = node as PrefixExpression
713728 if ( op === '++' || op === '--' ) {
0 commit comments