forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFIVoid.class.st
101 lines (87 loc) · 2.45 KB
/
FFIVoid.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
96
97
98
99
100
101
"
I'm a void type.
I'm used always as pointer type, otherwise it does not have any sense.
"
Class {
#name : #FFIVoid,
#superclass : #FFIExternalType,
#category : #'UnifiedFFI-Types'
}
{ #category : #accessing }
FFIVoid class >> externalType [
^ ExternalType void
]
{ #category : #private }
FFIVoid >> basicHandle: aHandle at: index [
self error: 'You can not access plain void types (it does not has sense)'
]
{ #category : #private }
FFIVoid >> basicHandle: aHandle at: index put: value [
self error: 'You can not access plain void types (it is meaningless)'
]
{ #category : #accessing }
FFIVoid >> callbackReturnOn: callbackContext for: anObject [
"Void returns does not set anything"
self isPointer ifFalse: [ ^ nil ].
^ callbackContext wordResult: anObject asInteger.
]
{ #category : #accessing }
FFIVoid >> defaultReturnOnError [
^ nil
]
{ #category : #'emitting code' }
FFIVoid >> emitPointerReturn: aBuilder resultTempVar: resultVar context: aContext [
^ aBuilder
addTemp: #tmpResult;
"keep invoke result into the tmpResult var"
storeTemp: #tmpResult;
popTop;
"return := self objectClass basicNew"
pushLiteralVariable: self objectClass binding;
send: #basicNew;
storeTemp: resultVar;
popTop;
"return instVarAt: (index of argName) put: tmpResult"
pushTemp: resultVar;
pushLiteral: (self objectClass
instVarIndexFor: #handle
ifAbsent: [ self error: 'No handle instVar' ]);
pushTemp: #tmpResult;
send: #instVarAt:put:;
pushTemp: resultVar;
returnTop
]
{ #category : #'emitting code' }
FFIVoid >> emitReturn: aBuilder resultTempVar: resultVar context: aContext [
self isPointer
ifTrue: [ ^ super emitReturn: aBuilder resultTempVar: resultVar context: aContext ].
^ self emitSelfReturn: aBuilder
]
{ #category : #'emitting code' }
FFIVoid >> emitSelfReturn: aBuilder [
^ aBuilder
popTop;
pushReceiver;
returnTop
]
{ #category : #accessing }
FFIVoid >> externalTypeSize [
self pointerArity < 1 ifTrue: [ ^ self error: 'void has unknown size' ].
^ self pointerSize
]
{ #category : #testing }
FFIVoid >> isVoid [
^ true
]
{ #category : #testing }
FFIVoid >> needsArityPacking [
"Void just have sense if they are pointers, so the roll function just have sense for bigger
arities"
^ self pointerArity > 1
]
{ #category : #testing }
FFIVoid >> needsArityUnpacking [
"Void just have sense if they are pointers, so the unpack function just have sense
if they have been rolled before"
^ self needsArityPacking
]