Skip to content

Feat/improving ffi #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: pharo-12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f90f8d
- Adding primitive that extracts the pointer to the content of the ob…
tesonep Jan 13, 2025
bd814d4
Co-authored-by: doste <[email protected]>
tesonep Jan 23, 2025
81fcdbf
- Adding tests for the FFI calls
tesonep Feb 3, 2025
f374b68
Adding pragma to mark functions that need all localized variables to …
tesonep Feb 5, 2025
dbfb5fa
Adding externenalization for supporting functions that require all lo…
tesonep Feb 5, 2025
4a7246f
- Fixing problems with localized variables
tesonep Feb 5, 2025
3d1fb90
- Adding tests
tesonep Mar 1, 2025
ee88308
Adding required extensions to the InstructionClient so the StackDepth…
tesonep Mar 3, 2025
a81e552
Improving tests to handle correctly the arguments in a FFI test
tesonep Mar 18, 2025
9212a66
Handling arguments for X64 SystemV
tesonep Mar 18, 2025
e405146
Implementing the fetch of arguments in the superclass
tesonep Mar 20, 2025
42edeee
Fixing accessing to floating point registers
tesonep Mar 20, 2025
d397a36
Extending the unicorn simulator to handle the different ABIs of X64
tesonep Mar 20, 2025
c12852d
- Making it work in Windows ABI
tesonep Mar 21, 2025
b2ead2b
Adding accessors for registers in calling convention
tesonep Mar 21, 2025
9b96b5c
Updating versions for OSX (ARM / Intel)
tesonep Mar 25, 2025
27c4244
Merge branch 'new-lib-versions-p12' into feat/improving-FFI
tesonep Mar 25, 2025
8a40d5a
Merge branch 'pharo-12' into new-lib-versions-p12
tesonep Mar 25, 2025
b1011e5
Fixing Freetype2 version
tesonep Mar 25, 2025
236cfc9
Merge branch 'new-lib-versions-p12' into feat/improving-FFI
tesonep Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions cmake/importCairo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ if (BUILD_BUNDLE)
add_third_party_dependency("libpng-1.6.37")
endif()
elseif(OSX)
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
add_third_party_dependency("pixman-0.40.0")
add_third_party_dependency("cairo-1.17.4")
add_third_party_dependency("libpng-1.6.37")
else()
add_third_party_dependency("pixman-0.40.0")
add_third_party_dependency("cairo-1.17.4")
add_third_party_dependency("libpng-1.6.37")
endif()
add_third_party_dependency("pixman-0.44.2")
add_third_party_dependency("cairo-1.18.4")
add_third_party_dependency("libpng-1.6.47")
else() #Linux
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
add_third_party_dependency("pixman-0.40.0")
Expand Down
14 changes: 5 additions & 9 deletions cmake/importFreetype2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ function(download_Freetype)
add_third_party_dependency("harfbuzz-5.3.1")
endif()
elseif(OSX)
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
add_third_party_dependency("freetype-2.12.1")
add_third_party_dependency("fontconfig-2.13.1")
add_third_party_dependency("harfbuzz-5.3.1")
else()
add_third_party_dependency("freetype-2.12.1")
add_third_party_dependency("fontconfig-2.13.1")
add_third_party_dependency("harfbuzz-5.3.1")
endif()
add_third_party_dependency("freetype-2.13.3")
add_third_party_dependency("fontconfig-2.16.0")
add_third_party_dependency("harfbuzz-11.0.0")
add_third_party_dependency("bzip2-1.0.9")
add_third_party_dependency("zlib-1.3.1")
else() # linuxes, only for ARM
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
add_third_party_dependency("freetype-2.10.0")
Expand Down
4 changes: 1 addition & 3 deletions cmake/importLibGit2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ function(download_git2)
add_third_party_dependency("zlib-1.2.13")
add_third_party_dependency("ssh2-1.10.0")
elseif(OSX)
add_third_party_dependency("libgit2-1.6.4")
add_third_party_dependency("openssl-1.1.1k")
add_third_party_dependency("libssh2-1.10.0")
add_third_party_dependency("libgit2-1.9.0")
else() # LINUX
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
add_third_party_dependency("libgit2-1.4.4")
Expand Down
8 changes: 2 additions & 6 deletions cmake/importSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ function(download_SDL2)
add_third_party_dependency("SDL2-2.24.1")
endif()
elseif(OSX)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
add_third_party_dependency("SDL2-2.30.6")
else()
add_third_party_dependency("SDL2-2.30.6")
endif()
add_third_party_dependency("SDL2-2.32.2")
else() #LINUX
If(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
add_third_party_dependency("SDL2-2.0.14")
Expand All @@ -40,7 +36,7 @@ function(build_SDL2)
include(cmake/DownloadProject.cmake)
download_project(PROJ SDL2
GIT_REPOSITORY https://github.com/pharo-project/SDL2.git
GIT_TAG "v2.30.6"
GIT_TAG "v2.32.2"
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
add_subdirectory(${SDL2_SOURCE_DIR} ${SDL2_BINARY_DIR} EXCLUDE_FROM_ALL)
Expand Down
89 changes: 66 additions & 23 deletions smalltalksrc/Melchor/MLLocalizationTestCase.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ MLLocalizationTestCase >> testAutoLocalizeVariableDoesNotLineariseUnnecessarySta

printedString := String streamContents: [ :str | (block asCASTIn: ccg) prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
nonInlinedMethodNotUsingAutolocalizedVariables(nonInlinedMethodNotUsingAutolocalizedVariables());
}'
]
Expand All @@ -184,7 +184,7 @@ MLLocalizationTestCase >> testAutoLocalizeVariableExternalizesBeforeReturnRefere
printedString := String streamContents: [ :str |
((TStatementListNode statements: (interpretMethod statements last: 2)) asCASTIn: ccg)
prettyPrintOn: str ].
self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
local_autoLocalizedVariable += 1;
{
autoLocalizedVariable = local_autoLocalizedVariable;
Expand Down Expand Up @@ -240,14 +240,50 @@ MLLocalizationTestCase >> testAutoLocalizeVariableReplacesByLocalOnInline [
self assert: (variableNode isVariable and: [ variableNode name = #local_autoLocalizedVariable ]).
]

{ #category : 'tests - localisation' }
MLLocalizationTestCase >> testBytecodeUsingExternalizeAllVariables [

| interpretMethod cast printedString linearizedBlock |

MockLocalizationInterpreterMock initializeWithBytecodeUsingExternalizeAllVariables.

interpretMethod := self applyLocalizationTo: #interpretWithSeveralVariablesToLocalize.

"Assert that the send node is preceded by variable externalization"
linearizedBlock := self linearizedBlockOfCaseMethod: interpretMethod.
cast := linearizedBlock asCASTIn: ccg.

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

"The if statement should not be wrapped. Only the inner statements"
self assert: printedString trimBoth equals:
'{
{
autoLocalizedVariable = local_autoLocalizedVariable;
autoLocalizedVariable1 = local_autoLocalizedVariable1;
autoLocalizedVariable2 = local_autoLocalizedVariable2;
autoLocalizedVariable3 = local_autoLocalizedVariable3;
autoLocalizedVariable4 = local_autoLocalizedVariable4;
aMethodHavingExternalizeAllVariables();
local_autoLocalizedVariable = autoLocalizedVariable;
local_autoLocalizedVariable1 = autoLocalizedVariable1;
local_autoLocalizedVariable2 = autoLocalizedVariable2;
local_autoLocalizedVariable3 = autoLocalizedVariable3;
local_autoLocalizedVariable4 = autoLocalizedVariable4;
}
}
' trimBoth
]

{ #category : 'tests - free variables' }
MLLocalizationTestCase >> testCollectFreeVariablesOfMethodWithManyCallers [

| collector |
collector := SLCallGraphFreeVariableCollector codeGenerator: ccg.

ccg addClass: MockLocalizationInterpreterMock.
ccg prepareMethods.

"
variableToLocalize should be considered free in the entire transitive call graph.

Expand All @@ -259,10 +295,17 @@ MLLocalizationTestCase >> testCollectFreeVariablesOfMethodWithManyCallers [
"
collector startFromSelector: #methodWithDiamond.

self assert: ((collector freeVariablesUsedByMethodNamed: #bytecodeUsingLocalizedVariable) includes: #variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed: #methodCallingBytecodeUsingLocalizedVariable) includes: #variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed: #methodCallingBytecodeUsingLocalizedVariable2) includes: #variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed: #methodWithDiamond) includes: #variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed:
#bytecodeUsingLocalizedVariable) includes: #variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed:
#methodCallingBytecodeUsingLocalizedVariable) includes:
#variableToLocalize).
self assert: ((collector freeVariablesUsedByMethodNamed:
#methodCallingBytecodeUsingLocalizedVariable2) includes:
#variableToLocalize).
self assert:
((collector freeVariablesUsedByMethodNamed: #methodWithDiamond)
includes: #variableToLocalize)
]

{ #category : 'tests - localisation' }
Expand All @@ -277,7 +320,7 @@ MLLocalizationTestCase >> testExternalEscapingAsArgument [

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals:
self assert: printedString trimBoth equals:
'{
sqInt t0;

Expand All @@ -303,7 +346,7 @@ MLLocalizationTestCase >> testExternalEscapingAsArgumentOfExternalCall [

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
sqInt t0;

{
Expand Down Expand Up @@ -335,7 +378,7 @@ MLLocalizationTestCase >> testExternalEscapingSendNodeInInlinedMethod [

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
autoLocalizedVariable = local_autoLocalizedVariable;
autoLocalizedVariable1 = local_autoLocalizedVariable1;
foo2();
Expand All @@ -357,7 +400,7 @@ MLLocalizationTestCase >> testExternalEscapingSendNodeShouldBeTranslatedWithExte

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
local_autoLocalizedVariable += 1;
{
autoLocalizedVariable = local_autoLocalizedVariable;
Expand All @@ -380,7 +423,7 @@ MLLocalizationTestCase >> testExternalEscapingStatementInConditionalBody [
printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

"The if statement should not be wrapped. Only the inner statements"
self assert: printedString equals:
self assert: printedString trimBoth equals:
'{
if (1) {
sqInt t0;
Expand Down Expand Up @@ -411,7 +454,7 @@ MLLocalizationTestCase >> testExternalPerform [

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals:
self assert: printedString trimBoth trimBoth equals:
'{
{
autoLocalizedVariable = local_autoLocalizedVariable;
Expand All @@ -433,7 +476,7 @@ MLLocalizationTestCase >> testExternalSendNodeExternalizeAndInternalizeOnlyNeede
cast := linearizedBlock asCASTIn: ccg.

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].
self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
local_autoLocalizedVariable += 1;
{
autoLocalizedVariable = local_autoLocalizedVariable;
Expand All @@ -460,7 +503,7 @@ MLLocalizationTestCase >> testExternalSendNodeShouldBeTranslatedWithExternalizat
cast := linearizedBlock asCASTIn: ccg.
printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
sqInt t0;

{
Expand Down Expand Up @@ -499,8 +542,8 @@ MLLocalizationTestCase >> testLinearizeAndInsideValueIf [
t0
ifTrue: [ t0 := self condition ]
ifFalse: [ t0 := t0 ] ].
overflow := t0.
^ overflow'.
_overflow := t0.
^ _overflow'.
]

{ #category : 'tests - linearization' }
Expand Down Expand Up @@ -532,8 +575,8 @@ MLLocalizationTestCase >> testLinearizeAndInsideValueIfNestedTwice [
t0
ifTrue: [ t0 := self condition ]
ifFalse: [ t0 := t0 ] ] ].
overflow := t0.
^ overflow'.
_overflow := t0.
^ _overflow'.
]

{ #category : 'tests - linearization' }
Expand Down Expand Up @@ -640,7 +683,7 @@ MLLocalizationTestCase >> testLinearizeNestedCallsWithAssignment [
arguments: { TVariableNode named: 't0' }))).
self assert: (replacementBlock statements third
isSameAs: (TAssignmentNode
variableNamed: 'foo'
variableNamed: '_foo'
expression: (TVariableNode named: 't1')))
]

Expand Down Expand Up @@ -728,8 +771,8 @@ MLLocalizationTestCase >> testLinearizeReceiverOfConditionalAndAssigned [
self assert: replacementBlock isRewrittenAs: '
t0 := self nonInlinedMethodUsingAutolocalizedVariable.
t0 ifTrue: [ t1 := self nonInlinedMethodUsingAutolocalizedVariable ] ifFalse: [ t1 := t0 ].
var := t1.
var ifTrue: [nil]'.
_var := t1.
_var ifTrue: [nil]'.
]

{ #category : 'tests - linearization' }
Expand Down Expand Up @@ -883,7 +926,7 @@ MLLocalizationTestCase >> testNoExternalSendNodeOnSafeExternalCall [

printedString := String streamContents: [ :str | cast prettyPrintOn: str ].

self assert: printedString equals: '{
self assert: printedString trimBoth equals: '{
nonInlinedMethodNotUsingAutolocalizedVariables((local_autoLocalizedVariable += 1));
}'
]
23 changes: 23 additions & 0 deletions smalltalksrc/Melchor/MockLocalizationInterpreterMock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ MockLocalizationInterpreterMock class >> initializeWithAutoLocalizedVariableOnly
)
]

{ #category : 'initialization' }
MockLocalizationInterpreterMock class >> initializeWithBytecodeUsingExternalizeAllVariables [

BytecodeTable := Array new: 1.
self table: BytecodeTable from:
#(
( 0 bytecodeUsingExternalizeAllVariables)
)
]

{ #category : 'initialization' }
MockLocalizationInterpreterMock class >> initializeWithEscapingCall [

Expand Down Expand Up @@ -152,6 +162,13 @@ MockLocalizationInterpreterMock class >> initializeWithoutAutoLocalizedVariable
)
]

{ #category : 'interpreter shell' }
MockLocalizationInterpreterMock >> aMethodHavingExternalizeAllVariables [

<inline: false>
<externalizeAllVariables>
]

{ #category : 'interpreter shell' }
MockLocalizationInterpreterMock >> bytecodeInliningSharedMethod [

Expand Down Expand Up @@ -183,6 +200,12 @@ MockLocalizationInterpreterMock >> bytecodeUsingComplexAssert [
self assert: (self foo or: [ self bar and: [ self fum ] ])
]

{ #category : 'interpreter shell' }
MockLocalizationInterpreterMock >> bytecodeUsingExternalizeAllVariables [

self aMethodHavingExternalizeAllVariables
]

{ #category : 'interpreter shell' }
MockLocalizationInterpreterMock >> bytecodeUsingExternalizedAutoLocalizedVariable [

Expand Down
8 changes: 8 additions & 0 deletions smalltalksrc/Melchor/VMClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,14 @@ VMClass >> logDebug: aFormat _: aParameter [
(aFormat printf: { aParameter }) traceCr
]

{ #category : 'logging' }
VMClass >> logDebug: aFormat _: aParameter _:anotherParam [

<doNotGenerate>

(aFormat printf: { aParameter. anotherParam }) traceCr
]

{ #category : 'debug support' }
VMClass >> logError: aMessage [

Expand Down
1 change: 1 addition & 0 deletions smalltalksrc/Melchor/VMObjectIndices.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Class {
'SelectorCannotReturn',
'SelectorCounterTripped',
'SelectorDoesNotUnderstand',
'SelectorInvalidFFICall',
'SelectorMustBeBoolean',
'SelectorRunWithIn',
'SelectorSistaTrap',
Expand Down
3 changes: 2 additions & 1 deletion smalltalksrc/Slang/CCodeGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5274,7 +5274,8 @@ CCodeGenerator >> validateLocalizationOfGlobals: varList exceptMethod: methodNam
methodFreeVariables := meth freeVariableReferences asSet.
localizationCandidates do: [ :candidate |
(methodFreeVariables includes: candidate)
ifTrue: [ variablesInConflict add: candidate ] ] ] ].
ifTrue: [
variablesInConflict add: candidate ] ] ] ].

variablesInConflict ifNotEmpty: [ | errorMessage |
errorMessage := String streamContents: [ :stream |
Expand Down
6 changes: 5 additions & 1 deletion smalltalksrc/Slang/SLAutomaticLocalization.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ SLAutomaticLocalization >> autoLocalizationOfVariablesIn: aSelector withVariable
(replacementList isNil or: [ replacementList isEmpty ]) ifTrue: [ ^ self ].

codeGenerator currentMethod: m.

replacementDict := (replacementList collect: [ :asso |
asso key -> (TVariableNode named: asso value) ]) asDictionary.

callgraphVariableCollector candidateVariables: replacementDict keys.

"Replace all localized variables by their localized versions"
m parseTree
bindVariablesIn: replacementDict.
Expand Down Expand Up @@ -107,6 +110,7 @@ SLAutomaticLocalization >> codeGenerator: anObject [

codeGenerator := anObject.
callgraphVariableCollector := SLCallGraphFreeVariableCollector codeGenerator: codeGenerator

]

{ #category : 'applying' }
Expand Down
Loading