Commit graph

79 commits

Author SHA1 Message Date
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
bfbbef952a vm: move InteropNameToID to emit package 2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
3831aec53f vm: make NewBigInteger accept *big.Int
It creates big.Int internally anyway, so this is the most flexible way.
2020-04-16 15:54:58 +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
c71ad6a5db cli: output contract after compiling only with --verbose flag
Also remove Debug from compiler option as it is used only in CLI.
2020-04-08 13:09:51 +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
a43c9b9246 compiler: calculate stack size more precisely
When calculating number of local variables, only
defining assignments (i.e. via `:=`) must be taken into account.
2020-04-01 17:36:19 +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
Anna Shaleva
37cb60a0b5 compiler/interop: add missing methods to interop.Iterator
Add Next() and Value() to interop.Iterator and corresponding syscalls to
compiler
2020-03-26 16:39:10 +03:00
Evgenii Stratonikov
f0b6f783aa compiler: allow for loops with empty condition 2020-03-26 15:00:14 +03:00
Roman Khimov
abd7855890
Merge pull request #742 from nspcc-dev/add-dynamic-appcall
vm: add support for dynamic invocations in APPCALL
2020-03-11 17:27:05 +03:00
Roman Khimov
8318adac56 vm: add support for dynamic invocations in APPCALL
Fixes #740.
2020-03-10 17:17:36 +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
a3dacd3b74 tests: replace t.Fatal with require where possible
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +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
8ea3ef0b62 compiler: process empty []byte{} literals as ByteArrays
It is wrong to count an empty byte slice as an Array.
2020-02-12 12:16:15 +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
52d8d58593 compiler,interop: make AppCall accept varargs 2020-02-10 10:51:29 +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