Skip to content

Commit

Permalink
proxies working on TFFI (and worker VM)
Browse files Browse the repository at this point in the history
added some comments
  • Loading branch information
estebanlm committed Feb 3, 2020
1 parent 1e0da9d commit 4aa8322
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 17 deletions.
23 changes: 20 additions & 3 deletions src/ObjectiveC/ObjCProxyCallback.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"
I'm a special callback, meant to implement proxy methods.
ObjC will call Pharo using this callbacks.
"
Class {
#name : #ObjCProxyCallback,
#superclass : #FFICallback,
Expand All @@ -12,12 +16,25 @@ ObjCProxyCallback >> parseSignature: signature [
^ self newParser parseSignature: signature
]

{ #category : #initialization }
ObjCProxyCallback >> signature: signature block: aBlock [

super signature: signature block: aBlock.
functionSpec arguments: {
ObjCProxyCallbackArgument new. "receiver"
ObjCProxyCallbackArgument new. "selector"
},
functionSpec arguments.

]

{ #category : #evaluation }
ObjCProxyCallback >> valueWithArguments: args [

^ [
"skip self, SEL and keep just the arguments"
block value: (args allButFirst: 2) ]
^ [ block
value: args first
value: args second
value: (args allButFirst: 2) ]
on: Error
fork: [ :e | e debug ]
return: [ self returnOnError ]
Expand Down
52 changes: 52 additions & 0 deletions src/ObjectiveC/ObjCProxyCallbackArgument.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"
I'm a function argument type to be used on the declaration of proxy methods.
I am needed because in ObjC every method implementation has the same structure:
id (*IMP)(receiver, selector, ...)
https://developer.apple.com/documentation/objectivec/objective-c_runtime/imp
being the first two arguments the receiver and the selector.
this is internally converted to a send of the form
receiver selector: arg
(a call with the arguments).
To match a regular send, we need to add this arguments to the callback, but they are hidden to the user.
"
Class {
#name : #ObjCProxyCallbackArgument,
#superclass : #FFIFunctionArgument,
#traits : 'TObjCLibrary',
#classTraits : 'TObjCLibrary classTrait',
#category : #'ObjectiveC-Proxy'
}

{ #category : #resolution }
ObjCProxyCallbackArgument >> asOldArraySpec [

^ #()
]

{ #category : #initialization }
ObjCProxyCallbackArgument >> initialize [

super initialize.
type := ObjCTypeDeclaration newType: (FFIVoid new
pointerArity: 1;
yourself)
]

{ #category : #resolution }
ObjCProxyCallbackArgument >> resolveUsing: aResolver [
"Do nothing"
]

{ #category : #initialization }
ObjCProxyCallbackArgument >> resolvedType [

^ type resolvedType
]
5 changes: 4 additions & 1 deletion src/ObjectiveC/ObjCProxyClass.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"
I define a class that will be installed in ObjC and will work as a proxy between ObjC and Pharo
"
Class {
#name : #ObjCProxyClass,
#superclass : #Object,
Expand Down Expand Up @@ -95,7 +98,7 @@ ObjCProxyClass >> class_addMethodClass: cls selector: name implementation: imp s
{ #category : #private }
ObjCProxyClass >> createCallbackFor: aSelector signature: aString [

^ ObjCProxyCallback
^ ObjCProxyCallback
signature: aString
block: [ :receiver :ignoredSelector :args |
self
Expand Down
13 changes: 0 additions & 13 deletions src/ObjectiveC/ObjCProxyObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ Class {
#superclass : #Object,
#traits : 'TObjCProxyClass',
#classTraits : 'TObjCProxyClass classTrait',
#instVars : [
'proxy'
],
#category : #'ObjectiveC-Proxy'
}

Expand All @@ -32,13 +29,3 @@ ObjCProxyObject >> initialize [
ObjCProxyObject >> initializeProxy [

]

{ #category : #accessing }
ObjCProxyObject >> proxy [
^ proxy
]

{ #category : #accessing }
ObjCProxyObject >> proxy: anObject [
proxy := anObject.
]
4 changes: 4 additions & 0 deletions src/ObjectiveC/ObjCTypeDeclaration.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"
I'm a type declaration for ObjC functions.
I'm needed because when matching ObjC functions I already have all needed data, so I can skip the resolution of type.
"
Class {
#name : #ObjCTypeDeclaration,
#superclass : #FFITypeDeclaration,
Expand Down

0 comments on commit 4aa8322

Please sign in to comment.