-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMAbstractFFITest.class.st
95 lines (70 loc) · 2.49 KB
/
VMAbstractFFITest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Class {
#name : #VMAbstractFFITest,
#superclass : #VMAbstractPrimitiveTest,
#pools : [
'LibFFIConstants'
],
#category : #VMMakerTests
}
{ #category : #helpers }
VMAbstractFFITest >> createExternalFunctionFor: aBlock withArgumentTypes: argumentTypes withReturnType: returnType [
| functionAddress tfExternalFunction functionExternalAddress tfFunctionDefinition cif cifExternalAddress |
functionAddress := interpreter libFFI registerFunction: aBlock.
tfExternalFunction := self newObjectWithSlots: 2.
functionExternalAddress := self newExternalAddress: functionAddress.
tfFunctionDefinition := self newObjectWithSlots: 1.
cif := interpreter libFFI newCif.
cif argumentTypes: argumentTypes.
cif returnType: returnType.
cifExternalAddress := self newExternalAddress: (cif address).
memory storePointer: 0 ofObject: tfExternalFunction withValue: functionExternalAddress.
memory storePointer: 1 ofObject: tfExternalFunction withValue: tfFunctionDefinition.
memory storePointer: 0 ofObject: tfFunctionDefinition withValue: cifExternalAddress.
^ tfExternalFunction
]
{ #category : #helpers }
VMAbstractFFITest >> createReturnFloatExternalFunctionFor: aBlock [
^ self
createExternalFunctionFor: aBlock
withArgumentTypes: #()
withReturnType: interpreter libFFI float
]
{ #category : #helpers }
VMAbstractFFITest >> createReturnFloatExternalFunctionFor: aBlock withArgumentTypes: argumentTypes [
^ self
createExternalFunctionFor: aBlock
withArgumentTypes: argumentTypes
withReturnType: interpreter libFFI float
]
{ #category : #helpers }
VMAbstractFFITest >> initializationOptions [
^ super initializationOptions , {
#FEATURE_FFI . true }
]
{ #category : #helpers }
VMAbstractFFITest >> interpreterClass [
^ VMTestMockInterpreter
]
{ #category : #helpers }
VMAbstractFFITest >> newExternalAddress: anInteger [
| anExternalAddress |
anExternalAddress := self
newObjectWithSlots: (memory numSlotsForBytes: self wordSize)
format: (memory byteFormatForNumBytes: self wordSize)
classIndex: memory classExternalAddressIndex.
memory storePointer: 0 ofObject: anExternalAddress withValue: anInteger.
^ anExternalAddress
]
{ #category : #helpers }
VMAbstractFFITest >> readyProcesses [
| collection |
collection := OrderedCollection new.
interpreter processesInProcessListDo: [ :e | collection add: e ].
^ collection
]
{ #category : #initialization }
VMAbstractFFITest >> setUp [
super setUp.
interpreter libFFI: LibFFI new.
interpreter libFFI interpreter: interpreter.
]