Browse Source

Get rid of basicXxx in Package.

Herbert Vojčík 1 year ago
parent
commit
245b334405
6 changed files with 163 additions and 164 deletions
  1. 6 0
      API-CHANGES.txt
  2. 11 6
      src/Compiler-Core.js
  3. 3 3
      src/Compiler-Core.st
  4. 111 125
      src/Kernel-Infrastructure.js
  5. 31 29
      src/Kernel-Infrastructure.st
  6. 1 1
      support/kernel-fundamentals.js

+ 6 - 0
API-CHANGES.txt

@@ -20,6 +20,9 @@
   + stubToAtMost:
 + NonBooleanReceiver class >>
   + signalOn:
++ Package >>
+  + evalBlock
+  + evalBlock:
 + Package class >>
   + named:javaScriptDescriptor:
 + SmalltalkImage >>
@@ -30,6 +33,9 @@
 + UndefinedObject >>
   + ==
 
+- Package >>
+  - basicName:
+  - basicImports
 - ProtoObject >>
   - isSameInstanceAs:
 - ObjectTest >>

+ 11 - 6
src/Compiler-Core.js

@@ -656,20 +656,25 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return aPackage && aPackage.innerEval
-		? aPackage.innerEval(aString)
-		: eval(aString);
-return self;
+var $receiver;
+if(($receiver = aPackage) == null || $receiver.a$nil){
+return $self._eval_(aString);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["eval:"]=1;
+//>>excludeEnd("ctx");
+} else {
+return $recv(aPackage)._eval_(aString);
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage},$globals.Compiler)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString", "aPackage"],
-source: "eval: aString forPackage: aPackage\x0a\x09<inlineJS: 'return aPackage && aPackage.innerEval\x0a\x09\x09? aPackage.innerEval(aString)\x0a\x09\x09: eval(aString)'>",
+source: "eval: aString forPackage: aPackage\x0a\x09^ aPackage\x0a\x09\x09ifNil: [ self eval: aString ]\x0a\x09\x09ifNotNil: [ aPackage eval: aString ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["ifNil:ifNotNil:", "eval:"]
 }),
 $globals.Compiler);
 

+ 3 - 3
src/Compiler-Core.st

@@ -176,9 +176,9 @@ eval: aString
 !
 
 eval: aString forPackage: aPackage
-	<inlineJS: 'return aPackage && aPackage.innerEval
-		? aPackage.innerEval(aString)
-		: eval(aString)'>
+	^ aPackage
+		ifNil: [ self eval: aString ]
+		ifNotNil: [ aPackage eval: aString ]
 !
 
 evaluateExpression: aString

File diff suppressed because it is too large
+ 111 - 125
src/Kernel-Infrastructure.js


+ 31 - 29
src/Kernel-Infrastructure.st

@@ -288,7 +288,7 @@ initialize
 ! !
 
 Object subclass: #Package
-	instanceVariableNames: 'transport imports dirty'
+	instanceVariableNames: 'evalBlock basicTransport name transport imports dirty organization'
 	package: 'Kernel-Infrastructure'!
 !Package commentStamp!
 I am similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Amber does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
@@ -341,11 +341,17 @@ definition
 		tab; write: { 'transport: ('. self transport definition. ')' } ]
 !
 
+evalBlock
+	^ evalBlock
+!
+
+evalBlock: aBlock
+	evalBlock := aBlock
+!
+
 imports
 	^ imports ifNil: [
-		| parsed |
-		parsed := self importsFromJson: self basicImports.
-		self imports: parsed.
+		self imports: #().
 		imports ]
 !
 
@@ -364,36 +370,33 @@ importsDefinition
 !
 
 javaScriptDescriptor: anObject
-	| basicEval basicImports basicTransport |
+	| basicEval basicImports |
 
 	basicEval := (anObject at: 'innerEval' ifAbsent: [ nil asJavaScriptObject ]).
 	basicImports := (anObject at: 'imports' ifAbsent: [ #() ]).
 	basicTransport := (anObject at: 'transport' ifAbsent: []).
 			
 	self
-		basicAt: 'innerEval' put: basicEval;
-		basicAt: 'imports' put: basicImports;
-		basicAt: 'transport' put: basicTransport
+		evalBlock: basicEval;
+		imports: (self importsFromJson: basicImports)
 !
 
 name
-	<inlineJS: 'return self.pkgName'>
+	^ name
 !
 
 name: aString
-	self basicName: aString.
-	self beDirty
+	name := aString
 !
 
 organization
-	^ self basicAt: 'organization'
+	^ organization
 !
 
 transport
 	^ transport ifNil: [ 
-		transport := (PackageTransport fromJson: self basicTransport)
-			package: self;
-			yourself ]
+		self transport: (PackageTransport fromJson: self basicTransport).
+		transport ]
 !
 
 transport: aPackageTransport
@@ -479,12 +482,21 @@ traitCompositions
 	^ traitCompositions reject: [ :each | each isEmpty ]
 ! !
 
+!Package methodsFor: 'evaluating'!
+
+eval: aString
+	^ evalBlock
+		ifNotNil: [ evalBlock value: aString ]
+		ifNil: [ Compiler eval: aString ]
+! !
+
 !Package methodsFor: 'initialization'!
 
 initialize
 	super initialize.
 
-	self basicAt: 'organization' put: PackageOrganizer new.
+	organization := PackageOrganizer new.
+	evalBlock := nil.
 	dirty := nil.
 	imports := nil.
 	transport := nil
@@ -502,20 +514,10 @@ printOn: aStream
 
 !Package methodsFor: 'private'!
 
-basicImports
-	"Answer the imports literal JavaScript object as setup in the JavaScript file, if any"
-	
-	<inlineJS: 'return self.imports || []'>
-!
-
-basicName: aString
-	<inlineJS: 'self.pkgName = aString'>
-!
-
 basicTransport
 	"Answer the transport literal JavaScript object as setup in the JavaScript file, if any"
 	
-	<inlineJS: 'return self.transport'>
+	^ basicTransport
 !
 
 sortedImportsAsArray
@@ -599,7 +601,7 @@ named: aString javaScriptDescriptor: anObject
 
 new: aString
 	^ Package new
-		basicName: aString;
+		name: aString;
 		yourself
 ! !
 
@@ -985,7 +987,7 @@ renamePackage: packageName to: newName
 	| pkg |
 	pkg := self packageAt: packageName ifAbsent: [ self error: 'Missing package: ', packageName ].
 	self packageAt: newName ifAbsent: [ self error: 'Already exists a package called: ', newName ].
-	pkg name: newName.
+	pkg name: newName; beDirty.
 	self packageDictionary
 		at: newName put: pkg;
 		removeKey: packageName

+ 1 - 1
support/kernel-fundamentals.js

@@ -161,7 +161,7 @@ define(['./compatibility' /* TODO remove */], function () {
             var traitOrClass = globals.hasOwnProperty(builder.className) && globals[builder.className];
             if (traitOrClass) {
                 if (!traitOrClass.pkg) throw new Error("Updated trait or class must have package: " + traitOrClass.className);
-                if (traitOrClass.pkg.pkgName !== pkgName) throw new Error("Incompatible cross-package update of trait or class: " + traitOrClass.className);
+                // if (traitOrClass.pkg.pkgName !== pkgName) throw new Error("Incompatible cross-package update of trait or class: " + traitOrClass.className);
                 builder.updateExisting(traitOrClass);
             } else {
                 traitOrClass = builder.make();