mirror of https://github.com/status-im/nimplay.git
Add support for only handling annoted public functions.
This commit is contained in:
parent
83bc66813e
commit
b13f970f96
|
@ -23,6 +23,7 @@ type
|
||||||
payable*: bool
|
payable*: bool
|
||||||
method_id*: string
|
method_id*: string
|
||||||
method_sig*: string
|
method_sig*: string
|
||||||
|
is_private*: bool
|
||||||
|
|
||||||
|
|
||||||
proc generate_method_sig*(func_sig: FunctionSignature, v2_sig: bool = false): string =
|
proc generate_method_sig*(func_sig: FunctionSignature, v2_sig: bool = false): string =
|
||||||
|
@ -59,6 +60,10 @@ proc generate_function_signature*(proc_def: NimNode): FunctionSignature =
|
||||||
case child.kind:
|
case child.kind:
|
||||||
of nnkIdent:
|
of nnkIdent:
|
||||||
func_sig.name = strVal(child)
|
func_sig.name = strVal(child)
|
||||||
|
func_sig.is_private = true
|
||||||
|
of nnkPostfix:
|
||||||
|
func_sig.name = strVal(child[1])
|
||||||
|
func_sig.is_private = false
|
||||||
of nnkFormalParams:
|
of nnkFormalParams:
|
||||||
for param in child:
|
for param in child:
|
||||||
case param.kind
|
case param.kind
|
||||||
|
|
|
@ -4,7 +4,7 @@ import system
|
||||||
import strformat
|
import strformat
|
||||||
import tables
|
import tables
|
||||||
import endians
|
import endians
|
||||||
|
import sequtils
|
||||||
|
|
||||||
import ./eth_abi_utils, ./builtin_keywords
|
import ./eth_abi_utils, ./builtin_keywords
|
||||||
|
|
||||||
|
@ -24,14 +24,18 @@ type
|
||||||
# Global temp variables create at beginning of the function.
|
# Global temp variables create at beginning of the function.
|
||||||
keyword_define_stmts: NimNode
|
keyword_define_stmts: NimNode
|
||||||
# Map of temp variables that have to be replaced by.
|
# Map of temp variables that have to be replaced by.
|
||||||
global_keyword_map: Table[string, string]
|
global_keyword_map: Table[string, string]
|
||||||
|
|
||||||
|
|
||||||
proc get_func_name(proc_def: NimNode): string =
|
proc get_func_name(proc_def: NimNode): string =
|
||||||
var func_name = ""
|
var func_name = ""
|
||||||
for child in proc_def:
|
for child in proc_def:
|
||||||
|
if child.kind == nnkPostfix:
|
||||||
|
func_name = strVal(child[1])
|
||||||
|
break
|
||||||
if child.kind == nnkIdent:
|
if child.kind == nnkIdent:
|
||||||
func_name = strVal(child)
|
func_name = strVal(child)
|
||||||
|
break
|
||||||
return func_name
|
return func_name
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,6 +154,14 @@ proc handle_contract_interface(stmts: NimNode): NimNode =
|
||||||
discard
|
discard
|
||||||
# raise newException(ParserError, ">> Invalid stmt \"" & getTypeInst(child) & "\" not supported in contract block")
|
# raise newException(ParserError, ">> Invalid stmt \"" & getTypeInst(child) & "\" not supported in contract block")
|
||||||
|
|
||||||
|
echo function_signatures
|
||||||
|
|
||||||
|
if filter(function_signatures, proc(x: FunctionSignature): bool = x.is_private).len == 0:
|
||||||
|
raise newException(
|
||||||
|
ParserError,
|
||||||
|
"No public functions have defined, use * postfix to annotate public functions."
|
||||||
|
)
|
||||||
|
|
||||||
# Build Main Entrypoint.
|
# Build Main Entrypoint.
|
||||||
var out_stmts = newStmtList()
|
var out_stmts = newStmtList()
|
||||||
out_stmts.add(
|
out_stmts.add(
|
||||||
|
@ -188,15 +200,12 @@ proc handle_contract_interface(stmts: NimNode): NimNode =
|
||||||
newIdentNode("selector")
|
newIdentNode("selector")
|
||||||
)
|
)
|
||||||
|
|
||||||
# selector_CaseStmt.add(newIdentNode("selector"))
|
# Build function selector.
|
||||||
# nnkStmtList.newTree(
|
|
||||||
# nnkCall.newTree(
|
|
||||||
# newIdentNode("hello"),
|
|
||||||
# newIdentNode("a")
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
||||||
for func_sig in function_signatures:
|
for func_sig in function_signatures:
|
||||||
|
if func_sig.is_private:
|
||||||
|
echo "!!!"
|
||||||
|
continue
|
||||||
echo "Building " & func_sig.method_sig
|
echo "Building " & func_sig.method_sig
|
||||||
var call_and_copy_block = nnkStmtList.newTree()
|
var call_and_copy_block = nnkStmtList.newTree()
|
||||||
var call_to_func = nnkCall.newTree(
|
var call_to_func = nnkCall.newTree(
|
||||||
|
|
|
@ -7,8 +7,8 @@ import endians
|
||||||
import macros
|
import macros
|
||||||
import stint
|
import stint
|
||||||
|
|
||||||
|
expandMacros:
|
||||||
contract("MyContract"):
|
contract("MyContract"):
|
||||||
|
|
||||||
# proc becomeKing(): uint256 =
|
# proc becomeKing(): uint256 =
|
||||||
# var a: int32
|
# var a: int32
|
||||||
|
@ -16,10 +16,17 @@ contract("MyContract"):
|
||||||
# a += 1.int32
|
# a += 1.int32
|
||||||
# return a.stuint(256)
|
# return a.stuint(256)
|
||||||
|
|
||||||
|
proc get_sender222(): address =
|
||||||
|
if true:
|
||||||
|
return msg.sender
|
||||||
|
|
||||||
proc get_sender(): address =
|
proc get_sender(): address =
|
||||||
if true:
|
if true:
|
||||||
return msg.sender
|
return msg.sender
|
||||||
|
|
||||||
|
proc publicGetSender*(): address =
|
||||||
|
return msg.sender
|
||||||
|
|
||||||
# getCaller(addr tmp_addr)
|
# getCaller(addr tmp_addr)
|
||||||
# proc addition(a: uint256, b: uint256): uint256 =
|
# proc addition(a: uint256, b: uint256): uint256 =
|
||||||
# return a + b
|
# return a + b
|
||||||
|
|
Loading…
Reference in New Issue