-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMClass.class.st
1361 lines (1129 loc) · 40.2 KB
/
VMClass.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
"
I am an abstract superclass for all classes in the VM that want to maintain a source timeStamp. I am also the holder of the InitializationOptions class variable which holds options such as which JIT or which memory manager to use when creating or generating a VM.
"
Class {
#name : #VMClass,
#superclass : #SlangClass,
#instVars : [
'memoryManager'
],
#classVars : [
'DefaultBase',
'InitializationOptions'
],
#pools : [
'VMBasicConstants',
'VMObjectIndices'
],
#classInstVars : [
'timeStamp'
],
#category : #Melchor
}
{ #category : #translation }
VMClass class >> apiExportHeaderName [
"VM classesd that want to generate an api export header override this."
^nil
]
{ #category : #'adding/removing methods' }
VMClass class >> basicRemoveSelector: aSelector [
"Override to update the timeStamp"
^(super basicRemoveSelector: aSelector) ifNotNil:
[:oldMethod| self touch. oldMethod]
]
{ #category : #accessing }
VMClass class >> bytesPerOop [
^ BytesPerOop
]
{ #category : #accessing }
VMClass class >> bytesPerOop: anInteger [
BytesPerOop := anInteger
]
{ #category : #accessing }
VMClass class >> bytesPerWord [
^ BytesPerWord
]
{ #category : #accessing }
VMClass class >> bytesPerWord: anInteger [
^ BytesPerWord := anInteger
]
{ #category : #'accessing class hierarchy' }
VMClass class >> cogitClass [
"Answer the cogitClass in effect. Ensure that StackInterpreter has a nil cogitClass."
(self isInterpreterClass and: [self hasCogit not]) ifTrue:
[^nil].
^Smalltalk classNamed: (InitializationOptions
at: #Cogit
ifAbsent: [#StackToRegisterMappingCogit])
]
{ #category : #'accessing class hierarchy' }
VMClass class >> constantClass [
^ VMBasicConstants
]
{ #category : #'accessing class hierarchy' }
VMClass class >> coreInterpreterClass [
"While the interpreterClass/vmClass for translation may be
a subclass that holds a few primitives we want the actual
interpreter name at the head of the generated file."
^((name endsWith: 'Primitives')
and: [name beginsWith: superclass name])
ifTrue: [superclass]
ifFalse: [self]
]
{ #category : #translation }
VMClass class >> declareC: arrayOfVariableNames as: aCType in: aCCodeGenerator [
"Declare the variables in arrayOfVariableNames with the given type."
arrayOfVariableNames
do: [:varName | aCCodeGenerator var: varName type: aCType]
]
{ #category : #translation }
VMClass class >> declareCAsOop: arrayOfVariableNames in: aCCodeGenerator [
"Declare the variables in arrayOfVariableNames with type representing position in object memory."
arrayOfVariableNames do:
[:varName| aCCodeGenerator var: varName type: #usqInt]
]
{ #category : #translation }
VMClass class >> declareCAsUSqLong: arrayOfVariableNames in: aCCodeGenerator [
"Declare the variables in arrayOfVariableNames with type representing position in object memory."
arrayOfVariableNames do:
[:varName| aCCodeGenerator var: varName type: #usqLong]
]
{ #category : #translation }
VMClass class >> declareCVarsIn: aCCodeGenerator [
"Declare any additional variables and/or add type declarations for existing variables."
aCCodeGenerator
var: #expensiveAsserts
declareC: 'char expensiveAsserts = 0'
]
{ #category : #translation }
VMClass class >> declareInterpreterVersionIn: aCCodeGenerator defaultName: defaultName [
aCCodeGenerator
var: #interpreterVersion
declareC: 'const char *interpreterVersion = "Croquet Closure ', defaultName, ' VM [',
(aCCodeGenerator shortMonticelloDescriptionForClass: self),']"'.
]
{ #category : #'accessing class hierarchy' }
VMClass class >> hasCogit [
^false
]
{ #category : #translation }
VMClass class >> implicitReturnTypeFor: aSelector [
"Answer the return type for methods that don't have an explicit return."
^#sqInt
]
{ #category : #initialization }
VMClass class >> initializationOptions [
^InitializationOptions
]
{ #category : #initialization }
VMClass class >> initialize [
InitializationOptions ifNil: [InitializationOptions := Dictionary new].
ExpensiveAsserts := false
]
{ #category : #initialization }
VMClass class >> initializePrimitiveErrorCodes [
"Define the VM's primitive error codes. N.B. these are
replicated in platforms/Cross/vm/sqVirtualMachine.h."
"VMClass initializePrimitiveErrorCodes"
| pet |
PrimErrTableIndex := 51. "Zero-relative"
"See SmalltalkImage>>recreateSpecialObjectsArray for the table definition.
If the table exists and is large enough the corresponding entry is returned as
the primitive error, otherwise the error is answered numerically."
pet := Smalltalk specialObjectsArray at: PrimErrTableIndex + 1 ifAbsent: [#()].
pet isArray ifFalse: [pet := #()].
PrimNoErr := 0. "for helper methods that need to answer success or an error code."
PrimErrGenericFailure := pet indexOf: nil ifAbsent: 1.
PrimErrBadReceiver := pet indexOf: #'bad receiver' ifAbsent: 2.
PrimErrBadArgument := pet indexOf: #'bad argument' ifAbsent: 3.
PrimErrBadIndex := pet indexOf: #'bad index' ifAbsent: 4.
PrimErrBadNumArgs := pet indexOf: #'bad number of arguments' ifAbsent: 5.
PrimErrInappropriate := pet indexOf: #'inappropriate operation' ifAbsent: 6.
PrimErrUnsupported := pet indexOf: #'unsupported operation' ifAbsent: 7.
PrimErrNoModification := pet indexOf: #'no modification' ifAbsent: 8.
PrimErrNoMemory := pet indexOf: #'insufficient object memory' ifAbsent: 9.
PrimErrNoCMemory := pet indexOf: #'insufficient C memory' ifAbsent: 10.
PrimErrNotFound := pet indexOf: #'not found' ifAbsent: 11.
PrimErrBadMethod := pet indexOf: #'bad method' ifAbsent: 12.
PrimErrNamedInternal := pet indexOf: #'internal error in named primitive machinery' ifAbsent: 13.
PrimErrObjectMayMove := pet indexOf: #'object may move' ifAbsent: 14.
PrimErrLimitExceeded := pet indexOf: #'resource limit exceeded' ifAbsent: 15.
PrimErrObjectIsPinned := pet indexOf: #'object is pinned' ifAbsent: 16.
PrimErrWritePastObject := pet indexOf: #'primitive write beyond end of object' ifAbsent: 17.
PrimErrObjectMoved := pet indexOf: #'object moved' ifAbsent: 18.
PrimErrObjectNotPinned := pet indexOf: #'object not pinned' ifAbsent: 19.
PrimErrCallbackError := pet indexOf: #'error in callback' ifAbsent: 20.
PrimErrOSError := pet indexOf: #'operating system error' ifAbsent: 21.
PrimErrFFIException := pet indexOf: #'ffi call exception' ifAbsent: 22.
PrimErrNeedCompaction := pet indexOf: #'heap compaction needed' ifAbsent: 23. "N.B. This is currently an internal error in Spur image segment saving."
PrimErrOperationFailed := pet indexOf: #'operation failed' ifAbsent: 24
]
{ #category : #initialization }
VMClass class >> initializeWithOptions: optionsDictionaryOrArray [
"Initialize the receiver, typically initializing class variables. Initialize any class variables
whose names occur in optionsDictionary with the corresponding values there-in."
InitializationOptions := optionsDictionaryOrArray isArray
ifTrue: [Dictionary newFromPairs: optionsDictionaryOrArray]
ifFalse: [optionsDictionaryOrArray].
ExpensiveAsserts := InitializationOptions at: #ExpensiveAsserts ifAbsent: [false]
]
{ #category : #'accessing class hierarchy' }
VMClass class >> interpreterClass [
^self isInterpreterClass ifTrue: [self]
]
{ #category : #accessing }
VMClass class >> interpreterVersion [
^ self subclassResponsibility
]
{ #category : #translation }
VMClass class >> isAcceptableAncilliaryClass: aClass [
^true
]
{ #category : #translation }
VMClass class >> isAccessor: aSelector [
"Answer if aSelector is simply an accessor method for one of our fields.
Answer false by default. VMStructType classes redefine this appropriately."
^false
]
{ #category : #translation }
VMClass class >> isCogitClass [
"The various Cogit classes override this."
^false
]
{ #category : #translation }
VMClass class >> isInterpreterClass [
"The various Interpreter classes override this."
^false
]
{ #category : #translation }
VMClass class >> isNonArgumentImplicitReceiverVariableName: aString [
^false
]
{ #category : #translation }
VMClass class >> isPluginClass [
"InterpreterPlugin class override this."
^false
]
{ #category : #translation }
VMClass class >> isSpurMemoryManagerClass [
^ false
]
{ #category : #accessing }
VMClass class >> memoryManagerVersion [
^ self subclassResponsibility
]
{ #category : #translation }
VMClass class >> monticelloDescription [
"Answer the Monticello version of the packlage containing the receiver.
This is a hook to allow subclasses to expand upon the default monticello description."
^CCodeGenerator monticelloDescriptionFor: self
]
{ #category : #translation }
VMClass class >> mustBeGlobal: var [
"Answer if a variable must be global and exported. Used for inst vars that are accessed from VM support code."
^var = #expensiveAsserts
]
{ #category : #translation }
VMClass class >> noteCompilationOf: aSelector meta: isMeta [
"note the recompiliation by resetting the timeStamp "
timeStamp := Time totalSeconds.
^super noteCompilationOf: aSelector meta: isMeta
]
{ #category : #'accessing class hierarchy' }
VMClass class >> objectMemoryClass [
^Smalltalk at: (InitializationOptions
at: #ObjectMemory
ifAbsent: [ #Spur32BitMemoryManager ])
]
{ #category : #'accessing class hierarchy' }
VMClass class >> objectRepresentationClass [
^self objectMemoryClass objectRepresentationClass
]
{ #category : #accessing }
VMClass class >> resetInitializationOptions [
self release.
InitializationOptions := nil
]
{ #category : #translation }
VMClass class >> shouldGenerateTypedefFor: aStructClass [
"Hack to work-around multiple definitions. Sometimes a type has been defined in an include."
^aStructClass shouldBeGenerated
]
{ #category : #translation }
VMClass class >> shouldIncludeMethodForSelector: selector [
"Answer whether a primitive method should be translated. Emit a warning to the transcript if the method doesn't exist."
^(self whichClassIncludesSelector: selector)
ifNotNil:
[:c|
(c >> selector pragmaAt: #option:)
ifNotNil:
[:pragma|
(self constantClass defineAtCompileTime: pragma arguments first)
or: [InitializationOptions
at: pragma arguments first
ifAbsent: [(self bindingOf: pragma arguments first)
ifNil: [false]
ifNotNil: [:binding| binding value ~~ #undefined]]]]
ifNil: [true]]
ifNil:
[Transcript nextPutAll: 'Cannot find implementation of '; nextPutAll: selector; nextPutAll: ' in hierarchy of '; print: self; newLine; flush.
false]
]
{ #category : #simulation }
VMClass class >> simulatorClass [
"For running from Smalltalk - answer a class that can be used to simulate the receiver."
^self
]
{ #category : #translation }
VMClass class >> specialValueForConstant: constantName default: defaultValue [
^nil
]
{ #category : #translation }
VMClass class >> staticallyResolvePolymorphicSelector: aSelectorSymbol [
^((self name select: [:ea| ea isUppercase]), '_', aSelectorSymbol) asSymbol
]
{ #category : #translation }
VMClass class >> timeStamp [
^timeStamp ifNil:[0]
]
{ #category : #translation }
VMClass class >> touch [
"Reset the timeStamp"
"Smalltalk allClasses select:
[:c| (c category includesSubString: 'VMMaker-JIT') ifTrue: [c touch]]"
"InterpreterPlugin withAllSubclassesDo:[:pl| pl touch]"
timeStamp := Time totalSeconds
]
{ #category : #translation }
VMClass class >> translationClass [
"Return the class to use as the interpreterCLass when translating. For the all-in-one
VMs that inherit from ObjectMemory this is the receiver. But for the separate VMs
where most primitives are in a subclass it will be the subclass with the primitives."
^self
]
{ #category : #translation }
VMClass class >> writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator: aCCodeGenerator [
"Generate the contents of interp.h on aStream. Specific Interpreter subclasses
override to add more stuff."
aCCodeGenerator
putDefineOf: 'VM_PROXY_MAJOR' as: self vmProxyMajorVersion on: aStream;
putDefineOf: 'VM_PROXY_MINOR' as: self vmProxyMinorVersion on: aStream.
aStream newLine.
aCCodeGenerator
putDefineOf: 'SQ_VI_BYTES_PER_WORD' as: bytesPerWord on: aStream.
aStream newLine.
"The most basic constants must be defined here, not in e.g. the plugin sources, to allow those
other sources to be shared between different builds (Spur vs SqueakV3, 32-bit vs 64-bit, etc)"
self constantClass mostBasicConstantNames asSet sorted do:
[:constName|
(self constantClass classPool at: constName ifAbsent: []) ifNotNil:
[:const| aCCodeGenerator putDefineOf: constName as: const on: aStream]].
aStream newLine.
((self constantClass classPool associations select: [:a| a key beginsWith: 'PrimErr'])
sorted: [:a1 :a2| a1 value <= a2 value])
do: [:a| aCCodeGenerator putDefineOf: a key as: a value on: aStream].
aStream newLine.
aCCodeGenerator
putDefineOf: 'MinSmallInteger' as: self objectMemoryClass minSmallInteger on: aStream;
putDefineOf: 'MaxSmallInteger' as: self objectMemoryClass maxSmallInteger on: aStream;
putDefineOf: 'NumSmallIntegerTagBits' as: self objectMemoryClass numSmallIntegerTagBits on: aStream.
aStream newLine
]
{ #category : #'translation support' }
VMClass >> addressOf: anObject [
<doNotGenerate>
"Translates into &anObject in C."
^anObject
]
{ #category : #'translation support' }
VMClass >> addressOf: anObject put: aBlock [
<doNotGenerate>
"Simulate a C pointer. Translates into &anObject in C. Provides something
that evaluates aBlock with the new value in response to at:put:"
| thing |
thing := anObject.
^CPluggableAccessor new
setObject: nil;
atBlock: [:obj :idx| thing]
atPutBlock: [:obj :idx :val| aBlock value: (thing := val)]
]
{ #category : #'C library simulation' }
VMClass >> alloca: desiredSize [
"Simulation of alloca(3)"
<doNotGenerate>
| address |
address := 0 "Does not really matter for now".
^ CNewArrayAccessor new
setObject: (SlangMemoryRegion new
start: address;
memory: (ByteArray new: desiredSize);
originallyRequestedMemory: desiredSize;
yourself);
address: address;
yourself
]
{ #category : #'C library extensions' }
VMClass >> alloca: numElements type: elementType [
<cmacro: '(numElements, elementType) alloca((numElements)*sizeof(elementType))'>
^CArrayAccessor on: ((1 to: numElements) collect: [:ign| elementType new])
]
{ #category : #'C library extensions' }
VMClass >> asString: aStringOrStringIndex [
"aStringOrStringIndex is either a string or an address in the heap.
Create a String of the requested length form the bytes in the
heap starting at stringIndex."
<doNotGenerate>
| sz |
aStringOrStringIndex isString ifTrue:
[^aStringOrStringIndex].
sz := self strlen: aStringOrStringIndex.
^self strncpy: (ByteString new: sz) _: aStringOrStringIndex _: sz
]
{ #category : #'debug support' }
VMClass >> assert: aBooleanExpression l: linenum [
<doNotGenerate>
^self assert: aBooleanExpression
]
{ #category : #'debug support' }
VMClass >> asserta: aBooleanExpression [
<doNotGenerate>
| result |
(result := aBooleanExpression value) ifFalse:
[AssertionFailure signal: 'Assertion failed'].
^result
]
{ #category : #'debug support' }
VMClass >> asserta: aBooleanExpression l: linenum [
<doNotGenerate>
^self asserta: aBooleanExpression
]
{ #category : #'memory access' }
VMClass >> cCoerce: value to: cTypeString [
"Type coercion. For translation a cast will be emmitted. When running in Smalltalk
answer a suitable wrapper for correct indexing."
<doNotGenerate>
^value
ifNil: [value]
ifNotNil: [value coerceTo: cTypeString sim: self]
]
{ #category : #'translation support' }
VMClass >> cCoerceSimple: value to: cTypeString [
<doNotGenerate>
"Type coercion for translation and simulation.
For simulation answer a suitable surrogate for the struct types"
^cTypeString caseOf:
{ [#'unsigned long'] -> [value].
[#'unsigned int'] -> [value].
[#'unsigned short'] -> [value].
[#sqInt] -> [value].
[#'sqIntptr_t'] -> [value].
[#'usqIntptr_t'] -> [value].
[#usqInt] -> [value].
[#sqLong] -> [value].
[#usqLong] -> [value].
[#'AbstractInstruction *'] -> [value].
[#'SpurSegmentInfo *'] -> [value].
[#'BytecodeFixup *'] -> [value].
[#'CogMethod *'] -> [value].
[#'char *'] -> [value].
[#'sqInt *'] -> [value].
[#'void *'] -> [value].
[#void] -> [value].
[#'void (*)()'] -> [value].
[#'void (*)(void)'] -> [value].
[#'unsigned long (*)(void)'] -> [value].
[#'void (*)(unsigned long,unsigned long)'] -> [value].
[#'usqIntptr_t (*)(void)'] -> [value] }
]
{ #category : #'C library simulation' }
VMClass >> calloc: num _: size [
<doNotGenerate>
^ self malloc: num * size
]
{ #category : #'translation support' }
VMClass >> contentsOf: valueHolder [
<cmacro: '(value) value'>
^ valueHolder contents
]
{ #category : #'translation support' }
VMClass >> cppIf: conditionBlockOrValue ifTrue: trueExpressionOrBlock [
"When translated, produces #if (condition) #else #endif CPP directives.
Example usage:
self cppIf: IMMUTABILITY
ifTrue: [(self internalIsImmutable: obj) ifTrue:
[^self primitiveFailFor: PrimErrNoModification]]"
<doNotGenerate>
^self cppIf: conditionBlockOrValue ifTrue: trueExpressionOrBlock ifFalse: nil
]
{ #category : #'C pre-processor extensions' }
VMClass >> defined: aSymbol [
"Simulated version of the C pre-processor defined()"
<doNotGenerate>
^(self class bindingOf: aSymbol)
ifNil: [false]
ifNotNil: [:binding| binding value ~~ #undefined]
]
{ #category : #'druid support' }
VMClass >> druidExitPoint [
"Mark an exit point. From this point on, the current execution branch should not be compiled"
<druidExitPoint>
]
{ #category : #'druid support' }
VMClass >> druidFail [
self error
]
{ #category : #'druid support' }
VMClass >> druidIgnore: aBlock [
"Execute the block during interpretation, ignore it during compilation.
Should be used only to avoid extra fast-cases during compilation"
^ aBlock value
]
{ #category : #'memory access' }
VMClass >> fetchSingleFloatAtPointer: pointer into: aFloat [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and aFloat is a 32-bit single precision float."
<doNotGenerate>
^self fetchSingleFloatAt: pointer into: aFloat
]
{ #category : #'file primitives' }
VMClass >> fgetc: file [
<doNotGenerate>
^ file next
]
{ #category : #'memory access' }
VMClass >> floatAtPointer: pointer [
<doNotGenerate>
self notYetImplemented
]
{ #category : #'memory access' }
VMClass >> floatAtPointer: pointer put: value [
<doNotGenerate>
self notYetImplemented
]
{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format [
<doNotGenerate>
^ self fprintf: aStream format: format arguments: { }
]
{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format _: aValue [
<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue }
]
{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format _: aValue _: otherValue [
<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue. otherValue }
]
{ #category : #'file primitives' }
VMClass >> fprintf: aStream format: aFormat arguments: arguments [
<doNotGenerate>
| printf |
printf := PrintfFormatString new setFormat: aFormat.
(ZnNewLineWriterStream on: aStream)
nextPutAll: (printf
printf: arguments;
string);
flush
]
{ #category : #'C library simulation' }
VMClass >> free: pointer [
<doNotGenerate>
"Do nothing"
]
{ #category : #'memory access' }
VMClass >> int16AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 16 bit integer."
<doNotGenerate>
^self shortAt: pointer
]
{ #category : #'memory access' }
VMClass >> int16AtPointer: pointer put: value [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 16 bit integer."
<doNotGenerate>
^self shortAt: pointer put: value
]
{ #category : #'memory access' }
VMClass >> int32AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 32 bit integer."
<doNotGenerate>
^self longAt: pointer
]
{ #category : #'memory access' }
VMClass >> int32AtPointer: pointer put: value [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 32 bit integer."
<doNotGenerate>
^self longAt: pointer put: value
]
{ #category : #'memory access' }
VMClass >> int64AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is the width of a machine word."
<doNotGenerate>
^ memoryManager long64At: pointer
]
{ #category : #'memory access' }
VMClass >> int64AtPointer: pointer put: longValue [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and longValue is the width of a machine word."
<doNotGenerate>
^ memoryManager long64At: pointer put: longValue
]
{ #category : #'memory access' }
VMClass >> int8AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 16 bit integer."
<doNotGenerate>
^self at: pointer
]
{ #category : #'memory access' }
VMClass >> int8AtPointer: pointer put: value [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 16 bit integer."
<doNotGenerate>
^self at: pointer put: value
]
{ #category : #'druid support' }
VMClass >> interpreterIgnore: aBlock [
"Ignore the block during interpretation, consider it during compilation.
Should be used only to control compilation in very few cases only"
]
{ #category : #'plugin support' }
VMClass >> isInterpreterProxy [
<doNotGenerate>
"Return false since I am a real Interpreter simulation"
^false
]
{ #category : #'hack compatibility' }
VMClass >> localNameFor: aString [
<doNotGenerate>
^ aString asFileReference basename
]
{ #category : #logging }
VMClass >> logDebug: aFormat _: aParameter [
<doNotGenerate>
(aFormat printf: { aParameter }) traceCr
]
{ #category : #'debug support' }
VMClass >> logError: aMessage [
<doNotGenerate>
self logError: aMessage withArgs: #()
]
{ #category : #'debug support' }
VMClass >> logError: aFormat _: arg1 [
<doNotGenerate>
self logError: aFormat withArgs: { arg1 }
]
{ #category : #'debug support' }
VMClass >> logError: aFormat _: arg1 _: arg2 [
<doNotGenerate>
self logError: aFormat withArgs: { arg1. arg2 }
]
{ #category : #'debug support' }
VMClass >> logError: aFormat withArgs: args [
<doNotGenerate>
Error signal: (aFormat printf: args)
]
{ #category : #'debug support' }
VMClass >> logWarn: aMessage [
<doNotGenerate>
self logWarn: aMessage withArgs: #()
]
{ #category : #'debug support' }
VMClass >> logWarn: aMessage _: anArgument [
<doNotGenerate>
self logWarn: aMessage withArgs: { anArgument }
]
{ #category : #'debug support' }
VMClass >> logWarn: aFormat withArgs: args [
<doNotGenerate>
(aFormat printf: args) traceCr
]
{ #category : #'memory access' }
VMClass >> long64AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is the width of a machine word."
<doNotGenerate>
^self halt
]
{ #category : #'memory access' }
VMClass >> long64AtPointer: pointer put: longValue [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and longValue is the width of a machine word."
<doNotGenerate>
^self halt.
]
{ #category : #'memory access' }
VMClass >> longAtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is the width of a machine word."
<doNotGenerate>
^self longAt: pointer
]
{ #category : #'memory access' }
VMClass >> longAtPointer: pointer put: longValue [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and longValue is the width of a machine word."
<doNotGenerate>
^self longAt: pointer put: longValue
]
{ #category : #'simulation support' }
VMClass >> majorVersion [
"This is implemented in sqVirtualMachine.c, so this form is for simulation only."
<doNotGenerate>
^self class vmProxyMajorVersion
]
{ #category : #'C library simulation' }
VMClass >> malloc: size [
<doNotGenerate>
| address region |
size = 0 ifTrue: [ ^ nil ].
address := memoryManager allocate: size.
region := memoryManager regionAtAddress: address.
^ CNewArrayAccessor new
setObject: region;
address: address;
yourself
]
{ #category : #'C library simulation' }
VMClass >> memcpy: dest _: src _: bytes [
<doNotGenerate>
"implementation of memcpy(3). N.B. If ranges overlap, must use memmove."
| getBlock setBlock source destination |
source := src isVMSimulationAddress
ifTrue: [src asInteger]
ifFalse: [src].
destination := dest isVMSimulationAddress
ifTrue: [dest asInteger]
ifFalse: [dest].
(source isInteger and: [destination isInteger]) ifTrue:
[ self deny: ((destination <= source and: [destination + bytes > source])
or: [source <= destination and: [source + bytes > destination]])].
"Determine the source and destination access blocks based on the parameter type"
getBlock := source isCollection ifTrue:
[source isString ifTrue:
"basicAt: answers integers"
[[ :idx | source basicAt: idx]]
ifFalse:
[source class == ByteArray ifTrue:
[[ :idx | source at: idx]]]]
ifFalse:
[source isInteger ifTrue:
[[ :idx | self byteAt: source + idx - 1]]
ifFalse:
[source isCArray ifTrue:
[[ :idx | source at: idx - 1]]]].
getBlock ifNil: [self error: 'unhandled type of source string'].
setBlock := destination isCollection ifTrue:
[destination isString ifTrue:
"basicAt:put: stores integers"
[[ :idx | destination basicAt: idx put: (getBlock value: idx)]]
ifFalse:
[destination class == ByteArray ifTrue:
[[ :idx | destination at: idx put: (getBlock value: idx)]]]]
ifFalse:
[destination isInteger ifTrue:
[[ :idx | self byteAt: destination + idx - 1 put: (getBlock value: idx)]]
ifFalse:
[destination isCArray ifTrue:
[[ :idx | destination at: idx - 1 put: (getBlock value: idx)]]]].
setBlock ifNil: [self error: 'unhandled type of destination string'].
1 to: bytes do: setBlock.
^destination
]
{ #category : #'C library simulation' }
VMClass >> memmove: destAddress _: sourceAddress _: bytes [
<doNotGenerate>
| dst src |
dst := destAddress asInteger.
src := sourceAddress asInteger.
"Emulate the c library memmove function"
self assert: bytes \\ 4 = 0.
destAddress > sourceAddress
ifTrue:
[bytes - 4 to: 0 by: -4 do:
[:i| self longAt: dst + i put: (self longAt: src + i)]]
ifFalse:
[0 to: bytes - 4 by: 4 do:
[:i| self longAt: dst + i put: (self longAt: src + i)]]
]
{ #category : #accessing }
VMClass >> memoryManager [
<doNotGenerate>
^ memoryManager
]
{ #category : #accessing }
VMClass >> memoryManager: aMemoryManager [
<doNotGenerate>
memoryManager := aMemoryManager
]
{ #category : #'simulation support' }
VMClass >> minorVersion [
"This is implemented in sqVirtualMachine.c, so this form is for simulation only."
<doNotGenerate>
^self class vmProxyMinorVersion
]
{ #category : #'translation support' }
VMClass >> notYetImplemented [
<inline: true>
self notYetImplemented: 'Not Yet Implemented!'
]
{ #category : #'translation support' }
VMClass >> notYetImplemented: aMessage [
<inline: true>
self
cCode: [
self logError: aMessage.
self abort ]
inSmalltalk: [ super notYetImplemented ]
]
{ #category : #accessing }
VMClass >> objectRepresentationClass [
<doNotGenerate>
^self class objectRepresentationClass
]
{ #category : #'oop comparison' }
VMClass >> oop: anOop isGreaterThan: otherOop [
"Compare two oop values, treating them as object memory locations; i.e. use unsigned comparisons.
Use a macro, instead of #cCoerce:to: to provide fast simulation and inline code in conditionals,
since the inliner doesn't inline in condtionals."
<cmacro: '(anOop,otherOop) ((usqInt)(anOop) > (usqInt)(otherOop))'>
^anOop > otherOop
]
{ #category : #'oop comparison' }
VMClass >> oop: anOop isGreaterThan: baseOop andLessThan: limitOop [
"Compare two oop values, treating them as object memory locations; i.e. use unsigned comparisons.
Use a macro, instead of #cCoerce:to: to provide fast simulation and inline code in conditionals,
since the inliner doesn't inline in condtionals."
<cmacro: '(anOop,baseOop,limitOop) ((usqInt)(anOop) > (usqInt)(baseOop) && (usqInt)(anOop) < (usqInt)(limitOop))'>
^anOop > baseOop and: [anOop < limitOop]
]
{ #category : #'oop comparison' }
VMClass >> oop: anOop isGreaterThanOrEqualTo: otherOop [
"Compare two oop values, treating them as object memory locations; i.e. use unsigned comparisons.
Use a macro, instead of #cCoerce:to: to provide fast simulation and inline code in conditionals,
since the inliner doesn't inline in condtionals."
<cmacro: '(anOop,otherOop) ((usqInt)(anOop) >= (usqInt)(otherOop))'>
^anOop >= otherOop
]
{ #category : #'oop comparison' }
VMClass >> oop: anOop isGreaterThanOrEqualTo: baseOop andLessThan: limitOop [
"Compare two oop values, treating them as object memory locations; i.e. use unsigned comparisons.
Use a macro, instead of #cCoerce:to: to provide fast simulation and inline code in conditionals,
since the inliner doesn't inline in condtionals."
<cmacro: '(anOop,baseOop,limitOop) ((usqInt)(anOop) >= (usqInt)(baseOop) && (usqInt)(anOop) < (usqInt)(limitOop))'>
^anOop >= baseOop and: [anOop < limitOop]
]
{ #category : #'oop comparison' }
VMClass >> oop: anOop isGreaterThanOrEqualTo: baseOop andLessThanOrEqualTo: limitOop [
"Compare two oop values, treating them as object memory locations; i.e. use unsigned comparisons.
Use a macro, instead of #cCoerce:to: to provide fast simulation and inline code in conditionals,
since the inliner doesn't inline in condtionals."
<cmacro: '(anOop,baseOop,limitOop) ((usqInt)(anOop) >= (usqInt)(baseOop) && (usqInt)(anOop) <= (usqInt)(limitOop))'>
^anOop >= baseOop and: [anOop <= limitOop]