Browse Source

kernel: Simplify class / trait creation.

Kernel API only creates or modifies in-place, throws if changes are too complex
(change of superclass or constructor).
There's Smalltalk-level IDE code for such changes.
Herbert Vojčík 7 years ago
parent
commit
e53d59da14
2 changed files with 9 additions and 21 deletions
  1. 8 11
      support/kernel-fundamentals.js
  2. 1 10
      support/kernel-language.js

+ 8 - 11
support/kernel-fundamentals.js

@@ -214,20 +214,17 @@ define(['./compatibility'], function () {
         this.buildBehaviorBody = function (pkgName, builder) {
             var pkg = st.packages[pkgName];
             if (!pkg) throw new Error("Missing package " + pkgName);
-            var behaviorBody = makeBehaviorBody(builder, pkg);
-            addBehaviorBody(behaviorBody);
-            return behaviorBody;
-        };
 
-        function makeBehaviorBody (builder, pkg) {
             var behaviorBody = globals.hasOwnProperty(builder.className) && globals[builder.className];
-            if (!behaviorBody) return builder.make(pkg);
-            if (builder.updateExisting(behaviorBody, pkg)) return behaviorBody;
+            if (behaviorBody) {
+                builder.updateExisting(behaviorBody, pkg);
+            } else {
+                behaviorBody = builder.make(pkg);
+            }
 
-            var rebuilder = builder.rebuilderForExisting(behaviorBody);
-            removeBehaviorBody(behaviorBody);
-            return makeBehaviorBody(rebuilder, pkg);
-        }
+            addBehaviorBody(behaviorBody);
+            return behaviorBody;
+        };
 
         function addBehaviorBody (behaviorBody) {
             globals[behaviorBody.className] = behaviorBody;

+ 1 - 10
support/kernel-language.js

@@ -101,10 +101,6 @@ define(['./compatibility'], function () {
                 },
                 updateExisting: function (trait, pkg) {
                     if (pkg) trait.pkg = pkg;
-                    return true;
-                },
-                rebuilderForExisting: function (trait) {
-                    return traitBuilder(className);
                 }
             };
         }
@@ -256,12 +252,7 @@ define(['./compatibility'], function () {
                     if (klass.superclass == superclass && (!fn || fn === klass.fn)) {
                         if (iVarNames) klass.iVarNames = iVarNames;
                         if (pkg) klass.pkg = pkg;
-                        return true;
-                    }
-                    return false;
-                },
-                rebuilderForExisting: function (klass) {
-                    return classBuilder(className, superclass, iVarNames || klass.iVarNames, fn);
+                    } else throw new Error("Incompatible change of class: " + klass.className);
                 }
             };
         }