| 
					
				 | 
			
			
				@@ -1,7 +1,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Store } from './store/store'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Modes } from './modes'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Context } from './context'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { Types, fromOrdToType } from './../typeSystem/types'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { Types } from './../typeSystem/types'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Operators } from './../ast/operators'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { LanguageDefinedFunction } from './definedFunctions'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { resultTypeAfterInfixOp, resultTypeAfterUnaryOp } from './compatibilityTable'; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -127,17 +127,6 @@ export class IVProgProcessor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const funcName = func.isMain ? IVProgProcessor.MAIN_INTERNAL_ID : func.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const funcStore = new Store(funcName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     funcStore.extendStore(this.globalStore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let dimensions = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let type_ord = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if(func.returnType instanceof ArrayType) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      // multi dimensional return... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      dimensions = func.returnType.dimensions; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      type_ord = func.returnType.innerType.ord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      type_ord = func.returnType.ord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    funcStore.insertStore("$dim", new StoreValue(Types.INTEGER, dimensions)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    funcStore.insertStore("$type", new StoreValue(Types.INTEGER, type_ord)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const newFuncStore$ = this.associateParameters(func.formalParameters, actualParameters, store, funcStore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return newFuncStore$.then(sto => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       this.context.push(Context.FUNCTION); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -445,28 +434,29 @@ export class IVProgProcessor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   executeReturn (store, cmd) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const return_type_ord = store.applyStore('$type').get(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const return_dim = store.applyStore('$dim').get(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      let funcType = fromOrdToType(return_type_ord).getOrElse(Types.UNDEFINED); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if(return_dim > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        funcType = new ArrayType(funcType, return_dim); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const $value = this.evaluateExpression(store, cmd.expression); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const funcName = store.name === IVProgProcessor.MAIN_INTERNAL_ID ?  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         LanguageDefinedFunction.getMainFunctionName() : store.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      const func = this.findFunction(funcName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      const funcType = func.returnType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      const $value = this.evaluateExpression(store, cmd.expression); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+       
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return $value.then(value => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let real_value = value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(value === null && funcType.isCompatible(Types.VOID)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           store.mode = Modes.RETURN; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           return Promise.resolve(store); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (value === null || !funcType.isCompatible(value.type)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          const stringInfo = funcType.stringInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          if(!Config.enable_type_casting || !Store.canImplicitTypeCast(funcType, value.type)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stringInfo = funcType.stringInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           const info = stringInfo[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           return Promise.reject(ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          real_value = Store.doImplicitCasting(funcType, value); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          store.insertStore('$', value); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          store.insertStore('$', real_value); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           store.mode = Modes.RETURN; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           return Promise.resolve(store); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |