Skip to content

Commit

Permalink
Resolution of constants
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Sep 26, 2019
1 parent da75938 commit a28d091
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/UnifiedFFI-Tests/FFIFunctionParserTest.class.st
Expand Up @@ -13,6 +13,12 @@ FFIFunctionParserTest >> assertIsFalse: anArgument [
self assert: anArgument value equals: 'false'
]

{ #category : #asserting }
FFIFunctionParserTest >> assertIsNULL: anArgument [

self assert: anArgument value equals: 'NULL'
]

{ #category : #asserting }
FFIFunctionParserTest >> assertIsNil: anArgument [

Expand Down Expand Up @@ -211,6 +217,18 @@ FFIFunctionParserTest >> testUntypedFalseArgumentIsFalse [
self assertIsFalse: argument
]

{ #category : #tests }
FFIFunctionParserTest >> testUntypedNilArgumentIsNULL [
| parser argument |

parser := self newParser
setStream: 'NULL' readStream;
yourself.

argument := parser parseArgument.
self assertIsNULL: argument
]

{ #category : #tests }
FFIFunctionParserTest >> testUntypedNilArgumentIsNil [
| parser argument |
Expand Down
86 changes: 84 additions & 2 deletions src/UnifiedFFI-Tests/FFIFunctionResolutionTest.class.st
Expand Up @@ -7,10 +7,22 @@ Class {
#category : #'UnifiedFFI-Tests-Tests'
}

{ #category : #helpers }
FFIFunctionResolutionTest >> pushInstVar: anInteger [

stack push: {#ivar . anInteger}
]

{ #category : #helpers }
FFIFunctionResolutionTest >> pushLiteral: aLiteral [

stack push: aLiteral
stack push: { #literal . aLiteral }
]

{ #category : #helpers }
FFIFunctionResolutionTest >> pushReceiver [

stack push: #( self )
]

{ #category : #running }
Expand All @@ -20,6 +32,20 @@ FFIFunctionResolutionTest >> setUp [
stack := Stack new.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantFalseShouldSetConstantZeroLoader [

| argument |
argument := FFIValueArgument new
value: 'false';
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . 0 }.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantIntegerShouldSetConstantLoader [

Expand All @@ -31,5 +57,61 @@ FFIFunctionResolutionTest >> testResolveConstantIntegerShouldSetConstantLoader [
argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: 1.
self assert: stack pop equals: { #literal . 1}.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNULLShouldSetConstantNullLoader [

| argument |
argument := FFIValueArgument new
value: 'NULL';
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . ExternalAddress null}.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNilShouldSetConstantNullLoader [

| argument |
argument := FFIValueArgument new
value: 'nil';
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . ExternalAddress null }.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantSelfShouldSetConstantSelfLoader [

| argument |
argument := FFIValueArgument new
value: 'self';
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: #(#self).
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantTrueShouldSetConstantOneLoader [

| argument |
argument := FFIValueArgument new
value: 'true';
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . 1 }.
]
10 changes: 9 additions & 1 deletion src/UnifiedFFI/FFIValueArgument.class.st
Expand Up @@ -40,7 +40,15 @@ FFIValueArgument >> loader [

{ #category : #resolving }
FFIValueArgument >> resolveUsing: aResolver [


value = 'false' ifTrue: [
^ resolution := FFIConst value: 0 type: (aResolver resolveType: #bool) ].
value = 'true' ifTrue: [
^ resolution := FFIConst value: 1 type: (aResolver resolveType: #bool) ].
(value = 'nil' or: [ value = 'NULL' ]) ifTrue: [
^ resolution := FFIConst value: ExternalAddress null type: (aResolver resolveType: #'void *') ].
value = 'self' ifTrue: [
^ resolution := FFISelfArgument new ].
resolution := FFIConst value: value
]

Expand Down

0 comments on commit a28d091

Please sign in to comment.