From 21156d7d2c1ce6f16831df02d0976c84409de048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Mon, 16 Oct 2023 21:32:35 +0200 Subject: [PATCH 1/5] Add PLUS_PLUS, MINUS_MINUS prefix support --- lib/src/eval/compiler/expression/postfix.dart | 12 ++-- lib/src/eval/compiler/expression/prefix.dart | 59 +++++++++++++++---- .../compiler/expression/postfix_test.dart | 58 ++++++++++++++++++ .../eval/compiler/expression/prefix_test.dart | 58 ++++++++++++++++++ 4 files changed, 173 insertions(+), 14 deletions(-) create mode 100644 test/lib/src/eval/compiler/expression/postfix_test.dart create mode 100644 test/lib/src/eval/compiler/expression/prefix_test.dart diff --git a/lib/src/eval/compiler/expression/postfix.dart b/lib/src/eval/compiler/expression/postfix.dart index 45aac18..c7c36a3 100644 --- a/lib/src/eval/compiler/expression/postfix.dart +++ b/lib/src/eval/compiler/expression/postfix.dart @@ -8,7 +8,7 @@ import 'package:dart_eval/src/eval/runtime/runtime.dart'; Variable compilePostfixExpression(PostfixExpression e, CompilerContext ctx) { final V = compileExpressionAsReference(e.operand, ctx); - var L = V.getValue(ctx); + final L = V.getValue(ctx); var out = L; if (L.name != null) { @@ -18,12 +18,16 @@ Variable compilePostfixExpression(PostfixExpression e, CompilerContext ctx) { CopyValue.LEN); } - final opMap = {TokenType.PLUS_PLUS: '+', TokenType.MINUS_MINUS: '-'}; + const opMap = {TokenType.PLUS_PLUS: '+', TokenType.MINUS_MINUS: '-'}; V.setValue( + ctx, + L.invoke( ctx, - L.invoke(ctx, opMap[e.operator.type]!, - [BuiltinValue(intval: 1).push(ctx)]).result); + opMap[e.operator.type]!, + [BuiltinValue(intval: 1).push(ctx)], + ).result, + ); return out; } diff --git a/lib/src/eval/compiler/expression/prefix.dart b/lib/src/eval/compiler/expression/prefix.dart index 9ffb6d6..c4c42f0 100644 --- a/lib/src/eval/compiler/expression/prefix.dart +++ b/lib/src/eval/compiler/expression/prefix.dart @@ -5,20 +5,23 @@ import 'package:dart_eval/src/eval/compiler/builtins.dart'; import 'package:dart_eval/src/eval/compiler/context.dart'; import 'package:dart_eval/src/eval/compiler/type.dart'; import 'package:dart_eval/src/eval/compiler/variable.dart'; +import 'package:dart_eval/src/eval/runtime/runtime.dart'; import '../errors.dart'; import 'expression.dart'; +const _opMap = { + TokenType.MINUS: '-', + TokenType.BANG: '!', + TokenType.PLUS_PLUS: '+', + TokenType.MINUS_MINUS: '-', +}; + /// Compile a [PrefixExpression] to EVC bytecode Variable compilePrefixExpression(CompilerContext ctx, PrefixExpression e) { var V = compileExpression(e.operand, ctx); - final opMap = { - TokenType.MINUS: '-', - TokenType.BANG: '!', - }; - - var method = opMap[e.operator.type] ?? + final method = _opMap[e.operator.type] ?? (throw CompileError('Unknown unary operator ${e.operator.type}')); if (method == '-' && @@ -34,8 +37,44 @@ Variable compilePrefixExpression(CompilerContext ctx, PrefixExpression e) { if (method == "!") { return V.invoke(ctx, method, []).result; } - final zero = V.type == CoreTypes.int.ref(ctx) - ? BuiltinValue(intval: 0) - : BuiltinValue(doubleval: 0.0); - return zero.push(ctx).invoke(ctx, method, [V]).result; + + if ([TokenType.PLUS_PLUS, TokenType.MINUS_MINUS].contains(e.operator.type)) { + return _handleDoubleOperands(e, ctx); + } + + return _zeroForType(V.type, ctx).push(ctx).invoke(ctx, method, [V]).result; +} + +BuiltinValue _zeroForType(TypeRef type, CompilerContext ctx) => + type == CoreTypes.int.ref(ctx) + ? BuiltinValue(intval: 0) + : BuiltinValue(doubleval: 0.0); + +BuiltinValue _oneForType(TypeRef type, CompilerContext ctx) => + type == CoreTypes.int.ref(ctx) + ? BuiltinValue(intval: 1) + : BuiltinValue(doubleval: 1.0); + +Variable _handleDoubleOperands(PrefixExpression e, CompilerContext ctx) { + var V = compileExpression(e.operand, ctx); + final ref = compileExpressionAsReference(e.operand, ctx); + final L = ref.getValue(ctx); + var out = L; + + if (L.name != null) { + out = Variable.alloc(ctx, L.type); + ctx.pushOp(PushNull.make(), PushNull.LEN); + ctx.pushOp(CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), + CopyValue.LEN); + } + + ref.setValue( + ctx, + L.invoke( + ctx, + _opMap[e.operator.type]!, + [_oneForType(V.type, ctx).push(ctx)], + ).result, + ); + return out; } diff --git a/test/lib/src/eval/compiler/expression/postfix_test.dart b/test/lib/src/eval/compiler/expression/postfix_test.dart new file mode 100644 index 0000000..46041c0 --- /dev/null +++ b/test/lib/src/eval/compiler/expression/postfix_test.dart @@ -0,0 +1,58 @@ +import 'package:dart_eval/dart_eval.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Postfix', () { + late Compiler compiler; + + setUp(() { + compiler = Compiler(); + }); + + test('i++', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + num main() { + var d = 0.0; + d++; + var i = 0; + i++; + return i + d; + } + ''' + } + }); + + expect( + runtime.executeLib('package:eval_test/main.dart', 'main'), + // ignore: unnecessary_cast + equals($num(2 as num)), + ); + }); + + test('i--', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + num main() { + var d = 1.0; + d--; + var i = 1; + i--; + return i + d; + } + ''' + } + }); + + expect( + runtime.executeLib('package:eval_test/main.dart', 'main'), + // ignore: unnecessary_cast + equals($num(0 as num)), + ); + }); + }); +} diff --git a/test/lib/src/eval/compiler/expression/prefix_test.dart b/test/lib/src/eval/compiler/expression/prefix_test.dart new file mode 100644 index 0000000..f18d8b5 --- /dev/null +++ b/test/lib/src/eval/compiler/expression/prefix_test.dart @@ -0,0 +1,58 @@ +import 'package:dart_eval/dart_eval.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Prefix', () { + late Compiler compiler; + + setUp(() { + compiler = Compiler(); + }); + + test('++i', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + num main() { + var d = 0.0; + ++d; + var i = 0; + ++i; + return i + d; + } + ''' + } + }); + + expect( + runtime.executeLib('package:eval_test/main.dart', 'main'), + // ignore: unnecessary_cast + equals($num(2 as num)), + ); + }); + + test('--i', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + num main() { + var d = 1.0; + d--; + var i = 1; + i--; + return i + d; + } + ''' + } + }); + + expect( + runtime.executeLib('package:eval_test/main.dart', 'main'), + // ignore: unnecessary_cast + equals($num(0 as num)), + ); + }); + }); +} From a6dded3ea83df1887ba4f7f4cabb1cdc2bc9647b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Tue, 17 Oct 2023 20:51:44 +0200 Subject: [PATCH 2/5] Avoid multiple expression compilations, fix tests, fix prefix behavior --- lib/src/eval/compiler/expression/prefix.dart | 48 ++++++++------ .../compiler/expression/postfix_test.dart | 58 ----------------- .../eval/compiler/expression/prefix_test.dart | 58 ----------------- test/postfix_test.dart | 65 +++++++++++++++++++ test/prefix_test.dart | 65 +++++++++++++++++++ 5 files changed, 158 insertions(+), 136 deletions(-) delete mode 100644 test/lib/src/eval/compiler/expression/postfix_test.dart delete mode 100644 test/lib/src/eval/compiler/expression/prefix_test.dart create mode 100644 test/postfix_test.dart create mode 100644 test/prefix_test.dart diff --git a/lib/src/eval/compiler/expression/prefix.dart b/lib/src/eval/compiler/expression/prefix.dart index c4c42f0..23dc8c1 100644 --- a/lib/src/eval/compiler/expression/prefix.dart +++ b/lib/src/eval/compiler/expression/prefix.dart @@ -3,6 +3,7 @@ import 'package:analyzer/dart/ast/token.dart'; import 'package:dart_eval/dart_eval_bridge.dart'; import 'package:dart_eval/src/eval/compiler/builtins.dart'; import 'package:dart_eval/src/eval/compiler/context.dart'; +import 'package:dart_eval/src/eval/compiler/reference.dart'; import 'package:dart_eval/src/eval/compiler/type.dart'; import 'package:dart_eval/src/eval/compiler/variable.dart'; import 'package:dart_eval/src/eval/runtime/runtime.dart'; @@ -19,11 +20,18 @@ const _opMap = { /// Compile a [PrefixExpression] to EVC bytecode Variable compilePrefixExpression(CompilerContext ctx, PrefixExpression e) { - var V = compileExpression(e.operand, ctx); - final method = _opMap[e.operator.type] ?? (throw CompileError('Unknown unary operator ${e.operator.type}')); + if ([TokenType.PLUS_PLUS, TokenType.MINUS_MINUS].contains(e.operator.type)) { + final V = compileExpressionAsReference(e.operand, ctx); + final L = V.getValue(ctx); + final type = V.resolveType(ctx); + return _handleDoubleOperands(e, ctx, V, type, L); + } + + final V = compileExpression(e.operand, ctx); + if (method == '-' && V.type != CoreTypes.int.ref(ctx) && V.type != CoreTypes.double.ref(ctx)) { @@ -38,10 +46,6 @@ Variable compilePrefixExpression(CompilerContext ctx, PrefixExpression e) { return V.invoke(ctx, method, []).result; } - if ([TokenType.PLUS_PLUS, TokenType.MINUS_MINUS].contains(e.operator.type)) { - return _handleDoubleOperands(e, ctx); - } - return _zeroForType(V.type, ctx).push(ctx).invoke(ctx, method, [V]).result; } @@ -55,26 +59,30 @@ BuiltinValue _oneForType(TypeRef type, CompilerContext ctx) => ? BuiltinValue(intval: 1) : BuiltinValue(doubleval: 1.0); -Variable _handleDoubleOperands(PrefixExpression e, CompilerContext ctx) { - var V = compileExpression(e.operand, ctx); - final ref = compileExpressionAsReference(e.operand, ctx); - final L = ref.getValue(ctx); +Variable _handleDoubleOperands( + PrefixExpression e, + CompilerContext ctx, + Reference V, + TypeRef type, + Variable L, +) { var out = L; if (L.name != null) { out = Variable.alloc(ctx, L.type); ctx.pushOp(PushNull.make(), PushNull.LEN); - ctx.pushOp(CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), - CopyValue.LEN); + ctx.pushOp( + CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), + CopyValue.LEN, + ); } - ref.setValue( + final result = out.invoke( ctx, - L.invoke( - ctx, - _opMap[e.operator.type]!, - [_oneForType(V.type, ctx).push(ctx)], - ).result, - ); - return out; + _opMap[e.operator.type]!, + [_oneForType(type, ctx).push(ctx)], + ).result; + + V.setValue(ctx, result); + return result; } diff --git a/test/lib/src/eval/compiler/expression/postfix_test.dart b/test/lib/src/eval/compiler/expression/postfix_test.dart deleted file mode 100644 index 46041c0..0000000 --- a/test/lib/src/eval/compiler/expression/postfix_test.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:dart_eval/dart_eval.dart'; -import 'package:dart_eval/stdlib/core.dart'; -import 'package:test/expect.dart'; -import 'package:test/scaffolding.dart'; - -void main() { - group('Postfix', () { - late Compiler compiler; - - setUp(() { - compiler = Compiler(); - }); - - test('i++', () { - final runtime = compiler.compileWriteAndLoad({ - 'eval_test': { - 'main.dart': ''' - num main() { - var d = 0.0; - d++; - var i = 0; - i++; - return i + d; - } - ''' - } - }); - - expect( - runtime.executeLib('package:eval_test/main.dart', 'main'), - // ignore: unnecessary_cast - equals($num(2 as num)), - ); - }); - - test('i--', () { - final runtime = compiler.compileWriteAndLoad({ - 'eval_test': { - 'main.dart': ''' - num main() { - var d = 1.0; - d--; - var i = 1; - i--; - return i + d; - } - ''' - } - }); - - expect( - runtime.executeLib('package:eval_test/main.dart', 'main'), - // ignore: unnecessary_cast - equals($num(0 as num)), - ); - }); - }); -} diff --git a/test/lib/src/eval/compiler/expression/prefix_test.dart b/test/lib/src/eval/compiler/expression/prefix_test.dart deleted file mode 100644 index f18d8b5..0000000 --- a/test/lib/src/eval/compiler/expression/prefix_test.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:dart_eval/dart_eval.dart'; -import 'package:dart_eval/stdlib/core.dart'; -import 'package:test/expect.dart'; -import 'package:test/scaffolding.dart'; - -void main() { - group('Prefix', () { - late Compiler compiler; - - setUp(() { - compiler = Compiler(); - }); - - test('++i', () { - final runtime = compiler.compileWriteAndLoad({ - 'eval_test': { - 'main.dart': ''' - num main() { - var d = 0.0; - ++d; - var i = 0; - ++i; - return i + d; - } - ''' - } - }); - - expect( - runtime.executeLib('package:eval_test/main.dart', 'main'), - // ignore: unnecessary_cast - equals($num(2 as num)), - ); - }); - - test('--i', () { - final runtime = compiler.compileWriteAndLoad({ - 'eval_test': { - 'main.dart': ''' - num main() { - var d = 1.0; - d--; - var i = 1; - i--; - return i + d; - } - ''' - } - }); - - expect( - runtime.executeLib('package:eval_test/main.dart', 'main'), - // ignore: unnecessary_cast - equals($num(0 as num)), - ); - }); - }); -} diff --git a/test/postfix_test.dart b/test/postfix_test.dart new file mode 100644 index 0000000..cca0ac0 --- /dev/null +++ b/test/postfix_test.dart @@ -0,0 +1,65 @@ +import 'package:dart_eval/dart_eval.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Postfix', () { + late Compiler compiler; + + setUp(() { + compiler = Compiler(); + }); + + test('i++', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + void main() { + double d = 0.0; + double di = d++; + print(di); + print(d); + int i = 0; + int ii = i++; + print(ii); + print(i); + } + ''' + } + }); + + expect( + () { + runtime.executeLib('package:eval_test/main.dart', 'main'); + }, + prints('0.0\n1.0\n0\n1\n'), + ); + }); + + test('i--', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + void main() { + double d = 1.0; + double di = d--; + print(di); + print(d); + int i = 1; + int ii = i--; + print(ii); + print(i); + } + ''' + } + }); + + expect( + () { + runtime.executeLib('package:eval_test/main.dart', 'main'); + }, + prints('1.0\n0.0\n1\n0\n'), + ); + }); + }); +} diff --git a/test/prefix_test.dart b/test/prefix_test.dart new file mode 100644 index 0000000..c9fc9c0 --- /dev/null +++ b/test/prefix_test.dart @@ -0,0 +1,65 @@ +import 'package:dart_eval/dart_eval.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Prefix', () { + late Compiler compiler; + + setUp(() { + compiler = Compiler(); + }); + + test('++i', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + void main() { + double d = 0.0; + double di = ++d; + print(di); + print(d); + int i = 0; + int ii = ++i; + print(ii); + print(i); + } + ''' + } + }); + + expect( + () { + runtime.executeLib('package:eval_test/main.dart', 'main'); + }, + prints('1.0\n1.0\n1\n1\n'), + ); + }); + + test('--i', () { + final runtime = compiler.compileWriteAndLoad({ + 'eval_test': { + 'main.dart': ''' + void main() { + double d = 1.0; + double di = --d; + print(di); + print(d); + int i = 1; + int ii = --i; + print(ii); + print(i); + } + ''' + } + }); + + expect( + () { + runtime.executeLib('package:eval_test/main.dart', 'main'); + }, + prints('0.0\n0.0\n0\n0\n'), + ); + }); + }); +} From ad441ac5a060570df70fd7e19ca4cf2340de37ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Wed, 18 Oct 2023 20:32:05 +0200 Subject: [PATCH 3/5] Use L.type intead of resolving, remove L.name check, update tests --- lib/src/eval/compiler/expression/postfix.dart | 10 ++++---- lib/src/eval/compiler/expression/prefix.dart | 24 ++++++++----------- test/postfix_test.dart | 9 +++++-- test/prefix_test.dart | 8 +++++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/src/eval/compiler/expression/postfix.dart b/lib/src/eval/compiler/expression/postfix.dart index c7c36a3..2fc3973 100644 --- a/lib/src/eval/compiler/expression/postfix.dart +++ b/lib/src/eval/compiler/expression/postfix.dart @@ -11,12 +11,10 @@ Variable compilePostfixExpression(PostfixExpression e, CompilerContext ctx) { final L = V.getValue(ctx); var out = L; - if (L.name != null) { - out = Variable.alloc(ctx, L.type); - ctx.pushOp(PushNull.make(), PushNull.LEN); - ctx.pushOp(CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), - CopyValue.LEN); - } + out = Variable.alloc(ctx, L.type); + ctx.pushOp(PushNull.make(), PushNull.LEN); + ctx.pushOp( + CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), CopyValue.LEN); const opMap = {TokenType.PLUS_PLUS: '+', TokenType.MINUS_MINUS: '-'}; diff --git a/lib/src/eval/compiler/expression/prefix.dart b/lib/src/eval/compiler/expression/prefix.dart index 23dc8c1..6c42034 100644 --- a/lib/src/eval/compiler/expression/prefix.dart +++ b/lib/src/eval/compiler/expression/prefix.dart @@ -26,8 +26,7 @@ Variable compilePrefixExpression(CompilerContext ctx, PrefixExpression e) { if ([TokenType.PLUS_PLUS, TokenType.MINUS_MINUS].contains(e.operator.type)) { final V = compileExpressionAsReference(e.operand, ctx); final L = V.getValue(ctx); - final type = V.resolveType(ctx); - return _handleDoubleOperands(e, ctx, V, type, L); + return _handleDoubleOperands(e, ctx, V, L); } final V = compileExpression(e.operand, ctx); @@ -63,24 +62,21 @@ Variable _handleDoubleOperands( PrefixExpression e, CompilerContext ctx, Reference V, - TypeRef type, Variable L, ) { - var out = L; + var l = L; - if (L.name != null) { - out = Variable.alloc(ctx, L.type); - ctx.pushOp(PushNull.make(), PushNull.LEN); - ctx.pushOp( - CopyValue.make(out.scopeFrameOffset, L.scopeFrameOffset), - CopyValue.LEN, - ); - } + l = Variable.alloc(ctx, L.type); + ctx.pushOp(PushNull.make(), PushNull.LEN); + ctx.pushOp( + CopyValue.make(l.scopeFrameOffset, L.scopeFrameOffset), + CopyValue.LEN, + ); - final result = out.invoke( + final result = l.invoke( ctx, _opMap[e.operator.type]!, - [_oneForType(type, ctx).push(ctx)], + [_oneForType(l.type, ctx).push(ctx)], ).result; V.setValue(ctx, result); diff --git a/test/postfix_test.dart b/test/postfix_test.dart index cca0ac0..e55acd1 100644 --- a/test/postfix_test.dart +++ b/test/postfix_test.dart @@ -23,6 +23,9 @@ void main() { int ii = i++; print(ii); print(i); + List list = [0]; + print(list[0]++); + print(list.first); } ''' } @@ -32,7 +35,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('0.0\n1.0\n0\n1\n'), + prints('0.0\n1.0\n0\n1\n0\n1\n'), ); }); @@ -49,6 +52,8 @@ void main() { int ii = i--; print(ii); print(i); + List list = [1]; + print(list[0]--); } ''' } @@ -58,7 +63,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('1.0\n0.0\n1\n0\n'), + prints('1.0\n0.0\n1\n0\n1\n'), ); }); }); diff --git a/test/prefix_test.dart b/test/prefix_test.dart index c9fc9c0..d9167f3 100644 --- a/test/prefix_test.dart +++ b/test/prefix_test.dart @@ -23,6 +23,8 @@ void main() { int ii = ++i; print(ii); print(i); + List list = [0]; + print(++list[0]); } ''' } @@ -32,7 +34,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('1.0\n1.0\n1\n1\n'), + prints('1.0\n1.0\n1\n1\n1\n'), ); }); @@ -49,6 +51,8 @@ void main() { int ii = --i; print(ii); print(i); + List list = [1]; + print(--list[0]); } ''' } @@ -58,7 +62,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('0.0\n0.0\n0\n0\n'), + prints('0.0\n0.0\n0\n0\n0\n'), ); }); }); From cd589d6b1c38591aea90c5f1be0883f325c6054f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Wed, 18 Oct 2023 20:40:02 +0200 Subject: [PATCH 4/5] Switch to list[0] --- test/postfix_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/postfix_test.dart b/test/postfix_test.dart index e55acd1..e279d7b 100644 --- a/test/postfix_test.dart +++ b/test/postfix_test.dart @@ -25,7 +25,7 @@ void main() { print(i); List list = [0]; print(list[0]++); - print(list.first); + print(list[0]); } ''' } From 22386d8ba86a9e82d896744170323b8cfdc657ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Thu, 19 Oct 2023 20:18:33 +0200 Subject: [PATCH 5/5] Fix list elements boxing issue --- lib/src/eval/compiler/expression/prefix.dart | 3 +-- test/postfix_test.dart | 3 ++- test/prefix_test.dart | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/eval/compiler/expression/prefix.dart b/lib/src/eval/compiler/expression/prefix.dart index 6c42034..b6a11c2 100644 --- a/lib/src/eval/compiler/expression/prefix.dart +++ b/lib/src/eval/compiler/expression/prefix.dart @@ -79,6 +79,5 @@ Variable _handleDoubleOperands( [_oneForType(l.type, ctx).push(ctx)], ).result; - V.setValue(ctx, result); - return result; + return V.setValue(ctx, result); } diff --git a/test/postfix_test.dart b/test/postfix_test.dart index e279d7b..6e8a64e 100644 --- a/test/postfix_test.dart +++ b/test/postfix_test.dart @@ -54,6 +54,7 @@ void main() { print(i); List list = [1]; print(list[0]--); + print(list[0]); } ''' } @@ -63,7 +64,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('1.0\n0.0\n1\n0\n1\n'), + prints('1.0\n0.0\n1\n0\n1\n0\n'), ); }); }); diff --git a/test/prefix_test.dart b/test/prefix_test.dart index d9167f3..fe98208 100644 --- a/test/prefix_test.dart +++ b/test/prefix_test.dart @@ -25,6 +25,7 @@ void main() { print(i); List list = [0]; print(++list[0]); + print(list[0]); } ''' } @@ -34,7 +35,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('1.0\n1.0\n1\n1\n1\n'), + prints('1.0\n1.0\n1\n1\n1\n1\n'), ); }); @@ -53,6 +54,7 @@ void main() { print(i); List list = [1]; print(--list[0]); + print(list[0]); } ''' } @@ -62,7 +64,7 @@ void main() { () { runtime.executeLib('package:eval_test/main.dart', 'main'); }, - prints('0.0\n0.0\n0\n0\n0\n'), + prints('0.0\n0.0\n0\n0\n0\n0\n'), ); }); });