Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Four NeoVM OpCode #33

Open
carltraveler opened this issue Dec 20, 2018 · 0 comments
Open

Add Four NeoVM OpCode #33

carltraveler opened this issue Dec 20, 2018 · 0 comments
Assignees

Comments

@carltraveler
Copy link

Title: Add Four NeoVM OpCode

Author: [email protected]

Created Dec. 20th. 2018

Add Four NeoVM OpCode

Abstraction

​ add HASKEY, KEYS, VALUES, DCALL four NeoVM OpCode.

​ NeoVM already have the opcode NEWMAP. that is to say, map is a baisc type of NeoVM, acctually, NeoVM has bytearray, interger, boolean, array, interop, struct type. Now NeoVM opcode can get these type's characteristic, like element of array, len of bytearray, etc. however NeoVM now can only new a map through NEWMAP opcode. and do not have any other way to get the map's characteristic, like keys, values. this lackless limited the usage of neovm baisc map type. any language convert it's type to neovm map can not get any other infomation. casually, the python map object almost have the same semantic of neovm map. so the python map object convert neovm map object is the best choice. however, now can not get the keys, and values.

​ as we know, the CALL only leave 2 bytes to save the offsets which is equal jump target sub call offset(address). now a smartcontract's source code exceed more than 1000 lines. usually, the compile will failed due to the call 2 bytes limit.

Specification

HASKEY

​ this opcode used to check whether arg 'key' is a map's key. the typical python code is below:

map_t = {1: 'a', 2: 'b', 3:'c'}
exist_k = map_t.has_key(2)

acctually this opcode is not necessary if realize the keys already. haskey function can get the keys first. then compare to the arg key by travel all elements in keys. if find a element equal. return True, else return False.

VALUES

​ this opcode used to get the values of a map, and return the map's values as a list on the top of the stack. the typical python code is below:

map_t = {1: 'a', 2: 'b', 3:'c'}
exist_k = map_t.values(2)

the values attribute function will compile to opcode VALUES as a builtin function.

KEYS

​ this opcode used to get the keys of a map, and return the map's keys as a list on the top of the stack. the typical python code is below:

map_t = {1: 'a', 2: 'b', 3:'c'}
exist_k = map_t.keys(2)

the keys attribute function will compile to opcode KEYS as a builtin function.

DCALL

​ this opcode used to do the vm context switch. however different with CALL get the two bytes offset after CALL opcode, stored in the avm code stream, DCALL just get the jump target(not relative offset compare to CALL offset) from the top stack of the evaluation stack. this will solve the function call distance two long which can not convert such offset to two bytes. and gives more flexibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants