Browse Source

Get rid of basicXxx in Package.

Herbert Vojčík 5 months 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 @@
20 20
   + stubToAtMost:
21 21
 + NonBooleanReceiver class >>
22 22
   + signalOn:
23
++ Package >>
24
+  + evalBlock
25
+  + evalBlock:
23 26
 + Package class >>
24 27
   + named:javaScriptDescriptor:
25 28
 + SmalltalkImage >>
@@ -30,6 +33,9 @@
30 33
 + UndefinedObject >>
31 34
   + ==
32 35
 
36
+- Package >>
37
+  - basicName:
38
+  - basicImports
33 39
 - ProtoObject >>
34 40
   - isSameInstanceAs:
35 41
 - ObjectTest >>

+ 11 - 6
src/Compiler-Core.js

@@ -656,20 +656,25 @@ var self=this,$self=this;
656 656
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
657 657
 return $core.withContext(function($ctx1) {
658 658
 //>>excludeEnd("ctx");
659
-return aPackage && aPackage.innerEval
660
-		? aPackage.innerEval(aString)
661
-		: eval(aString);
662
-return self;
659
+var $receiver;
660
+if(($receiver = aPackage) == null || $receiver.a$nil){
661
+return $self._eval_(aString);
662
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
663
+$ctx1.sendIdx["eval:"]=1;
664
+//>>excludeEnd("ctx");
665
+} else {
666
+return $recv(aPackage)._eval_(aString);
667
+}
663 668
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
664 669
 }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage},$globals.Compiler)});
665 670
 //>>excludeEnd("ctx");
666 671
 },
667 672
 //>>excludeStart("ide", pragmas.excludeIdeData);
668 673
 args: ["aString", "aPackage"],
669
-source: "eval: aString forPackage: aPackage\x0a\x09<inlineJS: 'return aPackage && aPackage.innerEval\x0a\x09\x09? aPackage.innerEval(aString)\x0a\x09\x09: eval(aString)'>",
674
+source: "eval: aString forPackage: aPackage\x0a\x09^ aPackage\x0a\x09\x09ifNil: [ self eval: aString ]\x0a\x09\x09ifNotNil: [ aPackage eval: aString ]",
670 675
 referencedClasses: [],
671 676
 //>>excludeEnd("ide");
672
-messageSends: []
677
+messageSends: ["ifNil:ifNotNil:", "eval:"]
673 678
 }),
674 679
 $globals.Compiler);
675 680
 

+ 3 - 3
src/Compiler-Core.st

@@ -176,9 +176,9 @@ eval: aString
176 176
 !
177 177
 
178 178
 eval: aString forPackage: aPackage
179
-	<inlineJS: 'return aPackage && aPackage.innerEval
180
-		? aPackage.innerEval(aString)
181
-		: eval(aString)'>
179
+	^ aPackage
180
+		ifNil: [ self eval: aString ]
181
+		ifNotNil: [ aPackage eval: aString ]
182 182
 !
183 183
 
184 184
 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
288 288
 ! !
289 289
 
290 290
 Object subclass: #Package
291
-	instanceVariableNames: 'transport imports dirty'
291
+	instanceVariableNames: 'evalBlock basicTransport name transport imports dirty organization'
292 292
 	package: 'Kernel-Infrastructure'!
293 293
 !Package commentStamp!
294 294
 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
341 341
 		tab; write: { 'transport: ('. self transport definition. ')' } ]
342 342
 !
343 343
 
344
+evalBlock
345
+	^ evalBlock
346
+!
347
+
348
+evalBlock: aBlock
349
+	evalBlock := aBlock
350
+!
351
+
344 352
 imports
345 353
 	^ imports ifNil: [
346
-		| parsed |
347
-		parsed := self importsFromJson: self basicImports.
348
-		self imports: parsed.
354
+		self imports: #().
349 355
 		imports ]
350 356
 !
351 357
 
@@ -364,36 +370,33 @@ importsDefinition
364 370
 !
365 371
 
366 372
 javaScriptDescriptor: anObject
367
-	| basicEval basicImports basicTransport |
373
+	| basicEval basicImports |
368 374
 
369 375
 	basicEval := (anObject at: 'innerEval' ifAbsent: [ nil asJavaScriptObject ]).
370 376
 	basicImports := (anObject at: 'imports' ifAbsent: [ #() ]).
371 377
 	basicTransport := (anObject at: 'transport' ifAbsent: []).
372 378
 			
373 379
 	self
374
-		basicAt: 'innerEval' put: basicEval;
375
-		basicAt: 'imports' put: basicImports;
376
-		basicAt: 'transport' put: basicTransport
380
+		evalBlock: basicEval;
381
+		imports: (self importsFromJson: basicImports)
377 382
 !
378 383
 
379 384
 name
380
-	<inlineJS: 'return self.pkgName'>
385
+	^ name
381 386
 !
382 387
 
383 388
 name: aString
384
-	self basicName: aString.
385
-	self beDirty
389
+	name := aString
386 390
 !
387 391
 
388 392
 organization
389
-	^ self basicAt: 'organization'
393
+	^ organization
390 394
 !
391 395
 
392 396
 transport
393 397
 	^ transport ifNil: [ 
394
-		transport := (PackageTransport fromJson: self basicTransport)
395
-			package: self;
396
-			yourself ]
398
+		self transport: (PackageTransport fromJson: self basicTransport).
399
+		transport ]
397 400
 !
398 401
 
399 402
 transport: aPackageTransport
@@ -479,12 +482,21 @@ traitCompositions
479 482
 	^ traitCompositions reject: [ :each | each isEmpty ]
480 483
 ! !
481 484
 
485
+!Package methodsFor: 'evaluating'!
486
+
487
+eval: aString
488
+	^ evalBlock
489
+		ifNotNil: [ evalBlock value: aString ]
490
+		ifNil: [ Compiler eval: aString ]
491
+! !
492
+
482 493
 !Package methodsFor: 'initialization'!
483 494
 
484 495
 initialize
485 496
 	super initialize.
486 497
 
487
-	self basicAt: 'organization' put: PackageOrganizer new.
498
+	organization := PackageOrganizer new.
499
+	evalBlock := nil.
488 500
 	dirty := nil.
489 501
 	imports := nil.
490 502
 	transport := nil
@@ -502,20 +514,10 @@ printOn: aStream
502 514
 
503 515
 !Package methodsFor: 'private'!
504 516
 
505
-basicImports
506
-	"Answer the imports literal JavaScript object as setup in the JavaScript file, if any"
507
-	
508
-	<inlineJS: 'return self.imports || []'>
509
-!
510
-
511
-basicName: aString
512
-	<inlineJS: 'self.pkgName = aString'>
513
-!
514
-
515 517
 basicTransport
516 518
 	"Answer the transport literal JavaScript object as setup in the JavaScript file, if any"
517 519
 	
518
-	<inlineJS: 'return self.transport'>
520
+	^ basicTransport
519 521
 !
520 522
 
521 523
 sortedImportsAsArray
@@ -599,7 +601,7 @@ named: aString javaScriptDescriptor: anObject
599 601
 
600 602
 new: aString
601 603
 	^ Package new
602
-		basicName: aString;
604
+		name: aString;
603 605
 		yourself
604 606
 ! !
605 607
 
@@ -985,7 +987,7 @@ renamePackage: packageName to: newName
985 987
 	| pkg |
986 988
 	pkg := self packageAt: packageName ifAbsent: [ self error: 'Missing package: ', packageName ].
987 989
 	self packageAt: newName ifAbsent: [ self error: 'Already exists a package called: ', newName ].
988
-	pkg name: newName.
990
+	pkg name: newName; beDirty.
989 991
 	self packageDictionary
990 992
 		at: newName put: pkg;
991 993
 		removeKey: packageName

+ 1 - 1
support/kernel-fundamentals.js

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