-
Notifications
You must be signed in to change notification settings - Fork 67
/
InterpreterProxy.class.st
1220 lines (1031 loc) · 33.2 KB
/
InterpreterProxy.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
This class should provide the definition of what interpreter support plugins need and can have access to. Note that the proxy related files platforms - Cross - vm - sqVirtualMachine.[ch] are kept under the git tree at http://www.github.com/opensmalltalk/vm.
The main use of the class is to support the vm simulator and the RSqueak VM, which implements as many primitives as possible in Smalltalk.
"
Class {
#name : #InterpreterProxy,
#superclass : #Object,
#instVars : [
'primFailCode',
'remapBuffer',
'stack',
'method',
'argumentCount',
'bb',
'thisSessionID',
'osErrorCode',
'exceptionPC'
],
#pools : [
'VMBasicConstants'
],
#category : #'VMMaker-InterpreterSimulation'
}
{ #category : #translation }
InterpreterProxy class >> implicitReturnTypeFor: aSelector [
"Answer the return type for methods that don't have an explicit return."
^#sqInt
]
{ #category : #translation }
InterpreterProxy class >> renameSelectorIfStaticallyResolved: aString [
^ aString
]
{ #category : #private }
InterpreterProxy class >> validateProxyImplementation: anInterpreter [
"InterpreterProxy validateProxyImplementation: Interpreter"
| proxyClass catList |
proxyClass := InterpreterProxy.
catList := proxyClass organization categories copy asOrderedCollection.
catList remove: 'initialize' ifAbsent:[].
catList remove: 'private' ifAbsent:[].
catList do:[:categ|
(proxyClass organization listAtCategoryNamed: categ) do:[:selector|
(anInterpreter canUnderstand: selector)
ifFalse:
[self notifyWithLabel: selector, ' is not implemented in ', anInterpreter name]]]
]
{ #category : #'object access' }
InterpreterProxy >> argumentCountOf: methodPointer [
^methodPointer numArgs
]
{ #category : #'object access' }
InterpreterProxy >> arrayValueOf: oop [
<returnTypeC: 'void *'>
self success: (self isWordsOrBytes: oop).
^CArrayAccessor on: oop.
]
{ #category : #other }
InterpreterProxy >> become: array1 with: array2 [
<returnTypeC: #sqInt>
array1 elementsExchangeIdentityWith: array2
]
{ #category : #converting }
InterpreterProxy >> booleanValueOf: obj [
obj == true ifTrue:[^true].
obj == false ifTrue:[^false].
self primitiveFail.
^nil
]
{ #category : #private }
InterpreterProxy >> byteAt: accessor [
^accessor byteAt: 0
]
{ #category : #private }
InterpreterProxy >> byteAt: accessor put: value [
^accessor byteAt: 0 put: value
]
{ #category : #private }
InterpreterProxy >> byteAtPointer: accessor [
^ self byteAt: accessor
]
{ #category : #'object access' }
InterpreterProxy >> byteSizeOf: oop [
"Return the size of the receiver in bytes"
^oop class isBits
ifTrue: [oop basicSize * oop class elementSize]
ifFalse: [(self slotSizeOf: oop) * Smalltalk wordSize]
]
{ #category : #other }
InterpreterProxy >> byteSwapped32IfBigEndian: anInteger [
"Note: for simulation only.
This message is not generated in C but replaced with a macro"
<doNotGenerate>
self vmEndianness = 1 ifTrue: [^anInteger byteSwap32].
^anInteger
]
{ #category : #other }
InterpreterProxy >> byteSwapped64IfBigEndian: anInteger [
"Note: for simulation only.
This message is not generated in C but replaced with a macro"
<doNotGenerate>
self vmEndianness = 1 ifTrue: [^anInteger byteSwap64].
^anInteger
]
{ #category : #testing }
InterpreterProxy >> cStringOrNullFor: oop [
"Answer either a malloced string with the null-terminated contents of oop if oop is a string,
or the null pointer if oop is nil, or fail. It is the client's responsibility to free the string later."
<returnTypeC: #'char *'>
oop isString ifTrue: [^oop] ifFalse: [self primitiveFail. ^0]
]
{ #category : #'callback support' }
InterpreterProxy >> callbackLeave: cbID [
"Leave from a previous callback"
^self notYetImplementedError
]
{ #category : #'object access' }
InterpreterProxy >> characterObjectOf: characterCode [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^StackInterpreter objectMemoryClass characterObjectOf: characterCode
]
{ #category : #'object access' }
InterpreterProxy >> characterValueOf: aCharacter [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^aCharacter asInteger
]
{ #category : #converting }
InterpreterProxy >> checkedIntegerValueOf: intOop [
(self isIntegerObject: intOop)
ifTrue:[^self integerValueOf: intOop]
ifFalse:[self primitiveFail. ^0].
]
{ #category : #'special classes' }
InterpreterProxy >> classArray [
^Array
]
{ #category : #'special classes' }
InterpreterProxy >> classBitmap [
^Bitmap
]
{ #category : #'special classes' }
InterpreterProxy >> classByteArray [
^ByteArray
]
{ #category : #'special classes' }
InterpreterProxy >> classCharacter [
^Character
]
{ #category : #'FFI support' }
InterpreterProxy >> classExternalAddress [
^Smalltalk at: #ExternalAddress ifAbsent:[nil]
]
{ #category : #'special classes' }
InterpreterProxy >> classFloat [
^Float
]
{ #category : #'special classes' }
InterpreterProxy >> classLargeNegativeInteger [
^LargeNegativeInteger
]
{ #category : #'special classes' }
InterpreterProxy >> classLargePositiveInteger [
^LargePositiveInteger
]
{ #category : #'special classes' }
InterpreterProxy >> classPoint [
^Point
]
{ #category : #'special classes' }
InterpreterProxy >> classSemaphore [
^Semaphore
]
{ #category : #'special classes' }
InterpreterProxy >> classSmallInteger [
^SmallInteger
]
{ #category : #'special classes' }
InterpreterProxy >> classString [
^ByteString
]
{ #category : #'instance creation' }
InterpreterProxy >> clone: oop [
^oop shallowCopy
]
{ #category : #'BitBlt support' }
InterpreterProxy >> copyBits [
<returnTypeC: #sqInt>
bb copyBits
]
{ #category : #'BitBlt support' }
InterpreterProxy >> copyBitsFrom: leftX to: rightX at: yValue [
<returnTypeC: #sqInt>
bb copyBitsFrom: leftX to: rightX at: yValue.
]
{ #category : #'special objects' }
InterpreterProxy >> displayObject [
^Display
]
{ #category : #other }
InterpreterProxy >> failed [
^primFailCode ~= 0
]
{ #category : #'special objects' }
InterpreterProxy >> falseObject [
^false
]
{ #category : #'object access' }
InterpreterProxy >> fetchArray: fieldIndex ofObject: objectPointer [
"Fetch the instance variable at the given index of the given object. Return the address of first indexable field of resulting array object, or fail if the instance variable does not contain an indexable bytes or words object."
"Note: May be called by translated primitive code."
| arrayOop |
<returnTypeC: 'void *'>
arrayOop := self fetchPointer: fieldIndex ofObject: objectPointer.
^ self arrayValueOf: arrayOop
]
{ #category : #'object access' }
InterpreterProxy >> fetchClassOf: oop [
^oop class
]
{ #category : #'object access' }
InterpreterProxy >> fetchFloat: fieldIndex ofObject: objectPointer [
"Fetch the instance variable at the given index of the given object. Return the C double precision floating point value of that instance variable, or fail if it is not a Float."
"Note: May be called by translated primitive code."
| floatOop |
<returnTypeC: 'double'>
floatOop := self fetchPointer: fieldIndex ofObject: objectPointer.
^ self floatValueOf: floatOop
]
{ #category : #'object access' }
InterpreterProxy >> fetchInteger: fieldIndex ofObject: objectPointer [
"Note: May be called by translated primitive code."
| intOop |
<inline: false>
intOop := self fetchPointer: fieldIndex ofObject: objectPointer.
^self checkedIntegerValueOf: intOop
]
{ #category : #private }
InterpreterProxy >> fetchIntegerOrTruncFloat: fieldIndex ofObject: objectPointer [
"Support for BitBlt simulation only"
| intOrFloat |
intOrFloat := self fetchPointer: fieldIndex ofObject: objectPointer.
(self isIntegerObject: intOrFloat) ifTrue: [^ self integerValueOf: intOrFloat].
intOrFloat isFloat ifTrue:[^intOrFloat truncated].
^self primitiveFail.
]
{ #category : #'object access' }
InterpreterProxy >> fetchLong32: fieldIndex ofObject: oop [
"fetchWord:ofObject: is rescinded as of VMMaker 3.8 64bit VM. This is the same code as used therein and may need revision for 64 bit cleanliness"
^oop instVarAt: fieldIndex+1
]
{ #category : #'object access' }
InterpreterProxy >> fetchPointer: index ofObject: oop [
^oop instVarAt: index+1
]
{ #category : #'object access' }
InterpreterProxy >> firstFixedField: oop [
<returnTypeC:'void *'>
^CObjectAccessor on: oop
]
{ #category : #'object access' }
InterpreterProxy >> firstIndexableField: oop [
<returnTypeC:'void *'>
^CArrayAccessor on: oop
]
{ #category : #'stack access' }
InterpreterProxy >> floatArg: offset [
"Like #stackFloatValue: but access method arguments left-to-right"
"Obsolete; was never used; replaced with methodReturnString: in the VirtualMachine struct."
| oop |
<returnTypeC: #double>
self deprecated.
oop := self methodArg: offset.
(self isFloatObject: oop) ifFalse: [self primitiveFail. ^0.0].
^oop
]
{ #category : #converting }
InterpreterProxy >> floatObjectOf: aFloat [
<returnTypeC: #sqInt> "...because answering the float argument causes the type inferencer to say this answers a float."
<var: #aFloat type: #double>
aFloat isFloat ifFalse: [self error:'Not a float object'].
^aFloat
]
{ #category : #converting }
InterpreterProxy >> floatValueOf: oop [
<returnTypeC:'double'>
oop isFloat
ifTrue:[^oop]
ifFalse:[self primitiveFail. ^0.0].
]
{ #category : #other }
InterpreterProxy >> fullGC [
<returnTypeC: #sqInt>
Smalltalk garbageCollect
]
{ #category : #'special objects' }
InterpreterProxy >> getDeferDisplayUpdates [
^false
]
{ #category : #other }
InterpreterProxy >> getStackPointer [
<returnTypeC: #'sqInt *'>
^self notYetImplementedError
]
{ #category : #other }
InterpreterProxy >> getThisSessionID [
"Answer a session identifier which represents the current instance of Squeak.
The identifier is expected to be unique among all instances of Squeak on a
network at any point in time."
[thisSessionID = 0]
whileTrue:
[thisSessionID := (Random new next * (SmallInteger maxVal min: 16rFFFFFFFF)) asInteger].
^ thisSessionID
]
{ #category : #testing }
InterpreterProxy >> includesBehavior: aClass ThatOf: aSuperclass [
^aClass includesBehavior: aSuperclass
]
{ #category : #initialize }
InterpreterProxy >> initialize [
primFailCode := 0.
remapBuffer := OrderedCollection new.
stack := OrderedCollection new.
]
{ #category : #'object access' }
InterpreterProxy >> instanceSizeOf: classObj [
^classObj instSize
]
{ #category : #'instance creation' }
InterpreterProxy >> instantiateClass: classPointer indexableSize: size [
^size = 0
ifTrue:[classPointer basicNew]
ifFalse:[classPointer basicNew: size]
]
{ #category : #'stack access' }
InterpreterProxy >> integerArg: offset [
"Like #stackIntegerValue: but access method arguments left-to-right"
"Obsolete; was never used; replaced with methodReturnInteger: in the VirtualMachine struct."
| oop |
self deprecated.
oop := self methodArg: offset.
(self isIntegerObject: oop) ifFalse: [self primitiveFail. ^0].
^oop
]
{ #category : #converting }
InterpreterProxy >> integerObjectOf: value [
value class == SmallInteger ifFalse:[self error:'Not a SmallInteger object'].
^value
]
{ #category : #converting }
InterpreterProxy >> integerValueOf: oop [
oop class == SmallInteger ifFalse:[self error:'Not a SmallInteger'].
^oop
]
{ #category : #converting }
InterpreterProxy >> ioFilename: aCharBuffer fromString: aFilenameString ofLength: filenameLength resolveAliases: aBoolean [
<var: #aCharBuffer type: #'char *'>
<var: #aFilenameString type: #'char *'>
"the vm has to convert aFilenameString via any canonicalization and char-mapping and put the result in aCharBuffer. This doesn't translate well in Smalltalk since we know how long strings are rather than considering them terminated by a 0 char. Do the best we can.
Note the resolveAliases flag - this is an awful artefact of OSX and Apples demented alias handling. When opening a file, the flag must be true, when closing or renaming it must be false. Sigh."
aCharBuffer replaceFrom:1 to: filenameLength with: aFilenameString
]
{ #category : #'FFI support' }
InterpreterProxy >> ioLoadFunction: functionName From: moduleName [
<returnTypeC: #'void *'>
<var: #functionName type: #'char *'>
<var: #moduleName type: #'char *'>
"Dummy - provided by support code"
^0
]
{ #category : #'FFI support' }
InterpreterProxy >> ioLoadFunction: functionName From: moduleName AccessorDepthInto: accessorDepthPtr [
<returnTypeC: #'void *'>
<var: #functionName type: #'char *'>
<var: #moduleName type: #'char *'>
<var: #accessorDepthPtr type: #'sqInt *'>
"Dummy - provided by support code"
^0
]
{ #category : #'FFI support' }
InterpreterProxy >> ioLoadModule: moduleNameIndex OfLength: moduleLength [
<returnTypeC: #'void *'>
"Dummy - provided by support code"
^0
]
{ #category : #'FFI support' }
InterpreterProxy >> ioLoadSymbol: functionNameIndex OfLength: functionLength FromModule: moduleHandle [
<returnTypeC: #'void *'>
"Dummy - provided by support code"
^0
]
{ #category : #other }
InterpreterProxy >> ioMicroMSecs [
^Time millisecondClockValue
]
{ #category : #testing }
InterpreterProxy >> is: oop KindOf: aString [
"InterpreterProxy new is: 42 KindOf: 'Number'"
<var: #aString type: 'char *'>
<returnTypeC: #sqInt>
(Smalltalk at: aString asSymbol ifAbsent:[nil])
ifNil:[false]
ifNotNil: [:theClass| oop isKindOf: theClass]
]
{ #category : #testing }
InterpreterProxy >> is: oop KindOfClass: aClass [
"InterpreterProxy new is: 42 KindOfClass: Number"
^oop isKindOf: aClass
]
{ #category : #testing }
InterpreterProxy >> is: oop MemberOf: aString [
"InterpreterProxy new is: 42 MemberOf:'SmallInteger'"
| theClass |
<var: #aString type:'char *'>
theClass := Smalltalk at: aString asSymbol ifAbsent:[nil].
^theClass isNil
ifTrue:[false]
ifFalse:[^oop isMemberOf: theClass]
]
{ #category : #testing }
InterpreterProxy >> isArray: oop [
^(self isNonImmediate: oop) and: [oop class instSpec = 2]
]
{ #category : #testing }
InterpreterProxy >> isBooleanObject: oop [
<option: #(atLeastVMProxyMajor:minor: 1 15)>
^oop == true or: [oop == false]
]
{ #category : #testing }
InterpreterProxy >> isBytes: oop [
^oop class isBytes
]
{ #category : #testing }
InterpreterProxy >> isCharacterObject: oop [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^oop isCharacter
]
{ #category : #testing }
InterpreterProxy >> isCharacterValue: anInteger [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^(self isIntegerValue: anInteger) and: [anInteger >= 0]
]
{ #category : #testing }
InterpreterProxy >> isFloatObject: oop [
^oop isFloat
]
{ #category : #testing }
InterpreterProxy >> isImmediate: anObject [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^StackInterpreter objectMemoryClass isImmediate: anObject
]
{ #category : #'FFI support' }
InterpreterProxy >> isInMemory: address [
"Return true if the given address is in ST object memory"
^true
]
{ #category : #testing }
InterpreterProxy >> isIndexable: oop [
^oop class isVariable
]
{ #category : #testing }
InterpreterProxy >> isIntegerObject: objectPointer [
^objectPointer class == SmallInteger
]
{ #category : #testing }
InterpreterProxy >> isIntegerValue: intValue [
^intValue class == SmallInteger
]
{ #category : #private }
InterpreterProxy >> isInterpreterProxy [
"Return true since I am not a real Interpreter simulation"
^true
]
{ #category : #testing }
InterpreterProxy >> isKindOfInteger: objectOrientedPointer [
^objectOrientedPointer isInteger
]
{ #category : #testing }
InterpreterProxy >> isLargeIntegerObject: objectOrientedPointer [
^objectOrientedPointer isKindOf: LargePositiveInteger
]
{ #category : #testing }
InterpreterProxy >> isLargeNegativeIntegerObject: objectOrientedPointer [
^objectOrientedPointer isMemberOf: LargeNegativeInteger
]
{ #category : #testing }
InterpreterProxy >> isLargePositiveIntegerObject: objectOrientedPointer [
^objectOrientedPointer isMemberOf: LargePositiveInteger
]
{ #category : #testing }
InterpreterProxy >> isNonImmediate: anObject [
^ (self isImmediate: anObject) not
]
{ #category : #'object access' }
InterpreterProxy >> isOopImmutable: oop [
<option: #IMMUTABILITY>
^StackInterpreter objectMemoryClass isOopImmutable: oop
]
{ #category : #testing }
InterpreterProxy >> isOopMutable: anOop [
<api>
^self notYetImplementedError
]
{ #category : #testing }
InterpreterProxy >> isPinned: anObject [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^self shouldBeImplemented
]
{ #category : #testing }
InterpreterProxy >> isPointers: oop [
^oop class isPointers
]
{ #category : #testing }
InterpreterProxy >> isPositiveMachineIntegerObject: oop [
<option: #(atLeastVMProxyMajor:minor: 1 15)>
^oop isInteger and: [oop >= 0 and: [oop digitLength <= Smalltalk wordSize]]
]
{ #category : #testing }
InterpreterProxy >> isWeak: oop [
^oop class isWeak
]
{ #category : #testing }
InterpreterProxy >> isWords: oop [
^oop class isPointers not and:[oop class isBytes not]
]
{ #category : #testing }
InterpreterProxy >> isWordsOrBytes: oop [
^(self isBytes: oop) or:[self isWords: oop]
]
{ #category : #'FFI support' }
InterpreterProxy >> isYoung: anOop [
^self notYetImplementedError
]
{ #category : #'object access' }
InterpreterProxy >> literal: offset ofMethod: methodPointer [
^methodPointer literalAt: offset+1
]
{ #category : #'object access' }
InterpreterProxy >> literalCountOf: methodPointer [
^methodPointer numLiterals
]
{ #category : #'BitBlt support' }
InterpreterProxy >> loadBitBltFrom: bbOop [
<returnTypeC: #sqInt>
bb := bbOop
]
{ #category : #initialize }
InterpreterProxy >> loadStackFrom: aContext [
self push: aContext receiver.
method := aContext method.
argumentCount := method numArgs.
1 to: argumentCount do:[:i| self push: (aContext at: i) ].
]
{ #category : #private }
InterpreterProxy >> long32At: arrayOffset [
^ arrayOffset long32At: 0
]
{ #category : #private }
InterpreterProxy >> longAt: accessor [
^accessor longAt: 0
]
{ #category : #private }
InterpreterProxy >> longAt: accessor put: value [
^accessor longAt: 0 put: value
]
{ #category : #other }
InterpreterProxy >> majorVersion [
^ 1
]
{ #category : #'instance creation' }
InterpreterProxy >> makePointwithxValue: xValue yValue: yValue [
(xValue class == SmallInteger and:[yValue class == SmallInteger])
ifFalse:[self error:'Not SmallInteger objects'].
^xValue@yValue
]
{ #category : #'stack access' }
InterpreterProxy >> methodArg: offset [
"Like #stackValue: but access method arguments left-to-right"
"Obsolete; was never used; replaced with methodReturnBool: in the VirtualMachine struct."
self deprecated.
offset > argumentCount + 1 ifTrue:[^self primitiveFail].
^self stackValue: argumentCount - offset
]
{ #category : #'object access' }
InterpreterProxy >> methodArgumentCount [
^argumentCount
]
{ #category : #'object access' }
InterpreterProxy >> methodPrimitiveIndex [
^method primitive
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnBool: boolean [
"Sets the return value for a method"
self pop: argumentCount+1 thenPushBool: boolean.
^0
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnFloat: aFloat [
"Sets the return value for a method"
<var: 'aFloat' type: #double>
self pop: argumentCount+1 thenPushFloat: aFloat.
^0
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnInteger: integer [
"Sets the return value for a method"
self pop: argumentCount+1 thenPushInteger: integer.
^0
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnReceiver [
"Sets the return value for a method"
self pop: argumentCount.
^0
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnString: aCString [
"Sets the return value for a method."
"THIS IS DUBIOUS! CONSIDER REMOVING IT! RIGHT NOW IT IS NOT SENT."
<var: 'aCString' type: #'char *'>
(self stringForCString: aCString)
ifNil: [primFailCode := PrimErrNoMemory]
ifNotNil: [:result| self pop: argumentCount+1 thenPush: result].
^0
]
{ #category : #'stack access' }
InterpreterProxy >> methodReturnValue: oop [
"Sets the return value for a method"
self pop: argumentCount+1 thenPush: oop.
^0
]
{ #category : #other }
InterpreterProxy >> minorVersion [
^ 8
]
{ #category : #'special objects' }
InterpreterProxy >> nilObject [
^nil
]
{ #category : #private }
InterpreterProxy >> notYetImplementedError [
^self error: 'not yet implemented in Smalltalk'
]
{ #category : #'stack access' }
InterpreterProxy >> objectArg: offset [
"Like #stackObjectValue: but access method arguments left-to-right"
"Obsolete; was never used; replaced with methodReturnFloat: in the VirtualMachine struct."
| oop |
self deprecated.
oop := self methodArg: offset.
(self isImmediate: oop) ifTrue: [self primitiveFail. ^ nil].
^oop
]
{ #category : #'object access' }
InterpreterProxy >> obsoleteDontUseThisFetchWord: fieldIndex ofObject: oop [
"fetchWord:ofObject: is rescinded as of VMMaker 3.8 64bit VM. This is a placeholder to sit in the sqVirtualMachine structure to support older plugins for a while"
self halt: 'deprecated method'
]
{ #category : #'FFI support' }
InterpreterProxy >> ownVM: flags [
^self notYetImplementedError
]
{ #category : #'object access' }
InterpreterProxy >> pinObject: anObject [
<option: #(atLeastVMProxyMajor:minor: 1 13)>
^self shouldBeImplemented
]
{ #category : #'stack access' }
InterpreterProxy >> pop: nItems [
<returnTypeC: #sqInt>
1 to: nItems do:[:i| stack removeLast].
]
{ #category : #'stack access' }
InterpreterProxy >> pop: nItems thenPush: oop [
<returnTypeC: #void>
self pop: nItems.
self push: oop
]
{ #category : #private }
InterpreterProxy >> pop: nItems thenPushBool: boolean [
<returnTypeC: #sqInt>
self pop: nItems.
self push: (boolean ifTrue: [self trueObject] ifFalse: [self falseObject])
]
{ #category : #private }
InterpreterProxy >> pop: nItems thenPushFloat: float [
<var: #float type: #double>
<returnTypeC: #sqInt>
self pop: nItems.
self push: (self floatObjectOf: float)
]
{ #category : #private }
InterpreterProxy >> pop: nItems thenPushInteger: integer [
<returnTypeC: #sqInt>
self pop: nItems.
self push: (self integerObjectOf: integer)
]
{ #category : #'instance creation' }
InterpreterProxy >> popRemappableOop [
^remapBuffer removeLast
]
{ #category : #converting }
InterpreterProxy >> positive32BitIntegerFor: integerValue [
<returnTypeC: #sqInt>
<var: 'integerValue' type: #'unsigned int'>
integerValue isInteger ifFalse:[self error:'Not an Integer object'].
^integerValue > 0
ifTrue:[integerValue]
ifFalse:[ (1 bitShift: 32) + integerValue]
]
{ #category : #converting }
InterpreterProxy >> positive32BitValueOf: oop [
<returnTypeC: #'unsigned int'>
oop isInteger ifFalse:[self error:'Not an integer object'].
oop < 0
ifTrue:[self primitiveFail. ^0]
ifFalse:[^oop]
]
{ #category : #converting }
InterpreterProxy >> positive64BitIntegerFor: integerValue [
<api>
<returnTypeC: #sqInt> "...because answering the 64-bit argument causes the type inferencer to say this answers 64-bits."
<var: 'integerValue' type: #usqLong>
integerValue isInteger ifFalse:[self error:'Not an Integer object'].
^integerValue > 0
ifTrue:[integerValue]
ifFalse:[ (1 bitShift: 64) + integerValue]
]
{ #category : #converting }
InterpreterProxy >> positive64BitValueOf: oop [
<returnTypeC: #usqLong>
oop isInteger ifFalse:[self error:'Not an integer object'].
oop < 0
ifTrue:[self primitiveFail. ^0]
ifFalse:[^oop]
]
{ #category : #converting }
InterpreterProxy >> positiveMachineIntegerValueOf: oop [
<returnTypeC: #'usqIntptr_t'>
oop isInteger ifFalse:[self error: 'Not an integer object'].
^oop < 0
ifTrue: [self primitiveFail. 0]
ifFalse: [oop]
]
{ #category : #'special objects' }
InterpreterProxy >> primitiveErrorTable [
^Smalltalk primitiveErrorTable
]
{ #category : #other }
InterpreterProxy >> primitiveFail [
<returnTypeC: #sqInt>
"Set general (unspecified) primitive failure."
self primitiveFailFor: 1
]
{ #category : #other }
InterpreterProxy >> primitiveFailFor: reasonCode [
"Set specific primitive failure.
N.B. primitiveFailFor: PrimNoErr is expected to clear the primFailCode.
Primitive 255 is called to indicate that we are currently simulating a primitive that should fail and the VM should handle that case appropriately (if supported by the VM)."
<primitive: 255>
^ primFailCode := reasonCode
]
{ #category : #other }
InterpreterProxy >> primitiveFailForFFIException: exceptionCode at: pc [
<var: 'exceptionCode' type: #usqLong>
<var: 'pc' type: #usqInt>
<option: #(atLeastVMProxyMajor:minor: 1 14)>
"Set PrimErrFFIException primitive failure and associated exceptionCode (a.k.a.
osErrorCode) and exceptionPC."
<primitive: 255>
osErrorCode := exceptionCode.
exceptionPC := pc.
^primFailCode := PrimErrFFIException
]
{ #category : #other }
InterpreterProxy >> primitiveFailForOSError: osError [
<var: 'osError' type: #sqLong>
<option: #(atLeastVMProxyMajor:minor: 1 14)>
"Set PrimErrOSError primitive failure and associated osErrorCode.
Primitive 255 is called to indicate that we are currently simulating a primitive that should fail and the VM should handle that case appropriately (if supported by the VM)."
<primitive: 255>
osErrorCode := osError.
^primFailCode := PrimErrOSError
]
{ #category : #other }
InterpreterProxy >> primitiveFailureCode [
^primFailCode
]
{ #category : #'object access' }
InterpreterProxy >> primitiveIndexOf: methodPointer [
^methodPointer primitive
]
{ #category : #'object access' }
InterpreterProxy >> primitiveMethod [
"Return the method an external primitive was defined in"
^method
]
{ #category : #'stack access' }
InterpreterProxy >> push: object [
<returnTypeC: #sqInt>
stack addLast: object
]
{ #category : #'stack access' }
InterpreterProxy >> pushBool: trueOrFalse [
<returnTypeC: #sqInt>
(trueOrFalse == true or:[trueOrFalse == false]) ifFalse:[self error:'Not a Boolean'].
self push: trueOrFalse
]
{ #category : #'stack access' }
InterpreterProxy >> pushFloat: f [
<returnTypeC: #sqInt>
<var: #f type: 'double '>
f isFloat ifFalse:[^self error:'Not a Float'].
self push: f.
]
{ #category : #'stack access' }
InterpreterProxy >> pushInteger: integerValue [
<returnTypeC: #sqInt>
self push: (self integerObjectOf: integerValue).
]
{ #category : #'instance creation' }
InterpreterProxy >> pushRemappableOop: oop [
<returnTypeC: #void>
remapBuffer addLast: oop
]
{ #category : #'callback support' }
InterpreterProxy >> reestablishContextPriorToCallback: callbackContext [
"callbackContext is an activation of invokeCallback:stack:registers:jmpbuf:. Its sender
is the interpreter's state prior to the callback. Reestablish that state."
<returnTypeC: #sqInt>
self notYetImplemented
]
{ #category : #'callback support' }
InterpreterProxy >> returnAs: returnTypeOop ThroughCallback: vmCallbackContext Context: callbackMethodContext [
<returnTypeC: #sqInt>
<var: #vmCallbackContext type: #'VMCallbackContext *'>
"callbackMethodContext is an activation of invokeCallback:[stack:registers:jmpbuf:].
Its sender is the VM's state prior to the callback. Reestablish that state (via longjmp),
and mark callbackMethodContext as dead."
self notYetImplemented
]
{ #category : #'callback support' }
InterpreterProxy >> sendInvokeCallback: thunkPtr Stack: stackPtr Registers: regsPtr Jmpbuf: jmpBufPtr [
"Send the 4 argument callback message invokeCallback:stack:registers:jmpbuf: