Evgenii Stratonikov
156a2eddc5
compiler: support using return
in some branches
...
When `return` is used in one codepath, but not the other,
we do not clean altstack properly. This commit fixes it.
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
d18199ce42
vm: implement REVERSE* opcodes
...
Use new opcodes in the compiler instead of XSWAP/ROLL.
2020-05-06 13:03:49 +03:00
Evgenii Stratonikov
9081211f12
vm: implement NOTEQUAL opcode
2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
519b31a704
vm: remove crypto-related opcodes
...
All cryptography has moved to interops in NEO3.
There is no SHA256 interop RN, but it is to appear later.
Closes #777 .
2020-04-29 19:16:38 +03:00
Evgenii Stratonikov
2fd63387c0
compiler: support CONVERT interops
...
When result is needed to have certain type, we should have ability
to convert it, with the help of CONVERT opcode.
2020-04-28 16:44:06 +03:00
Evgenii Stratonikov
bfcb1a409f
compiler: extend possible returned values
...
All integer values (int32, uint64...) should be able to be returned.
2020-04-28 16:44:06 +03:00
Evgenii Stratonikov
03761421f8
vm: reorder Array/Map opcodes
...
Also SIZE can be used for both Arrays/Maps and ByteArrays.
2020-04-24 13:48:44 +03:00
Evgenii Stratonikov
d6624a92ca
vm: implement new JMP* and CALL* opcodes
...
In compiler JMP*_L opcodes are always used, as this requires less effort.
2020-04-24 10:16:41 +03:00
Evgenii Stratonikov
4ad29d0867
compiler: emit Neo.Crypto.ECDsaVerify syscall instead of CHECKSIG
...
Also change the name of `VerifySignature` interop, to match
syscall's name. It also accepts arguments in different order.
2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
948729137f
vm: remove HASH160/HASH256 opcodes
2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
da826522f8
compiler: set variable index on first declaration
...
This way variables will have indices corresponding to their
order of appearance in a source file.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
457e7e006a
compiler: support exporting method variables in debug info
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
5bdee683e6
cli,compiler: support emitting debug info in a file
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
5d3da26e1e
compiler: support sequence points in debug info
...
Sequence points is a way to map a specific instruction offset
from a compiled contract to a text span in a source file.
This commit implements mapping only for `return` statements.
Further improvements are straight-forward.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
24fef35ead
compiler: split Compile info sub-functions
...
Also add tests for basic debug info.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
00c40b58aa
compiler: record basic debug info
...
Save info about method's byte-code sections.
2020-04-06 15:30:06 +03:00
Evgenii Stratonikov
efad66aee1
compiler: make Notify accept varargs
2020-04-06 09:31:09 +03:00
Evgenii Stratonikov
3cbd138b67
compiler: allow to declare variables of struct type
...
Previously, struct variables were initialize with VM's nil value
which is of primitive type. Thus SETITEM used for struct's field
updating wasn't working.
2020-03-27 13:50:09 +03:00
Evgenii Stratonikov
6baed7a010
compiler: allow to declare slices of compound types
...
Previously this declarations were ignored which resulted
in runtime errors, because VM's nil is an element of primitive type
and can't be converted to an array.
2020-03-27 13:50:09 +03:00
Evgenii Stratonikov
f0b6f783aa
compiler: allow for loops with empty condition
2020-03-26 15:00:14 +03:00
Evgenii Stratonikov
2a1402f25d
compiler: clean up stack on branch statements
...
When `return` or `break` statement is encountered inside
a for/range/switch statement, top stack items can be auxilliary.
They need to be cleaned up before returning from the function.
2020-03-10 15:26:00 +03:00
Evgenii Stratonikov
91301df161
compiler: implement fallthrough in switch
...
Closes #628 .
2020-03-10 12:34:07 +03:00
Roman Khimov
e41d434a49
*: move all packages from CityOfZion to nspcc-dev
2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
b461a6ab63
compiler: do not short-circuit in complex conditions
...
Current implementation of short-circuting is just plain wrong
as it uses `last` or `before-last` labels which meaning depend
on context. It doesn't even handle simple assignements like
`a := x == 1 && y == 2`.
This commit makes all jumps in such conditions local
and adds tests.
Closes #699 , #700 .
2020-02-28 17:44:46 +03:00
Evgenii Stratonikov
177b725dc1
compiler: make writeJumps return error for bad jumps
...
The script is invalid anyway so it is better to notify user.
2020-02-21 17:45:45 +03:00
Evgenii Stratonikov
5e229d84d4
compiler: use uint16 for label numbers
...
As noted in #687 this will make compiler a bit more predictable.
2020-02-21 17:45:45 +03:00
Evgenii Stratonikov
da89f18999
compiler: support break and continue in range loops
2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
ccb53414f2
compiler: support break in switch statements
2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
03dc6f7cbb
compiler: support continue statement in for loops
2020-02-21 12:03:36 +03:00
Evgenii Stratonikov
fa2edc46e0
compiler: support break statement in for loops
2020-02-21 11:38:23 +03:00
Roman Khimov
d16121c10a
Merge pull request #654 from nspcc-dev/feat/subslice
...
compiler: support sub-slicing
2020-02-16 23:49:53 +03:00
Roman Khimov
4a4cd6416c
Merge pull request #658 from nspcc-dev/feature/range
...
compiler: support for-range loops
2020-02-16 23:49:30 +03:00
Evgenii Stratonikov
32bce30777
compiler: support sub-slicing
2020-02-12 12:16:15 +03:00
Evgenii Stratonikov
310f7449d7
compiler: support for-range loops
2020-02-12 12:16:04 +03:00
Evgenii Stratonikov
ae03560589
compiler: support initializing struct fields from a variable
...
While initializing a struct, it is a top item on ALTSTACK.
This means that if we need to load a local variable,
DUPFROMALTSTACK won't longer push an array of locals on stack
but rather a currently initializing struct.
Closes #656 .
2020-02-12 12:15:54 +03:00
Evgenii Stratonikov
3e84f2bdf8
compiler: rewrite jump targets properly
...
Old implementation could view 0x62 byte in
a script as a JMP instruction irregardless of whether it is
a real opcode or a part of a parameter of another instruction.
In this commit instructions are decoded together with parameters
during jump label rewriting.
2020-02-12 10:58:53 +03:00
Evgenii Stratonikov
895a8d9ebc
compiler: reverse args in AppCall
...
Invoked contract is expecting first argument to be on top of the stack.
Change test to use non-commutative operation to catch this behaviour.
2020-02-10 10:53:58 +03:00
Evgenii Stratonikov
1fc64d515f
compiler: abstract out emitReverse
...
Extract logic of reversing top n items of the stack
in a separate function.
2020-02-10 10:43:31 +03:00
Evgenii Stratonikov
dbc41b3044
compiler: replace emit* instructions with those from emit/ package
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
c3094123a1
compiler: do not store constants as variables
...
Because the constants are loaded directly via `emitLoadConst`, there is no need to store
them in an array of locals. It can have a big overhead, because it
is done at the beginning of every function.
2020-02-03 13:29:28 +03:00
Evgenii Stratonikov
8b922c057c
compiler: fix a bug with assignment to underscore
...
When using underscore it does not appear in the list
of local variables, so it can't be assigned.
In this commit the value is dropped.
2020-01-29 17:07:55 +03:00
Evgenii Stratonikov
7053b3b2c0
compiler: optimize append argument processing
...
Append should leave it's result on top of the stack.
Thus we need to transform top of the stack:
(top) a . b --> (top) a . b . b
It can be done with just OVER + SWAP.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
b6629fb6bd
compiler: refactor argument handling for builtins
...
It is more convenient to have all unusual logic in one place.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
d2326a8b96
compiler: support panic
in source
...
In situations where VM's FAULT state needs to be reached,
panic function can be used. It compiles to THROW instruction.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
e0f47decc7
compiler: replace ROLL(2) with equivalent ROT
2020-01-29 09:56:16 +03:00
Evgenii Stratonikov
28571bd3dc
compiler: implement switch statement support
2020-01-29 09:56:16 +03:00
Evgenii Stratonikov
77f9a2ee26
compiler: convert AppCall parameter from string properly
2020-01-27 15:34:03 +03:00
Evgenii Stratonikov
d65d6ab08d
compiler: allow to convert string constants to []byte
...
Also load constant directly into stack, not by name.
2020-01-27 15:29:52 +03:00
Evgenii Stratonikov
097d35b9d5
compiler: fix a bug with FromAddress handling
...
Conversion of string to address with FromAddress is performed
at compile time so there is no need to push parameters on stack.
2020-01-27 13:14:40 +03:00
Evgenii Stratonikov
330db36168
compiler: implement engine.AppCall interop
2020-01-27 13:14:36 +03:00
Evgenii Stratonikov
4fd766fe09
compiler: allow usage of string literals in index expressions
2020-01-23 17:28:35 +03:00
Evgenii Stratonikov
058958729d
compiler: support map literals
2020-01-23 17:06:15 +03:00
Evgenii Stratonikov
def73db8e9
compiler: support variables in slice literals
2020-01-23 15:51:16 +03:00
Roman Khimov
67fe99b0ba
Merge pull request #618 from nspcc-dev/feature/for
...
compiler: support for loops with no init/post condition
2020-01-23 13:19:55 +03:00
Evgenii Stratonikov
328267ca6f
compiler: support for loops with no init/post condition
...
Make it possible to use `for` loop with a single condition.
2020-01-23 11:48:43 +03:00
Evgenii Stratonikov
bd37359393
compiler: implement ECDSA signature verification
...
Add VerifySignature interop for signature verification.
It is converted to VERIFY opcode.
2020-01-23 10:56:15 +03:00
Roman Khimov
9145855d2c
Merge pull request #579 from nspcc-dev/refactor-crypto
...
This moves some functionality into micro-packages, improves testing,
unexports some code and fixes bugs along the way.
2019-12-25 18:12:50 +03:00
Roman Khimov
b246653f62
address: rename functions as per #579 comments
...
Make them more clear to understand.
2019-12-25 17:34:18 +03:00
Roman Khimov
e685e9bf9a
address: move into its own package
...
Doesn't really belong to the crypto.
2019-12-25 15:22:02 +03:00
Evgenii Stratonikov
f4571ba8cf
compiler: implement multiple return support
2019-12-24 16:46:43 +03:00
Roman Khimov
79323cc10b
Merge pull request #567 from nspcc-dev/feature/codegen_add_mod
...
compiler: Add Mod token, closes #563
2019-12-19 15:32:18 +03:00
Vsevolod Brekelov
3c7ac7eb95
compiler: add mod
2019-12-19 15:23:14 +03:00
Evgenii Stratonikov
891a878af1
compiler: implement assignment to a variable index
...
Fixes #564 .
2019-12-19 13:14:17 +03:00
Evgenii Stratonikov
57efad912c
util: add LE suffix to Uint160 methods
2019-12-06 12:16:55 +03:00
Roman Khimov
852e6a335b
compiler: move it up from vm
...
It really deserves it, I think. Especially given that it doesn't have any
direct usage of `vm` package now.
2019-12-03 18:23:46 +03:00