2
0
Vladislav Folts 10 жил өмнө
parent
commit
c539ced6a7

BIN
bin/compiled.zip


+ 0 - 29
src/context.js

@@ -42,23 +42,6 @@ var HandleSymbolAsType = ContextType.HandleSymbolAsType;
 HandleSymbolAsType.extend = Class.extend;
 HandleSymbolAsType.extend = Class.extend;
 HandleSymbolAsType.prototype.init = ContextType.HandleSymbolAsType;
 HandleSymbolAsType.prototype.init = ContextType.HandleSymbolAsType;
 
 
-function assertProcType(type, info){
-    var unexpected;
-    if ( !type )
-        unexpected = info.idType();
-    else if (((info instanceof TypeId.Type) || !(type instanceof Type.Procedure)) 
-        && !(type instanceof Module.AnyType))
-        unexpected = type.description();
-    if (unexpected)
-        throw new Errors.Error("PROCEDURE expected, got '" + unexpected + "'");
-    return type;
-}
-
-function assertProcStatementResult(type){
-    if (type && !(type instanceof Module.AnyType))
-        throw new Errors.Error("procedure returning a result cannot be used as a statement");
-}
-
 function beginCallMsg(){}
 function beginCallMsg(){}
 function endCallMsg(){}
 function endCallMsg(){}
 
 
@@ -212,19 +195,7 @@ var ModuleImport = ChainedContext.extend({
 });
 });
 exports.ModuleImport = ModuleImport;
 exports.ModuleImport = ModuleImport;
 
 
-function makeProcCall(context, type, info){
-    assertProcType(type, info);
-    var l = context.root().language();
-    return type.callGenerator(
-        { types: l.types, 
-          rtl: function(){ return l.rtl(); }, 
-          qualifyScope: context.qualifyScope.bind(context)
-        });
-}
-
-exports.assertProcStatementResult = assertProcStatementResult;
 exports.beginCallMsg = beginCallMsg;
 exports.beginCallMsg = beginCallMsg;
 exports.endCallMsg = endCallMsg;
 exports.endCallMsg = endCallMsg;
 exports.Chained = ChainedContext;
 exports.Chained = ChainedContext;
-exports.makeProcCall = makeProcCall;
 exports.HandleSymbolAsType = HandleSymbolAsType;
 exports.HandleSymbolAsType = HandleSymbolAsType;

+ 1 - 1
src/eberon/EberonArray.ob

@@ -43,7 +43,7 @@ END MethodIndexOf.callGenerator;
 PROCEDURE MethodCallIndexOf.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE MethodCallIndexOf.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
     argCode <- Procedure.makeArgumentsCode(cx);
     argCode <- Procedure.makeArgumentsCode(cx);
-    argType <- Procedure.checkSingleArgument(args, SELF, cx.types, argCode).type();
+    argType <- Procedure.checkSingleArgument(args, SELF, cx.language.types, argCode).type();
     RETURN Expression.makeSimple("(" + argCode.result() + ")", Types.basic.integer)
     RETURN Expression.makeSimple("(" + argCode.result() + ")", Types.basic.integer)
 END MethodCallIndexOf.make;
 END MethodCallIndexOf.make;
 
 

+ 3 - 3
src/eberon/EberonCast.ob

@@ -31,7 +31,7 @@ BEGIN
 END;
 END;
 
 
 PROCEDURE CastOpToDynamicArray.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
 PROCEDURE CastOpToDynamicArray.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
-    RETURN copyArray(left.type()(Types.PArray), left.code(), right.code(), cx.rtl()^)
+    RETURN copyArray(left.type()(Types.PArray), left.code(), right.code(), cx.language.rtl^)
 END;
 END;
 
 
 PROCEDURE CastOpToMap.make(cx: LanguageContext.PType; e: Expression.PType): Expression.PType;
 PROCEDURE CastOpToMap.make(cx: LanguageContext.PType; e: Expression.PType): Expression.PType;
@@ -39,11 +39,11 @@ PROCEDURE CastOpToMap.make(cx: LanguageContext.PType; e: Expression.PType): Expr
 END;
 END;
 
 
 PROCEDURE CastOpToMap.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
 PROCEDURE CastOpToMap.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
-    RETURN cx.rtl().copy(right.code(), left.code(), EberonOperator.generateTypeInfo(left.type()));
+    RETURN cx.language.rtl.copy(right.code(), left.code(), EberonOperator.generateTypeInfo(left.type()));
 END;
 END;
 
 
 PROCEDURE CastOpToMap.clone(cx: LanguageContext.PType; e: Expression.PType): STRING;
 PROCEDURE CastOpToMap.clone(cx: LanguageContext.PType; e: Expression.PType): STRING;
-    RETURN cx.rtl().clone(e.code(), EberonOperator.generateTypeInfo(e.type()), "undefined");
+    RETURN cx.language.rtl.clone(e.code(), EberonOperator.generateTypeInfo(e.type()), "undefined");
 END;
 END;
 
 
 PROCEDURE isOpenCharArray(type: Types.PType): BOOLEAN;
 PROCEDURE isOpenCharArray(type: Types.PType): BOOLEAN;

+ 5 - 5
src/eberon/EberonConstructor.ob

@@ -26,20 +26,20 @@ TYPE
 PROCEDURE checkArgs(call: ConstructorCall; args: ARRAY OF Expression.PType; cx: LanguageContext.PType): STRING;
 PROCEDURE checkArgs(call: ConstructorCall; args: ARRAY OF Expression.PType; cx: LanguageContext.PType): STRING;
 BEGIN
 BEGIN
     argCode <- Procedure.makeArgumentsCode(cx);
     argCode <- Procedure.makeArgumentsCode(cx);
-    Procedure.processArguments(args, call.args, argCode, cx.types);
+    Procedure.processArguments(args, call.args, argCode, cx.language.types);
     RETURN argCode.result();
     RETURN argCode.result();
 END;
 END;
 
 
 PROCEDURE ConstructorCall.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE ConstructorCall.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
     argCode <- checkArgs(SELF, args, cx);
     argCode <- checkArgs(SELF, args, cx);
-    RETURN Expression.makeSimple(Record.initializer(cx^, SELF.recordType^, argCode), SELF.resultType);
+    RETURN Expression.makeSimple(Record.initializer(cx.cx^, SELF.recordType^, argCode), SELF.resultType);
 END;
 END;
 
 
 PROCEDURE BaseConstructorCall.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE BaseConstructorCall.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
     argCode <- checkArgs(SELF, args, cx);
     argCode <- checkArgs(SELF, args, cx);
-    code <- Record.constructor(cx^, SELF.recordType^) + ".call(this, " + argCode + ");" + Stream.kCR;
+    code <- Record.constructor(cx.cx^, SELF.recordType^) + ".call(this, " + argCode + ");" + Stream.kCR;
     RETURN Expression.makeSimple(code, NIL);
     RETURN Expression.makeSimple(code, NIL);
 END;
 END;
 
 
@@ -83,7 +83,7 @@ BEGIN
         raiseSingleArgumentException(SELF);
         raiseSingleArgumentException(SELF);
     END;
     END;
 
 
-    IF SELF.cx.types.implicitCast(e.type(), SELF.type, FALSE, op)
+    IF SELF.cx.language.types.implicitCast(e.type(), SELF.type, FALSE, op)
         # Cast.errNo THEN
         # Cast.errNo THEN
             Errors.raise("type mismatch: field '" + SELF.field + "' is '" + SELF.type.description()
             Errors.raise("type mismatch: field '" + SELF.field + "' is '" + SELF.type.description()
                          + "' and cannot be initialized using '" + e.type().description() + "' expression");
                          + "' and cannot be initialized using '" + e.type().description() + "' expression");
@@ -115,7 +115,7 @@ BEGIN
         instType := EberonRecord.instantiateForNew;
         instType := EberonRecord.instantiateForNew;
     END;
     END;
     
     
-    EberonRecord.ensureCanBeInstantiated(cx^, recordType, instType);
+    EberonRecord.ensureCanBeInstantiated(cx.cx^, recordType, instType);
     IF forNew THEN
     IF forNew THEN
         resultType := NEW Record.Pointer("", typeId);
         resultType := NEW Record.Pointer("", typeId);
     END;
     END;

+ 4 - 4
src/eberon/EberonDynamicArray.ob

@@ -119,14 +119,14 @@ BEGIN
         NEW Types.ProcedureArgument(SELF.elementsType, FALSE), 
         NEW Types.ProcedureArgument(SELF.elementsType, FALSE), 
         0, 
         0, 
         argCode, 
         argCode, 
-        SELF.cx.types);
+        SELF.cx.language.types);
     SELF.code := argCode.result();
     SELF.code := argCode.result();
     
     
     t <- e.type();
     t <- e.type();
     IF t IS Types.PArray THEN
     IF t IS Types.PArray THEN
         SELF.code := Cast.cloneArray(t, SELF.code, SELF.cx);
         SELF.code := Cast.cloneArray(t, SELF.code, SELF.cx);
     ELSIF t IS Record.PType THEN
     ELSIF t IS Record.PType THEN
-        SELF.code := SELF.cx.rtl().clone(SELF.code, EberonOperator.generateTypeInfo(t), Record.constructor(SELF.cx^, t^));
+        SELF.code := SELF.cx.language.rtl.clone(SELF.code, EberonOperator.generateTypeInfo(t), Record.constructor(SELF.cx.cx^, t^));
     END;
     END;
 END AddCallGenerator.handleArgument;
 END AddCallGenerator.handleArgument;
 
 
