Commit graph

316 commits

Author SHA1 Message Date
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
Evgenii Stratonikov
0f11116040 compiler: support make() 2020-08-25 08:53:28 +03:00
Evgenii Stratonikov
354645fbe3 compiler: allow to use switch without tag 2020-08-24 19:35:25 +03:00
Evgenii Stratonikov
e58616b975 compiler: drop unused call results
Close #683.
2020-08-24 19:34:51 +03:00
Evgenii Stratonikov
f70cb4f34a compiler: do not use voidCalls when calculating stack size
This was probably a part of some earlier logic.
2020-08-24 19:34:51 +03:00
Roman Khimov
d8badd9a8d
Merge pull request #1351 from nspcc-dev/compiler/jmps
Make use of extended JMP* opcodes
2020-08-24 19:22:24 +03:00
Evgenii Stratonikov
9dc3edf351 compiler: make use of extended JMP* opcodes 2020-08-24 11:19:54 +03:00
Evgenii Stratonikov
51f3baf68e compiler: refactor BinaryExpr handling
Reuse code between if conditions and expression context.
2020-08-24 09:46:11 +03:00
Evgenii Stratonikov
4d04c56efb compiler: make toShortForm accept an opcode 2020-08-24 09:44:44 +03:00
Evgenii Stratonikov
1be1b8de9e compiler: merge && and || processing 2020-08-24 09:44:44 +03:00
Evgenii Stratonikov
59367c96d1 compiler: allow to use += on strings 2020-08-24 09:44:44 +03:00
Evgenii Stratonikov
fd7af77895 compiler: refactor convertToken func
Move `getEqualityOpcode` into `convertToken`.
`convertToken` does not need codegen.
2020-08-24 09:44:44 +03:00
Evgenii Stratonikov
ae88c77a8a compiler: process nil comparisons separately 2020-08-24 09:44:16 +03:00
Roman Khimov
9c72ea1d64 core/interop: add base58 encoding/decoding syscalls
Follow neo-project/neo#1833.
2020-08-23 17:19:56 +03:00