Evgeniy Stratonikov
d16ef53653
compiler: support ellipsis for append of non-byte slices
...
NeoVM lacks opcode for array append, thus some
kind of loop is needed for this.
2021-02-17 17:14:32 +03:00
Evgeniy Stratonikov
fc3b840335
compiler: append bytes >0x80 properly
...
NeoVM encoding for int(0x80) is []byte{0x80, 0x00} and
byte constant can be used both as integer and as an element
of byte-slice. Thus special case needs to be taken in
`append`.
2021-02-17 16:34:34 +03:00
Evgeniy Stratonikov
cf459002f7
compiler: allow to inline global variables
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
6e560c6c9f
compiler: allow to inline var arg functions
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
339187a56d
compiler: count locals number properly
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
57a0377c81
compiler: load nil
directly on inline
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
3484025065
compiler: load constants directly on inline
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
27e60455c7
compiler: do not introduce excessive locals on inline
...
When function call-site parameter is an identifier,
we may load it directly. Currently it can be also modified,
this will be fixed in a separate commit.
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
1ae0d022dd
compiler: support basic inlining
2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
1f238ce6fd
compiler: do not emit RET twice for nested BlockStmt
...
When function finishes with `*ast.BlockStmt`, last return
in that block should be looked for.
2021-02-15 18:48:33 +03:00
Roman Khimov
754c985424
Merge pull request #1736 from nspcc-dev/preview5-compatibility-fixes
...
core: preview-5 states difference fixes
2021-02-12 23:58:22 +03:00
Anna Shaleva
0f1473897b
core: temp manifest.Extra marshalling fix
...
Manifest.Extra still serialized as JSON message with undefined order
of items, so it affects contract states dumps.
2021-02-12 23:48:30 +03:00
Roman Khimov
ca08a559fa
interop: allow transfer calls to read states
...
Follow-up to #1734 .
2021-02-12 12:56:15 +03:00
Evgeniy Stratonikov
560aff6155
compiler: adjust init/_deploy method offsets during optimization
...
Because `_initialize` and `_deploy` methods encompass multiple
Go functions, their offsets are stored differently and need
special treatment.
2021-02-11 15:59:02 +03:00
Evgeniy Stratonikov
e1d2a5b5b7
state: split ContractBase and UpdateCounter
...
Latter doesn't make sense for native contracts.
2021-02-11 12:24:09 +03:00
Evgeniy Stratonikov
18b7584cb4
compiler/interop: add Manifest to Contract struct
2021-02-08 13:13:11 +03:00
Evgeniy Stratonikov
6cf40749a9
compiler: add tests for native wrappers
2021-02-08 13:13:10 +03:00
Evgeniy Stratonikov
73a75cc27a
compiler: do not convert interop types on assertion
2021-02-08 13:11:39 +03:00
Evgeniy Stratonikov
2f6345f2d9
compiler: add Hash compatibility test
2021-02-08 13:09:41 +03:00
Evgeniy Stratonikov
69c011b3e7
compiler: implement Ledger contract wrapper
2021-02-08 13:09:41 +03:00
Evgeniy Stratonikov
2f26490e59
compiler: implement RoleManagement contract wrapper
2021-02-08 11:44:39 +03:00
Evgeniy Stratonikov
3c237e2a29
compiler: implement NameService contract wrapper
2021-02-08 11:44:39 +03:00
Evgeniy Stratonikov
6e866b622a
compiler: implement NEO contract wrapper
2021-02-08 11:44:39 +03:00
Evgeniy Stratonikov
e5d8c1c985
compiler: allow conversion to types from external packages
2021-02-08 11:02:45 +03:00
Roman Khimov
ac527650eb
native: add Ledger contract, fix #1696
...
But don't change the way we process/store transactions and blocks. Effectively
it's just an interface for smart contracts that replaces old syscalls.
Transaction definition is moved temporarily to runtime package and Block
definition is removed (till we solve #1691 properly).
2021-02-04 13:12:11 +03:00
Evgeniy Stratonikov
c1cc7e6f9d
native: add additional parameters to deploy
...
1. Management contract has 2 overloads of `deploy` method.
2. Normal contracts should have `_deploy` with 2 parameters.
2021-01-29 12:19:08 +03:00
Evgeniy Stratonikov
f0fe03117a
compiler: optimize struct copy a bit
...
POPITEM is cheaper than PUSH + PICKITEM.
2021-01-19 09:46:01 +03:00
Evgeniy Stratonikov
9b1a7021ba
core: add PickN flags to Storage.Find
...
Allow to pick items by index from serialized struct or array.
2021-01-15 21:12:10 +03:00
Evgeniy Stratonikov
44af99fd07
core: add Deserialize flag to Storage.Find
...
Allow to deserialize values being iterated over.
2021-01-15 21:12:10 +03:00
Evgeniy Stratonikov
7fc0c04dba
core: add flags to Storage.Find
...
It can be iterated over keys, values or both.
Prefix can be stripped.
2021-01-15 21:12:08 +03:00
Evgeniy Stratonikov
2130e17f0c
core,vm: remove System.Enumerator.*
interops
...
Map iterator now returns key-value pair, while array/byte-array
iterators work like old enumerators.
Follow neo-project/neo#2190 .
2021-01-15 21:11:32 +03:00
Evgeniy Stratonikov
d04b000748
vm: remove iterator/enumerator Concat API
...
Follow neo-project/neo#2170 .
2021-01-15 21:08:59 +03:00
Evgenii Stratonikov
1c0c331e25
core: update System.Contract.Call
syscall
...
1. Remove `System.Contract.CallEx`.
2. Extend number of parameters.
3. Add return value count to `VM.Context`.
2021-01-14 18:23:36 +03:00
Evgenii Stratonikov
dbe81f9b80
smartcontract: move flags to a separate package
2021-01-14 17:52:09 +03:00
Evgeniy Stratonikov
0b26b46234
state: store NEF instead of script for contract
...
NEFs for native contracts are set statically, thus
field values are taken from the reference implementation.
2021-01-13 15:34:10 +03:00
Roman Khimov
459ad521ab
*: fix misspellings spotted by goreportcard
2020-12-28 17:27:04 +03:00
Roman Khimov
811f38eaed
*: gofmt -s
2020-12-28 17:23:30 +03:00
Roman Khimov
ab12eee346
native: move contract deployment to management contract
...
See neo-project/neo#2119 .
2020-12-14 15:23:46 +03:00
Roman Khimov
fc361213a7
Merge pull request #1608 from nspcc-dev/core/callflags
...
core: adjust call flags
2020-12-11 19:23:15 +03:00
Anna Shaleva
fadbae8997
core: rename call flags
...
Also new States flag is added and ReadOnly flag is adjusted.
2020-12-11 10:34:01 +03:00
Evgenii Stratonikov
4dc5877674
compiler: remove unused code and simplify error handling
...
After cbf26f3
some errors can't occur.
2020-12-10 18:56:08 +03:00
Evgenii Stratonikov
2341ae0c53
compiler: specify safe methods in config
2020-12-10 18:00:43 +03:00
Evgenii Stratonikov
d7194e4da5
compiler: do not check for main package in ConvertToManifest
2020-12-10 17:45:23 +03:00
Evgenii Stratonikov
9fd8577dd9
compiler: use Options
in ConvertToManifest()
2020-12-10 17:43:25 +03:00
Roman Khimov
a3f91ba8c5
Merge pull request #1603 from nspcc-dev/compiler/types
...
compiler: enforce `Hash160` and `Hash256` size in literals
2020-12-10 14:55:03 +03:00
Roman Khimov
f3e64e08d7
Merge pull request #1602 from nspcc-dev/fix/test
...
vmcli/test: run shell after providing input
2020-12-10 14:42:30 +03:00
Evgenii Stratonikov
ff4880249d
compiler: enforce Hash160
and Hash256
size in literals
...
Can be useful to prevent small typos.
2020-12-10 14:11:28 +03:00
Evgenii Stratonikov
37a8550215
compiler: add contract.CallEx
interop
2020-12-10 13:45:10 +03:00
Evgenii Stratonikov
ec58bec803
compiler: fix global constant traversal
...
There can be no global variables, but some global constants.
Introduced in 0b44a430
.
2020-12-10 13:45:10 +03:00
Evgenii Stratonikov
b807fd9e7f
compiler: rename engine.AppCall()
to contract.Call()
2020-12-10 13:45:10 +03:00
Evgenii Stratonikov
c7ce9cd4f6
compiler: defer dir removal right after creation
2020-12-10 13:40:29 +03:00
Roman Khimov
d828096cbf
Merge pull request #1599 from nspcc-dev/compiler/debuginfo
...
compiler: save both VM and smartcontract types
2020-12-09 23:30:59 +03:00
Evgenii Stratonikov
cbf26f315c
compiler: save both VM and smartcontract types
...
VM types are used in debugger, while smartcontract ones are used in
manifest. We can't save only one of them, because conversion in either
side is lossy:
1. VM has `Array` and `Struct` but smartcontract only has `Array`.
2. Smartcontract has `Hash160` etc, which are all `ByteString` or
`Buffer` in VM.
And to spice things a bit more, return type in debugger can be `Void`,
which corresponds to no real stackitem type (as it must exist).
2020-12-09 22:35:22 +03:00
Evgenii Stratonikov
b7e86fa6a3
manifest: add Safe
flag to method descriptor
...
`interop.Contex.AddMethod` sets `Safe` flag for native
contracts. This allows not to forget to change manifest
when changing call flags.
Also fixed invalid `Safe` flags for `Notary` and `Designate` contracts.
2020-12-08 13:27:43 +03:00
Evgenii Stratonikov
573d1d10c0
cli: add tests for contract
command
2020-12-04 11:05:48 +03:00
Roman Khimov
1cf1fe5d74
*: introduce stable contract hashes
...
Follow neo-project/neo#2044 .
2020-11-27 21:47:08 +03:00
Roman Khimov
b92ea2a48a
manifest/compiler: drop hashes from ABI and debug info
...
See neo-project/neo-devpack-dotnet#391 and neo-project/neo#2044 .
2020-11-26 18:30:49 +03:00
Evgenii Stratonikov
75a9a42403
compiler: check emitted event names
...
Check that all `Notify` invocations in source correspond to some event
in manifest.
Helpful for typos such as `transfer` instead of `Transfer`.
2020-11-26 13:49:58 +03:00
Evgenii Stratonikov
25f1db6de0
compiler: check supported standards
...
Check that emitted manifest complies with supported standards.
This can be made a separate flag.
2020-11-26 12:51:39 +03:00
Evgenii Stratonikov
7d91a3a89e
pkg: move internal/ package to the root directory
...
This way we can use it in scripts and cli.
2020-11-24 16:39:56 +03:00
Evgenii Stratonikov
c849176be7
manifest: include contract Name
2020-11-24 11:23:44 +03:00
Evgenii Stratonikov
1869d6d460
core: allow to use state root in header
2020-11-20 17:16:32 +03:00
Roman Khimov
286d9185f4
smartcontract: remove contract features
...
We're featureless now, all contracts have access to storage and payable status
is to be determined via new NEP. Follow neo-project/neo#2060 .
2020-11-13 21:26:23 +03:00
Evgenii Stratonikov
d193e16662
compiler: support System.Binary.Atoi/Itoa
syscalls
2020-11-10 16:15:10 +03:00
Evgenii Stratonikov
01ccaefe2f
compiler: refactor void calls processing
...
Call result is not used only if it occurs inside a `ExprStmt`.
Otherwise (`IfStmt`, `BinExpr`...) it is used.
Fix #1495 .
2020-10-19 10:43:47 +03:00
Roman Khimov
e9a8e957f8
Merge pull request #1488 from nspcc-dev/fix/compiler
...
compiler: fix manifest method offset
2020-10-14 15:12:57 +03:00
Evgenii Stratonikov
1f2d76a1c2
compiler: fix manifest method offset
...
While optimizing jumps, old offsets should be compared
with the method offset before optimization, not with
the constantly changing value.
2020-10-14 15:04:33 +03:00
Anna Shaleva
f8d5c40928
compiler: do not DROP return value with type assertion
...
The same problem as with IF. Example:
```
func foo() interface{} {
...
}
func Main() int{} {
return foo().(int) <--- panic here
}
```
2020-10-13 19:14:44 +03:00
Anna Shaleva
dbce3c9a19
compiler: do not DROP unary expression value inside IF stmt
...
We dropped values from such calls because they where marked as unused
(consequently, were followed by DROP instructions). Example:
if !foo() { <--- panic here
...
}
This commit prevents the following runtime error during script execution:
```
"error encountered at instruction ** (NOT): runtime error: invalid memory address or nil pointer dereference"
```
2020-10-13 19:14:44 +03:00
Evgenii Stratonikov
c4a8770215
compiler: support _deploy
method
2020-10-06 19:12:35 +03:00
Evgenii Stratonikov
6701e8cda0
compiler: allow to use local variables in init()
...
Because body of multiple `init()` functions constitute single
method in contract, we initialize slot with maximum amount of
locals encounterered in any of `init()` functions and clear them
before emitting body of each instance of `init()`.
2020-10-06 19:08:32 +03:00
Evgenii Stratonikov
b2a3a0851e
emit: accept multiple opcodes in Opcode()
2020-10-06 18:03:25 +03:00
Evgenii Stratonikov
fd52dee79f
compiler: process literals in analyzeVoidCalls
...
Function call can occur in the slice or map literal
and its result surely isn't unused.
2020-09-25 15:34:49 +03:00
Evgenii Stratonikov
5f3b8c6d51
compiler: allow variables in byte-slice literals
2020-09-24 20:20:34 +03:00
Roman Khimov
5f22bdfecf
Merge pull request #1375 from nspcc-dev/compiler/types
...
Smartcontract types definition in interops
2020-09-16 14:43:50 +03:00
Evgenii Stratonikov
bcc11cbd74
compiler: support removing slice elements
...
Go-way of removing elements from slice is via `append` builtin.
There is a separate opcode for removing elements from
Arrays, which is cheaper and supported in this commit.
2020-09-15 16:33:43 +03:00
Evgenii Stratonikov
78948ef7af
compiler: emit error for non-byte subslices
...
They are not supported for now, as VM has only
`SUBSTR` opcode for Buffers (`[]byte` in Go).
2020-09-15 16:21:44 +03:00
Evgenii Stratonikov
37f7363386
interop: return struct pointers where needed
...
`Transaction`, `Block` and `Contract` are represented as
`Array`s in VM, so we must return pointers.
Revert a1f98f92
.
2020-09-09 13:10:04 +03:00
Evgenii Stratonikov
25f8545cdf
compiler: extend manifest generation with custom types
2020-09-09 13:06:44 +03:00
Evgenii Stratonikov
7483e3b054
compiler: support delete()
builtin
2020-09-06 15:49:41 +03:00
Evgenii Stratonikov
18369c489e
compiler: do not allocate slotes for unused "_" vars
2020-09-06 15:27:46 +03:00
Evgenii Stratonikov
0b44a43043
compiler: do not allocate static slot for constants
...
Their value is known at compile time.
2020-09-06 15:20:17 +03:00
Roman Khimov
18204ec21a
Merge pull request #1383 from nspcc-dev/compiler/switchtag
...
compiler: fix a bug with type conversion in switch
2020-09-03 14:40:17 +03:00
Anna Shaleva
70a58b6522
compiler: do not convert methods to manifest methods
...
Close #1381
2020-09-02 22:41:54 +03:00
Anna Shaleva
058da7c2bd
compiler: getFuncNameFromDecl for methods on pointers
...
Declaration has *ast.StarExpr type in case of method on pointer.
2020-09-02 22:41:54 +03:00
Evgenii Stratonikov
74dda0ac66
compiler: allow to use type conversion in range
2020-09-02 15:35:20 +03:00
Evgenii Stratonikov
3af7ce8c6b
compiler: allow to use copy()
return value
2020-09-02 15:29:59 +03:00
Evgenii Stratonikov
3d8c7af66c
compiler: handle void call to recover()
...
Other builtins such as `len` and `make` can be ignored,
because not-assigning `make` result is catched by parser.
2020-09-02 15:20:43 +03:00
Evgenii Stratonikov
7d61a567d5
compiler: fix a bug with type conversion in switch
...
It was incorrectly parsed as void call.
2020-09-02 14:48:19 +03:00
Evgenii Stratonikov
5d82b82efb
compiler: support recover()
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
14ea3c2228
compiler: do not log panic message
...
In NEO3 THROW accepts an argument and exceptions can be handled, so
there is no need to log it.
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
fa1d1a8b00
compiler: support defer
statement
...
Compile `defer` statement to a TRY/ENDFINALLY opcode pair.
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
b18a7f200c
compiler: calculate local variables properly
...
In case when right-hand side of an assignment is a function,
left-hand side should be used.
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
84c36326f5
compiler: allow init statement in if
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
d73f3cd24c
compiler: support calling function literals
2020-08-27 10:28:50 +03:00
Roman Khimov
962f45f35e
Merge pull request #1361 from nspcc-dev/feature/iota
...
compiler: support `iota`
2020-08-25 15:50:20 +03:00
Evgenii Stratonikov
05ef951055
compiler: support iota
2020-08-25 10:22:58 +03:00
Roman Khimov
a1fbe51bca
Merge pull request #1352 from nspcc-dev/compiler/make
...
Fix MEMCPY, support `copy` and `make` in compiler
2020-08-25 09:33:16 +03:00
Evgenii Stratonikov
69989e1227
compiler: support copy()
2020-08-25 08:53:29 +03:00
Evgenii Stratonikov
931dc6c64f
compiler: remove debug PrintOps() from tests
2020-08-25 08:53:29 +03:00