Fix compilation for negative integers
Motivation and Context
It was reported in issue #1506 that pushing negative number onto the stack emit NEG
Fixes #1506
Description
This MR adds a peephole optimization in self_michelson,
that checks for such patterns like PUSH int 100 ; NEG
and turns them into PUSH int -100
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
Improves the Michelson compilation for negative integers, removes the unnecessary NEG
instruction in the case of negative integers
Before:
$ ligo.55 compile expression cameligo ' -100' --without-run
{ PUSH int 100 ; NEG }
After
$ ligo compile expression cameligo ' -100' --without-run
{ PUSH int -100 }
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha