xcbosa mbp16 2 лет назад
Родитель
Сommit
a4ff688f91

+ 0 - 236
Interop/Invocation.swift

@@ -1,236 +0,0 @@
-//
-//  Dynamic
-//  Created by Mhd Hejazi on 4/15/20.
-//  Modify by XCBOSA on 6/3/23
-//  Copyright © 2020 Samabox. All rights reserved.
-//
-
-import Foundation
-
-class Invocation {
-    public static var loggingEnabled: Bool = false
-
-    private let target: NSObject
-    private let selector: Selector
-
-    var invocation: NSObject?
-
-    var typeEncoding: String?
-    var numberOfArguments: Int = 0
-    var returnLength: Int = 0
-    var returnType: UnsafePointer<CChar>?
-    var returnTypeString: String? {
-        guard let returnType = returnType else { return nil }
-        return String(cString: returnType)
-    }
-    var returnsObject: Bool {
-        /// `@` is the type encoding for an object
-        returnTypeString == "@"
-    }
-    var returnsAny: Bool {
-        /// `v` is the type encoding for Void
-        returnTypeString != "v"
-    }
-    lazy var returnedObject: AnyObject? = {
-        returnedObjectValue()
-    }()
-    private(set) var isInvoked: Bool = false
-
-    init(target: NSObject, selector: Selector) throws {
-        self.target = target
-        self.selector = selector
-        try initialize()
-    }
-
-    private func initialize() throws {
-        /// `NSMethodSignature *methodSignature = [target methodSignatureForSelector: selector]`
-        let methodSignature: NSObject
-        do {
-            let selector = NSSelectorFromString("methodSignatureForSelector:")
-            let signature = (@convention(c)(NSObject, Selector, Selector) -> Any).self
-            let method = unsafeBitCast(target.method(for: selector), to: signature)
-            guard let result = method(target, selector, self.selector) as? NSObject else {
-                let error = InvocationError.unrecognizedSelector(type(of: target), self.selector)
-                throw error
-            }
-            methodSignature = result
-        }
-
-        /// `numberOfArguments = methodSignature.numberOfArguments`
-        self.numberOfArguments = methodSignature.value(forKeyPath: "numberOfArguments") as? Int ?? 0
-
-        /// `methodReturnLength = methodSignature.methodReturnLength`
-        self.returnLength = methodSignature.value(forKeyPath: "methodReturnLength") as? Int ?? 0
-
-        /// `methodReturnType = methodSignature.methodReturnType`
-        let methodReturnType: UnsafePointer<CChar>
-        do {
-            let selector = NSSelectorFromString("methodReturnType")
-            let signature = (@convention(c)(NSObject, Selector) -> UnsafePointer<CChar>).self
-            let method = unsafeBitCast(methodSignature.method(for: selector), to: signature)
-            methodReturnType = method(methodSignature, selector)
-        }
-        self.returnType = methodReturnType
-
-        /// `NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: methodSignature]`
-        let invocation: NSObject
-        do {
-            let NSInvocation = NSClassFromString("NSInvocation") as AnyObject
-            let selector = NSSelectorFromString("invocationWithMethodSignature:")
-            let signature = (@convention(c)(AnyObject, Selector, AnyObject) -> AnyObject).self
-            let method = unsafeBitCast(NSInvocation.method(for: selector), to: signature)
-            guard let result = method(NSInvocation, selector, methodSignature) as? NSObject else {
-                let error = InvocationError.unrecognizedSelector(type(of: target), self.selector)
-                throw error
-            }
-            invocation = result
-        }
-        self.invocation = invocation
-
-        /// `invocation.selector = selector`
-        do {
-            let selector = NSSelectorFromString("setSelector:")
-            let signature = (@convention(c)(NSObject, Selector, Selector) -> Void).self
-            let method = unsafeBitCast(invocation.method(for: selector), to: signature)
-            method(invocation, selector, self.selector)
-        }
-
-        /// `[invocation retainArguments]`
-        do {
-            let selector = NSSelectorFromString("retainArguments")
-            let signature = (@convention(c)(NSObject, Selector) -> Void).self
-            let method = unsafeBitCast(invocation.method(for: selector), to: signature)
-            method(invocation, selector)
-        }
-    }
-    
-    private func getArgumentType(at index: NSInteger) -> String? {
-        guard let invocation = invocation else { return nil }
-        
-        let methodSignatureSelector = NSSelectorFromString("methodSignature")
-        let methodSignatureSignature = (@convention(c)(NSObject, Selector) -> NSObject).self
-        let methodSignatureMethod = unsafeBitCast(invocation.method(for: methodSignatureSelector), to: methodSignatureSignature)
-        
-        let methodSignature = methodSignatureMethod(invocation, methodSignatureSelector)
-        
-        let selector = NSSelectorFromString("getArgumentTypeAtIndex:")
-        let signature = (@convention(c)(NSObject, Selector, NSInteger) -> UnsafePointer<CChar>).self
-        let method = unsafeBitCast(methodSignature.method(for: selector), to: signature)
-        
-        let rawType = method(methodSignature, selector, index)
-        return NSString(cString: rawType, encoding: NSUTF8StringEncoding) as? String
-    }
-
-    func setArgument(_ argument: Any?, at index: NSInteger) {
-        guard let invocation = invocation else { return }
-        
-        let argument = TypeMapping.convertToObjCType(argument) ?? argument
-        guard let realArgumentType = self.getArgumentType(at: index) else { return }
-
-        /// `[invocation setArgument:&argument atIndex:i + 2]`
-        let selector = NSSelectorFromString("setArgument:atIndex:")
-        let signature = (@convention(c)(NSObject, Selector, UnsafeRawPointer, Int) -> Void).self
-        let method = unsafeBitCast(invocation.method(for: selector), to: signature)
-        
-//        if let valueArgument = argument as? NSNumber {
-//            /// Get the type byte size
-////            valueArgument = NSNumber(floatLiteral: argument as! Double)
-//            let typeSize = UnsafeMutablePointer<Int>.allocate(capacity: 1)
-//            defer { typeSize.deallocate() }
-//            NSGetSizeAndAlignment(valueArgument.objCType, typeSize, nil)
-//
-//            /// Get the actual value
-//            let buffer = UnsafeMutablePointer<Int8>.allocate(capacity: typeSize.pointee)
-//            defer { buffer.deallocate() }
-//            valueArgument.getValue(buffer)
-//
-//            method(invocation, selector, buffer, index)
-//        } else {
-            withUnsafePointer(to: argument) { pointer in
-                method(invocation, selector, pointer, index)
-//            }
-        }
-    }
-
-    func invoke() {
-        guard let invocation = invocation, !isInvoked else { return }
-
-        isInvoked = true
-
-        /// `[invocation invokeWithTarget: target]`
-        do {
-            let selector = NSSelectorFromString("invokeWithTarget:")
-            let signature = (@convention(c)(NSObject, Selector, AnyObject) -> Void).self
-            let method = unsafeBitCast(invocation.method(for: selector), to: signature)
-            method(invocation, selector, target)
-        }
-    }
-
-    func getReturnValue<T>(result: inout T) {
-        guard let invocation = invocation else { return }
-
-        /// `[invocation getReturnValue: returnValue]`
-        do {
-            let selector = NSSelectorFromString("getReturnValue:")
-            let signature = (@convention(c)(NSObject, Selector, UnsafeMutableRawPointer) -> Void).self
-            let method = unsafeBitCast(invocation.method(for: selector), to: signature)
-            withUnsafeMutablePointer(to: &result) { pointer in
-                method(invocation, selector, pointer)
-            }
-        }
-    }
-
-    private func returnedObjectValue() -> AnyObject? {
-        guard returnsObject, returnLength > 0 else {
-            return nil
-        }
-
-        var result: AnyObject?
-
-        getReturnValue(result: &result)
-
-        guard let object = result else {
-            return nil
-        }
-
-        /// Take the ownership of the initialized objects to ensure they're deallocated properly.
-        if isRetainingMethod() {
-            return Unmanaged.passRetained(object).takeRetainedValue()
-        }
-
-        /// `NSInvocation.getReturnValue()` doesn't give us the ownership of the returned object, but the compiler
-        /// tries to release this object anyway. So, we are retaining it to balance with the compiler's release.
-        return Unmanaged.passRetained(object).takeUnretainedValue()
-    }
-
-    private func isRetainingMethod() -> Bool {
-        /// Refer to: https://bit.ly/308okXm
-        let selector = NSStringFromSelector(self.selector)
-        return selector == "alloc" ||
-            selector.hasPrefix("new") ||
-            selector.hasPrefix("copy") ||
-            selector.hasPrefix("mutableCopy")
-    }
-}
-
-internal enum InvocationError: CustomNSError {
-    case unrecognizedSelector(_ classType: AnyClass, _ selector: Selector)
-
-    internal static var errorDomain: String { String(describing: Invocation.self) }
-
-    internal var errorCode: Int {
-        switch self {
-        case .unrecognizedSelector:
-            return 404
-        }
-    }
-
-    internal var errorUserInfo: [String: Any] {
-        var message: String
-        switch self {
-        case .unrecognizedSelector(let classType, let selector):
-            message = "'\(String(describing: classType))' doesn't recognize selector '\(selector)'"
-        }
-        return [NSLocalizedDescriptionKey: message]
-    }
-}

+ 0 - 128
Interop/TypeMapping.swift

@@ -1,128 +0,0 @@
-//
-//  Dynamic
-//  Created by Mhd Hejazi on 4/18/20.
-//  Modify by XCBOSA on 6/3/23
-//  Copyright © 2020 Samabox. All rights reserved.
-//
-
-// swiftlint:disable cyclomatic_complexity syntactic_sugar
-
-import Foundation
-
-/// The type mapping table can be found here:
-///   https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/working_with_foundation_types
-class TypeMapping {
-    private static let typePairs: [(swiftType: Any.Type, objCType: AnyObject.Type)] = [
-        (Array<Any>.self, NSArray.self),
-        (Calendar.self, NSCalendar.self),
-        (CharacterSet.self, NSCharacterSet.self),
-        (Data.self, NSData.self),
-        (DateComponents.self, NSDateComponents.self),
-        (DateInterval.self, NSDateInterval.self),
-        (Date.self, NSDate.self),
-        (Decimal.self, NSDecimalNumber.self),
-        (Dictionary<AnyHashable, Any>.self, NSDictionary.self),
-        (IndexPath.self, NSIndexPath.self),
-        (IndexSet.self, NSIndexSet.self),
-        (Locale.self, NSLocale.self),
-        (Notification.self, NSNotification.self),
-        (PersonNameComponents.self, NSPersonNameComponents.self),
-        (Set<AnyHashable>.self, NSSet.self),
-        (String.self, NSString.self),
-        (TimeZone.self, NSTimeZone.self),
-        (URL.self, NSURL.self),
-        (URLComponents.self, NSURLComponents.self),
-        (URLQueryItem.self, NSURLQueryItem.self),
-        (URLRequest.self, NSURLRequest.self),
-        (UUID.self, NSUUID.self)
-    ]
-
-    private static let swiftToObjCTypes: [ObjectIdentifier: AnyObject.Type] = {
-        let pairs = typePairs.map {
-            (ObjectIdentifier($0.swiftType), $0.objCType)
-        }
-        return [ObjectIdentifier: AnyObject.Type](uniqueKeysWithValues: pairs)
-    }()
-
-    private static let objCToSwiftTypes: [ObjectIdentifier: Any.Type] = {
-        let pairs = typePairs.map {
-            (ObjectIdentifier($0.objCType), $0.swiftType)
-        }
-        return [ObjectIdentifier: Any.Type](uniqueKeysWithValues: pairs)
-    }()
-
-    static func swiftType(for type: Any.Type) -> Any.Type? {
-        objCToSwiftTypes[ObjectIdentifier(type)]
-    }
-
-    static func objCType(for type: Any.Type) -> Any.Type? {
-        swiftToObjCTypes[ObjectIdentifier(type)]
-    }
-
-    static func mappedType(for type: Any.Type) -> Any.Type? {
-        swiftType(for: type) ?? objCType(for: type)
-    }
-
-    static func convertToObjCType(_ object: Any?) -> Any? {
-        switch object {
-        case is Array<Any>: return object as? NSArray
-        case is Calendar: return object as? NSCalendar
-        case is CharacterSet: return object as? NSCharacterSet
-        case is Data: return object as? NSData
-        case is DateComponents: return object as? NSDateComponents
-        case is DateInterval: return object as? NSDateInterval
-        case is Date: return object as? NSDate
-        case is Decimal: return object as? NSDecimalNumber
-        case is Dictionary<AnyHashable, Any>: return object as? NSDictionary
-        case is IndexPath: return object as? NSIndexPath
-        case is IndexSet: return object as? NSIndexSet
-        case is Locale: return object as? NSLocale
-        case is Notification: return object as? NSNotification
-        case is PersonNameComponents: return object as? NSPersonNameComponents
-        case is Set<AnyHashable>: return object as? NSSet
-        case is String: return object as? NSString
-        case is TimeZone: return object as? NSTimeZone
-        case is URL: return object as? NSURL
-        case is URLComponents: return object as? NSURLComponents
-        case is URLQueryItem: return object as? NSURLQueryItem
-        case is URLRequest: return object as? NSURLRequest
-        case is UUID: return object as? NSUUID
-        case is Double: return object as? NSNumber
-        case is Bool: return object as? NSValue
-        default: return nil
-        }
-    }
-
-    static func convertToSwiftType(_ object: Any?) -> Any? {
-        switch object {
-        case is NSArray: return object as? Array<Any>
-        case is NSCalendar: return object as? Calendar
-        case is NSCharacterSet: return object as? CharacterSet
-        case is NSData: return object as? Data
-        case is NSDateComponents: return object as? DateComponents
-        case is NSDateInterval: return object as? DateInterval
-        case is NSDate: return object as? Date
-        case is NSDecimalNumber: return object as? Decimal
-        case is NSDictionary: return object as? Dictionary<AnyHashable, Any>
-        case is NSIndexPath: return object as? IndexPath
-        case is NSIndexSet: return object as? IndexSet
-        case is NSLocale: return object as? Locale
-        case is NSMeasurement: return object as? Measurement
-        case is NSNotification: return object as? Notification
-        case is NSPersonNameComponents: return object as? PersonNameComponents
-        case is NSSet: return object as? Set<AnyHashable>
-        case is NSString: return object as? String
-        case is NSTimeZone: return object as? TimeZone
-        case is NSURL: return object as? URL
-        case is NSURLComponents: return object as? URLComponents
-        case is NSURLQueryItem: return object as? URLQueryItem
-        case is NSURLRequest: return object as? URLRequest
-        case is NSUUID: return object as? UUID
-        default: return nil
-        }
-    }
-
-    static func convertType(of object: Any?) -> Any? {
-        convertToObjCType(object) ?? convertToSwiftType(object)
-    }
-}

+ 1 - 9
XCTreeLang.xcodeproj/project.pbxproj

@@ -61,8 +61,6 @@
 		756916A72A28FF3D005FF14B /* module.modulemap in Sources */ = {isa = PBXBuildFile; fileRef = 756916A62A28FF3D005FF14B /* module.modulemap */; };
 		756916AA2A29A0B8005FF14B /* XCTLPrefixExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916A92A29A0B8005FF14B /* XCTLPrefixExpression.swift */; };
 		756916AC2A29A357005FF14B /* XCTLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916AB2A29A357005FF14B /* XCTLExpression.swift */; };
-		756916AF2A29CD2C005FF14B /* Invocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916AE2A29CD2C005FF14B /* Invocation.swift */; };
-		756916B12A29D74E005FF14B /* TypeMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916B02A29D74E005FF14B /* TypeMapping.swift */; };
 		756916B42A2B7D20005FF14B /* XCTLInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 756916B22A2B7D20005FF14B /* XCTLInvocation.h */; };
 		756916B52A2B7D20005FF14B /* XCTLInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 756916B32A2B7D20005FF14B /* XCTLInvocation.m */; };
 		756916B92A2B86AA005FF14B /* XCTLSwiftInvocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916B82A2B86AA005FF14B /* XCTLSwiftInvocation.swift */; };
@@ -153,8 +151,6 @@
 		756916A62A28FF3D005FF14B /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
 		756916A92A29A0B8005FF14B /* XCTLPrefixExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTLPrefixExpression.swift; sourceTree = "<group>"; };
 		756916AB2A29A357005FF14B /* XCTLExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTLExpression.swift; sourceTree = "<group>"; };
-		756916AE2A29CD2C005FF14B /* Invocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Invocation.swift; sourceTree = "<group>"; };
-		756916B02A29D74E005FF14B /* TypeMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeMapping.swift; sourceTree = "<group>"; };
 		756916B22A2B7D20005FF14B /* XCTLInvocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XCTLInvocation.h; sourceTree = "<group>"; };
 		756916B32A2B7D20005FF14B /* XCTLInvocation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XCTLInvocation.m; sourceTree = "<group>"; };
 		756916B82A2B86AA005FF14B /* XCTLSwiftInvocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTLSwiftInvocation.swift; sourceTree = "<group>"; };
@@ -190,7 +186,6 @@
 				756916C12A2BA456005FF14B /* GithubImages */,
 				756916C02A2B9963005FF14B /* README.md */,
 				7520C3DC2A283AFC0010E7F8 /* XCTreeLang */,
-				756916AD2A29CD1A005FF14B /* Interop */,
 				7520C43F2A283CA70010E7F8 /* TestApp */,
 				7520C3DB2A283AFC0010E7F8 /* Products */,
 				756916782A283E78005FF14B /* Frameworks */,
