Skip to content

Commit c2d9874

Browse files
committed
cffi: refactor cffi declarations
1 parent 84822b2 commit c2d9874

File tree

3 files changed

+13
-68
lines changed

3 files changed

+13
-68
lines changed

compiler/compiler/func.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value {
123123

124124
funcRetType, treReturnTypes, llvmParams, treParams, isVariadicFunc, argumentReturnValuesCount := c.funcType(argTypes, retTypes)
125125

126-
isTxFFIFuncs := c.currentPackageName == "tx" &&
127-
(compiledName == "is_owner_mode" ||
128-
compiledName == "script_verify" ||
129-
compiledName == "get_utxo_inputs" ||
130-
compiledName == "get_utxo_outputs" ||
131-
compiledName == "check_enhanced_owner_mode" ||
132-
compiledName == "get_owner_mode" ||
133-
compiledName == "get_flags" ||
134-
compiledName == "get_err" ||
135-
compiledName == "execute_scripts" ||
136-
compiledName == "simple_udt" ||
137-
compiledName == "parse_args")
138126
var fn *ir.Func
139127
var entry *ir.Block
140128

@@ -153,7 +141,7 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value {
153141
} else {
154142
fn = c.module.NewFunc(compiledName, funcRetType.LLVM(), llvmParams...)
155143
// register ffi function definnition for tx package and os package
156-
if isTxFFIFuncs {
144+
if v.IsCFunc {
157145
// do not generate block
158146
} else {
159147
entry = fn.NewBlock(name.Block())
@@ -170,7 +158,7 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value {
170158

171159
// register ffi function definition for tx package
172160
// without generate func body
173-
if isTxFFIFuncs {
161+
if v.IsCFunc {
174162
val := value.Value{
175163
Type: typesFunc,
176164
Value: fn,

pkg/cell/cell.cell

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Script table {
2020
type XudtArgs table {
2121
owner_mode bool
2222
err int64
23-
flags uint32
23+
flags int64
2424
script [32768]byte
2525
codeBuf_padding [4076]byte
2626
codeBuf [1843200]byte

pkg/tx/tx.cell

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,39 @@ const (
1212
SUCCESS = iota
1313
)
1414

15-
function script_verify() bool {
16-
return true
17-
}
15+
cfunction script_verify() bool
16+
cfunction is_owner_mode() bool
17+
cfunction get_utxo_inputs() []cell.Cell
18+
cfunction get_utxo_outputs() []cell.Cell
19+
1820
function scriptVerify() bool {
1921
return script_verify()
2022
}
21-
22-
function is_owner_mode() bool {
23-
return true
24-
}
2523
function isOwnerMode() bool {
2624
return is_owner_mode()
2725
}
28-
29-
function get_utxo_inputs() []cell.Cell {
30-
return []cell.Cell{}
31-
}
3226
function inputs() []cell.Cell {
3327
return get_utxo_inputs()
3428
}
35-
36-
function get_utxo_outputs() []cell.Cell {
37-
return []cell.Cell{}
38-
}
3929
function outputs() []cell.Cell {
4030
return get_utxo_outputs()
4131
}
4232

4333
// xudt related API and ffi functions
44-
function parse_args() *cell.XudtArgs {
45-
return 0
46-
}
34+
cfunction parse_args() *cell.XudtArgs
35+
cfunction check_enhanced_owner_mode(args *cell.XudtArgs) bool
36+
cfunction simple_udt(owner_mode bool) int64
37+
cfunction execute_scripts(args *cell.XudtArgs) bool
38+
4739
function xudtArgs() *cell.XudtArgs {
4840
return parse_args()
4941
}
50-
51-
function check_enhanced_owner_mode(args *cell.XudtArgs) bool {
52-
return false
53-
}
5442
function checkEnhancedOwnerMode(args *cell.XudtArgs) bool {
5543
return check_enhanced_owner_mode(args)
5644
}
57-
58-
function simple_udt(owner_mode bool) int64 {
59-
return 0
60-
}
6145
function sudt(owner_mode bool) int64 {
6246
return simple_udt(owner_mode)
6347
}
64-
65-
function get_flags(args uintptr) int64 {
66-
return 0
67-
}
68-
function getFlags(args uintptr) int64 {
69-
return get_flags(args)
70-
}
71-
72-
function get_err(args uintptr) int64 {
73-
return 0
74-
}
75-
function getErr(args uintptr) int64 {
76-
return get_err(args)
77-
}
78-
79-
function get_owner_mode(args uintptr) int64 {
80-
return 0
81-
}
82-
function getOwnerMode(args *cell.XudtArgs) int64 {
83-
return get_owner_mode(args)
84-
}
85-
86-
function execute_scripts(args *cell.XudtArgs) bool {
87-
return false
88-
}
8948
function executeScripts(args *cell.XudtArgs) bool {
9049
return execute_scripts(args)
9150
}
92-
93-

0 commit comments

Comments
 (0)