Skip to content

Commit

Permalink
Changed tests as suggested to check Slang methods annotated with type…
Browse files Browse the repository at this point in the history
…s, either using built-in and without built-in C operations.

Simplify test cases using getTMethod: by automatically preparing the method.
Removed test cases where invalid C were generated.
  • Loading branch information
Hernán Morales Durand committed Aug 7, 2023
1 parent cdcfdd5 commit dbf4149
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 144 deletions.
157 changes: 35 additions & 122 deletions smalltalksrc/Slang-Tests/SlangBasicTranslationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ SlangBasicTranslationTest >> getTMethodFrom: selector [
"Generate a TMethod from a SlangBasicTranslationTestClass method."

generator addClass: SlangBasicTranslationTestClass.
generator inferTypes.
generator
inferTypes;
prepareMethods.
^ generator methodNamed: selector
]

Expand Down Expand Up @@ -1156,162 +1158,73 @@ SlangBasicTranslationTest >> testGoto [
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsNoPrepare [
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithAnnotations [
| tMethod translation |
tMethod := (self getTMethodFrom: #methodSumParameters:to:with:).
generator doBasicInlining: true.
translation := self translate: tMethod.
translation := translation trimBoth.
self
assert: translation
equals: '/* SlangBasicTranslationTestClass>>#methodSumParameters:to:with: */
static sqInt
methodSumParameterstowith(sqInt pFrom, sqInt pTo, sqInt anInteger)
{
sqInt i;
sqInt pFrom1;
sqInt pTo1;

/* begin methodFrom:to: */
pFrom1 = pFrom + anInteger;
pTo1 = pTo + anInteger;
for (i = 0; i <= 5; i += 1) {
pTo1[i] = pFrom1[i];
};
return 0;
}'
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsPrepared [
| tMethod translation |
tMethod := (self getTMethodFrom: #methodSumParameters:to:with:).
generator
prepareMethods;
doBasicInlining: true.
translation := self translate: tMethod.
translation := translation trimBoth.
self
assert: translation
equals: '/* SlangBasicTranslationTestClass>>#methodSumParameters:to:with: */
static sqInt
methodSumParameterstowith(sqInt pFrom, sqInt pTo, sqInt anInteger)
{
sqInt i;

/* begin methodFrom:to: */
for (i = 0; i <= 5; i += 1) {
(pTo + anInteger)[i] = pFrom + anInteger[i];
};
return 0;
}'
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithAnnotationsNoPrepare [
| tMethod translation |
tMethod := (self getTMethodFrom: #methodSumParametersWithAnnotations:to:with:).
tMethod := (self getTMethodFrom: #methodUseParametersWithAnnotations:to:with:).
" Adding a method already does prepare methods "
generator doBasicInlining: true.
translation := self translate: tMethod.
translation := translation trimBoth.
self
assert: translation
equals: '/* SlangBasicTranslationTestClass>>#methodSumParametersWithAnnotations:to:with: */
equals: '/* SlangBasicTranslationTestClass>>#methodUseParametersWithAnnotations:to:with: */
static sqInt
methodSumParametersWithAnnotationstowith(unsigned int *pFrom, unsigned int *pTo, sqInt anInteger)
methodUseParametersWithAnnotationstowith(unsigned int *pFrom, unsigned int *pTo, sqInt anInteger)
{
sqInt i;
unsigned int *pFrom1;
sqInt pFrom1;
unsigned int *pTo1;

/* begin methodFromWithAnnotations:to:len: */
pFrom1 = pFrom + anInteger;
pTo1 = pTo + anInteger;
for (i = 0, iLimiT = 5 - 1; i <= iLimiT; i += 1) {
pTo1[i] = pFrom1[i];
pTo1 = ((unsigned int *) (yourself(pTo)) );
for (i = 0; i < 5; i += 1) {
pTo1[i] = pFrom + anInteger[i];
};
return 0;
}'
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithAnnotationsPrepared [
| tMethod translation |
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithAnnotationsUseBuiltIn [
| tMethod translation codeGenerator inlinedMethod |
tMethod := (self getTMethodFrom: #methodSumParametersWithAnnotations:to:with:).
generator
prepareMethods;
doBasicInlining: true.
tMethod := self getTMethodFrom: #methodUseParametersWithAnnotationsBuiltIn:to:with:.
inlinedMethod := ((SlangBasicTranslationTestClass >> #methodFromWithAnnotations:to:) asTranslationMethodOfClass: TMethod).
codeGenerator := CCodeGeneratorGlobalStructure new.
codeGenerator vmMaker: VMMaker new.
codeGenerator vmMaker vmmakerConfiguration: VMMakerConfiguration.
codeGenerator
addMethod: tMethod;
addMethod: inlinedMethod;
doInlining: true.
self assert: (tMethod locals includesAll: inlinedMethod locals).
translation := self translate: tMethod.
translation := translation trimBoth.
self
self
assert: translation
equals: '/* SlangBasicTranslationTestClass>>#methodSumParametersWithAnnotations:to:with: */
equals: '/* SlangBasicTranslationTestClass>>#methodUseParametersWithAnnotationsBuiltIn:to:with: */
static sqInt
methodSumParametersWithAnnotationstowith(unsigned int *pFrom, unsigned int *pTo, sqInt anInteger)
methodUseParametersWithAnnotationsBuiltIntowith(unsigned int *pFrom, unsigned int *pTo, sqInt anInteger)
{
sqInt i;
sqInt pFrom1;
sqInt pTo1;

/* begin methodFromWithAnnotations:to:len: */
for (i = 0; i < 5; i += 1) {
(pTo + anInteger)[i] = pFrom + anInteger[i];
/* begin methodFromWithAnnotations:to: */
pFrom1 = ((sqInt) (pFrom + anInteger) );
for (i = 0; i <= 10; i += 1) {
pTo[i] = pFrom1[i];
};
return 0;
}'
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithLengthNoPrepare [
| translation codeGenerator inlinedMethod |
translation := self getTMethodFrom: #methodSumParameters:to:with:len:.
inlinedMethod := ((SlangBasicTranslationTestClass >> #methodFrom:to:len:) asTranslationMethodOfClass: TMethod).
codeGenerator := CCodeGeneratorGlobalStructure new.
codeGenerator vmMaker: VMMaker new.
codeGenerator vmMaker vmmakerConfiguration: VMMakerConfiguration.
codeGenerator
addMethod: translation;
addMethod: inlinedMethod;
doInlining: true.
(translation asCASTIn: codeGenerator) asString.
(inlinedMethod asCASTIn: codeGenerator) asString.
self assert: (translation locals includesAll: inlinedMethod locals)
]
{ #category : #'tests-inline-builtins' }
SlangBasicTranslationTest >> testInlineMethodSumArgumentsWithLengthPrepared [
| translation codeGenerator inlinedMethod |
translation := self getTMethodFrom: #methodSumParameters:to:with:len:.
inlinedMethod := ((SlangBasicTranslationTestClass >> #methodFrom:to:len:) asTranslationMethodOfClass: TMethod).
codeGenerator := CCodeGeneratorGlobalStructure new.
codeGenerator vmMaker: VMMaker new.
codeGenerator vmMaker vmmakerConfiguration: VMMakerConfiguration.
codeGenerator
addMethod: translation;
addMethod: inlinedMethod;
prepareMethods;
doInlining: true.
(translation asCASTIn: codeGenerator) asString.
(inlinedMethod asCASTIn: codeGenerator) asString.
self assert: (translation locals includesAll: inlinedMethod locals)
]
{ #category : #'tests-inlinenode' }
SlangBasicTranslationTest >> testInlineNodeDoesNotInitializeReadBeforeWrittenArrayTemp [
Expand Down
39 changes: 17 additions & 22 deletions smalltalksrc/Slang-Tests/SlangBasicTranslationTestClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ SlangBasicTranslationTestClass >> methodDefiningSingleVariable [
]

{ #category : #'generation-targets' }
SlangBasicTranslationTestClass >> methodFrom: pFrom to: pTo [
SlangBasicTranslationTestClass >> methodFrom: pFrom to: pTo len: sizeLen [

0 to: 5 do: [ : i | pTo at: i put: (pFrom at: i) ]
0 to: sizeLen - 1 do: [ : i | pTo at: i put: (pFrom at: i) ]
]

{ #category : #'generation-targets' }
SlangBasicTranslationTestClass >> methodFrom: pFrom to: pTo len: sizeLen [
SlangBasicTranslationTestClass >> methodFromWithAnnotations: pFrom to: pTo [
<var: #pTo type: #'unsigned int *'>
<var: #pFrom type: #'unsigned int *'>

0 to: sizeLen - 1 do: [ : i | pTo at: i put: (pFrom at: i) ]
0 to: 10 do: [ : i | pTo at: i put: (pFrom at: i) ].
]

{ #category : #'generation-targets' }
Expand All @@ -95,32 +97,25 @@ SlangBasicTranslationTestClass >> methodFromWithAnnotations: pFrom to: pTo len:
]

{ #category : #'generation-targets' }
SlangBasicTranslationTestClass >> methodSumParameters: pFrom to: pTo with: anInteger [

self
methodFrom: pFrom + anInteger
to: pTo + anInteger
]
SlangBasicTranslationTestClass >> methodUseParametersWithAnnotations: pFrom to: pTo with: anInteger [

{ #category : #'generation-targets' }
SlangBasicTranslationTestClass >> methodSumParameters: pFrom to: pTo with: anInteger len: sizeLen [
<var: #pTo type: #'unsigned int *'>
<var: #pFrom type: #'unsigned int *'>

self
methodFrom: pFrom + anInteger
to: pTo + anInteger
len: sizeLen - 1
^ self
methodFromWithAnnotations: pFrom + anInteger
to: pTo yourself
len: 5
]

{ #category : #'generation-targets' }
SlangBasicTranslationTestClass >> methodSumParametersWithAnnotations: pFrom to: pTo with: anInteger [

SlangBasicTranslationTestClass >> methodUseParametersWithAnnotationsBuiltIn: pFrom to: pTo with: anInteger [
<var: #pTo type: #'unsigned int *'>
<var: #pFrom type: #'unsigned int *'>

^ self
methodFromWithAnnotations: pFrom + anInteger
to: pTo + anInteger
len: 5
self
methodFromWithAnnotations: pFrom + anInteger
to: pTo
]

{ #category : #inline }
Expand Down

0 comments on commit dbf4149

Please sign in to comment.