Przeglądaj źródła

clean generated code for record constructor

Vladislav Folts 10 lat temu
rodzic
commit
43b8f96a05

BIN
bin/compiled.zip


+ 10 - 6
build.py

@@ -197,15 +197,19 @@ def build_html(options):
         with open(build_version_path, 'w') as f:
             f.write(version)
 
-def pre_commit_check(options):
-    bin = os.path.join(root, 'bin')
-    run_tests(bin)
+def recompile_with_replace(bin, skip_tests = False):
     recompiled = recompile(bin)
-    run_tests(recompiled)
+    if not skip_tests:
+        run_tests(recompiled)
     
     print('%s -> %s' % (recompiled, bin))
     cleanup(bin)
     os.rename(recompiled, bin)
+
+def pre_commit_check(options):
+    bin = os.path.join(root, 'bin')
+    run_tests(bin)
+    recompile_with_replace(bin)
     
     print('packaging compiled js to %s...' % package.root)
     package.pack()
@@ -227,11 +231,11 @@ class self_recompile_target(object):
 
     @staticmethod
     def setup_options(parser):
-        pass
+        parser.add_option('--skip-tests', help='do not run test after recompile')
 
     def __init__(self, options):
         bin = os.path.join(root, 'bin')
-        recompile(bin)
+        recompile_with_replace(bin, options.skip_tests)
 
 class html_target(object):
     name = 'html'

+ 11 - 12
src/context.js

@@ -1714,7 +1714,7 @@ function isTypeRecursive(type, base){
     return false;
 }
 