@@ -220,6 +215,7 @@
 				7520C4162A283B1E0010E7F8 /* XCTLEngine.swift */,
 				7520C40B2A283B1E0010E7F8 /* XCTLGenerateProtocol.swift */,
 				756916A62A28FF3D005FF14B /* module.modulemap */,
+				756916AD2A29CD1A005FF14B /* Interop */,
 			);
 			path = XCTreeLang;
 			sourceTree = "<group>";
@@ -354,8 +350,6 @@
 		756916AD2A29CD1A005FF14B /* Interop */ = {
 			isa = PBXGroup;
 			children = (
-				756916AE2A29CD2C005FF14B /* Invocation.swift */,
-				756916B02A29D74E005FF14B /* TypeMapping.swift */,
 				756916B82A2B86AA005FF14B /* XCTLSwiftInvocation.swift */,
 			);
 			path = Interop;
@@ -501,7 +495,6 @@
 				7520C4352A283B1E0010E7F8 /* XCTLRuntimeContext.swift in Sources */,
 				7520C4272A283B1E0010E7F8 /* XCTLFunctionCallStatement.swift in Sources */,
 				7520C41B2A283B1E0010E7F8 /* XCTLTokenType.swift in Sources */,
-				756916AF2A29CD2C005FF14B /* Invocation.swift in Sources */,
 				7520C4322A283B1E0010E7F8 /* XCTLRuntimeSubContext.swift in Sources */,
 				7520C42F2A283B1E0010E7F8 /* XCTLGenerateProtocol.swift in Sources */,
 				756916952A28C622005FF14B /* XCTLForStatement.swift in Sources */,
@@ -519,7 +512,6 @@
 				756916872A2851DF005FF14B /* XCTLStream.swift in Sources */,
 				756916B92A2B86AA005FF14B /* XCTLSwiftInvocation.swift in Sources */,
 				756916A22A28FE20005FF14B /* XCTLRuntimeTypeInstance.m in Sources */,
-				756916B12A29D74E005FF14B /* TypeMapping.swift in Sources */,
 				7520C41E2A283B1E0010E7F8 /* XCTLImmediateStatement.swift in Sources */,
 				756916892A286A90005FF14B /* XCTLSetStatement.swift in Sources */,
 				756916972A28DFE7005FF14B /* XCTLBreakStatement.swift in Sources */,

+ 85 - 10
XCTreeLang.xcodeproj/xcuserdata/xcbosa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -947,8 +947,8 @@
             filePath = "XCTreeLang/Statements/XCTLVariableRefStatement.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "139"
-            endingLineNumber = "139"
+            startingLineNumber = "124"
+            endingLineNumber = "124"
             landmarkName = "evaluateBack(_:inContext:)"
             landmarkType = "7">
             <Locations>
@@ -1012,6 +1012,21 @@
                   endingLineNumber = "139"
                   offsetFromSymbolStart = "844">
                </Location>
+               <Location
+                  uuid = "C3B0488E-C243-48F8-A91B-52C5156798CE - b2953dc3cfc33d7f"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "XCTreeLang.XCTLVariableRefStatement.evaluateBack(_: XCTreeLang.XCTLRuntimeVariable, inContext: XCTreeLang.XCTLRuntimeAbstractContext) throws -&gt; XCTreeLang.XCTLRuntimeVariable"
+                  moduleName = "XCTreeLang"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/xcbosa/Documents/LibraryProjects/XCTreeLang/XCTreeLang/Statements/XCTLVariableRefStatement.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "124"
+                  endingLineNumber = "124"
+                  offsetFromSymbolStart = "844">
+               </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
@@ -1025,8 +1040,8 @@
             filePath = "XCTreeLang/Statements/XCTLVariableRefStatement.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "153"
-            endingLineNumber = "153"
+            startingLineNumber = "138"
+            endingLineNumber = "138"
             landmarkName = "evaluateBack(_:inContext:)"
             landmarkType = "7">
             <Locations>
@@ -1090,6 +1105,21 @@
                   endingLineNumber = "153"
                   offsetFromSymbolStart = "1848">
                </Location>
+               <Location
+                  uuid = "C0E92D41-309C-419D-BDAE-E705374FB334 - b2953dc3cfc33b2d"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "XCTreeLang.XCTLVariableRefStatement.evaluateBack(_: XCTreeLang.XCTLRuntimeVariable, inContext: XCTreeLang.XCTLRuntimeAbstractContext) throws -&gt; XCTreeLang.XCTLRuntimeVariable"
+                  moduleName = "XCTreeLang"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/xcbosa/Documents/LibraryProjects/XCTreeLang/XCTreeLang/Statements/XCTLVariableRefStatement.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "138"
+                  endingLineNumber = "138"
+                  offsetFromSymbolStart = "1848">
+               </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
@@ -1103,8 +1133,8 @@
             filePath = "XCTreeLang/Statements/XCTLVariableRefStatement.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "156"
-            endingLineNumber = "156"
+            startingLineNumber = "141"
+            endingLineNumber = "141"
             landmarkName = "evaluateBack(_:inContext:)"
             landmarkType = "7">
             <Locations>
@@ -1168,6 +1198,21 @@
                   endingLineNumber = "156"
                   offsetFromSymbolStart = "2444">
                </Location>
+               <Location
+                  uuid = "13C4A8A4-B94A-43B8-8601-88F10E7EAC2A - b2953dc3cfc33b4e"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "XCTreeLang.XCTLVariableRefStatement.evaluateBack(_: XCTreeLang.XCTLRuntimeVariable, inContext: XCTreeLang.XCTLRuntimeAbstractContext) throws -&gt; XCTreeLang.XCTLRuntimeVariable"
+                  moduleName = "XCTreeLang"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/xcbosa/Documents/LibraryProjects/XCTreeLang/XCTreeLang/Statements/XCTLVariableRefStatement.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "141"
+                  endingLineNumber = "141"
+                  offsetFromSymbolStart = "2444">
+               </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
@@ -1181,8 +1226,8 @@
             filePath = "XCTreeLang/Statements/XCTLVariableRefStatement.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "108"
-            endingLineNumber = "108"
+            startingLineNumber = "93"
+            endingLineNumber = "93"
             landmarkName = "evaluate(inContext:)"
             landmarkType = "7">
             <Locations>
@@ -1246,6 +1291,21 @@
                   endingLineNumber = "108"
                   offsetFromSymbolStart = "2596">
                </Location>
+               <Location
+                  uuid = "4D7F9232-F6DA-4173-82A0-FC2A293AB3FF - 819511eaf925e71d"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "XCTreeLang.XCTLVariableRefStatement.evaluate(inContext: XCTreeLang.XCTLRuntimeAbstractContext) throws -&gt; XCTreeLang.XCTLRuntimeVariable"
+                  moduleName = "XCTreeLang"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/xcbosa/Documents/LibraryProjects/XCTreeLang/XCTreeLang/Statements/XCTLVariableRefStatement.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "93"
+                  endingLineNumber = "93"
+                  offsetFromSymbolStart = "2596">
+               </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
@@ -1259,8 +1319,8 @@
             filePath = "XCTreeLang/Statements/XCTLVariableRefStatement.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "111"
-            endingLineNumber = "111"
+            startingLineNumber = "96"
+            endingLineNumber = "96"
             landmarkName = "evaluate(inContext:)"
             landmarkType = "7">
             <Locations>
@@ -1324,6 +1384,21 @@
                   endingLineNumber = "111"
                   offsetFromSymbolStart = "3192">
                </Location>
+               <Location
+                  uuid = "F8BFE289-40FB-4CC2-8200-C286FC68D912 - 819511eaf925e7f0"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "XCTreeLang.XCTLVariableRefStatement.evaluate(inContext: XCTreeLang.XCTLRuntimeAbstractContext) throws -&gt; XCTreeLang.XCTLRuntimeVariable"
+                  moduleName = "XCTreeLang"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/xcbosa/Documents/LibraryProjects/XCTreeLang/XCTreeLang/Statements/XCTLVariableRefStatement.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "96"
+                  endingLineNumber = "96"
+                  offsetFromSymbolStart = "3192">
+               </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>

+ 0 - 0
Interop/XCTLSwiftInvocation.swift → XCTreeLang/Interop/XCTLSwiftInvocation.swift


+ 4 - 8
XCTreeLang/Runtime/XCTLRuntimeContext.swift

@@ -214,14 +214,10 @@ internal class XCTLRuntimeContext: XCTLRuntimeAbstractContext {
         }
         if let klass: AnyObject = NSClassFromString(name),
            let klass = klass as? NSObject {
-            let invocation = try Invocation(target: klass, selector: NSSelectorFromString("alloc"))
-            invocation.invoke()
-            if let obj = invocation.returnedObject as? NSObject {
-                let invocation = try Invocation(target: obj, selector: NSSelectorFromString("init"))
-                invocation.invoke()
-                if let obj = invocation.returnedObject as? NSObject {
-                    return XCTLRuntimeVariable(rawObject: obj)
-                }
+            if let object = klass.perform(NSSelectorFromString("alloc")).takeRetainedValue() as? NSObject {
+                let invocation = XCTLSwiftInvocation(target: object, selector: NSSelectorFromString("init"))
+                let result = try invocation.invokeMemberFunc(params: [])
+                return try XCTLRuntimeVariable.variableFromSwiftAny(result)
             }
         }
         throw XCTLRuntimeError.generateProtocolNotFoundedError(name: name)

+ 19 - 0
XCTreeLang/Runtime/XCTLRuntimeVariable.swift

@@ -29,6 +29,25 @@ public class XCTLRuntimeVariable: NSObject {
         return self.rawValue
     }
     
+    public class func variableFromSwiftAny(_ value: Any) throws -> XCTLRuntimeVariable {
+        if value is NSNull {
+            return .void
+        }
+        if let value = value as? String {
+            return XCTLRuntimeVariable(type: .typeString, rawValue: value)
+        }
+        if let value = value as? Double {
+            return XCTLRuntimeVariable(type: .typeNumber, rawValue: value.description)
+        }
+        if let value = value as? Bool {
+            return XCTLRuntimeVariable(type: .typeBoolean, rawValue: value.description)
+        }
+        if let value = value as? NSObject {
+            return XCTLRuntimeVariable(rawObject: value)
+        }
+        throw XCTLRuntimeError.callingTypeEncodingError
+    }
+    
     public init(type: XCTLRuntimeVariableType, rawValue: String) {
         self.type = type
         self.rawValue = rawValue

+ 1 - 16
XCTreeLang/Statements/XCTLVariableRefStatement.swift

@@ -84,22 +84,7 @@ internal class XCTLVariableRefStatement: XCTLStatement, XCTLBackableStatement, X
                         let funcIntrinsicVariable = XCTLRuntimeVariable { args in
                             let invocation = XCTLSwiftInvocation(target: rawObject, selector: selector)
                             let value = try invocation.invokeMemberFunc(params: args.map({ $0.nativeValue }))
-                            if value is NSNull {
-                                return .void
-                            }
-                            if let value = value as? String {
-                                return XCTLRuntimeVariable(type: .typeString, rawValue: value)
-                            }
-                            if let value = value as? Double {
-                                return XCTLRuntimeVariable(type: .typeNumber, rawValue: value.description)
-                            }
-                            if let value = value as? Bool {
-                                return XCTLRuntimeVariable(type: .typeBoolean, rawValue: value.description)
-                            }
-                            if let value = value as? NSObject {
-                                return XCTLRuntimeVariable(rawObject: value)
-                            }
-                            throw XCTLRuntimeError.callingTypeEncodingError
+                            return try XCTLRuntimeVariable.variableFromSwiftAny(value)
                         }
                         context.variableStack.pushVariable(funcIntrinsicVariable)
                         return funcIntrinsicVariable