zoukankan      html  css  js  c++  java
  • swift的调用约定

    swift的静态绑定

    Swift Calling Convention @convention(swift)

     func foo(_ x:Int, y:Int)

    sil @foo : $(x:Int, y:Int) -> () {

    entry(%x : $Int, %y : $Int):

      ...

    }

    func bar(_ x:Int, y:(Int, Int))

    sil @bar : $(x:Int, y:(Int, Int)) -> () {

    entry(%x : $Int, %y0 : $Int, %y1 : $Int):

      ...

    }

    func call_foo_and_bar() {

      foo(1, 2)

      bar(4, (5, 6))

    }

    sil @call_foo_and_bar : $() -> () {

    entry:

      ...

      %foo = function_ref @foo : $(x:Int, y:Int) -> ()

      %foo_result = apply %foo(%1, %2) : $(x:Int, y:Int) -> ()

      ...

      %bar = function_ref @bar : $(x:Int, y:(Int, Int)) -> ()

      %bar_result = apply %bar(%4, %5, %6) : $(x:Int, y:(Int, Int)) -> ()

    }

    Swift Method Calling Convention @convention(method)

    The method calling convention is currently identical to the freestanding function convention. Methods are considered to be curried functions, taking the "self" argument as their outer argument clause, and the method arguments as the inner argument clause(s). When uncurried, the "self" argument is thus passed last:

    struct Foo {

      func method(_ x:Int) -> Int {}

    }

    sil @Foo_method_1 : $((x : Int), @inout Foo) -> Int { ... }

    //例子

    class NSObjectBase: NSObject {

        func Msg_Second(str:String){}

    }

    // NSObjectBase.Msg_Second(str:)

    sil hidden @NSObjectBase.NSObjectBase.Msg_Second(str: Swift.String) -> () : $@convention(method) (@guaranteed String, @guaranteed NSObjectBase) -> ()

    sil_vtable NSObjectBase {

      #NSObjectBase.Msg_Second!1: (NSObjectBase) -> (String) -> () : @NSObjectBase.NSObjectBase.Msg_Second(str: Swift.String) -> () // NSObjectBase.Msg_Second(str:)

    }

    Objective-C Calling Convention @convention(objc_method)

    https://github.com/apple/swift/blob/master/docs/SIL.rst#objective-c-calling-convention-convention-objc-method

  • 相关阅读:
    Zookeeper安装部署
    dubbo/dubbox部署资料收集
    Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
    ios开发--清理缓存
    从零开始,让你的框架支持CocoaPods
    iOS 开发-- Runtime 1小时入门教程
    iOS 开发--github的demo
    linux 防火墙iptables简明教程
    利用BBRSACryptor实现iOS端的RSA加解密
    iOS开发--数组
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10601596.html
Copyright © 2011-2022 走看看