Skip to content

Commit

Permalink
Move interop implementation into the image
Browse files Browse the repository at this point in the history
This makes it possible to properly support higher-level data structures, such as OrderedCollections, DateAndTime, and Exceptions.
  • Loading branch information
fniephaus committed Mar 5, 2021
1 parent 2a82afa commit 6df3b81
Show file tree
Hide file tree
Showing 190 changed files with 871 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*TruffleSqueak-Core-executable
interopExecute: arguments
^ (self numArgs == arguments size)
ifTrue: [ self valueWithArguments: arguments ]
ifFalse: [ "TODO: throw ArityException" nil ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-executable
interopGetExecutableName
^ self asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-executable
interopHasExecutableName
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-executable
interopIsExecutable
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"class" : {
},
"instance" : {
"interopExecute:" : "fn 3/4/2021 11:52",
"interopGetExecutableName" : "fn 11/24/2020 14:01",
"interopHasExecutableName" : "fn 11/24/2020 14:01",
"interopIsExecutable" : "fn 11/24/2020 13:50" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "BlockClosure" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-boolean
interopIsBoolean
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"interopIsBoolean" : "fn 3/4/2021 11:12" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Boolean" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*TruffleSqueak-Core-arrays
interopReadArrayElement: index
| value |
value := self byteAt: index + 1.
^ value <= 128
ifTrue: [ value ]
ifFalse: [ value - 256 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"interopReadArrayElement:" : "fn 3/5/2021 12:48" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "ByteArray" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-meta-object
interopGetMetaQualifiedName
^ self asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-meta-object
interopGetMetaSimpleName
^ self asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*TruffleSqueak-Core-instantiable
interopInstantiate: arguments
^ arguments isEmpty
ifTrue: [ self new ]
ifFalse: [ | arg |
arg := arguments first.
(arg isInteger and: [ arg isLarge not ])
ifTrue: [ self new: arg ]
ifFalse: [ self new ]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-instantiable
interopIsInstantiable
^ self isImmediateClass not
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-meta-object
interopIsMetaInstance: instance
^ instance isKindOf: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-meta-object
interopIsMetaObject
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"class" : {
},
"instance" : {
"interopGetMetaQualifiedName" : "fn 11/24/2020 12:54",
"interopGetMetaSimpleName" : "fn 11/24/2020 12:54",
"interopInstantiate:" : "fn 11/24/2020 13:36",
"interopIsInstantiable" : "fn 11/24/2020 13:36",
"interopIsMetaInstance:" : "fn 11/24/2020 12:55",
"interopIsMetaObject" : "fn 11/24/2020 16:01" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Class" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*TruffleSqueak-Core
interopAsDate
^ Interop asHostObject: ((Java type: 'java.time.LocalDate')
ofEpochDay: start julianDayNumber - start posixEpochJulianDays)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core
interopIsDate
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"interopAsDate" : "fn 3/4/2021 16:53",
"interopIsDate" : "fn 11/20/2020 16:45" } }
2 changes: 2 additions & 0 deletions src/TruffleSqueak-Core.package/Date.extension/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Date" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopAsDate
^ self asDate interopAsDate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopAsInstant
^ Interop asHostObject: ((Java type: 'java.time.Instant') ofEpochSecond: self asUnixTime)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*TruffleSqueak-Core-date and time
interopAsTime
^ Interop asHostObject: ((Java type: 'java.time.LocalTime')
ofNanoOfDay: self asNanoSeconds)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopAsTimeZone
^ self class localTimeZone interopAsTimeZone
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopIsDate
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopIsTime
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopIsTimeZone
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"class" : {
},
"instance" : {
"interopAsDate" : "fn 3/4/2021 16:28",
"interopAsInstant" : "fn 3/4/2021 16:19",
"interopAsTime" : "fn 3/4/2021 17:16",
"interopAsTimeZone" : "fn 3/4/2021 16:17",
"interopIsDate" : "fn 11/20/2020 17:16",
"interopIsTime" : "fn 11/20/2020 17:16",
"interopIsTimeZone" : "fn 11/20/2020 17:16" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "DateAndTime" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*TruffleSqueak-Core-duration
interopAsDuration
^ Interop asHostObject: ((Java type: 'java.time.Duration')
ofSeconds: seconds nanoAdjustment: nanos)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-duration
interopIsDuration
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"interopAsDuration" : "fn 3/4/2021 13:08",
"interopIsDuration" : "fn 11/24/2020 12:39" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Duration" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopGetExceptionMessage
^ messageText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopGetExceptionType
^ Interop runtimeExceptionType
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopHasExceptionMessage
^ messageText ~~ nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopIsException
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopThrowException
^ self signal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"class" : {
},
"instance" : {
"interopGetExceptionMessage" : "fn 11/24/2020 12:45",
"interopGetExceptionType" : "fn 3/4/2021 12:03",
"interopHasExceptionMessage" : "fn 11/24/2020 12:45",
"interopIsException" : "fn 11/24/2020 12:42",
"interopThrowException" : "fn 11/24/2020 12:43" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Exception" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-boolean
interopAsBoolean
^ (Java type: 'java.lang.Boolean') FALSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"interopAsBoolean" : "fn 3/4/2021 11:12" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "False" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
asHostObject: aGuestObject
<primitive: 'primitiveToHostObject' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
asJavaInteger: aString
<primitive: 'primitiveToJavaInteger' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
asJavaString: aString
<primitive: 'primitiveToJavaString' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
asTriState: aBoolean
<primitive: 'primitiveToTriState' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
parseExceptionType
<primitive: 'primitiveGetParseExceptionType' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitives internal
runtimeExceptionType
<primitive: 'primitiveGetRuntimeExceptionType' module: 'PolyglotPlugin'>
self primitiveFailed
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
"asDate:" : "fn 12/12/2019 20:42",
"asDouble:" : "fn 11/11/2019 22:10",
"asDuration:" : "fn 12/12/2019 22:40",
"asHostObject:" : "fn 3/4/2021 13:08",
"asInstant:" : "fn 12/12/2019 22:54",
"asJavaInteger:" : "fn 3/4/2021 11:46",
"asJavaString:" : "fn 3/4/2021 11:46",
"asLong:" : "fn 11/11/2019 22:10",
"asPointer:" : "fn 11/11/2019 22:10",
"asScope:" : "fn 11/12/2020 11:18",
"asString:" : "fn 11/11/2019 22:10",
"asTime:" : "fn 12/12/2019 20:42",
"asTimeZone:" : "fn 12/12/2019 23:09",
"asTriState:" : "fn 3/4/2021 11:55",
"execute:with:" : "fn 12/3/2019 11:40",
"fitsInDouble:" : "fn 11/11/2019 21:58",
"fitsInLong:" : "fn 11/11/2019 21:58",
Expand Down Expand Up @@ -86,10 +90,12 @@
"isString:" : "fn 11/11/2019 22:02",
"isTime:" : "fn 12/12/2019 20:42",
"isTimeZone:" : "fn 12/12/2019 23:09",
"parseExceptionType" : "fn 3/4/2021 12:04",
"readArrayElement:index:" : "fn 12/3/2019 11:53",
"readMember:member:" : "fn 2/11/2021 12:32",
"removeArrayElement:index:" : "fn 12/3/2019 11:53",
"removeMember:member:" : "fn 12/3/2019 11:55",
"runtimeExceptionType" : "fn 3/4/2021 12:03",
"throwException:" : "fn 12/12/2019 20:57",
"toDisplayString:" : "fn 5/6/2020 14:49",
"writeArrayElement:index:value:" : "fn 12/3/2019 11:57",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-number
interopIsNumber
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"interopIsNumber" : "fn 11/24/2020 12:35" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Number" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-exception
interopGetExceptionType
^ Interop parseExceptionType
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"interopGetExceptionType" : "fn 3/4/2021 12:04" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "NumberParserError" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*TruffleSqueak-Core
interopMemberToSelector: aMember
| selectorName selectorNameVariant currentClass |
selectorName := aMember asString copyReplaceAll: '_' with: ':'.
selectorNameVariant := (selectorName, ':').
currentClass := self.
[ currentClass isNil ] whileFalse: [
currentClass selectors
detect: [ :ea | ea = selectorName or: [ ea = selectorNameVariant ] ]
ifFound: [ :s | ^ s ].
currentClass := currentClass superclass ].
^(NotFound object: aMember) signal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*TruffleSqueak-Core
interopSelectorToMember: aSelector
| member |
member := aSelector asString.
member last = $: ifTrue: [ member := member allButLast copyReplaceAll: ':' with: '_' ].
^ member
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-boolean
interopAsBoolean
self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-number
interopAsByte
self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-date and time
interopAsDate
self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*TruffleSqueak-Core-number
interopAsDouble
self subclassResponsibility
Loading

0 comments on commit 6df3b81

Please sign in to comment.