@@ -178,14 +178,14 @@ END;
 
 
 PROCEDURE MethodCallClear.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE MethodCallClear.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
-    Procedure.processArguments(args, SELF.args, NIL, cx.types);
+    Procedure.processArguments(args, SELF.args, NIL, cx.language.types);
     RETURN Expression.makeSimple("(0, Number.MAX_VALUE)", NIL)
     RETURN Expression.makeSimple("(0, Number.MAX_VALUE)", NIL)
 END MethodCallClear.make;
 END MethodCallClear.make;
 
 
 PROCEDURE MethodCallRemove.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE MethodCallRemove.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
     argCode <- Procedure.makeArgumentsCode(cx);
     argCode <- Procedure.makeArgumentsCode(cx);
-    arg <- Procedure.checkSingleArgument(args, SELF, cx.types, argCode);
+    arg <- Procedure.checkSingleArgument(args, SELF, cx.language.types, argCode);
     value <- arg.constValue();
     value <- arg.constValue();
     IF (value # NIL) & (value^ IS ConstValue.Int) THEN
     IF (value # NIL) & (value^ IS ConstValue.Int) THEN
         Code.checkIndex(value.value);
         Code.checkIndex(value.value);

+ 1 - 1
src/eberon/EberonMap.ob

@@ -80,7 +80,7 @@ END;
 PROCEDURE MethodCallRemove.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE MethodCallRemove.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
 BEGIN
 BEGIN
     argCode <- Procedure.makeArgumentsCode(cx);
     argCode <- Procedure.makeArgumentsCode(cx);
-    arg <- Procedure.checkSingleArgument(args, SELF, cx.types, argCode);
+    arg <- Procedure.checkSingleArgument(args, SELF, cx.language.types, argCode);
     RETURN Expression.makeSimple("[" + argCode.result() + "]", NIL)
     RETURN Expression.makeSimple("[" + argCode.result() + "]", NIL)
 END;        
 END;        
 
 

+ 4 - 3
src/eberon/EberonOperator.ob

@@ -98,9 +98,10 @@ BEGIN
         IF (right.designator() = NIL) & (left.type() = right.type()) THEN
         IF (right.designator() = NIL) & (left.type() = right.type()) THEN
             result := leftLval + " = " + right.code();
             result := leftLval + " = " + right.code();
         ELSE
         ELSE
-            result := leftLval + " = " + cx.rtl().clone(right.code(), 
-                                                      generateTypeInfo(left.type()), 
-                                                      Record.constructor(cx^, left.type()(Record.PType)^));
+            result := leftLval + " = " 
+                    + cx.language.rtl.clone(right.code(), 
+                                            generateTypeInfo(left.type()), 
+                                            Record.constructor(cx.cx^, left.type()(Record.PType)^));
         END;
         END;
     ELSE
     ELSE
         result := SUPER(cx, left, right);
         result := SUPER(cx, left, right);

+ 10 - 8
src/eberon/EberonRecord.ob

@@ -1,6 +1,8 @@
 MODULE EberonRecord;
 MODULE EberonRecord;
 IMPORT 
 IMPORT 
-    Cast, Chars, Context, EberonContext, EberonTypes, Errors, JS, Object, Base := Record, Scope, ScopeBase, String, Types;
+    Cast, Chars, Context, EberonContext, EberonTypes, 
+    Errors, JS, Object, Procedure, Base := Record, 
+    Scope, ScopeBase, String, Types;
 CONST
 CONST
     instantiateForVar* = 0;    
     instantiateForVar* = 0;    
     instantiateForNew* = 1;    
     instantiateForNew* = 1;    
@@ -16,16 +18,16 @@ TYPE
     Record* = RECORD(Base.Type)
     Record* = RECORD(Base.Type)
         PROCEDURE Record(name: STRING; cons: STRING; scope: ScopeBase.PType);
         PROCEDURE Record(name: STRING; cons: STRING; scope: ScopeBase.PType);
 
 
-        PROCEDURE declareConstructor(type: Types.PDefinedProcedure; exported: BOOLEAN);
+        PROCEDURE declareConstructor(type: Procedure.PType; exported: BOOLEAN);
         PROCEDURE addMethod(methodId: Context.PIdentdefInfo; type: Types.PProcedure);
         PROCEDURE addMethod(methodId: Context.PIdentdefInfo; type: Types.PProcedure);
-        PROCEDURE defineConstructor(type: Types.PDefinedProcedure);
+        PROCEDURE defineConstructor(type: Procedure.PType);
         PROCEDURE defineMethod(methodId: Context.PIdentdefInfo; type: EberonTypes.PMethodType);
         PROCEDURE defineMethod(methodId: Context.PIdentdefInfo; type: EberonTypes.PMethodType);
         PROCEDURE requireNewOnly();
         PROCEDURE requireNewOnly();
         PROCEDURE setBaseConstructorCallCode(code: STRING);
         PROCEDURE setBaseConstructorCallCode(code: STRING);
         PROCEDURE setFieldInitializationCode(field: STRING; code: STRING);
         PROCEDURE setFieldInitializationCode(field: STRING; code: STRING);
         PROCEDURE setRecordInitializationCode(baseConstructorCallCode: STRING);
         PROCEDURE setRecordInitializationCode(baseConstructorCallCode: STRING);
 
 
-        customConstructor-: Types.PDefinedProcedure;
+        customConstructor-: Procedure.PType;
         customConstructorExported: BOOLEAN;
         customConstructorExported: BOOLEAN;
         customConstructorDefined: BOOLEAN;
         customConstructorDefined: BOOLEAN;
         customInitedfields-: ARRAY * OF STRING;
         customInitedfields-: ARRAY * OF STRING;
@@ -211,7 +213,7 @@ PROCEDURE FieldAsMethod.asVar(leadCode: STRING; isReadOnly: BOOLEAN; cx: Context
     RETURN NEW EberonTypes.MethodVariable(SELF.type()(Types.PProcedure)); 
     RETURN NEW EberonTypes.MethodVariable(SELF.type()(Types.PProcedure)); 
 END;
 END;
 
 
-PROCEDURE constructor*(r: Record): Types.PDefinedProcedure;
+PROCEDURE constructor*(r: Record): Procedure.PType;
 BEGIN
 BEGIN
     result <- r.customConstructor;
     result <- r.customConstructor;
     IF (result = NIL) & (r.base # NIL) THEN
     IF (result = NIL) & (r.base # NIL) THEN
@@ -336,7 +338,7 @@ END;
 
 
 PROCEDURE Record.defineMethod(methodId: Context.PIdentdefInfo; type: EberonTypes.PMethodType);
 PROCEDURE Record.defineMethod(methodId: Context.PIdentdefInfo; type: EberonTypes.PMethodType);
 VAR 
 VAR 
-    existingType: Types.PDefinedProcedure;
+    existingType: Procedure.PType;
 BEGIN
 BEGIN
     id <- methodId.id();
     id <- methodId.id();
     IF SELF.definedMethods.indexOf(id) # -1 THEN
     IF SELF.definedMethods.indexOf(id) # -1 THEN
@@ -391,7 +393,7 @@ BEGIN
     SELF.baseConstructorCallCode := baseConstructorCallCode;
     SELF.baseConstructorCallCode := baseConstructorCallCode;
 END;
 END;
 
 
-PROCEDURE Record.declareConstructor(type: Types.PDefinedProcedure; exported: BOOLEAN);
+PROCEDURE Record.declareConstructor(type: Procedure.PType; exported: BOOLEAN);
 BEGIN
 BEGIN
     IF SELF.customConstructor # NIL THEN
     IF SELF.customConstructor # NIL THEN
         Errors.raise("constructor '" + SELF.name + "' already declared");
         Errors.raise("constructor '" + SELF.name + "' already declared");
@@ -404,7 +406,7 @@ BEGIN
     SELF.customConstructorExported := exported;
     SELF.customConstructorExported := exported;
 END;
 END;
 
 
-PROCEDURE Record.defineConstructor(type: Types.PDefinedProcedure);
+PROCEDURE Record.defineConstructor(type: Procedure.PType);
 BEGIN
 BEGIN
     IF SELF.customConstructor = NIL THEN
     IF SELF.customConstructor = NIL THEN
         Errors.raise("constructor was not declared for '" + SELF.name +"'");
         Errors.raise("constructor was not declared for '" + SELF.name +"'");

+ 6 - 6
src/eberon/EberonTypes.ob

@@ -2,14 +2,14 @@ MODULE EberonTypes;
 IMPORT Context, LanguageContext, Procedure, Record, Types;
 IMPORT Context, LanguageContext, Procedure, Record, Types;
 
 
 TYPE
 TYPE
-    CallGenerator = PROCEDURE(cx: LanguageContext.PType; type: Types.DefinedProcedure): Procedure.PCallGenerator;
+    CallGenerator = PROCEDURE(cx: LanguageContext.PType; type: Procedure.Type): Procedure.PCallGenerator;
 
 
     MethodType* = RECORD(Procedure.Std)
     MethodType* = RECORD(Procedure.Std)
-        PROCEDURE MethodType*(id: STRING; t: Types.PDefinedProcedure; call: CallGenerator);
+        PROCEDURE MethodType*(id: STRING; t: Procedure.PType; call: CallGenerator);
 
 
-        PROCEDURE procType*(): Types.PDefinedProcedure;
+        PROCEDURE procType*(): Procedure.PType;
 
 
-        type: Types.PDefinedProcedure;
+        type: Procedure.PType;
         call: CallGenerator
         call: CallGenerator
     END;
     END;
     PMethodType* = POINTER TO MethodType;
     PMethodType* = POINTER TO MethodType;
@@ -29,7 +29,7 @@ PROCEDURE MethodType.designatorCode(id: STRING): STRING;
     RETURN id
     RETURN id
 END MethodType.designatorCode;
 END MethodType.designatorCode;
 
 
-PROCEDURE MethodType.procType(): Types.PDefinedProcedure;
+PROCEDURE MethodType.procType(): Procedure.PType;
     RETURN SELF.type
     RETURN SELF.type
 END MethodType.procType;
 END MethodType.procType;
 
 
@@ -41,7 +41,7 @@ PROCEDURE MethodType.callGenerator(cx: LanguageContext.PType): Procedure.PCallGe
     RETURN SELF.call(cx, SELF.type^)
     RETURN SELF.call(cx, SELF.type^)
 END MethodType.callGenerator;
 END MethodType.callGenerator;
 
 
-PROCEDURE MethodType.MethodType(id: STRING; t: Types.PDefinedProcedure; call: CallGenerator)
+PROCEDURE MethodType.MethodType(id: STRING; t: Procedure.PType; call: CallGenerator)
     | SUPER(id, NIL);
     | SUPER(id, NIL);
 BEGIN
 BEGIN
     SELF.type := t;
     SELF.type := t;

+ 10 - 18
src/eberon/eberon_context.js

@@ -26,6 +26,7 @@ var EberonString = require("js/EberonString.js");
 var EberonTypes = require("js/EberonTypes.js");
 var EberonTypes = require("js/EberonTypes.js");
 var Errors = require("js/Errors.js");
 var Errors = require("js/Errors.js");
 var Expression = require("js/Expression.js");
 var Expression = require("js/Expression.js");
+var Module = require("js/Module.js");
 var op = require("js/Operator.js");
 var op = require("js/Operator.js");
 var eOp = require("js/EberonOperator.js");
 var eOp = require("js/EberonOperator.js");
 var Symbol = require("js/Symbols.js");
 var Symbol = require("js/Symbols.js");
@@ -199,17 +200,8 @@ var Identdef = Class.extend.call(ContextIdentdef.Type, {
     }
     }
 });
 });
 
 
-function makeContext(context){
-    var l = context.root().language();
-    return {
-        types: l.types, 
-        rtl: function(){return l.rtl();}, 
-        qualifyScope: context.qualifyScope.bind(context)
-        };
-    }
-
 function makeContextCall(context, call){
 function makeContextCall(context, call){
-    return call(makeContext(context));
+    return call(ContextHierarchy.makeLanguageContext(context));
     }
     }
 
 
 function OperatorNewMsg(e){
 function OperatorNewMsg(e){
@@ -273,7 +265,7 @@ var Designator = Class.extend.call(ContextDesignator.Type, {
 
 
         if (currentType instanceof EberonMap.Type){
         if (currentType instanceof EberonMap.Type){
             var indexType = currentType.valueType;
             var indexType = currentType.valueType;
-            var rval = this.root().language().rtl().getMappedValue(code, indexCode);
+            var rval = this.root().language().rtl.getMappedValue(code, indexCode);
             return { length: undefined, 
             return { length: undefined, 
                      type: indexType,
                      type: indexType,
                      info: new MapElementVariable(indexType, info.isReadOnly(), rval),
                      info: new MapElementVariable(indexType, info.isReadOnly(), rval),
@@ -341,7 +333,7 @@ var Designator = Class.extend.call(ContextDesignator.Type, {
             this.discardCode();
             this.discardCode();
         }
         }
         else
         else
-            this.__procCall = Context.makeProcCall(this, type, this.info);
+            this.__procCall = ContextProcedure.makeCall(this, type, this.info);
     },
     },
     __endCall: function(){
     __endCall: function(){
         var e = this.__procCall.end();
         var e = this.__procCall.end();
@@ -417,7 +409,7 @@ var InPlaceVariableInit = Context.Chained.extend({
             EberonRecord.ensureCanBeInstantiated(this, type, EberonRecord.instantiateForCopy);
             EberonRecord.ensureCanBeInstantiated(this, type, EberonRecord.instantiateForCopy);
             if (e.designator()){
             if (e.designator()){
                 var l = this.root().language();
                 var l = this.root().language();
-                this._code += l.rtl().clone(e.code(), l.types.typeInfo(type));
+                this._code += l.rtl.clone(e.code(), l.types.typeInfo(type));
             }
             }
             else // do not clone if it is temporary, e.g. constructor call
             else // do not clone if it is temporary, e.g. constructor call
                 this._code += e.code();
                 this._code += e.code();
@@ -429,7 +421,7 @@ var InPlaceVariableInit = Context.Chained.extend({
             var language = this.root().language();
             var language = this.root().language();
             var cloneOp;
             var cloneOp;
             language.types.implicitCast(type, type, false, {set: function(v){cloneOp = v;}, get:function(){return cloneOp;}});
             language.types.implicitCast(type, type, false, {set: function(v){cloneOp = v;}, get:function(){return cloneOp;}});
-            this._code += cloneOp.clone(language, e);
+            this._code += cloneOp.clone(ContextHierarchy.makeLanguageContext(this), e);
         }
         }
     },
     },
     _onParsed: function(){
     _onParsed: function(){
@@ -489,16 +481,16 @@ var AssignmentOrProcedureCall = Context.Chained.extend({
         var code;
         var code;
         if (this.__right){
         if (this.__right){
             var left = Expression.make(d.code(), type, d);
             var left = Expression.make(d.code(), type, d);
-            code = op.assign(left, this.__right, makeContext(this));
+            code = op.assign(left, this.__right, ContextHierarchy.makeLanguageContext(this));
         }
         }
         else if (!(d.info() instanceof ResultVariable)){
         else if (!(d.info() instanceof ResultVariable)){
-            var procCall = Context.makeProcCall(this, type, d.info());
+            var procCall = ContextProcedure.makeCall(this, type, d.info());
             var result = procCall.end();
             var result = procCall.end();
-            Context.assertProcStatementResult(result.type());
+            Module.assertProcStatementResult(result.type());
             code = d.code() + result.code();
             code = d.code() + result.code();
         }
         }
         else{
         else{
-            Context.assertProcStatementResult(type);
+            Module.assertProcStatementResult(type);
             code = d.code();
             code = d.code();
         }
         }
     
     

+ 1 - 1
src/nodejs.js

@@ -83,7 +83,7 @@ function compile(sources, language, handleErrors, includeDirs, outDir, importDir
             function(moduleResolver){return new ContextHierarchy.Root(
             function(moduleResolver){return new ContextHierarchy.Root(
                 { codeGenerator: language.codeGenerator.make(),
                 { codeGenerator: language.codeGenerator.make(),
                   moduleGenerator: moduleCode,
                   moduleGenerator: moduleCode,
-                  rtl: function(){return rtl;},
+                  rtl: rtl,
                   types: language.types,
                   types: language.types,
                   stdSymbols: language.stdSymbols,
                   stdSymbols: language.stdSymbols,
                   moduleResolver: moduleResolver
                   moduleResolver: moduleResolver

+ 7 - 6
src/ob/Cast.ob

@@ -61,13 +61,13 @@ PROCEDURE areTypesMatch*(t1: Types.PType; t2: Types.PType): BOOLEAN;
             OR ((t2 = Types.nil) & (matchesToNIL(t1^))))
             OR ((t2 = Types.nil) & (matchesToNIL(t1^))))
 END areTypesMatch;
 END areTypesMatch;
 
 
-PROCEDURE areArgsMatch(a1, a2: Types.PProcedureArgument; p1, p2: Types.PDefinedProcedure): BOOLEAN;
+PROCEDURE areArgsMatch(a1, a2: Types.PProcedureArgument; p1, p2: Types.PProcedure): BOOLEAN;
     RETURN (a1.isVar = a2.isVar)
     RETURN (a1.isVar = a2.isVar)
         & (    ((a1.type = p1) & (a2.type = p2))
         & (    ((a1.type = p1) & (a2.type = p2))
             OR areTypesExactlyMatch(a1.type, a2.type))
             OR areTypesExactlyMatch(a1.type, a2.type))
 END areArgsMatch;
 END areArgsMatch;
 
 
-PROCEDURE areProceduresMatch*(p1, p2: Types.PDefinedProcedure): BOOLEAN;
+PROCEDURE areProceduresMatch*(p1, p2: Types.PProcedure): BOOLEAN;
 VAR
 VAR
     result: BOOLEAN;
     result: BOOLEAN;
 BEGIN
 BEGIN
@@ -103,7 +103,7 @@ BEGIN
     ELSIF (t1 IS Record.PPointer) & (t2 IS Record.PPointer) THEN
     ELSIF (t1 IS Record.PPointer) & (t2 IS Record.PPointer) THEN
         result := areTypesMatch(Record.pointerBase(t1^), 
         result := areTypesMatch(Record.pointerBase(t1^), 
                                 Record.pointerBase(t2^));
                                 Record.pointerBase(t2^));
-    ELSIF (t1 IS Types.PDefinedProcedure) & (t2 IS Types.PDefinedProcedure) THEN
+    ELSIF (t1 IS Types.PProcedure) & (t2 IS Types.PProcedure) THEN
         result := areProceduresMatch(t1, t2);
         result := areProceduresMatch(t1, t2);
     END;
     END;
     RETURN result
     RETURN result
@@ -147,7 +147,8 @@ BEGIN
     IF t.elementsType.isScalar() THEN
     IF t.elementsType.isScalar() THEN
         result := code + ".slice()";
         result := code + ".slice()";
     ELSE
     ELSE
-        result := cx.rtl().clone(code, cx.types.typeInfo(t), "undefined");
+        l <- cx.language;
+        result := l.rtl.clone(code, l.types.typeInfo(t), "undefined");
     END;
     END;
     RETURN result
     RETURN result
 END;
 END;
@@ -161,7 +162,7 @@ PROCEDURE CastOpArray.clone(cx: LanguageContext.PType; e: Expression.PType): STR
 END;
 END;
 
 
 PROCEDURE CastOpRecord.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
 PROCEDURE CastOpRecord.assign(cx: LanguageContext.PType; left, right: Expression.PType): STRING;
-    RETURN cx.rtl().copy(right.code(), left.lval(), Record.generateTypeInfo(left.type()));
+    RETURN cx.language.rtl.copy(right.code(), left.lval(), Record.generateTypeInfo(left.type()));
 END;
 END;
 
 
 PROCEDURE CastOpStrToChar.make(cx: LanguageContext.PType; e: Expression.PType): Expression.PType;
 PROCEDURE CastOpStrToChar.make(cx: LanguageContext.PType; e: Expression.PType): Expression.PType;
@@ -233,7 +234,7 @@ BEGIN
         END;
         END;
     ELSIF (from = Types.nil) & matchesToNIL(to^) THEN
     ELSIF (from = Types.nil) & matchesToNIL(to^) THEN
         result := errNo;
         result := errNo;
-    ELSIF (from IS Types.PDefinedProcedure) & (to IS Types.PDefinedProcedure) THEN
+    ELSIF (from IS Types.PProcedure) & (to IS Types.PProcedure) THEN
         IF areProceduresMatch(from, to) THEN
         IF areProceduresMatch(from, to) THEN
             result := errNo;
             result := errNo;
         END
         END

+ 2 - 2
src/ob/ContextDesignator.ob

@@ -87,7 +87,7 @@ PROCEDURE Type.handleTypeCast(type: Types.PType);
 BEGIN
 BEGIN
     ContextExpression.checkTypeCast(SELF.info(Types.PVariable), SELF.currentType, type, "type cast");
     ContextExpression.checkTypeCast(SELF.info(Types.PVariable), SELF.currentType, type, "type cast");
 
 
-    code <- SELF.root().language().rtl().typeGuard(SELF.code, ContextExpression.castCode(type, SELF));
+    code <- SELF.root().language().rtl.typeGuard(SELF.code, ContextExpression.castCode(type, SELF));
     SELF.code := code;
     SELF.code := code;
 
 
     SELF.currentType := type;
     SELF.currentType := type;
@@ -230,7 +230,7 @@ BEGIN
 
 
     readOnly <- (info IS Types.PConst) 
     readOnly <- (info IS Types.PConst) 
              OR ((info IS Types.PVariable) & info.isReadOnly());
              OR ((info IS Types.PVariable) & info.isReadOnly());
-    v <- NEW Variable.PropertyVariable(indexType, leadCode, indexCode, readOnly, SELF.root().language().rtl());
+    v <- NEW Variable.PropertyVariable(indexType, leadCode, indexCode, readOnly, SELF.root().language().rtl);
     RETURN NEW Index(length, indexType, v, wholeCode, lval, indexCode);
     RETURN NEW Index(length, indexType, v, wholeCode, lval, indexCode);
 END;
 END;
 
 

+ 2 - 2
src/ob/ContextExpression.ob

@@ -519,7 +519,7 @@ BEGIN
         rightExpression := promoteTypeInExpression(rightExpression, leftExpression.type());
         rightExpression := promoteTypeInExpression(rightExpression, leftExpression.type());
 
 
         o <- SELF.doRelationOperation(leftExpression, rightExpression, SELF.relation);
         o <- SELF.doRelationOperation(leftExpression, rightExpression, SELF.relation);
-        SELF.expression := o(leftExpression, rightExpression, SELF.root().language());
+        SELF.expression := o(leftExpression, rightExpression, ContextHierarchy.makeLanguageContext(SELF(POINTER)));
     END;
     END;
 END;
 END;
 
 
@@ -984,7 +984,7 @@ BEGIN
     IF LEN(SELF.expression) = 0 THEN
     IF LEN(SELF.expression) = 0 THEN
         parent.handleExpression(expressionFromConst(Types.basic.set, NEW ConstValue.Set(SELF.value), String.fromInt(ORD(SELF.value))));
         parent.handleExpression(expressionFromConst(Types.basic.set, NEW ConstValue.Set(SELF.value), String.fromInt(ORD(SELF.value))));
     ELSE
     ELSE
-        code <- SELF.root().language().rtl().makeSet(SELF.expression);
+        code <- SELF.root().language().rtl.makeSet(SELF.expression);
         IF SELF.value # {} THEN
         IF SELF.value # {} THEN
             code := code + " | " + String.fromInt(ORD(SELF.value));
             code := code + " | " + String.fromInt(ORD(SELF.value));
         END;
         END;

+ 14 - 10
src/ob/ContextHierarchy.ob

@@ -38,9 +38,9 @@ TYPE
     END;
     END;
 
 
     Root* = RECORD(Node)
     Root* = RECORD(Node)
-        PROCEDURE Root(language: LanguageContext.PType);
+        PROCEDURE Root(language: LanguageContext.PLanguage);
 
 
-        PROCEDURE language*(): LanguageContext.PType;
+        PROCEDURE language*(): LanguageContext.PLanguage;
 
 
         PROCEDURE findSymbol*(ident: STRING): Symbols.PFoundSymbol;
         PROCEDURE findSymbol*(ident: STRING): Symbols.PFoundSymbol;
         PROCEDURE findModule(name: STRING): Types.PModule;
         PROCEDURE findModule(name: STRING): Types.PModule;
@@ -49,7 +49,7 @@ TYPE
         PROCEDURE pushScope*(scope: Scope.PType);
         PROCEDURE pushScope*(scope: Scope.PType);
         PROCEDURE popScope*();
         PROCEDURE popScope*();
 
 
-        mLanguage: LanguageContext.PType;
+        mLanguage: LanguageContext.PLanguage;
         scopes: ARRAY * OF Scope.PType;
         scopes: ARRAY * OF Scope.PType;
         gen: INTEGER;
         gen: INTEGER;
     END;
     END;
@@ -76,10 +76,6 @@ PROCEDURE Node.parent(): PNode;
     RETURN SELF.mParent;
     RETURN SELF.mParent;
 END;
 END;
 
 
-PROCEDURE Node.rtl(): OberonRtl.PType;
-    RETURN SELF.root().language().rtl();
-END;
-
 PROCEDURE Node.handleMessage(VAR msg: Message): Object.PType;
 PROCEDURE Node.handleMessage(VAR msg: Message): Object.PType;
     RETURN SELF.mParent.handleMessage(msg);
     RETURN SELF.mParent.handleMessage(msg);
 END;
 END;
@@ -92,6 +88,10 @@ PROCEDURE Node.qualifyScope(scope: ScopeBase.PType): STRING;
     RETURN SELF.mParent.qualifyScope(scope);
     RETURN SELF.mParent.qualifyScope(scope);
 END;
 END;
 
 
+PROCEDURE Node.rtl(): OberonRtl.PType;
+    RETURN SELF.root().language().rtl;
+END;
+
 PROCEDURE Node.handleLiteral(s: STRING);
 PROCEDURE Node.handleLiteral(s: STRING);
 END;
 END;
 
 
@@ -102,12 +102,12 @@ PROCEDURE Node.genTypeName(): STRING;
     RETURN SELF.mParent.genTypeName();
     RETURN SELF.mParent.genTypeName();
 END;
 END;
 
 
-PROCEDURE Root.Root(language: LanguageContext.PType)
+PROCEDURE Root.Root(language: LanguageContext.PLanguage)
     | SUPER(NIL),
     | SUPER(NIL),
       mLanguage(language);
       mLanguage(language);
-END;
+      END;
 
 
-PROCEDURE Root.language(): LanguageContext.PType;
+PROCEDURE Root.language(): LanguageContext.PLanguage;
     RETURN SELF.mLanguage;
     RETURN SELF.mLanguage;
 END;
 END;
 
 
@@ -200,4 +200,8 @@ PROCEDURE getSymbol*(cx: Root; id: STRING): Symbols.PSymbol;
     RETURN getSymbolAndScope(cx, id).symbol();
     RETURN getSymbolAndScope(cx, id).symbol();
 END;
 END;
 
 
+PROCEDURE makeLanguageContext*(cx: PNode): LanguageContext.PType;
+    RETURN NEW LanguageContext.Type(cx.root().language(), cx);
+END;
+
 END ContextHierarchy.
 END ContextHierarchy.

+ 32 - 6
src/ob/ContextProcedure.ob

@@ -3,7 +3,7 @@ IMPORT
     Cast, Chars, CodeGenerator, Context, ContextExpression, 
     Cast, Chars, CodeGenerator, Context, ContextExpression, 
     ContextHierarchy, ContextType, 
     ContextHierarchy, ContextType, 
     Errors, Expression, LanguageContext,
     Errors, Expression, LanguageContext,
-    Object, Procedure, Scope, Symbols, Types, Variable;
+    Object, Procedure, Scope, Symbols, TypeId, Types, Variable;
 TYPE
 TYPE
     Declaration* = RECORD(ContextType.DeclarationAndIdentHandle)
     Declaration* = RECORD(ContextType.DeclarationAndIdentHandle)
         PROCEDURE Declaration(parent: ContextHierarchy.PNode);
         PROCEDURE Declaration(parent: ContextHierarchy.PNode);
@@ -17,7 +17,7 @@ TYPE
 
 
         outerScope: Scope.PType;
         outerScope: Scope.PType;
         id: Context.PIdentdefInfo;
         id: Context.PIdentdefInfo;
-        type: Types.PDefinedProcedure;
+        type: Procedure.PType;
         multipleArguments: BOOLEAN;
         multipleArguments: BOOLEAN;
         returnParsed: BOOLEAN;
         returnParsed: BOOLEAN;
     END;
     END;
@@ -30,7 +30,7 @@ TYPE
         PROCEDURE doCheckResultType(type: Types.PStorageType);
         PROCEDURE doCheckResultType(type: Types.PStorageType);
 
 
         arguments: ARRAY * OF Types.PProcedureArgument;
         arguments: ARRAY * OF Types.PProcedureArgument;
-        type: Procedure.PType;
+        type: Procedure.PDefined;
         result: Types.PStorageType;
         result: Types.PStorageType;
     END;
     END;
 
 
@@ -96,7 +96,7 @@ END;
 
 
 PROCEDURE Declaration.setType(type: Types.PStorageType);
 PROCEDURE Declaration.setType(type: Types.PStorageType);
 BEGIN
 BEGIN
-    t <- type(Types.PDefinedProcedure);
+    t <- type(Procedure.PType);
     procSymbol <- NEW Symbols.Symbol(
     procSymbol <- NEW Symbols.Symbol(
         SELF.id.id(), NEW Types.ProcedureId(t));
         SELF.id.id(), NEW Types.ProcedureId(t));
     SELF.outerScope.addSymbol(procSymbol, SELF.id.exported());
     SELF.outerScope.addSymbol(procSymbol, SELF.id.exported());
@@ -158,7 +158,7 @@ BEGIN
             + type.description() + "'");
             + type.description() + "'");
     END;
     END;
 
 
-    SELF.codeGenerator().write("return " + op.clone(language, e) + ";" + Chars.ln);
+    SELF.codeGenerator().write("return " + op.clone(ContextHierarchy.makeLanguageContext(SELF(POINTER)), e) + ";" + Chars.ln);
 
 
     SELF.returnParsed := TRUE;
     SELF.returnParsed := TRUE;
 END;
 END;
@@ -178,7 +178,7 @@ END;
 
 
 PROCEDURE FormalParameters.FormalParameters(parent: ContextType.PDeclarationAndIdentHandle)
 PROCEDURE FormalParameters.FormalParameters(parent: ContextType.PDeclarationAndIdentHandle)
     | SUPER(parent),
     | SUPER(parent),
-      type(NEW Procedure.Type(parent.typeName()));
+      type(NEW Procedure.Defined(parent.typeName()));
 BEGIN
 BEGIN
     parent.setType(SELF.type);
     parent.setType(SELF.type);
 END;
 END;
@@ -273,4 +273,30 @@ PROCEDURE AddArgumentMsg.AddArgumentMsg(name: STRING; arg: Types.PProcedureArgum
       arg(arg);
       arg(arg);
 END;
 END;
 
 
+PROCEDURE assertProcType(type: Types.PType; info: Types.PId): Procedure.PType;
+VAR
+    unexpected: STRING;
+    result: Procedure.PType;
+BEGIN
+    IF type = NIL THEN
+        unexpected := info.idType();
+    ELSIF (info IS TypeId.PType) OR ~(type IS Procedure.PType) THEN
+        unexpected := type.description();
+    ELSE
+        result := type;
+    END;
+    
+    IF result = NIL THEN
+        Errors.raise("PROCEDURE expected, got '" + unexpected + "'");
+    END;
+    
+    RETURN result;
+END;
+
+PROCEDURE makeCall*(cx: ContextHierarchy.PNode; type: Types.PType; info: Types.PId): Procedure.PCallGenerator;
+BEGIN
+    RETURN assertProcType(type, info)
+          .callGenerator(ContextHierarchy.makeLanguageContext(cx));
+END;
+
 END ContextProcedure.
 END ContextProcedure.

+ 2 - 2
src/ob/ContextType.ob

@@ -157,7 +157,7 @@ VAR
     result: STRING;
     result: STRING;
     initializer: STRING;
     initializer: STRING;
 BEGIN
 BEGIN
-    rtl <- SELF.root().language().rtl();
+    rtl <- SELF.root().language().rtl;
     IF type = Types.basic.ch THEN
     IF type = Types.basic.ch THEN
         result := rtl.makeCharArray(dimensions);
         result := rtl.makeCharArray(dimensions);
     ELSE
     ELSE
@@ -366,7 +366,7 @@ BEGIN
     base <- SELF.type.base;
     base <- SELF.type.base;
     IF base # NIL THEN
     IF base # NIL THEN
         qualifiedBase <- SELF.qualifyScope(base.scope) + base.name; 
         qualifiedBase <- SELF.qualifyScope(base.scope) + base.name; 
-        result := SELF.root().language().rtl().extend(SELF.cons, qualifiedBase) + ";" + Chars.ln;
+        result := SELF.root().language().rtl.extend(SELF.cons, qualifiedBase) + ";" + Chars.ln;
     END;
     END;
     RETURN result;
     RETURN result;
 END;
 END;

+ 20 - 6
src/ob/LanguageContext.ob

@@ -1,5 +1,5 @@
 MODULE LanguageContext;
 MODULE LanguageContext;
-IMPORT Context, CodeGenerator, Expression, Symbols, T := Types;
+IMPORT CodeGenerator, Context, Expression, OberonRtl, Symbols, T := Types;
 
 
 TYPE
 TYPE
     PType* = POINTER TO Type;
     PType* = POINTER TO Type;
@@ -20,11 +20,25 @@ TYPE
     END;
     END;
     PTypes* = POINTER TO Types;
     PTypes* = POINTER TO Types;
 
 
-    Type* = RECORD(Context.Type)
-        moduleResolver*: PROCEDURE(name: STRING): T.PModule;
-        codeGenerator*: CodeGenerator.PIGenerator;
-        types*: PTypes;
-        stdSymbols*: Symbols.Map;
+    Language* = RECORD
+        moduleResolver-: PROCEDURE(name: STRING): T.PModule;
+        rtl-: OberonRtl.PType;
+        codeGenerator-: CodeGenerator.PIGenerator;
+        types-: PTypes;
+        stdSymbols-: Symbols.Map;
     END;
     END;
+    PLanguage* = POINTER TO Language;
+
+    Type* = RECORD
+        PROCEDURE Type*(language: PLanguage; cx: Context.PType);
+
+        language-: PLanguage;
+        cx-: Context.PType;
+    END;
+
+PROCEDURE Type.Type(language: PLanguage; cx: Context.PType)
+    | language(language),
+      cx(cx);
+END;
 
 
 END LanguageContext.
 END LanguageContext.

+ 46 - 11
src/ob/Module.ob

@@ -1,18 +1,18 @@
 MODULE Module;
 MODULE Module;
 IMPORT 
 IMPORT 
-    Context, Errors, Expression, LanguageContext, Procedure, Symbols, TypeId, Types;
+    Context, Errors, Expression, LanguageContext, Procedure, Symbols, TypeId, Types, Variable;
 TYPE
 TYPE
     Type* = RECORD(Types.Module)
     Type* = RECORD(Types.Module)
         PROCEDURE findSymbol*(id: STRING): Symbols.PFoundSymbol
         PROCEDURE findSymbol*(id: STRING): Symbols.PFoundSymbol
     END;
     END;
     PType* = POINTER TO Type;
     PType* = POINTER TO Type;
 
 
-    AnyType* = RECORD(Types.Procedure)
+    AnyType = RECORD(Procedure.Type)
         PROCEDURE AnyType();
         PROCEDURE AnyType();
+    END;
 
 
-        PROCEDURE callGenerator(cx: LanguageContext.PType): Procedure.PCallGenerator;
-
-        asVar: Types.PId
+    AnyVariable = RECORD(Variable.TypedVariable)
+        PROCEDURE AnyVariable();
     END;
     END;
 
 
     AnyField = RECORD(Types.Field)
     AnyField = RECORD(Types.Field)
@@ -21,7 +21,7 @@ TYPE
         mId: STRING;
         mId: STRING;
     END;
     END;
 
 
-    AnyTypeProc* = RECORD(Procedure.Std)
+    AnyTypeProc = RECORD(Procedure.Std)
     END;
     END;
 
 
     AnyProcCall = RECORD(Procedure.Call)
     AnyProcCall = RECORD(Procedure.Call)
@@ -32,6 +32,7 @@ TYPE
 VAR
 VAR
     doProcId, varTypeId: STRING;
     doProcId, varTypeId: STRING;
     any: POINTER TO AnyType;
     any: POINTER TO AnyType;
+    anyVar: POINTER TO AnyVariable;
     anyProc: AnyTypeProc;
     anyProc: AnyTypeProc;
     doProcSymbol, varTypeSymbol: Symbols.PSymbol;
     doProcSymbol, varTypeSymbol: Symbols.PSymbol;
 
 
@@ -63,6 +64,33 @@ PROCEDURE AnyType.isScalar(): BOOLEAN;
     RETURN FALSE;
     RETURN FALSE;
 END;
 END;
 
 
+PROCEDURE AnyType.args(): Types.ProcedureArguments;
+VAR
+    result: Types.ProcedureArguments;
+BEGIN
+    RETURN result;
+END;
+
+PROCEDURE AnyType.result(): Types.PType;
+    RETURN NIL;
+END;
+
+PROCEDURE AnyVariable.AnyVariable()
+    | SUPER(any);
+END;
+
+PROCEDURE AnyVariable.isReadOnly(): BOOLEAN;
+    RETURN FALSE;
+END;
+
+PROCEDURE AnyVariable.isReference(): BOOLEAN;
+    RETURN TRUE;
+END;
+
+PROCEDURE AnyVariable.referenceCode(): STRING;
+    RETURN "";
+END;
+
 PROCEDURE AnyField.id(): STRING;
 PROCEDURE AnyField.id(): STRING;
     RETURN "any field"
     RETURN "any field"
 END AnyField.id;
 END AnyField.id;
@@ -76,8 +104,8 @@ PROCEDURE AnyField.type(): Types.PStorageType;
 END AnyField.type;
 END AnyField.type;
 
 
 PROCEDURE AnyField.asVar(leadCode: STRING; isReadOnly: BOOLEAN; cx: Context.Type): Types.PId;
 PROCEDURE AnyField.asVar(leadCode: STRING; isReadOnly: BOOLEAN; cx: Context.Type): Types.PId;
-    RETURN any.asVar
-END AnyField.asVar;
+    RETURN anyVar;
+END;
 
 
 PROCEDURE AnyField.designatorCode(leadCode: STRING; cx: Context.Type): Types.PFieldCode;
 PROCEDURE AnyField.designatorCode(leadCode: STRING; cx: Context.Type): Types.PFieldCode;
     RETURN NEW Types.FieldCode(leadCode + "." + SELF.mId, "", "");
     RETURN NEW Types.FieldCode(leadCode + "." + SELF.mId, "", "");
@@ -128,7 +156,7 @@ VAR
         arg: Expression.PType;
         arg: Expression.PType;
         type: Types.PType;
         type: Types.PType;
     BEGIN
     BEGIN
-        arg := Procedure.checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := Procedure.checkSingleArgument(args, SELF, cx.language.types, NIL);
         type := arg.type();
         type := arg.type();
         IF ~(type IS Types.PString) THEN
         IF ~(type IS Types.PString) THEN
             Errors.raise("string is expected as an argument of "
             Errors.raise("string is expected as an argument of "
@@ -153,19 +181,26 @@ PROCEDURE makeJS*(): PType;
 END;
 END;
 
 
 PROCEDURE AnyType.AnyType()
 PROCEDURE AnyType.AnyType()
-    | SUPER("any type"),
-      asVar(NEW TypeId.Type(SELF(POINTER)));
+    | SUPER("any type");
 END;
 END;
 
 
 PROCEDURE AnyField.AnyField(id: STRING)
 PROCEDURE AnyField.AnyField(id: STRING)
     | mId(id);
     | mId(id);
 END;
 END;
 
 
+PROCEDURE assertProcStatementResult*(type: Types.PType);
+BEGIN
+    IF (type # NIL) & ~(type^ IS AnyType) THEN
+        Errors.raise("procedure returning a result cannot be used as a statement");
+    END;
+END;
+
 BEGIN
 BEGIN
     doProcId := "do$";
     doProcId := "do$";
     varTypeId := "var$";
     varTypeId := "var$";
     
     
     NEW(any);
     NEW(any);
+    NEW(anyVar);
 
 
     doProcSymbol := makeDoProcSymbol();
     doProcSymbol := makeDoProcSymbol();
     varTypeSymbol := makeVarTypeSymbol();
     varTypeSymbol := makeVarTypeSymbol();

+ 5 - 5
src/ob/Operator.ob

@@ -445,7 +445,7 @@ END codeSetInclR;
 
 
 PROCEDURE strCmp(op: STRING; left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE strCmp(op: STRING; left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
     RETURN Expression.makeSimple(
     RETURN Expression.makeSimple(
-            cx.rtl().strCmp(castToStr(left, cx), castToStr(right, cx)) + op + "0",
+            cx.language.rtl.strCmp(castToStr(left, cx), castToStr(right, cx)) + op + "0",
             Types.basic.bool)
             Types.basic.bool)
 END;
 END;
 
 
@@ -468,7 +468,7 @@ VAR
                          + String.fromInt(Types.stringLen(s))
                          + String.fromInt(Types.stringLen(s))
                          + "-character string");
                          + "-character string");
         END;
         END;
-        RETURN cx.rtl().assignArrayFromString(leftCode, rightCode)
+        RETURN cx.language.rtl.assignArrayFromString(leftCode, rightCode)
     END assignArrayFromString;
     END assignArrayFromString;
 BEGIN
 BEGIN
     designator := left.designator();
     designator := left.designator();
@@ -488,7 +488,7 @@ BEGIN
         & (rightType IS Types.PString) THEN
         & (rightType IS Types.PString) THEN
         result := assignArrayFromString(leftType(Types.PArray)^, rightType^);
         result := assignArrayFromString(leftType(Types.PArray)^, rightType^);
     ELSE
     ELSE
-        IF cx.types.implicitCast(rightType, leftType, FALSE, castOperation)
+        IF cx.language.types.implicitCast(rightType, leftType, FALSE, castOperation)
             # Cast.errNo THEN
             # Cast.errNo THEN
             Errors.raise("type mismatch: '" + left.code() + "' is '" + leftType.description()
             Errors.raise("type mismatch: '" + left.code() + "' is '" + leftType.description()
                          + "' and cannot be assigned to '" + rightType.description() + "' expression");
                          + "' and cannot be assigned to '" + rightType.description() + "' expression");
@@ -582,11 +582,11 @@ PROCEDURE setHasBit*(left, right: Expression.PType; cx: LanguageContext.PType):
 END;
 END;
 
 
 PROCEDURE setInclL*(left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE setInclL*(left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
-    RETURN binaryPred(left, right, cx.rtl(), opSetInclL, codeSetInclL)
+    RETURN binaryPred(left, right, cx.language.rtl, opSetInclL, codeSetInclL)
 END setInclL;
 END setInclL;
 
 
 PROCEDURE setInclR*(left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
 PROCEDURE setInclR*(left, right: Expression.PType; cx: LanguageContext.PType): Expression.PType;
-    RETURN binaryPred(left, right, cx.rtl(), opSetInclR, codeSetInclR)
+    RETURN binaryPred(left, right, cx.language.rtl, opSetInclR, codeSetInclR)
 END setInclR;
 END setInclR;
 
 
 PROCEDURE or*(left, right: Expression.PType): Expression.PType;
 PROCEDURE or*(left, right: Expression.PType): Expression.PType;

+ 54 - 37
src/ob/Procedure.ob

@@ -45,20 +45,22 @@ TYPE
         call: PCall
         call: PCall
     END;
     END;
 
 
-    Type* = RECORD(Types.DefinedProcedure)
-        PROCEDURE callGenerator(cx: LanguageContext.PType): PCallGenerator;
+    Type* = RECORD(Types.Procedure)
+        PROCEDURE callGenerator*(cx: LanguageContext.PType): PCallGenerator;
+    END;
+    PType* = POINTER TO Type;
+
+    Defined* = RECORD(Type)
         PROCEDURE define*(args: ARRAY OF Types.PProcedureArgument; result: Types.PType);
         PROCEDURE define*(args: ARRAY OF Types.PProcedureArgument; result: Types.PType);
 
 
         mArgs: Types.ProcedureArguments;
         mArgs: Types.ProcedureArguments;
         mResult: Types.PType
         mResult: Types.PType
     END;
     END;
-    PType* = POINTER TO Type;
+    PDefined* = POINTER TO Defined;
 
 
-    Std* = RECORD(Types.Procedure)
+    Std* = RECORD(Type)
         PROCEDURE Std*(name: STRING; call: PCall);
         PROCEDURE Std*(name: STRING; call: PCall);
 
 
-        PROCEDURE callGenerator*(cx: LanguageContext.PType): PCallGenerator;
-
         call: PCall
         call: PCall
     END;
     END;
 
 
@@ -159,12 +161,27 @@ BEGIN
     processArguments(actual, expected, NIL, types);
     processArguments(actual, expected, NIL, types);
 END checkArguments;
 END checkArguments;
 
 
+PROCEDURE Defined.designatorCode(id: STRING): STRING;
+    RETURN id;
+END;
+
 PROCEDURE Std.Std(name: STRING; call: PCall)
 PROCEDURE Std.Std(name: STRING; call: PCall)
     | SUPER(name);
     | SUPER(name);
 BEGIN
 BEGIN
     SELF.call := call;
     SELF.call := call;
 END;
 END;
 
 
+PROCEDURE Std.args(): Types.ProcedureArguments;
+VAR
+    result: Types.ProcedureArguments;
+BEGIN
+    RETURN result;
+END;
+
+PROCEDURE Std.result(): Types.PType;
+    RETURN NIL;
+END;
+
 PROCEDURE CallGeneratorImpl.handleArgument(e: Expression.PType);
 PROCEDURE CallGeneratorImpl.handleArgument(e: Expression.PType);
 BEGIN
 BEGIN
     SELF.args.add(e);
     SELF.args.add(e);
@@ -211,7 +228,7 @@ END GenArgCode.result;
 
 
 PROCEDURE makeProcCallGeneratorWithCustomArgs*(
 PROCEDURE makeProcCallGeneratorWithCustomArgs*(
     cx: LanguageContext.PType; 
     cx: LanguageContext.PType; 
-    type: Types.DefinedProcedure;
+    type: Type;
     argumentsCode: PArgumentsCode
     argumentsCode: PArgumentsCode
     ) : PCallGenerator;
     ) : PCallGenerator;
 TYPE
 TYPE
@@ -223,7 +240,7 @@ TYPE
 
 
     PROCEDURE CallImpl.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
     PROCEDURE CallImpl.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
     BEGIN
     BEGIN
-        processArguments(args, SELF.args, SELF.argumentsCode, cx.types);
+        processArguments(args, SELF.args, SELF.argumentsCode, cx.language.types);
         RETURN Expression.makeSimple(
         RETURN Expression.makeSimple(
                 "(" + SELF.argumentsCode.result() + ")",
                 "(" + SELF.argumentsCode.result() + ")",
                 SELF.result
                 SELF.result
@@ -246,7 +263,7 @@ END;
 
 
 PROCEDURE makeProcCallGenerator*(
 PROCEDURE makeProcCallGenerator*(
     cx: LanguageContext.PType; 
     cx: LanguageContext.PType; 
-    type: Types.DefinedProcedure
+    type: Type
     ) : PCallGenerator;
     ) : PCallGenerator;
     RETURN makeProcCallGeneratorWithCustomArgs(cx, type, makeArgumentsCode(cx))
     RETURN makeProcCallGeneratorWithCustomArgs(cx, type, makeArgumentsCode(cx))
 END makeProcCallGenerator;
 END makeProcCallGenerator;
@@ -309,7 +326,7 @@ PROCEDURE makeNew(): Symbols.PSymbol;
     VAR
     VAR
         result: Expression.PType;
         result: Expression.PType;
     BEGIN
     BEGIN
-        arg <- checkSingleArgument(args, SELF, cx.types, NIL);
+        arg <- checkSingleArgument(args, SELF, cx.language.types, NIL);
         argType <- arg.type();
         argType <- arg.type();
         IF ~(argType IS Record.PPointer) THEN
         IF ~(argType IS Record.PPointer) THEN
             Errors.raise("POINTER variable expected, got '" 
             Errors.raise("POINTER variable expected, got '" 
@@ -319,7 +336,7 @@ PROCEDURE makeNew(): Symbols.PSymbol;
             IF baseType IS Record.PNonExported THEN
             IF baseType IS Record.PNonExported THEN
                 Errors.raise("non-exported RECORD type cannot be used in NEW");
                 Errors.raise("non-exported RECORD type cannot be used in NEW");
             END;
             END;
-            right <- Expression.makeSimple(baseType.codeForNew(cx^), argType);
+            right <- Expression.makeSimple(baseType.codeForNew(cx.cx^), argType);
             result := Expression.makeSimple(Operator.assign(arg, right, cx), NIL);
             result := Expression.makeSimple(Operator.assign(arg, right, cx), NIL);
         END;
         END;
         RETURN result;
         RETURN result;
@@ -339,7 +356,7 @@ VAR
     arg: Expression.PType;
     arg: Expression.PType;
     argType: Types.PType;
     argType: Types.PType;
 BEGIN
 BEGIN
-    arg := checkSingleArgument(args, SELF, cx.types, NIL);
+    arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
     argType := arg.type();
     argType := arg.type();
     IF ~SELF.check(argType) THEN
     IF ~SELF.check(argType) THEN
         Errors.raise("ARRAY or string is expected as an argument of LEN, got '"
         Errors.raise("ARRAY or string is expected as an argument of LEN, got '"
@@ -369,7 +386,7 @@ PROCEDURE makeOdd(): Symbols.PSymbol;
         code: STRING;
         code: STRING;
         constValue: ConstValue.PType;
         constValue: ConstValue.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         code := Code.adjustPrecedence(arg, Precedence.bitAnd);
         code := Code.adjustPrecedence(arg, Precedence.bitAnd);
         
         
         constValue := arg.constValue();
         constValue := arg.constValue();
@@ -400,9 +417,9 @@ PROCEDURE makeAssert(): Symbols.PSymbol;
     VAR
     VAR
         arg: Expression.PType;
         arg: Expression.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         RETURN Expression.makeSimple(
         RETURN Expression.makeSimple(
-                cx.rtl().assertId() + "(" + arg.code() + ")",
+                cx.language.rtl.assertId() + "(" + arg.code() + ")",
                 NIL)
                 NIL)
     END CallImpl.make;
     END CallImpl.make;
 BEGIN
 BEGIN
@@ -427,7 +444,7 @@ PROCEDURE setBitImpl(name: STRING; bitOp: BinaryOpStr): Symbols.PSymbol;
         valueCode: STRING;
         valueCode: STRING;
         comment: STRING;
         comment: STRING;
     BEGIN
     BEGIN
-        checkArguments(args, SELF.args, cx.types);
+        checkArguments(args, SELF.args, cx.language.types);
         ASSERT(LEN(args) = 2);
         ASSERT(LEN(args) = 2);
         x := args[0];
         x := args[0];
         y := args[1];
         y := args[1];
@@ -499,7 +516,7 @@ PROCEDURE incImpl(name: STRING; unary: STRING; incOp: BinaryOpStr; incRefOp: Ope
         valueCode: STRING;
         valueCode: STRING;
     BEGIN
     BEGIN
         checkVariableArgumentsCount(1, 2, args);
         checkVariableArgumentsCount(1, 2, args);
-        checkArgumentsType(args, SELF.args, NIL, cx.types);
+        checkArgumentsType(args, SELF.args, NIL, cx.language.types);
         x := args[0];
         x := args[0];
         IF Cast.passedByReference(x) THEN
         IF Cast.passedByReference(x) THEN
             IF LEN(args) = 1 THEN
             IF LEN(args) = 1 THEN
@@ -563,7 +580,7 @@ PROCEDURE makeAbs(): Symbols.PSymbol;
         arg: Expression.PType;
         arg: Expression.PType;
         argType: Types.PType;
         argType: Types.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         argType := arg.type();
         argType := arg.type();
         IF Types.numeric.indexOf(argType) = -1 THEN
         IF Types.numeric.indexOf(argType) = -1 THEN
             Errors.raise("type mismatch: expected numeric type, got '"
             Errors.raise("type mismatch: expected numeric type, got '"
@@ -586,7 +603,7 @@ PROCEDURE makeFloor(): Symbols.PSymbol;
     VAR
     VAR
         arg: Expression.PType;
         arg: Expression.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         code <- Code.adjustPrecedence(arg, Precedence.bitOr) + " | 0";
         code <- Code.adjustPrecedence(arg, Precedence.bitOr) + " | 0";
         RETURN NEW Expression.Type(
         RETURN NEW Expression.Type(
             code,
             code,
@@ -612,7 +629,7 @@ PROCEDURE makeFlt(): Symbols.PSymbol;
         arg: Expression.PType;
         arg: Expression.PType;
         value: ConstValue.PType;
         value: ConstValue.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         value := arg.constValue();
         value := arg.constValue();
         IF value # NIL THEN
         IF value # NIL THEN
             value := NEW ConstValue.Real(FLT(value^(ConstValue.Int).value));
             value := NEW ConstValue.Real(FLT(value^(ConstValue.Int).value));
@@ -639,7 +656,7 @@ PROCEDURE bitShiftImpl(name: STRING; op: Operator.BinaryProc): Symbols.PSymbol;
 
 
     PROCEDURE CallImpl.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
     PROCEDURE CallImpl.make(args: ARRAY OF Expression.PType; cx: LanguageContext.PType): Expression.PType;
     BEGIN
     BEGIN
-        checkArguments(args, SELF.args, cx.types);
+        checkArguments(args, SELF.args, cx.language.types);
         ASSERT(LEN(args) = 2);
         ASSERT(LEN(args) = 2);
         RETURN SELF.op(args[0], args[1])
         RETURN SELF.op(args[0], args[1])
     END CallImpl.make;
     END CallImpl.make;
@@ -666,7 +683,7 @@ PROCEDURE makeOrd(): Symbols.PSymbol;
         ch: CHAR;
         ch: CHAR;
         result: Expression.PType;
         result: Expression.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         argType := arg.type();
         argType := arg.type();
         IF (argType = Types.basic.ch) OR (argType = Types.basic.set) THEN
         IF (argType = Types.basic.ch) OR (argType = Types.basic.set) THEN
             value := arg.constValue();
             value := arg.constValue();
@@ -712,7 +729,7 @@ PROCEDURE makeChr(): Symbols.PSymbol;
     VAR
     VAR
         arg: Expression.PType;
         arg: Expression.PType;
     BEGIN
     BEGIN
-        arg := checkSingleArgument(args, SELF, cx.types, NIL);
+        arg := checkSingleArgument(args, SELF, cx.language.types, NIL);
         RETURN Expression.makeSimple(arg.code(), Types.basic.ch)
         RETURN Expression.makeSimple(arg.code(), Types.basic.ch)
     END CallImpl.make;
     END CallImpl.make;
 BEGIN
 BEGIN
@@ -730,7 +747,7 @@ PROCEDURE makePack(): Symbols.PSymbol;
     VAR
     VAR
         x, y: Expression.PType;
         x, y: Expression.PType;
     BEGIN
     BEGIN
-        checkArguments(args, SELF.args, cx.types);
+        checkArguments(args, SELF.args, cx.language.types);
         x := args[0];
         x := args[0];
         y := args[1];
         y := args[1];
         RETURN Expression.makeSimple(
         RETURN Expression.makeSimple(
@@ -753,7 +770,7 @@ PROCEDURE makeUnpk(): Symbols.PSymbol;
     VAR
     VAR
         x, y: Expression.PType;
         x, y: Expression.PType;
     BEGIN
     BEGIN
-        checkArguments(args, SELF.args, cx.types);
+        checkArguments(args, SELF.args, cx.language.types);
         x := args[0];
         x := args[0];
         y := args[1];
         y := args[1];
         RETURN Expression.makeSimple(
         RETURN Expression.makeSimple(
@@ -769,7 +786,7 @@ BEGIN
     RETURN makeSymbol(NEW Std("UNPK", call))
     RETURN makeSymbol(NEW Std("UNPK", call))
 END makeUnpk;
 END makeUnpk;
 
 
-PROCEDURE dumpProcArgs(proc: Type): STRING;
+PROCEDURE dumpProcArgs(proc: Defined): STRING;
 VAR
 VAR
     result: STRING;
     result: STRING;
 BEGIN
 BEGIN
@@ -791,9 +808,9 @@ BEGIN
         result := result + ")";
         result := result + ")";
     END;
     END;
     RETURN result
     RETURN result
-END dumpProcArgs;
+END;
 
 
-PROCEDURE Type.description(): STRING;
+PROCEDURE Defined.description(): STRING;
 VAR
 VAR
     result: STRING;
     result: STRING;
 BEGIN
 BEGIN
@@ -805,13 +822,13 @@ BEGIN
         END;
         END;
     END;
     END;
     RETURN result
     RETURN result
-END Type.description;
+END;
 
 
-PROCEDURE Type.callGenerator(cx: LanguageContext.PType): PCallGenerator;
+PROCEDURE Defined.callGenerator(cx: LanguageContext.PType): PCallGenerator;
     RETURN makeProcCallGenerator(cx, SELF)
     RETURN makeProcCallGenerator(cx, SELF)
-END Type.callGenerator;
+END;
 
 
-PROCEDURE Type.define(args: ARRAY OF Types.PProcedureArgument; result: Types.PType);
+PROCEDURE Defined.define(args: ARRAY OF Types.PProcedureArgument; result: Types.PType);
 BEGIN
 BEGIN
     FOR i <- 0 TO LEN(args) - 1 DO
     FOR i <- 0 TO LEN(args) - 1 DO
         ASSERT(args[i].type # NIL);
         ASSERT(args[i].type # NIL);
@@ -821,15 +838,15 @@ BEGIN
         ASSERT(SELF.mArgs[i].type # NIL);
         ASSERT(SELF.mArgs[i].type # NIL);
     END;
     END;
     SELF.mResult := result;
     SELF.mResult := result;
-END Type.define;
+END;
 
 
-PROCEDURE Type.args(): Types.ProcedureArguments;
+PROCEDURE Defined.args(): Types.ProcedureArguments;
     RETURN SELF.mArgs
     RETURN SELF.mArgs
-END Type.args;
+END;
 
 
-PROCEDURE Type.result(): Types.PType;
+PROCEDURE Defined.result(): Types.PType;
     RETURN SELF.mResult
     RETURN SELF.mResult
-END Type.result;
+END;
 
 
 BEGIN
 BEGIN
     predefined.add(makeNew());
     predefined.add(makeNew());

+ 3 - 11
src/ob/Types.ob

@@ -104,10 +104,6 @@ TYPE
     END;
     END;
     PStaticArray* = POINTER TO StaticArray;
     PStaticArray* = POINTER TO StaticArray;
 
 
-    Procedure* = RECORD(NamedType)
-        PROCEDURE designatorCode*(id: STRING): STRING
-    END;
-
     ProcedureArgument* = RECORD
     ProcedureArgument* = RECORD
         PROCEDURE ProcedureArgument*(type: PStorageType; isVar: BOOLEAN);
         PROCEDURE ProcedureArgument*(type: PStorageType; isVar: BOOLEAN);
 
 
@@ -120,11 +116,11 @@ TYPE
     PProcedureArgument* = POINTER TO ProcedureArgument;
     PProcedureArgument* = POINTER TO ProcedureArgument;
     ProcedureArguments* = ARRAY * OF PProcedureArgument;
     ProcedureArguments* = ARRAY * OF PProcedureArgument;
 
 
-    DefinedProcedure* = RECORD(Procedure)
+    Procedure* = RECORD(NamedType)
         PROCEDURE args*(): ProcedureArguments;
         PROCEDURE args*(): ProcedureArguments;
-        PROCEDURE result*(): PType
+        PROCEDURE result*(): PType;
+        PROCEDURE designatorCode*(id: STRING): STRING
     END;
     END;
-    PDefinedProcedure* = POINTER TO DefinedProcedure;
 
 
     BasicType* = RECORD(NamedType)
     BasicType* = RECORD(NamedType)
         PROCEDURE BasicType*(name: STRING; initializer: STRING);
         PROCEDURE BasicType*(name: STRING; initializer: STRING);
@@ -322,10 +318,6 @@ PROCEDURE Procedure.isScalar(): BOOLEAN;
     RETURN TRUE;
     RETURN TRUE;
 END;
 END;
 
 
-PROCEDURE DefinedProcedure.designatorCode(id: STRING): STRING;
-    RETURN id
-END DefinedProcedure.designatorCode;
-
 PROCEDURE ProcedureArgument.description(): STRING;
 PROCEDURE ProcedureArgument.description(): STRING;
 VAR
 VAR
     result: STRING;
     result: STRING;

+ 2 - 2
src/ob/Variable.ob

@@ -2,8 +2,8 @@ MODULE Variable;
 IMPORT
 IMPORT
     OberonRtl, Types;
     OberonRtl, Types;
 TYPE
 TYPE
-    TypedVariable = RECORD(Types.Variable)
-        PROCEDURE TypedVariable(type: Types.PStorageType);
+    TypedVariable* = RECORD(Types.Variable)
+        PROCEDURE TypedVariable*(type: Types.PStorageType);
 
 
         mType: Types.PStorageType;
         mType: Types.PStorageType;
     END;
     END;

+ 6 - 3
src/oberon/oberon_context.js

@@ -4,10 +4,13 @@ var Class = require("rtl.js").Class;
 var CodeGenerator = require("js/CodeGenerator.js");
 var CodeGenerator = require("js/CodeGenerator.js");
 var Context = require("context.js");
 var Context = require("context.js");
 var ContextExpression = require("js/ContextExpression.js");
 var ContextExpression = require("js/ContextExpression.js");
+var ContextHierarchy = require("js/ContextHierarchy.js");
+var ContextProcedure = require("js/ContextProcedure.js");
 var ContextType = require("js/ContextType.js");
 var ContextType = require("js/ContextType.js");
 var ContextVar = require("js/ContextVar.js");
 var ContextVar = require("js/ContextVar.js");
 var Errors = require("js/Errors.js");
 var Errors = require("js/Errors.js");
 var Expression = require("js/Expression.js");
 var Expression = require("js/Expression.js");
+var Module = require("js/Module.js");
 var op = require("js/Operator.js");
 var op = require("js/Operator.js");
 var Record = require("js/Record.js");
 var Record = require("js/Record.js");
 var Type = require("js/Types.js");
 var Type = require("js/Types.js");
@@ -43,7 +46,7 @@ var ProcedureCall = Context.Chained.extend({
             var d = this.attributes.designator;
             var d = this.attributes.designator;
             this.__type = d.type();
             this.__type = d.type();
             this.__id = d.code();
             this.__id = d.code();
-            this.__procCall = Context.makeProcCall(this, this.__type, d.info());
+            this.__procCall = ContextProcedure.makeCall(this, this.__type, d.info());
             this.__callExpression = undefined;
             this.__callExpression = undefined;
         }
         }
         return this.__procCall;
         return this.__procCall;
@@ -73,7 +76,7 @@ var StatementProcedureCall = ProcedureCall.extend({
     },
     },
     endParse: function(){
     endParse: function(){
         var e = this.callExpression();
         var e = this.callExpression();
-        Context.assertProcStatementResult(e.type());
+        Module.assertProcStatementResult(e.type());
         this.parent().codeGenerator().write(e.code());
         this.parent().codeGenerator().write(e.code());
     }
     }
 });
 });
@@ -107,7 +110,7 @@ var Assignment = Context.Chained.extend({
     handleExpression: function(e){
     handleExpression: function(e){
         var d = this.attributes.designator;
         var d = this.attributes.designator;
         var left = Expression.make(d.code(), d.type(), d);
         var left = Expression.make(d.code(), d.type(), d);
-        this.parent().codeGenerator().write(op.assign(left, e, this.root().language()));
+        this.parent().codeGenerator().write(op.assign(left, e, ContextHierarchy.makeLanguageContext(this)));
     }
     }
 });
 });
 
 

+ 1 - 1
src/oc.js

@@ -131,7 +131,7 @@ function compile(text, language, handleErrors){
                 return new ContextHierarchy.Root(
                 return new ContextHierarchy.Root(
                     { codeGenerator: language.codeGenerator.make(),
                     { codeGenerator: language.codeGenerator.make(),
                       moduleGenerator: moduleCode,
                       moduleGenerator: moduleCode,
-                      rtl: function(){return rtl;},
+                      rtl: rtl,
                       types: language.types,
                       types: language.types,
                       stdSymbols: language.stdSymbols,
                       stdSymbols: language.stdSymbols,
                       moduleResolver: moduleResolver
                       moduleResolver: moduleResolver

+ 1 - 1
test/test_unit_common.js

@@ -33,7 +33,7 @@ var TestContext = Class.extend.call(ContextHierarchy.Root, {
                 this,
                 this,
                 { codeGenerator: language.codeGenerator.nil,
                 { codeGenerator: language.codeGenerator.nil,
                   moduleGenerator: function(){return new TestModuleGenerator();},
                   moduleGenerator: function(){return new TestModuleGenerator();},
-                  rtl: function(){return rtl;},
+                  rtl: rtl,
                   types: language.types,
                   types: language.types,
                   stdSymbols: language.stdSymbols
                   stdSymbols: language.stdSymbols
                 });
                 });