Commit graph

70 commits

Author SHA1 Message Date
Evgeniy Stratonikov
9871dc8f5a compiler: update x/tools package
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-01-20 13:21:26 +03:00
Roman Khimov
299a7ea614 compiler: use CALLT for native contract calls, fix #2257 2021-12-10 11:58:50 +03:00
Evgeniy Stratonikov
8a0429036b compiler: set type information during traversal, fix #2231
Set all necessary context before file traversal, not only import
maps. Also, we can skip restoring import maps because all our code is
processed via `For*` iterators which set necessary context.
We can also refactor this a bit to have all context in one place,
this will be done in #2086.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
b91de50e65 compiler: remove convert.To* from the list of builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:16:03 +03:00
Evgeniy Stratonikov
a92bf281c1 compiler: remove custom logic for util builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:12:47 +03:00
Roman Khimov
36295357d8 interop: add Abort() function to ABORT things
Related to #2227.
2021-10-22 14:50:51 +03:00
Evgeniy Stratonikov
0bc81aecf4 compiler: do not emit code for unused imported functions
Our current algorithm marks function as used if it is called
at least ones, even if the callee function is itself unused.
This commit implements more clever traversal to collect usage
information more precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-13 15:56:07 +03:00
Roman Khimov
4d1e952be6 go.mod: update go-datastructures to 1.0.53
We're only using queue library and it didn't change in any way, but 1.0.53 has
proper go.mod, so it's still an improvement.

It at the same time pulls some new packages also like x/tools.
2021-07-21 23:28:00 +03:00
Evgeniy Stratonikov
233996eec0 native/neo: add getAccountState method, close #1975 2021-05-27 10:59:38 +03:00
Evgeniy Stratonikov
60a3e0d778 compiler: count auxiliary locals introduced by inlining
During initialization of globals no function scope is present thus
locals number is not saved anywere. Save it in `codegen` directly.
2021-05-19 11:50:07 +03:00
Evgeniy Stratonikov
b693d54282 compiler: count local variables on the go
Create local variables as they are needed and remove `INITSLOT`
if there were no locals. This helps to eliminate a whole class
of bugs when calculated and real amount mismatched.
2021-05-19 11:50:07 +03:00
Evgeniy Stratonikov
2aaaf30db7 compiler: remove finallyProcessIndex from funcScope 2021-05-19 09:54:10 +03:00
Roman Khimov
cfc067dd24 *: remove dead code
Found by deadcode via golangci-lint.
2021-05-12 18:13:14 +03:00
Evgeniy Stratonikov
7160675ac1 compiler/interop: improve conversion to bytes interops
Allow to convert to both `Buffer` and `ByteString`
and explicitly mention VM types. Rename `ToByteArray` to `ToBytes`
to avoid ambiguity.
2021-03-10 13:38:44 +03:00
Roman Khimov
924de3e090
Merge pull request #1796 from nspcc-dev/compiler/pow
Add syscalls for POW and SQRT opcodes
2021-03-04 16:56:15 +03:00
Evgeniy Stratonikov
8f8c7d2839 compiler: fix import alias handling 2021-03-04 14:41:20 +03:00
Evgeniy Stratonikov
56fe6574c9 compiler: simplify convert.To* processing
With inlining there is no need for special logic in compiler.
2021-03-04 13:05:33 +03:00
Evgeniy Stratonikov
578bbabd1d compiler: allow to emit opcodes directly 2021-03-04 13:03:05 +03:00
Evgeniy Stratonikov
0a4ff9d3e4 compiler: allow to use inlined functions to init globals 2021-02-25 15:12:16 +03:00
Evgeniy Stratonikov
df5314f286 compiler: refactor syscall handling
Close #941.
2021-02-24 12:51:15 +03:00
Evgeniy Stratonikov
339187a56d compiler: count locals number properly 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
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
6e866b622a compiler: implement NEO contract wrapper 2021-02-08 11:44:39 +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
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
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
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
Evgenii Stratonikov
5d82b82efb compiler: support recover() 2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
69989e1227 compiler: support copy() 2020-08-25 08:53:29 +03:00
Evgenii Stratonikov
0f11116040 compiler: support make() 2020-08-25 08:53:28 +03:00
Evgenii Stratonikov
181569c2a1 compiler: allow to alias interop packages
Fix #397.
2020-08-19 10:13:36 +03:00
Evgenii Stratonikov
40fa7c0f6e compiler: emit all used files in DebugInfo.Documents 2020-08-11 11:12:29 +03:00
Evgenii Stratonikov
4488f61777 compiler: compile init even if there are no globals
`init` can be useful even if no globals are present,
e.g. we can use some syscall inside.
2020-08-05 12:59:53 +03:00
Evgenii Stratonikov
439d9ff94d compiler: initialize packages according to go spec
`init()` functions should be called during package initialization,
after global variables were processed.
2020-08-05 11:15:07 +03:00
Evgenii Stratonikov
6f2759be3a compiler: process packages in deterministic order 2020-08-05 11:00:25 +03:00
Evgenii Stratonikov
b771d2d024 compiler: allow to use init function
Process `init()` functions after global variables has been processed.
It's body is saved into the `_initialize` method where all
initialization is performed.
2020-08-05 11:00:25 +03:00
Evgenii Stratonikov
a781d299e0 compiler: use fully-qualified names for tracking functions
Function name now consists of 3 parts:
1) full package path
2) method receiver type (if any)
3) function name itself .

Fix #1150.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:07:06 +03:00
Evgenii Stratonikov
6df019913d compiler: allow to use exported variables
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
b8d7e93459 compiler: make ForEachFile accept a package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
ac040a6f22 compiler: remove unused resolveEntryPoint
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
7009417325 compiler: allow to declare global variables in multiple files
Traverse and count globals across all used files.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
685d44dbc1 *: support _initialize method in contracts
Invoke `_initialize` method on every call if present.
In NEO3 there is no entrypoint and methods are invoked by offset,
thus `Main` function is no longer required.
We still have special `Main` method in tests to simplify them.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
d2ddf7b7cb *: support invoking methods by offset
Allow to invoke methods by offset:
1. Every invoked contract must have manifest.
2. Check arguments count on invocation.
3. Change AppCall to a regular syscall.
4. Add test suite for `System.Contract.Call`.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
e87eba51f9 compiler: emit bytecode for unused exported functions
Exported functions should always be present in byte-code.
This will be needed later when arbitrary method calls are allowed.
2020-07-27 13:00:35 +03:00