-
Notifications
You must be signed in to change notification settings - Fork 68
/
SmartSyntaxPluginCodeGenerator.class.st
792 lines (667 loc) · 28.8 KB
/
SmartSyntaxPluginCodeGenerator.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
"
Subclass of CCodeGenerator, used in connection with TestInterpreterPlugin to generate named primitives with type coercion specifications. See the plugins implemeted as subclasses of TestInterpreterPlugin
"
Class {
#name : #SmartSyntaxPluginCodeGenerator,
#superclass : #VMPluginCodeGenerator,
#instVars : [
'debugFlag'
],
#category : #'VMMaker-SmartSyntaxPlugins'
}
{ #category : #utilities }
SmartSyntaxPluginCodeGenerator >> anyMethodNamed: selector [
"Answer any method in the code base (including api methods) with the given selector.
Override to find smart syntax methods that get entered in the dictionary under the
name specified in the primitive:parameters: send."
^(super anyMethodNamed: selector) ifNil:
[methods
detect: [:m| m smalltalkSelector == selector]
ifNone: []]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asBooleanValueFrom: anInteger [
"Answer codestring for boolean coercion (with validating side-effect) of object, as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy booleanValueOf:';
crtab: 2;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: ')'])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asCharPtrFrom: anInteger [
"Answer codestring for character pointer to first indexable field of object (without validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''char *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asCharPtrFrom: anInteger andThen: valBlock [
"Answer codestring for character pointer to first indexable field of object (without validating side-effect unless specified in valBlock), as described in comment to ccgLoad:expr:asRawOopFrom:"
^(valBlock value: anInteger), '.',
(aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''char *''']))
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asFloatValueFrom: anInteger [
"Answer codestring for double precision coercion (with validating side-effect) of oop, as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy stackFloatValue: ';
nextPutAll: anInteger asString])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asIntPtrFrom: anInteger [
"Answer codestring for integer pointer to first indexable field of object (without validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''int *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asIntPtrFrom: anInteger andThen: valBlock [
"Answer codestring for integer pointer to first indexable field of object (without validating side-effect unless specified in valBlock), as described in comment to ccgLoad:expr:asRawOopFrom:"
^(valBlock value: anInteger), '.',
(aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''int *''']))
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asIntegerValueFrom: anInteger [
"Answer codestring for integer coercion (with validating side-effect) of oop, as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy stackIntegerValue: ';
nextPutAll: anInteger asString])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asKindOf: aClass from: anInteger [
^String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy';
crtab: 2;
nextPutAll: 'is: (interpreterProxy stackValue: ';
nextPutAll: anInteger asString;
nextPutAll: ')';
crtab: 2;
nextPutAll: 'KindOf: ''';
nextPutAll: aClass asString;
nextPutAll: ''').';
newLine; tab;
nextPutAll: (self
ccgLoad: aBlock
expr: aString
asRawOopFrom: anInteger)]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asKindOfIntegerFrom: anInteger [
^String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy isKindOfInteger: (interpreterProxy stackValue: ';
nextPutAll: anInteger asString;
nextPutAll: ')).';
newLine; tab;
nextPutAll: (self
ccgLoad: aBlock
expr: aString
asRawOopFrom: anInteger)]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asMemberOf: aClass from: anInteger [
^String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy';
newLine; tab; tab;
nextPutAll: 'is: (interpreterProxy stackValue: ';
nextPutAll: anInteger asString;
nextPutAll: ')';
newLine; tab; tab;
nextPutAll: 'MemberOf: ''';
nextPutAll: aClass asString;
nextPutAll: ''').';
newLine; tab;
nextPutAll: (self
ccgLoad: aBlock
expr: aString
asRawOopFrom: anInteger)]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asMemberOfLargeNegativeIntegerFrom: anInteger [
^String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy isLargeNegativeIntegerObject: (interpreterProxy stackValue: ';
nextPutAll: anInteger asString;
nextPutAll: ')).';
newLine; tab;
nextPutAll: (self
ccgLoad: aBlock
expr: aString
asRawOopFrom: anInteger)]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asMemberOfLargePositiveIntegerFrom: anInteger [
^String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy isLargePositiveIntegerObject: (interpreterProxy stackValue: ';
nextPutAll: anInteger asString;
nextPutAll: ')).';
newLine; tab;
nextPutAll: (self
ccgLoad: aBlock
expr: aString
asRawOopFrom: anInteger)]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asNonIntegerValueFrom: anInteger [
"Answer codestring for oop (with validating side effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'interpreterProxy stackObjectValue: ';
nextPutAll: anInteger asString])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asOopPtrFrom: anInteger [
"Answer codestring for integer pointer to first indexable field of object (without validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents:
[:aStream |
aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
print: anInteger;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''sqInt *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asOopPtrFrom: anInteger andThen: valBlock [
"Answer codestring for integer pointer to first indexable field of object (without validating side-effect unless specified in valBlock), as described in comment to ccgLoad:expr:asRawOopFrom:"
^(valBlock value: anInteger), '.',
(aBlock value: (String streamContents:
[:aStream |
aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
print: anInteger;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''sqInt *''']))
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asRawOopFrom: anInteger [
"Answer a string for a Slang expression that will load an oop (without validation) from stack index anInteger. Apply aBlock that when passed an expression, will answer a string assigning the expression to the desired identifier, to the string before answering. aString is a Slang expression that refers to the stack value, once it has been loaded."
^aBlock value: 'interpreterProxy stackValue: ', anInteger printString
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asUnsignedPtrFrom: anInteger andThen: valBlock [
"Answer a codestring for integer pointer to first indexable field of object (without validating side-effect unless specified in valBlock), as described in comment to ccgLoad:expr:asRawOopFrom:"
^(valBlock value: anInteger), '.',
(aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy firstIndexableField:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''unsigned *''']))
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asUnsignedValueFrom: anInteger [
"Answer a codestring for positive integer coercion (with validating side-effect) of oop, as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream |
aStream
nextPutAll: '(interpreterProxy bytesPerOop = 4';
crtab: 2;
nextPutAll: 'ifTrue: [interpreterProxy positive32BitValueOf:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
print: anInteger;
nextPutAll: ')]';
crtab: 2;
nextPutAll: 'ifFalse: [interpreterProxy positive64BitValueOf:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
print: anInteger;
nextPutAll: ')])'])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asWBCharPtrFrom: anInteger [
"Answer codestring for char pointer to first indexable field of object (with validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy arrayValueOf:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''char *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asWBFloatPtrFrom: anInteger [
"Answer codestring for single-precision float pointer to first indexable field of object (with validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy arrayValueOf:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''float *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgLoad: aBlock expr: aString asWBIntPtrFrom: anInteger [
"Answer codestring for integer pointer to first indexable field of object (with validating side-effect), as described in comment to ccgLoad:expr:asRawOopFrom:"
^aBlock value: (String streamContents: [:aStream | aStream
nextPutAll: 'self cCoerce: (interpreterProxy arrayValueOf:';
crtab: 4;
nextPutAll: '(interpreterProxy stackValue:';
nextPutAll: anInteger asString;
nextPutAll: '))';
crtab: 3;
nextPutAll: 'to: ''int *'''])
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgSetBlock: aString [
^[:expr | aString, ' := ', expr]
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgTVarBlock: anInteger [
^[:expr | '(thisContext tempAt: 1) tempAt: ', anInteger asString, ' put: (', expr, ')']
]
{ #category : #coercing }
SmartSyntaxPluginCodeGenerator >> ccgValBlock: valString [
^[:index | String streamContents:
[:aStream | aStream
nextPutAll: 'interpreterProxy success: (interpreterProxy ';
nextPutAll: valString;
nextPutAll: ': (interpreterProxy stackValue: ';
nextPutAll: index asString;
nextPutAll: '))']]
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> genCallOf: aSelector with: aNode on: aStream [
pluginFunctionsUsed add: aSelector.
aStream nextPutAll: (self cFunctionNameFor: aSelector).
aStream nextPut: $(.
self emitCExpression: aNode on: aStream.
aStream nextPut: $)
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> genCallOf: aSelector with: firstArgNode with: secondArgNode on: aStream [
pluginFunctionsUsed add: aSelector.
aStream nextPutAll: (self cFunctionNameFor: aSelector).
aStream nextPut: $(.
self emitCExpression: firstArgNode on: aStream.
aStream nextPut: $,.
self emitCExpression: secondArgNode on: aStream.
aStream nextPut: $)
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> genCallOf: aSelector with: firstArgNode with: secondArgNode with: thirdArgNode on: aStream [
pluginFunctionsUsed add: aSelector.
aStream nextPutAll: (self cFunctionNameFor: aSelector).
aStream nextPut: $(.
self emitCExpression: firstArgNode on: aStream.
aStream nextPut: $,.
self emitCExpression: secondArgNode on: aStream.
aStream nextPut: $,.
self emitCExpression: thirdArgNode on: aStream.
aStream nextPut: $)
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsBooleanObj: aNode on: aStream indent: anInteger [
pluginFunctionsUsed add: #trueObject; add: #falseObject.
aStream nextPutAll: '(('.
self emitCExpression: aNode receiver on: aStream.
aStream nextPutAll: ') ? trueObject() : falseObject())'.
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsCBoolean: aNode on: aStream indent: anInteger [
self genCallOf: #booleanValueOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsCDouble: aNode on: aStream indent: anInteger [
self genCallOf: #floatValueOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsCInt: aNode on: aStream indent: anInteger [
self genCallOf: #integerValueOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsCUnsigned: aNode on: aStream indent: anInteger [
self genCallOf: #positive32BitValueOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsCharPtr: aNode on: aStream indent: anInteger [
self generateCoerceToPtr: 'char *' fromObject: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsFloatObj: aNode on: aStream indent: anInteger [
self genCallOf: #floatObjectOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsIfVar: aNode on: aStream indent: anInteger [
| cName fName class index |
cName := String streamContents:
[:scStr | self emitCExpression: aNode args first on: scStr].
(class := Smalltalk classNamed: cName) isBehavior ifFalse:
[^self error: 'first arg must identify class'].
fName := aNode args second value.
index := class
instVarIndexFor: fName
ifAbsent: [^self error: 'second arg must be instVar'].
pluginFunctionsUsed add: #fetchPointer:ofObject:.
aStream nextPutAll: 'fetchPointerofObject('; print: index - 1; nextPut: $,.
self emitCExpression: aNode receiver on: aStream.
aStream nextPut: $)
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsIfVarAsValue: aNode on: aStream indent: anInteger [
| cName fName class index fetchNode |
cName := String streamContents:
[:scStr | self emitCExpression: aNode args first on: scStr].
(class := Smalltalk classNamed: cName) isBehavior ifFalse:
[^self error: 'first arg must identify class'].
fName := aNode args second value.
index := class
instVarIndexFor: fName
ifAbsent: [^self error: 'second arg must be instVar'].
fetchNode := TSendNode new
setSelector: #fetchPointer:ofObject:
receiver: (TVariableNode new setName: 'self')
arguments: { TConstantNode value: index - 1. aNode receiver}.
cName := aNode args third nameOrValue.
(class := Smalltalk classNamed: cName) isBehavior ifFalse:
[^self error: 'third arg must identify class'].
class ccg: self generateCoerceToValueFrom: fetchNode on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsIfVarPut: aNode on: aStream indent: anInteger [
| cName fName class index |
cName := String streamContents:
[:scStr | self emitCExpression: aNode args first on: scStr].
(class := Smalltalk classNamed: cName) isBehavior ifFalse:
[^self error: 'first arg must identify class'].
fName := aNode args second value.
index := class
instVarIndexFor: fName
ifAbsent: [^self error: 'second arg must be instVar'].
pluginFunctionsUsed add: #storePointer:ofObject:withValue:.
aStream nextPutAll: 'storePointerofObjectwithValue('; print: index - 1; nextPut: $,.
self emitCExpression: aNode receiver on: aStream.
aStream nextPut: $,.
self emitCExpression: aNode args third on: aStream.
aStream nextPut: $)
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsIntPtr: aNode on: aStream indent: anInteger [
self generateCoerceToPtr: 'int *' fromObject: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsOop: aNode on: aStream indent: anInteger [
| cName class |
cName := aNode args first nameOrValue.
class := Smalltalk
at: (cName asSymbol)
ifAbsent: [nil].
(class isNil not and: [class isBehavior]) ifFalse:
[^self error: 'first arg must identify class'].
class ccg: self generateCoerceToOopFrom: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsPositiveIntegerObj: aNode on: aStream indent: anInteger [
self genCallOf: #positive32BitIntegerFor: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsSmallIntegerObj: aNode on: aStream indent: anInteger [
self genCallOf: #integerObjectOf: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateAsValue: aNode on: aStream indent: anInteger [
| cName class |
cName := aNode args first nameOrValue.
class := Smalltalk
at: (cName asSymbol)
ifAbsent: [nil].
(class isNil not and: [class isBehavior]) ifFalse:
[^self error: 'first arg must identify class'].
class ccg: self generateCoerceToValueFrom: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateCPtrAsOop: aNode on: aStream indent: anInteger [
aStream nextPutAll: '((sqInt)(sqIntptr_t)('.
self emitCExpression: aNode receiver on: aStream.
aStream nextPutAll: ') - BaseHeaderSize)'
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateClass: aNode on: aStream indent: anInteger [
self genCallOf: #fetchClassOf: with: aNode receiver on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToBooleanObjectFrom: aNode on: aStream [
pluginFunctionsUsed add: #trueObject; add: #falseObject.
aStream nextPutAll: '(('.
self emitCExpression: aNode on: aStream.
aStream nextPutAll: ') ? trueObject() : falseObject())'
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToBooleanValueFrom: aNode on: aStream [
self genCallOf: #booleanValueOf: with: aNode receiver on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToFloatObjectFrom: aNode on: aStream [
self genCallOf: #floatObjectOf: with: aNode on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToFloatValueFrom: aNode on: aStream [
self genCallOf: #floatValueOf: with: aNode on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToObjectFromPtr: aNode on: aStream [
"This code assumes no named instance variables"
aStream nextPutAll: '((sqInt)(('.
self emitCExpression: aNode on: aStream.
aStream nextPutAll: ') - BaseHeaderSize))'
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToPtr: aString fromObject: aNode on: aStream [
"This code assumes no named instance variables"
aStream
nextPutAll: '((';
nextPutAll: aString;
nextPut: $).
self genCallOf: #firstIndexableField: with: aNode on: aStream.
aStream nextPut: $)
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToSmallIntegerObjectFrom: aNode on: aStream [
self genCallOf: #integerObjectOf: with: aNode on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToSmallIntegerValueFrom: aNode on: aStream [
self genCallOf: #integerValueOf: with: aNode on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToUnsignedObjectFrom: aNode on: aStream [
self genCallOf: #positive32BitIntegerFor: with: aNode on: aStream
]
{ #category : #'asOop:/asValue:' }
SmartSyntaxPluginCodeGenerator >> generateCoerceToUnsignedValueFrom: aNode on: aStream [
self genCallOf: #positive32BitValueOf: with: aNode on: aStream
]
{ #category : #'debug code' }
SmartSyntaxPluginCodeGenerator >> generateDebugCode [
^ debugFlag
]
{ #category : #'debug code' }
SmartSyntaxPluginCodeGenerator >> generateDebugCode: aBool [
debugFlag := aBool
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateField: aNode on: aStream indent: anInteger [
self genCallOf: #fetchPointer:ofObject: with: aNode args first with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateFieldPut: aNode on: aStream indent: anInteger [
self genCallOf: #storePointer:ofObject:withValue:
with: aNode args first
with: aNode receiver
with: aNode args second
on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateFromStack: aNode on: aStream indent: anInteger [
| idList |
aNode args first isConstant ifFalse: [^self error: 'arg must be constant'].
pluginFunctionsUsed add: #stackValue:.
idList := aNode args first value.
(1 to: idList size)
do: [:i |
aStream
nextPutAll: (idList at: i);
nextPutAll: ' = stackValue(';
print: idList size - i;
nextPut: $)]
separatedBy: [aStream nextPut: $;; crtab: anInteger].
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsFloat: aNode on: aStream indent: anInteger [
self genCallOf: #isFloatObject: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsIndexable: aNode on: aStream indent: anInteger [
self genCallOf: #isIndexable: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsIntegerOop: aNode on: aStream indent: anInteger [
self genCallOf: #isIntegerObject: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsIntegerValue: aNode on: aStream indent: anInteger [
self genCallOf: #isIntegerValue: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsKindOf: aNode on: aStream indent: anInteger [
self genCallOf: #is:KindOf: with: aNode receiver with: aNode args first on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsMemberOf: aNode on: aStream indent: anInteger [
self genCallOf: #is:MemberOf: with: aNode receiver with: aNode args first on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsPointers: aNode on: aStream indent: anInteger [
self genCallOf: #isPointers: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsWords: aNode on: aStream indent: anInteger [
self genCallOf: #isWords: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateIsWordsOrBytes: aNode on: aStream indent: anInteger [
self genCallOf: #isWordsOrBytes: with: aNode receiver on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateNext: msgNode on: aStream indent: level [
"Generate the C code for this message onto the given stream."
| varNode |
varNode := msgNode receiver.
varNode isVariable
ifFalse: [ self error: 'next can only be applied to variables' ].
aStream nextPutAll: '*'.
aStream nextPutAll: varNode name.
aStream nextPutAll: '++'
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateStAt: aNode on: aStream indent: anInteger [
self genCallOf: #stObject:at: with: aNode receiver with: aNode args first on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateStAtPut: aNode on: aStream indent: anInteger [
self genCallOf: #stObject:at:put:
with: aNode receiver
with: aNode args first
with: aNode args second
on: aStream
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> generateStSize: aNode on: aStream indent: anInteger [
self genCallOf: #stSizeOf: with: aNode receiver on: aStream
]
{ #category : #initialize }
SmartSyntaxPluginCodeGenerator >> initialize [
super initialize.
debugFlag := false
]
{ #category : #'translating builtins' }
SmartSyntaxPluginCodeGenerator >> initializeCTranslationDictionary [
"Initialize the dictionary mapping message names to actions for C code generation."
| pairs |
super initializeCTranslationDictionary.
pairs := #(
#asCInt #generateAsCInt:on:indent:
#asCUnsigned #generateAsCUnsigned:on:indent:
#asCBoolean #generateAsCBoolean:on:indent:
#asCDouble #generateAsCDouble:on:indent:
#asSmallIntegerObj #generateAsSmallIntegerObj:on:indent:
#asPositiveIntegerObj #generateAsPositiveIntegerObj:on:indent:
#asBooleanObj #generateAsBooleanObj:on:indent:
#asFloatObj #generateAsFloatObj:on:indent:
#asIf:var: #generateAsIfVar:on:indent:
#asIf:var:asValue: #generateAsIfVarAsValue:on:indent:
#asIf:var:put: #generateAsIfVarPut:on:indent:
#field: #generateField:on:indent:
#field:put: #generateFieldPut:on:indent:
#class #generateClass:on:indent:
#stSize #generateStSize:on:indent:
#stAt: #generateStAt:on:indent:
#stAt:put: #generateStAtPut:on:indent:
#asCharPtr #generateAsCharPtr:on:indent:
#asIntPtr #generateAsIntPtr:on:indent:
#cPtrAsOop #generateCPtrAsOop:on:indent:
#next #generateNext:on:indent:
#asOop: #generateAsOop:on:indent:
#asValue: #generateAsValue:on:indent:
#isFloat #generateIsFloat:on:indent:
#isIndexable #generateIsIndexable:on:indent:
#isIntegerOop #generateIsIntegerOop:on:indent:
#isIntegerValue #generateIsIntegerValue:on:indent:
"#FloatOop #generateIsFloatValue:on:indent:" "unused, never implemented"
#isWords #generateIsWords:on:indent:
#isWordsOrBytes #generateIsWordsOrBytes:on:indent:
#isPointers #generateIsPointers:on:indent:
#isNil #generateCASTIsNil:
#isMemberOf: #generateIsMemberOf:on:indent:
#isKindOf: #generateIsKindOf:on:indent:
#fromStack: #generateFromStack:on:indent:
"#clone #generateClone:on:indent:" "unused, never implemented"
"#new #generateNew:on:indent:" "unused, never implemented"
"#new: #generateNewSize:on:indent:" "unused, never implemented"
"#superclass #generateSuperclass:on:indent:" "unused, never implemented"
).
1 to: pairs size by: 2 do: [:i |
translationDict at: (pairs at: i) put: (pairs at: i + 1)].
]
{ #category : #initialize }
SmartSyntaxPluginCodeGenerator >> translationMethodClass [
"return the class used to produce C translation methods from MethodNodes"
^SmartSyntaxPluginTMethod
]
{ #category : #transforming }
SmartSyntaxPluginCodeGenerator >> var: varName as: aClass [
"Record the given C declaration for a global variable"
variableDeclarations at: varName asString put: (aClass ccgDeclareCForVar: varName)
]