Skip to content

Commit

Permalink
cffi: refactor cffi declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Jul 11, 2024
1 parent 84822b2 commit c2d9874
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 68 deletions.
16 changes: 2 additions & 14 deletions compiler/compiler/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value {

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

isTxFFIFuncs := c.currentPackageName == "tx" &&
(compiledName == "is_owner_mode" ||
compiledName == "script_verify" ||
compiledName == "get_utxo_inputs" ||
compiledName == "get_utxo_outputs" ||
compiledName == "check_enhanced_owner_mode" ||
compiledName == "get_owner_mode" ||
compiledName == "get_flags" ||
compiledName == "get_err" ||
compiledName == "execute_scripts" ||
compiledName == "simple_udt" ||
compiledName == "parse_args")
var fn *ir.Func
var entry *ir.Block

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

// register ffi function definition for tx package
// without generate func body
if isTxFFIFuncs {
if v.IsCFunc {
val := value.Value{
Type: typesFunc,
Value: fn,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cell/cell.cell
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Script table {
type XudtArgs table {
owner_mode bool
err int64
flags uint32
flags int64
script [32768]byte
codeBuf_padding [4076]byte
codeBuf [1843200]byte
Expand Down
63 changes: 10 additions & 53 deletions pkg/tx/tx.cell
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,39 @@ const (
SUCCESS = iota
)

function script_verify() bool {
return true
}
cfunction script_verify() bool
cfunction is_owner_mode() bool
cfunction get_utxo_inputs() []cell.Cell
cfunction get_utxo_outputs() []cell.Cell

function scriptVerify() bool {
return script_verify()
}

function is_owner_mode() bool {
return true
}
function isOwnerMode() bool {
return is_owner_mode()
}

function get_utxo_inputs() []cell.Cell {
return []cell.Cell{}
}
function inputs() []cell.Cell {
return get_utxo_inputs()
}

function get_utxo_outputs() []cell.Cell {
return []cell.Cell{}
}
function outputs() []cell.Cell {
return get_utxo_outputs()
}

// xudt related API and ffi functions
function parse_args() *cell.XudtArgs {
return 0
}
cfunction parse_args() *cell.XudtArgs
cfunction check_enhanced_owner_mode(args *cell.XudtArgs) bool
cfunction simple_udt(owner_mode bool) int64
cfunction execute_scripts(args *cell.XudtArgs) bool

function xudtArgs() *cell.XudtArgs {
return parse_args()
}

function check_enhanced_owner_mode(args *cell.XudtArgs) bool {
return false
}
function checkEnhancedOwnerMode(args *cell.XudtArgs) bool {
return check_enhanced_owner_mode(args)
}

function simple_udt(owner_mode bool) int64 {
return 0
}
function sudt(owner_mode bool) int64 {
return simple_udt(owner_mode)
}

function get_flags(args uintptr) int64 {
return 0
}
function getFlags(args uintptr) int64 {
return get_flags(args)
}

function get_err(args uintptr) int64 {
return 0
}
function getErr(args uintptr) int64 {
return get_err(args)
}

function get_owner_mode(args uintptr) int64 {
return 0
}
function getOwnerMode(args *cell.XudtArgs) int64 {
return get_owner_mode(args)
}

function execute_scripts(args *cell.XudtArgs) bool {
return false
}
function executeScripts(args *cell.XudtArgs) bool {
return execute_scripts(args)
}


0 comments on commit c2d9874

Please sign in to comment.