From 3da6871a3d17b60d2495ad96c62556cf0a07c3f1 Mon Sep 17 00:00:00 2001 From: Dany LE Date: Sat, 18 Dec 2021 02:02:16 +0100 Subject: [PATCH] initial comit --- .project | 3 ++ .properties | 3 ++ Diya/DiyaBaseObject.class.st | 5 ++ Diya/DiyaBoot.class.st | 34 ++++++++++++ Diya/ImageInitializer.class.st | 95 ++++++++++++++++++++++++++++++++++ Diya/package.st | 1 + 6 files changed, 141 insertions(+) create mode 100644 .project create mode 100644 .properties create mode 100644 Diya/DiyaBaseObject.class.st create mode 100644 Diya/DiyaBoot.class.st create mode 100644 Diya/ImageInitializer.class.st create mode 100644 Diya/package.st diff --git a/.project b/.project new file mode 100644 index 0000000..5e7754f --- /dev/null +++ b/.project @@ -0,0 +1,3 @@ +{ + 'srcDirectory' : '' +} \ No newline at end of file diff --git a/.properties b/.properties new file mode 100644 index 0000000..ad0471d --- /dev/null +++ b/.properties @@ -0,0 +1,3 @@ +{ + #format : #tonel +} \ No newline at end of file diff --git a/Diya/DiyaBaseObject.class.st b/Diya/DiyaBaseObject.class.st new file mode 100644 index 0000000..3e45c0a --- /dev/null +++ b/Diya/DiyaBaseObject.class.st @@ -0,0 +1,5 @@ +Class { + #name : #DiyaBaseObject, + #superclass : #Object, + #category : #'Diya-Core' +} diff --git a/Diya/DiyaBoot.class.st b/Diya/DiyaBoot.class.st new file mode 100644 index 0000000..3dc163c --- /dev/null +++ b/Diya/DiyaBoot.class.st @@ -0,0 +1,34 @@ +Class { + #name : #DiyaBoot, + #superclass : #DiyaBaseObject, + #category : #'Diya-Runtime' +} + +{ #category : #'system startup' } +DiyaBoot class >> getLoadedClasses [ + ^ SessionManager default startupList + collect: [ :c | + (c respondsTo: #registeredClass) + ifTrue: [ c registeredClass ] + ifFalse: [ c ] ] +] + +{ #category : #'class initialization' } +DiyaBoot class >> initialize [ + Smalltalk addToStartUpList: DiyaBoot +] + +{ #category : #'system startup' } +DiyaBoot class >> startUp: status [ + self getLoadedClasses + do: [ :c | + Transcript + show: c className; + cr ]. + Transcript show: self tickSinceStart; cr. +] + +{ #category : #'system startup' } +DiyaBoot class >> tickSinceStart [ + ^ self ffiCall: #( uint clock() ) module: 'libc.so.6'. +] diff --git a/Diya/ImageInitializer.class.st b/Diya/ImageInitializer.class.st new file mode 100644 index 0000000..aaeea85 --- /dev/null +++ b/Diya/ImageInitializer.class.st @@ -0,0 +1,95 @@ +Class { + #name : #ImageInitializer, + #superclass : #CommandLineHandler, + #category : #'Diya-Runtime' +} + +{ #category : #accessing } +ImageInitializer class >> commandName [ + ^'init' +] + +{ #category : #activation } +ImageInitializer >> activate [ + self initializeImage. + (self hasOption: 'save') + ifTrue: [ + self snap + ]. + ^ self exitSuccess +] + +{ #category : #'init-image' } +ImageInitializer >> getInitListExclude: loaded [ + ^ Smalltalk allClasses + select: [ :c | + (loaded includes: c) not + and: (c class selectors indexOf: #initialize ifAbsent: [ ]) isNotNil ] +] + +{ #category : #'init-image' } +ImageInitializer >> getLoadedClasses [ + | list | + list := (SessionManager default startupList + collect: [ :c | + (c respondsTo: #registeredClass) + ifTrue: [ c registeredClass ] + ifFalse: [ c ] ]) asSet. + list add: SourceFileArray. + list add: FFICompilerPlugin. + ^ list +] + +{ #category : #'init-image' } +ImageInitializer >> initializeImage [ + | initializeList retryList loaded | + retryList := Set new. + loaded := self getLoadedClasses. + self preloadSystem: loaded. + initializeList := self getInitListExclude: loaded. + initializeList + do: [ :c | + [ c initialize ] + on: Error + do: [ c = Cursor + ifFalse: [ retryList add: c ] ] ]. + retryList + do: [ :c | + Transcript + show: 'CLASS: ' , c asString , ' is not initialized'; + cr. + c initialize ]. + FFIMethodRegistry resetAll. + Smalltalk garbageCollect. + SourceFiles := SourceFileArray new. + Transcript show: 'Image initialized'; cr. +] + +{ #category : #'init-image' } +ImageInitializer >> preloadSystem: loaded [ + "load unicode" + |udata ucase base| + base := Smalltalk imageDirectory pathString. + udata := base,'/UnicodeData.txt'. + ucase := base,'/CaseFolding-8.0.0.txt'. + loaded add: (TextConstants initialize; yourself ). + loaded add: (InflateStream initialize; yourself ). + loaded add: (FastInflateStream initialize; yourself ). + EncodedCharSet initialize. + Unicode initializeTagConstants. + Unicode + parseUnicodeDataFrom: (ZnCharacterReadStream on: (File named: udata ) readStream encoding: 'utf8'); + parseCaseMappingFrom: (ZnCharacterReadStream on: (File named: ucase ) readStream encoding: 'utf8'). + Character characterSet: Unicode. + ByteTextConverter initialize. + CombinedChar parseCompositionMappingFrom: (ZnCharacterReadStream on: (File named: udata ) readStream encoding: 'utf8'). +] + +{ #category : #activation } +ImageInitializer >> snap [ + |pkg| + self class removeFromSystem. + Smalltalk garbageCollect. + Smalltalk snapshot: true andQuit: false. + +] diff --git a/Diya/package.st b/Diya/package.st new file mode 100644 index 0000000..da3e8bb --- /dev/null +++ b/Diya/package.st @@ -0,0 +1 @@ +Package { #name : #Diya }