This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
TFCalloutMethodBuilder.class.st
70 lines (56 loc) · 2.06 KB
/
TFCalloutMethodBuilder.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"
I override some methods to correctly generate TFFI methods when using UFFI.
"
Class {
#name : #TFCalloutMethodBuilder,
#superclass : #FFICalloutMethodBuilder,
#category : #'ThreadedFFI-UFFI'
}
{ #category : #private }
TFCalloutMethodBuilder >> createFFICalloutLiteralFromSpec: functionSpec [
| function |
function := TFExternalFunction
name: functionSpec functionName
moduleName: self libraryName
parameterTypes: (functionSpec arguments collect: #tfExternalTypeWithArity)
returnType: functionSpec returnType tfExternalTypeWithArity.
^ function
]
{ #category : #private }
TFCalloutMethodBuilder >> generateFFICallout: builder spec: functionSpec ffiLibrary: ffiLibrary [
TFCalloutAPI isTracing ifTrue: [
TFCalloutAPI trace: sender.
builder
pushLiteral: TFCalloutAPI;
pushLiteral: sender;
send: #trace: ].
builder
pushLiteral: (ffiLibrary uniqueInstance runner).
"save ffi call as literal"
builder pushLiteral: (self createFFICalloutLiteralFromSpec: functionSpec).
"iterate arguments in order (in the function) to create the function call"
functionSpec arguments
do: [ :each |
each emitArgument: builder context: sender inCallout: self requestor.
each resolvedType tfExternalTypeWithArity emitMarshallToPrimitive: builder ].
"create the array"
builder pushConsArray: functionSpec arguments size.
builder addTemp: #argumentsArray.
builder storeTemp: #argumentsArray.
"send call and store into result"
builder send: #invokeFunction:withArguments:.
functionSpec arguments withIndexDo: [ :each :index|
each emitReturnArgument: builder context: sender.
each resolvedType tfExternalTypeWithArity
emitFreeIfNeededOfIndex: index
argumentsArrayTempName: #argumentsArray
withBuilder: builder ].
"Additional marshall in the case of TFFI"
functionSpec returnType resolvedType tfExternalTypeWithArity emitMarshallFromPrimitive: builder.
"convert in case return type needs it. And return reseult"
^ functionSpec returnType
emitReturn: builder
resultTempVar: #result
context: sender
inCallout: self requestor
]