-var RecordField = Type.Field.extend({
+var RecordField = Class.extend.call(Type.Field, {
     init: function Context$RecordField(identdef, type){
         this.__identdef = identdef;
         this.__type = type;
@@ -1732,11 +1732,10 @@ exports.RecordDecl = ChainedContext.extend({
     init: function RecordDeclContext(context, makeRecord){
         ChainedContext.prototype.init.call(this, context);
         var parent = this.parent();
-        var cons = parent.genTypeName();
-        var name = parent.isAnonymousDeclaration() ? "" : cons;
-        this.__type = makeRecord(name, cons, context.currentScope());
+        this.__cons = parent.genTypeName();
+        var name = parent.isAnonymousDeclaration() ? "" : this.__cons;
+        this.__type = makeRecord(name, this.__cons, context.currentScope());
         parent.setType(this.__type);
-        parent.codeGenerator().write("var " + cons + " = ");
     },
     type: function(){return this.__type;},
     addField: function(field, type){
@@ -1756,6 +1755,11 @@ exports.RecordDecl = ChainedContext.extend({
         if (isTypeRecursive(type, this.__type))
             throw new Errors.Error("recursive inheritance: '"
                 + Type.typeName(this.__type) + "'");
+
+        var gen = this.codeGenerator();
+        var qualifiedBase = this.qualifyScope(Type.recordScope(type)) + Type.typeName(type); 
+        gen.write(this.language().rtl.extend(this.__cons, qualifiedBase) + ";\n");
+
         Type.setRecordBase(this.__type, type);
     },
     endParse: function(){
@@ -1763,14 +1767,10 @@ exports.RecordDecl = ChainedContext.extend({
         var baseType = Type.recordBase(type);
         var gen = this.codeGenerator();
         var qualifiedBase = baseType ? this.qualifyScope(Type.recordScope(baseType)) + Type.typeName(baseType) : undefined; 
-        gen.write((baseType ? qualifiedBase + ".extend" 
-                            : this.language().rtl.extendId())
-                + "(");
-        gen.openScope();
-        gen.write("init: function " + Type.recordConstructor(this.__type) + "()");
+        gen.write("function " + this.__cons + "()");
         gen.openScope();
         if (baseType)
-            gen.write(qualifiedBase + ".prototype.init.call(this);\n");
+            gen.write(qualifiedBase + ".call(this);\n");
         var ownFields = Type.recordOwnFields(type);
         for(var f in ownFields){
             var fieldType = ownFields[f].type();
@@ -1778,7 +1778,6 @@ exports.RecordDecl = ChainedContext.extend({
         }
 
         gen.closeScope("");
-        gen.closeScope(");\n");
     },
     _makeField: function(field, type){
         return new RecordField(field, type);

+ 4 - 4
src/eberon/eberon_context.js

@@ -83,7 +83,7 @@ function getMethodSelf(){}
 function getSelfAsPointerMsg(){}
 function getMethodSuper(){}
 
-var ResultVariable = Type.Variable.extend({
+var ResultVariable = Class.extend.call(Type.Variable, {
     init: function(e){
         this.__e = e;
     },
@@ -93,7 +93,7 @@ var ResultVariable = Type.Variable.extend({
     idType: function(){return "procedure call " + (this.type() ? "result" : "statement");}
 });
 
-var TypeNarrowVariableBase = Type.Variable.extend({
+var TypeNarrowVariableBase = Class.extend.call(Type.Variable, {
     init: function TypeNarrowVariableBase(){
     }    
 });
@@ -371,9 +371,9 @@ var RecordFieldAsMethod = Context.RecordField.extend({
         return EberonTypes.makeMethod(this.type()); 
     }
 });
-var RecordType = Type.Record.extend({
+var RecordType = Class.extend.call(Type.Record, {
     init: function EberonContext$RecordType(name, cons, scope){
-        Type.Record.prototype.init.call(this);
+        Type.Record.call(this);
         Type.initRecord(this, name, cons, scope);
         this.__finalized = false;
         this.__declaredMethods = {};

+ 6 - 1
src/rtl.js

@@ -25,7 +25,12 @@ Class.extend = function extend(methods){
     };
 
 var impl = {
-    extend: Class.extend,
+    extend: function(cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
+    },
     typeGuard: function(from, to){
         if (!from)
             return from;

+ 4 - 22
test/expected/array.js

@@ -17,20 +17,6 @@ var RTL$ = {
                 result[i] = this.makeArray.apply(this, forward);
         return result;
     },
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     cloneArrayOfRecords: function (from){
         var length = from.length;
         var result = new Array(length);
@@ -82,10 +68,8 @@ var a1 = RTL$.makeArray(10, 0);var a11 = RTL$.makeArray(10, 0);
 var a2 = RTL$.makeArray(5, function(){return RTL$.makeArray(10, 0);});
 var a3 = RTL$.makeArray(5, false);
 var a4 = RTL$.makeArray(3, 4, false);
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-	}
-});
+function anonymous$1(){
+}
 var a5 = RTL$.makeArray(3, function(){return new anonymous$1();});
 
 function p(){
@@ -101,10 +85,8 @@ function p2(a/*VAR ARRAY 10 OF INTEGER*/){
 }
 
 function testAssign(){
-	var T = RTL$.extend({
-		init: function T(){
-		}
-	});
+	function T(){
+	}
 	var aInts1 = RTL$.makeArray(3, 0);var aInts2 = RTL$.makeArray(3, 0);
 	var aRecords1 = RTL$.makeArray(3, function(){return new T();});var aRecords2 = RTL$.makeArray(3, function(){return new T();});
 	var aPointers1 = RTL$.makeArray(3, null);var aPointers2 = RTL$.makeArray(3, null);

+ 22 - 35
test/expected/cast.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     },
     typeGuard: function (from, to){
         if (!from)
@@ -39,28 +31,23 @@ var RTL$ = {
     }
 };
 var m = function (){
-var Base = RTL$.extend({
-	init: function Base(){
-	}
-});
-var Derived1 = Base.extend({
-	init: function Derived1(){
-		Base.prototype.init.call(this);
-		this.field1 = 0;
-	}
-});
-var Derived2 = Derived1.extend({
-	init: function Derived2(){
-		Derived1.prototype.init.call(this);
-		this.field2 = 0;
-	}
-});
-var PAnonymousDerived = Base.extend({
-	init: function PAnonymousDerived(){
-		Base.prototype.init.call(this);
-		this.field3 = 0;
-	}
-});
+function Base(){
+}
+RTL$.extend(Derived1, Base);
+function Derived1(){
+	Base.call(this);
+	this.field1 = 0;
+}
+RTL$.extend(Derived2, Derived1);
+function Derived2(){
+	Derived1.call(this);
+	this.field2 = 0;
+}
+RTL$.extend(PAnonymousDerived, Base);
+function PAnonymousDerived(){
+	Base.call(this);
+	this.field3 = 0;
+}
 var pb = null;
 var pd1 = null;
 var pd2 = null;

+ 5 - 21
test/expected/eberon/designator.js

@@ -1,31 +1,15 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     makeRef: function (obj, prop){
         return {set: function(v){ obj[prop] = v; },
                 get: function(){ return obj[prop]; }};
     }
 };
 var m = function (){
-var TP = RTL$.extend({
-	init: function TP(){
-		this.i = 0;
-		this.proc = null;
-		this.procT = null;
-	}
-});
+function TP(){
+	this.i = 0;
+	this.proc = null;
+	this.procT = null;
+}
 
 function proc(){
 }

+ 3 - 19
test/expected/eberon/dynamic_array.js

@@ -1,18 +1,4 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     makeArray: function (/*dimensions, initializer*/){
         var forward = Array.prototype.slice.call(arguments);
         var result = new Array(forward.shift());
@@ -98,11 +84,9 @@ var RTL$ = {
     }
 };
 var m = function (){
-var T = RTL$.extend({
-	init: function T(){
-		this.a = [];
-	}
-});
+function T(){
+	this.a = [];
+}
 var r = new T();
 var a = RTL$.makeArray(3, 0);
 var dynamicInt = [];

+ 17 - 29
test/expected/eberon/generic_message_bus.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     },
     assert: function (condition){
         if (!condition)
@@ -19,22 +11,18 @@ var RTL$ = {
     }
 };
 var m = function (){
-var Message = RTL$.extend({
-	init: function Message(){
-	}
-});
-var Derived1 = Message.extend({
-	init: function Derived1(){
-		Message.prototype.init.call(this);
-		this.derivedField1 = false;
-	}
-});
-var Derived2 = Message.extend({
-	init: function Derived2(){
-		Message.prototype.init.call(this);
-		this.derivedField2 = false;
-	}
-});
+function Message(){
+}
+RTL$.extend(Derived1, Message);
+function Derived1(){
+	Message.call(this);
+	this.derivedField1 = false;
+}
+RTL$.extend(Derived2, Message);
+function Derived2(){
+	Message.call(this);
+	this.derivedField2 = false;
+}
 var d1 = new Derived1();
 var d2 = new Derived2();
 

+ 12 - 23
test/expected/eberon/in_place_variables.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     },
     makeArray: function (/*dimensions, initializer*/){
         var forward = Array.prototype.slice.call(arguments);
@@ -56,16 +48,13 @@ var RTL$ = {
     }
 };
 var m = function (){
-var Base = RTL$.extend({
-	init: function Base(){
-	}
-});
-var Derived = Base.extend({
-	init: function Derived(){
-		Base.prototype.init.call(this);
-		this.derivedField = 0;
-	}
-});
+function Base(){
+}
+RTL$.extend(Derived, Base);
+function Derived(){
+	Base.call(this);
+	this.derivedField = 0;
+}
 var r = new Derived();
 var pbVar = null;
 var pdVar = null;

+ 12 - 23
test/expected/eberon/method.js

@@ -1,30 +1,19 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     }
 };
 var m = function (){
-var T = RTL$.extend({
-	init: function T(){
-		this.i = 0;
-	}
-});
-var D = T.extend({
-	init: function D(){
-		T.prototype.init.call(this);
-	}
-});
+function T(){
+	this.i = 0;
+}
+RTL$.extend(D, T);
+function D(){
+	T.call(this);
+}
 var dp = null;
 T.prototype.p = function(){
 	this.i = 123;

+ 11 - 22
test/expected/eberon/modules.js

@@ -1,24 +1,14 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     }
 };
 var m1 = function (){
-var Base = RTL$.extend({
-	init: function Base(){
-	}
-});
+function Base(){
+}
 Base.prototype.p = function(){
 }
 return {
@@ -26,11 +16,10 @@ return {
 }
 }();
 var m2 = function (m1){
-var T = m1.Base.extend({
-	init: function T(){
-		m1.Base.prototype.init.call(this);
-	}
-});
+RTL$.extend(T, m1.Base);
+function T(){
+	m1.Base.call(this);
+}
 T.prototype.p = function(){
 	m1.Base.prototype.p.call(this);
 }

+ 4 - 22
test/expected/export.js

@@ -1,18 +1,4 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     makeArray: function (/*dimensions, initializer*/){
         var forward = Array.prototype.slice.call(arguments);
         var result = new Array(forward.shift());
@@ -34,14 +20,10 @@ var RTL$ = {
 };
 var m = function (){
 var ci = 123;
-var T1 = RTL$.extend({
-	init: function T1(){
-	}
-});
-var NotExportedRecord = RTL$.extend({
-	init: function NotExportedRecord(){
-	}
-});
+function T1(){
+}
+function NotExportedRecord(){
+}
 var pr1 = null;
 var p2 = null;
 var vi = 0;

+ 17 - 29
test/expected/is.js

@@ -1,36 +1,24 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     }
 };
 var m = function (){
-var Base = RTL$.extend({
-	init: function Base(){
-	}
-});
-var Derived1 = Base.extend({
-	init: function Derived1(){
-		Base.prototype.init.call(this);
-		this.field1 = 0;
-	}
-});
-var Derived2 = Derived1.extend({
-	init: function Derived2(){
-		Derived1.prototype.init.call(this);
-		this.field2 = 0;
-	}
-});
+function Base(){
+}
+RTL$.extend(Derived1, Base);
+function Derived1(){
+	Base.call(this);
+	this.field1 = 0;
+}
+RTL$.extend(Derived2, Derived1);
+function Derived2(){
+	Derived1.call(this);
+	this.field2 = 0;
+}
 var pb = null;
 var pd1 = null;
 var pd2 = null;

+ 9 - 27
test/expected/man_or_boy.js

@@ -1,31 +1,13 @@
-var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    }
-};
 var test = function (JS){
-var State = RTL$.extend({
-	init: function State(){
-		this.f = null;
-		this.k = 0;
-		this.x1 = null;
-		this.x2 = null;
-		this.x3 = null;
-		this.x4 = null;
-		this.x5 = null;
-	}
-});
+function State(){
+	this.f = null;
+	this.k = 0;
+	this.x1 = null;
+	this.x2 = null;
+	this.x3 = null;
+	this.x4 = null;
+	this.x5 = null;
+}
 var pB = null;
 
 function call(s/*PState*/){

+ 30 - 48
test/expected/modules.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     },
     typeGuard: function (from, to){
         if (!from)
@@ -62,31 +54,23 @@ var RTL$ = {
 };
 var m1 = function (){
 var ci = 123;
-var Base = RTL$.extend({
-	init: function Base(){
-		this.i = 0;
-	}
-});
-var T = Base.extend({
-	init: function T(){
-		Base.prototype.init.call(this);
-	}
-});
-var TPA = RTL$.extend({
-	init: function TPA(){
-	}
-});
-var TPB = Base.extend({
-	init: function TPB(){
-		Base.prototype.init.call(this);
-	}
-});
+function Base(){
+	this.i = 0;
+}
+RTL$.extend(T, Base);
+function T(){
+	Base.call(this);
+}
+function TPA(){
+}
+RTL$.extend(TPB, Base);
+function TPB(){
+	Base.call(this);
+}
 var i = 0;
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-		this.i = 0;
-	}
-});
+function anonymous$1(){
+	this.i = 0;
+}
 var pr = null;
 var pr2 = null;
 
@@ -120,12 +104,11 @@ return {
 }
 }();
 var m2 = function (m1){
-var T = m1.T.extend({
-	init: function T(){
-		m1.T.prototype.init.call(this);
-		this.i2 = 0;
-	}
-});
+RTL$.extend(T, m1.T);
+function T(){
+	m1.T.call(this);
+	this.i2 = 0;
+}
 var r = new m1.T();
 var r2 = new T();
 var pb = null;
@@ -151,11 +134,10 @@ p(m1.ci);
 ref(RTL$.makeRef(m1.pr2(), "i"));
 }(m1);
 var m3 = function (m1, m2){
-var T = m2.T.extend({
-	init: function T(){
-		m2.T.prototype.init.call(this);
-	}
-});
+RTL$.extend(T, m2.T);
+function T(){
+	m2.T.call(this);
+}
 var r = new m2.T();
 var r2 = new T();
 var a = RTL$.makeArray(3, function(){return new m2.Base();});

+ 8 - 30
test/expected/new.js

@@ -1,36 +1,14 @@
-var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    }
-};
 var m = function (){
-var T1 = RTL$.extend({
-	init: function T1(){
-		this.field1 = 0;
-	}
-});
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-	}
-});
+function T1(){
+	this.field1 = 0;
+}
+function anonymous$1(){
+}
 var p = null;
 var p1 = null;
-var anonymous$2 = RTL$.extend({
-	init: function anonymous$2(){
-		this.p = null;
-	}
-});
+function anonymous$2(){
+	this.p = null;
+}
 var r = new anonymous$2();
 p = new anonymous$1();
 p1 = new T1();

+ 2 - 20
test/expected/nil.js

@@ -1,24 +1,6 @@
-var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    }
-};
 var m = function (){
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-	}
-});
+function anonymous$1(){
+}
 var p = null;
 p = null;
 }();

+ 12 - 19
test/expected/nodejs/modules/m1.js

@@ -1,25 +1,18 @@
 var RTL$ = require("rtl.js");
 var ci = 123;
-var Base = RTL$.extend({
-	init: function Base(){
-		this.i = 0;
-	}
-});
-var T = Base.extend({
-	init: function T(){
-		Base.prototype.init.call(this);
-	}
-});
-var TPA = RTL$.extend({
-	init: function TPA(){
-	}
-});
+function Base(){
+	this.i = 0;
+}
+RTL$.extend(T, Base);
+function T(){
+	Base.call(this);
+}
+function TPA(){
+}
 var i = 0;
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-		this.i = 0;
-	}
-});
+function anonymous$1(){
+	this.i = 0;
+}
 var pr = null;
 var pr2 = null;
 

+ 11 - 35
test/expected/pointer.js

@@ -1,42 +1,18 @@
-var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    }
-};
 var m = function (){
-var T = RTL$.extend({
-	init: function T(){
-		this.p = null;
-		this.i = 0;
-	}
-});
-var T2 = RTL$.extend({
-	init: function T2(){
-		this.p = null;
-	}
-});
-var Forward = RTL$.extend({
-	init: function Forward(){
-	}
-});
+function T(){
+	this.p = null;
+	this.i = 0;
+}
+function T2(){
+	this.p = null;
+}
+function Forward(){
+}
 var r = new T();
 var r2 = null;
 var pf = null;
-var anonymous$1 = RTL$.extend({
-	init: function anonymous$1(){
-	}
-});
+function anonymous$1(){
+}
 var pAnonymous = null;
 r.p = new T();
 r.p.p = new T();

+ 13 - 24
test/expected/proc.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     }
 };
 var m = function (){
@@ -19,17 +11,14 @@ var i = 0;
 var byte = 0;
 
 function p1(arg1/*INTEGER*/){
-	var T1 = RTL$.extend({
-		init: function T1(){
-			this.field1 = 0;
-		}
-	});
-	var T2 = T1.extend({
-		init: function T2(){
-			T1.prototype.init.call(this);
-			this.field2 = false;
-		}
-	});
+	function T1(){
+		this.field1 = 0;
+	}
+	RTL$.extend(T2, T1);
+	function T2(){
+		T1.call(this);
+		this.field2 = false;
+	}
 	var i = 0;var j = 0;
 	var b = false;
 	var t1 = new T1();

+ 6 - 26
test/expected/proc_local.js

@@ -1,36 +1,16 @@
-var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    }
-};
 var m = function (){
 
 function p1(arg1/*INTEGER*/){
-	var T1 = RTL$.extend({
-		init: function T1(){
-			this.field1 = 0;
-		}
-	});
+	function T1(){
+		this.field1 = 0;
+	}
 	var i1 = 0;var j1 = 0;
 	var t1 = new T1();
 	
 	function p2(arg2/*BOOLEAN*/){
-		var T2 = RTL$.extend({
-			init: function T2(){
-				this.field2 = false;
-			}
-		});
+		function T2(){
+			this.field2 = false;
+		}
 		var b = false;
 		var t2 = new T2();
 		b = arg2;

+ 20 - 35
test/expected/record.js

@@ -1,17 +1,9 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
+    extend: function (cons, base){
+        function Type(){}
+        Type.prototype = base.prototype;
+        cons.prototype = new Type();
+        cons.prototype.constructor = cons;
     },
     makeArray: function (/*dimensions, initializer*/){
         var forward = Array.prototype.slice.call(arguments);
@@ -50,28 +42,21 @@ var RTL$ = {
     }
 };
 var m = function (){
-var Base1 = RTL$.extend({
-	init: function Base1(){
-	}
-});
-var T1 = Base1.extend({
-	init: function T1(){
-		Base1.prototype.init.call(this);
-		this.i = 0;
-	}
-});
-var RecordWithInnerRecord = RTL$.extend({
-	init: function RecordWithInnerRecord(){
-		this.$r = new T1();
-	}
-});
-var RecordWithInnerArray = RTL$.extend({
-	init: function RecordWithInnerArray(){
-		this.aInts = RTL$.makeArray(3, 0);
-		this.$aRecords = RTL$.makeArray(3, function(){return new T1();});
-		this.aPointers = RTL$.makeArray(3, null);
-	}
-});
+function Base1(){
+}
+RTL$.extend(T1, Base1);
+function T1(){
+	Base1.call(this);
+	this.i = 0;
+}
+function RecordWithInnerRecord(){
+	this.$r = new T1();
+}
+function RecordWithInnerArray(){
+	this.aInts = RTL$.makeArray(3, 0);
+	this.$aRecords = RTL$.makeArray(3, function(){return new T1();});
+	this.aPointers = RTL$.makeArray(3, null);
+}
 var b1 = new Base1();
 var r1 = new T1();
 var recordWithInnerRecord = new RecordWithInnerRecord();

+ 6 - 22
test/expected/var_parameter.js

@@ -17,34 +17,18 @@ var RTL$ = {
                 result[i] = this.makeArray.apply(this, forward);
         return result;
     },
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     makeRef: function (obj, prop){
         return {set: function(v){ obj[prop] = v; },
                 get: function(){ return obj[prop]; }};
     }
 };
 var m = function (){
-var R = RTL$.extend({
-	init: function R(){
-		this.i = 0;
-		this.byte = 0;
-		this.a = RTL$.makeArray(3, 0);
-		this.p = null;
-	}
-});
+function R(){
+	this.i = 0;
+	this.byte = 0;
+	this.a = RTL$.makeArray(3, 0);
+	this.p = null;
+}
 var i = 0;
 var byte = 0;
 var b = false;

+ 9 - 2
test/input/eberon/run/method.ob

@@ -2,12 +2,13 @@ MODULE m;
 TYPE
     T = RECORD 
     	PROCEDURE p();
-    	PROCEDURE pSuper(i: INTEGER)
+    	PROCEDURE pSuper(i: INTEGER);
     END;
 	TD = RECORD(T) END;
 
     Base = RECORD
-        PROCEDURE method(): STRING
+        PROCEDURE method(): STRING;
+        PROCEDURE baseOnly();
     END;
 
     Derived1 = RECORD(Base)
@@ -35,6 +36,9 @@ BEGIN
 	pSuperCalled := i;
 END T.pSuper;
 
+PROCEDURE Base.baseOnly();
+END Base.baseOnly;
+
 PROCEDURE TD.p();
 BEGIN
 	pDerivedCalled := TRUE;
@@ -60,6 +64,9 @@ BEGIN
 END copyRecord;
 
 BEGIN
+    d1.baseOnly();
+    d2.baseOnly();
+
 	ASSERT(~pCalled);
 	ASSERT(~pDerivedCalled);
 	r.p();