Пример #1
0
 internal Symbol(string name, IrisType type, StorageClass storage, int location, ImportedMember importInfo)
 {
     Name = name;
     Type = type;
     StorageClass = storage;
     Location = location;
     ImportInfo = importInfo;
 }
        public Symbol OpenMethod(string name, IrisType type)
        {
            Symbol methodSymbol = Add(name, type, StorageClass.Global); // Add the method itself to the symbol table

            // Create the local scope
            _local = new Dictionary<string, Symbol>(StringComparer.InvariantCultureIgnoreCase);

            return methodSymbol;
        }
        public Symbol Add(string name, IrisType type, StorageClass storage, int location, ImportedMember importInfo = null)
        {
            Symbol symbol = new Symbol(name, type, storage, location, importInfo);
            if (storage == StorageClass.Global)
                _global.Add(name, symbol);
            else
                _local.Add(name, symbol);

            return symbol;
        }
        public static Function MakeTestFunction(IrisType returnType, IrisType[] paramTypes)
        {
            Variable[] parameters = new Variable[paramTypes.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                string name = string.Format("p{0}", i);
                parameters[i] = new Variable(paramTypes[i], name);
            }

            return Function.Create(returnType, parameters);
        }
Пример #5
0
        private Symbol ParseLValue(Lexer lvalLexer)
        {
            if (lvalLexer.CurrentToken != Token.Identifier)
            {
                AddLValueError();
                return(null);
            }

            Symbol symbol = _context.SymbolTable.Lookup(lvalLexer.GetLexeme());

            if (symbol == null)
            {
                AddLValueError();
                return(null);
            }

            IrisType lhs = symbol.Type;

            lvalLexer.MoveNext();
            if (lhs.IsArray)
            {
                // We should have an open bracket (We don't support changing the array value itself)
                if (lvalLexer.CurrentToken != Token.ChrOpenBracket)
                {
                    AddLValueError();
                    return(null);
                }

                EmitLoadSymbol(symbol, SymbolLoadMode.Raw);

                lvalLexer.MoveNext();
                if (lvalLexer.CurrentToken != Token.Number)
                {
                    AddLValueError();
                    return(null);
                }

                int index = lvalLexer.ParseInteger();
                MethodGenerator.PushIntConst(index);
                lvalLexer.MoveNext();
                if (lvalLexer.CurrentToken != Token.ChrCloseBracket)
                {
                    AddLValueError();
                    return(null);
                }
            }
            else if (lhs.IsByRef)
            {
                EmitLoadSymbol(symbol, SymbolLoadMode.Raw);
            }

            return(symbol);
        }
        public void InitializeSymbols()
        {
            ImportedMethod currentMethod = Scope.TryImportCurrentMethod();

            if (currentMethod == null)
            {
                return; // Nothing to evaluate if we can't get the current method
            }
            // Add compiler intrinsics
            AddIntrinsics();

            // Add debugger intrinsics
            // (Not implemented yet)

            // Add globals
            ImportedType type = currentMethod.DeclaringType;

            foreach (ImportedField importedfield in type.GetFields())
            {
                IrisType irisType = importedfield.FieldType;
                if (irisType != IrisType.Invalid)
                {
                    SymbolTable.Add(importedfield.Name, irisType, StorageClass.Global, importedfield);
                }
            }

            // Add methods
            foreach (ImportedMethod importedMethod in type.GetMethods())
            {
                Method method = importedMethod.ConvertToIrisMethod();
                if (IsValidMethod(method))
                {
                    SymbolTable.Add(importedMethod.Name, method, StorageClass.Global, importedMethod);
                }
            }

            // Create symbol for query method and transition the SymbolTable to method scope
            _irisMethod = currentMethod.ConvertToIrisMethod();
            SymbolTable.OpenMethod("$.query", _irisMethod);

            // Add symbols for parameters
            foreach (Variable param in _irisMethod.GetParameters())
            {
                SymbolTable.Add(param.Name, param.Type, StorageClass.Argument);
            }

            // Add symbols for local variables
            foreach (LocalVariable local in Scope.GetLocals())
            {
                SymbolTable.Add(local.Name, local.Type, StorageClass.Local, local.Slot);
            }
        }
Пример #7
0
 private static void Findminmax(int N, IrisType[] T)
 {
     for (int j = 0; j < T.Length; j++)
     {
         Console.WriteLine(T[j].Name);
         string read = Console.ReadLine();
         string[] input = read.Split(' ');
         for (int i = 0; i < input.Length; i++)
         {
             T[j].minmax[N - 1].Add(double.Parse(input[i]));
         }
     }
 }
        protected IrisType ParseTerm(SymbolLoadMode mode)
        {
            IrisType     lhs = ParseFactor(mode);
            FilePosition fp  = _lexer.TokenStartPosition;
            Operator     opr = AcceptOperator(OperatorMaps.Instance.Term);

            if (opr != Operator.None)
            {
                IrisType rhs = ParseTerm(mode);
                return(ProcessArithemticOperator(fp, lhs, rhs, opr));
            }

            return(lhs);
        }
Пример #9
0
 public void StoreElement(IrisType elementType)
 {
     if (elementType == IrisType.Integer)
     {
         WriteInstruction("stelem.i4", null);
     }
     else if (elementType == IrisType.Boolean)
     {
         WriteInstruction("stelem.i1", null);
     }
     else
     {
         WriteInstruction("stelem.ref", null);
     }
 }
Пример #10
0
 public void LoadElement(IrisType elementType)
 {
     if (elementType == IrisType.Integer)
     {
         WriteInstruction("ldelem.i4", null);
     }
     else if (elementType == IrisType.Boolean)
     {
         WriteInstruction("ldelem.i1", null);
     }
     else
     {
         WriteInstruction("ldelem", IrisTypeToCilTypeName(elementType));
     }
 }
Пример #11
0
 public void Store(IrisType type)
 {
     if (type == IrisType.Boolean)
     {
         WriteInstruction("stind.i1", null);
     }
     else if (type == IrisType.Integer)
     {
         WriteInstruction("stind.i4", null);
     }
     else
     {
         WriteInstruction("stind.ref", null);
     }
 }
        protected IrisType ParseExpression(SymbolLoadMode mode = SymbolLoadMode.Dereference)
        {
            IrisType     lhs = ParseCompareExpression(mode);
            FilePosition fp  = _lexer.TokenStartPosition;
            Operator     opr = AcceptOperator(OperatorMaps.Instance.Logic);

            if (opr != Operator.None)
            {
                VerifyExpressionType(fp, lhs, IrisType.Boolean);
                IrisType rhs = ParseExpression(mode);
                VerifyExpressionType(fp, rhs, IrisType.Boolean);
                MethodGenerator.Operator(opr);
            }

            return(lhs);
        }
Пример #13
0
        private void InitArrayHelper(Symbol arraySymbol, int lowerBound, int dimension)
        {
            IrisType elementType = arraySymbol.Type.GetElementType();
            string   cilType     = IrisTypeToCilTypeName(elementType);

            PushIntConst(dimension);
            WriteInstruction("newarr", cilType);

            if (arraySymbol.StorageClass == StorageClass.Local)
            {
                StoreLocal(arraySymbol.Location);
            }
            else
            {
                StoreGlobal(arraySymbol);
            }
        }
        /// <summary>
        /// Convert a type from the debugger's type system into Iris's type system
        /// </summary>
        /// <param name="lmrType">LMR Type</param>
        /// <returns>Iris type</returns>
        public static IrisType GetIrisTypeForLmrType(Type lmrType)
        {
            if (lmrType.IsPrimitive)
            {
                switch (lmrType.FullName)
                {
                case "System.Int32":
                    return(IrisType.Integer);

                case "System.Boolean":
                    return(IrisType.Boolean);
                }
            }
            else if (lmrType.IsArray)
            {
                if (lmrType.GetArrayRank() != 1)
                {
                    return(IrisType.Invalid);
                }

                IrisType elementType = GetIrisTypeForLmrType(lmrType.GetElementType());
                if (elementType == IrisType.Invalid)
                {
                    return(IrisType.Invalid);
                }

                return(elementType.MakeArrayType());
            }
            else if (lmrType.IsByRef)
            {
                IrisType elementType = GetIrisTypeForLmrType(lmrType.GetElementType());
                if (elementType == IrisType.Invalid)
                {
                    return(IrisType.Invalid);
                }

                return(elementType.MakeByRefType());
            }
            else if (lmrType.FullName.Equals("System.String"))
            {
                return(IrisType.String);
            }

            // Unknown
            return(IrisType.Invalid);
        }
        public ImportedMethod TryFindMethod(string name, bool instance, IrisType returnType, IrisType[] paramTypes)
        {
            EnsureMethods();

            foreach (ImportedMethod method in _methods)
            {
                if (method.IsStatic == instance)
                {
                    continue;
                }

                if (method.ReturnType != returnType)
                {
                    continue;
                }

                if (!string.Equals(method.Name, name))
                {
                    continue;
                }

                Variable[] methodParams = method.GetParameters();
                if (methodParams.Length != paramTypes.Length)
                {
                    continue;
                }

                bool match = true;
                for (int i = 0; i < paramTypes.Length; i++)
                {
                    if (paramTypes[i] != methodParams[i].Type)
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    return(method); // Found
                }
            }

            return(null); // Not found
        }
        private IrisType ProcessArrayAccess(FilePosition fp, Symbol symbol, SymbolLoadMode mode)
        {
            IrisType symbolType = symbol.Type;
            IrisType resultType = IrisType.Invalid;

            if (symbolType != IrisType.Invalid)
            {
                if (!symbolType.IsArray)
                {
                    AddError(fp, string.Format("Symbol '{0}' is not an array, but is being used as an array.", _lexeme));
                }
                else
                {
                    EmitLoadSymbol(symbol, SymbolLoadMode.Dereference);
                    resultType = symbol.Type.GetElementType();
                }
            }

            FilePosition indexerPosition = _lexer.TokenStartPosition;
            IrisType     indexerType     = ParseExpression();

            if (indexerType != IrisType.Integer)
            {
                AddError(indexerPosition, "Expecting integer value as array index.");
            }

            Expect(Token.ChrCloseBracket);

            if (resultType != IrisType.Invalid)
            {
                if (mode == SymbolLoadMode.ElementAddress)
                {
                    MethodGenerator.LoadElementAddress(resultType);
                    resultType = resultType.MakeByRefType();
                }
                else if (mode == SymbolLoadMode.Element)
                {
                    MethodGenerator.LoadElement(resultType);
                }
            }

            return(resultType);
        }
        protected void ParseIf()
        {
            FilePosition fp   = _lexer.TokenStartPosition;
            IrisType     type = ParseExpression();

            VerifyExpressionType(fp, type, IrisType.Boolean);
            Expect(Token.KwThen);

            int label = GetNextLabel();

            MethodGenerator.BranchFalse(label);
            MethodGenerator.EndSourceLine(_lastParsedPosition);

            ParseStatement();

            FilePosition endOfIfStatement = _lastParsedPosition;
            FilePosition elseStart        = _lexer.TokenStartPosition;

            if (Accept(Token.KwElse))
            {
                int label2 = GetNextLabel();
                MethodGenerator.Goto(label2);
                MethodGenerator.Label(label);
                MethodGenerator.EndSourceLine(endOfIfStatement);
                MethodGenerator.BeginSourceLine(elseStart);
                if (Accept(Token.KwIf))
                {
                    ParseIf();
                }
                else
                {
                    MethodGenerator.EmitNonCodeLineInfo(elseStart.Expand(4 /* Length of "else" */));
                    ParseStatement();
                }

                MethodGenerator.Label(label2);
            }
            else
            {
                MethodGenerator.Label(label);
            }
        }
        private Dictionary <IrisType, List <MathVector> > GetData(List <string> data, bool has_headers = false)
        {
            var result = new Dictionary <IrisType, List <MathVector> >(3);

            for (int i = has_headers ? 1 : 0; i < data.Count; i++)
            {
                var      temp            = data[i].Split(',').ToList();
                var      last            = temp.Count - 1;
                IrisType currentIrisType = ToIrisTypeConverter.Convert(temp[last]);

                if (!result.ContainsKey(currentIrisType))
                {
                    result.Add(currentIrisType, new List <MathVector>()); //Adding new iris type to collection
                }

                AddListOfValues(result[currentIrisType], temp); //Adding new vector to concrete iris type
            }

            return(result);
        }
Пример #19
0
        /// <summary>
        /// This method is called by the debug engine to populate the text representing the type of
        /// a result.
        /// </summary>
        /// <param name="inspectionContext">Context of the evaluation.  This contains options/flags
        /// to be used during compilation. It also contains the InspectionSession.  The inspection
        /// session is the object that provides lifetime management for our objects.  When the user
        /// steps or continues the process, the debug engine will dispose of the inspection session</param>
        /// <param name="clrType">This is the raw type we want to format</param>
        /// <param name="customTypeInfo">If Expression Compiler passed any additional information
        /// about the type that doesn't exist in metadata, this parameter contais that information.</param>
        /// <param name="formatSpecifiers">A list of custom format specifiers that the debugger did
        /// not understand.  If you want special format specifiers for your language, handle them
        /// here.  The formatter should ignore any format specifiers it does not understand.</param>
        /// <returns>The text of the type name to display</returns>
        string IDkmClrFormatter.GetTypeName(
            DkmInspectionContext inspectionContext,
            DkmClrType clrType,
            DkmClrCustomTypeInfo customTypeInfo,
            ReadOnlyCollection <string> formatSpecifiers)
        {
            // Get the LMR type for the DkmClrType.  LMR Types (Microsoft.VisualStudio.Debugger.Metadata.Type)
            // are similar to System.Type, but represent types that live in the process being debugged.
            Type lmrType = clrType.GetLmrType();

            IrisType irisType = Utility.GetIrisTypeForLmrType(lmrType);

            if (irisType == IrisType.Invalid)
            {
                // We don't know about this type.  Delegate to the C# Formatter to format the
                // type name.
                return(inspectionContext.GetTypeName(clrType, customTypeInfo, formatSpecifiers));
            }

            return(irisType.ToString());
        }
Пример #20
0
        public void BeginMethod(
            string name,
            IrisType returnType,
            Variable[] parameters,
            Variable[] locals,
            bool entryPoint,
            string methodFileName)
        {
            if (!_outputEnabled)
            {
                return;
            }

            _emitter.BeginMethod(name, returnType, parameters, locals.ToArray(), entryPoint);
            if (_emitDebugInfo)
            {
                _emitter.EmitMethodLanguageInfo();
            }

            _methodFileName = methodFileName;
        }
        protected IrisType ParseCompareExpression(SymbolLoadMode mode)
        {
            IrisType     lhs = ParseArithmeticExpression(mode);
            FilePosition fp  = _lexer.TokenStartPosition;
            Operator     opr = AcceptOperator(OperatorMaps.Instance.Compare);

            if (opr != Operator.None)
            {
                IrisType rhs = ParseCompareExpression(mode);
                if (lhs == IrisType.String && rhs == IrisType.String)
                {
                    Symbol strcmp = LookupSymbol(fp, "strcmp");
                    MethodGenerator.Call(strcmp);
                    MethodGenerator.PushIntConst(0);
                }

                MethodGenerator.Operator(opr);
                return(ApplyTypeRules(fp, lhs, rhs, boolResult: true));
            }

            return(lhs);
        }
Пример #22
0
        public void BeginMethod(string name, IrisType returnType, Variable[] parameters, Variable[] locals, bool entryPoint)
        {
            string cilName = string.Format(
                "{0} {1}({2})",
                IrisTypeToCilTypeName(returnType),
                name,
                string.Join(", ", parameters.Select(v => IrisVarToCilVar(v))));

            WriteIndentedText(string.Format(".method public hidebysig static {0} cil managed", cilName));
            WriteIndentedText("{");

            _indentLevel++;

            if (entryPoint)
            {
                WriteIndentedText(".entrypoint");
            }

            if (locals.Length > 0)
            {
                StringBuilder localsBuilder = new StringBuilder();
                localsBuilder.Append(".locals init (");

                int localIndex = 0;
                foreach (Variable var in locals)
                {
                    if (localIndex != 0)
                    {
                        localsBuilder.Append(", ");
                    }

                    localsBuilder.AppendFormat("[{0}] {1}", localIndex, IrisVarToCilVar(var));
                    localIndex++;
                }

                localsBuilder.Append(")");
                WriteIndentedText(localsBuilder.ToString());
            }
        }
        private IrisType ParseExpressionAndReadFormatSpecifiers()
        {
            // Call the base class to parse the expression.
            // Then do our own parsing to handle format specifiers.
            IrisType resultType = ParseExpression();

            // If no compile errors, look for format specifiers
            if (_context.CompileErrors.Count > 0)
            {
                return(resultType);
            }

            if (_lexer.CurrentToken == Token.Eof)
            {
                return(resultType);
            }

            while (_lexer.CurrentToken == Token.ChrComma)
            {
                _lexer.MoveNext();
                if (_lexer.CurrentToken == Token.Identifier)
                {
                    _context.FormatSpecifiers.Add(_lexer.GetLexeme());
                    _lexer.MoveNext();
                }
                else
                {
                    AddErrorAtTokenStart("Invalid format specifier.");
                }
            }

            if (_lexer.CurrentToken != Token.Eof)
            {
                AddErrorAtTokenStart("Unexpected text after expression.");
            }

            return(resultType);
        }
        private IrisType ApplyTypeRules(FilePosition fp, IrisType lhs, IrisType rhs, bool boolResult = false)
        {
            // If there was a previous semantic error, don't apply any further rules.
            if (lhs == IrisType.Invalid || rhs == IrisType.Invalid)
            {
                return(IrisType.Invalid);
            }

            string semanticError = null;

            if (lhs == IrisType.Void || rhs == IrisType.Void)
            {
                semanticError = "Cannot apply operator to procedure call.";
            }
            else if (lhs.IsByRef || rhs.IsByRef)
            {
                semanticError = "Cannot take address of expression.";
            }
            else if (lhs != rhs)
            {
                semanticError = "Type mismatch error.";
            }
            else if (!lhs.IsPrimitive)
            {
                semanticError = "Operator requires a primitive type (boolean, integer, or string).";
            }

            if (semanticError != null)
            {
                AddError(fp, semanticError);
                return(IrisType.Invalid);
            }
            else
            {
                return(boolResult ? IrisType.Boolean : lhs);
            }
        }
Пример #25
0
        public static string ConvertBack(IrisType irisType)
        {
            string result = "";

            switch (irisType)
            {
            case IrisType.Setosa:
                result = "setosa";
                break;

            case IrisType.Versicolor:
                result = "versicolor";
                break;

            case IrisType.Virginica:
                result = "virginica";
                break;

            case IrisType.None:
                result = "None";
                break;
            }
            return(result);
        }
Пример #26
0
 public Variable(IrisType type, string name, SubRange subRange)
 {
     Type = type;
     Name = name;
     SubRange = subRange;
 }
 private Method CreateMethodHelper(IrisType returnType, Variable[] parameters)
 {
     if (returnType == IrisType.Void)
         return Procedure.Create(parameters);
     else
         return Function.Create(returnType, parameters);
 }
Пример #28
0
 public void Load(IrisType type)
 {
     _textEmitter.Load(type);
 }
Пример #29
0
 public void LoadElementAddress(IrisType elementType)
 {
     WriteInstruction("ldelema", IrisTypeToCilTypeName(elementType));
 }
Пример #30
0
 public void LoadElementAddress(IrisType elementType)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.LoadElemA, elementType));
 }
Пример #31
0
 public void Store(IrisType type)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.Assign, type));
 }
 public void StoreElement(IrisType elementType)
 {
     _textEmitter.StoreElement(elementType);
 }
 public void BeginMethod(string name, IrisType returnType, Variable[] parameters, Variable[] locals, bool entryPoint)
 {
     _textEmitter.BeginMethod(name, returnType, parameters, locals, entryPoint);
 }
Пример #34
0
        private static void Findminmax(int M, int k, int ii, IrisType[] I)
        {
            int[] l = { 0, 0, 0 };
            double min = dataList[M][ii].props[M];

            for (int i = ii; i < dataList[M].Count; i++)
            {
                for (int j = 0; j < I.Length; j++)
                {
                    if (dataList[M][i].Name == I[j].Name)
                    {
                        l[j]++;
                    }
                    if (l[j] == 3) { k = j; ii = i; break; }

                }
                if (l[k] == 3)
                {
                    break;
                }

            }

            ii = dr(M, ii, k, I);
            if (ii != min)
            {
                I[k].minmax[M - 1].Add(min);
                I[k].minmax[M - 1].Add(dataList[M][ii].props[M]);
            }
            if (ii + 1 < dataList[M].Count)
            {
                Findminmax(M, k, ii, I);
            }
        }
 public void Store(IrisType type)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.Assign, type));
 }
        private static string IrisTypeToCilTypeName(IrisType type)
        {
            if (type.IsPrimitive)
            {
                if (type == IrisType.Integer)
                    return "int32";
                else if (type == IrisType.String)
                    return "string";
                else if (type == IrisType.Boolean)
                    return "bool";
            }
            else if (type.IsArray)
            {
                return IrisTypeToCilTypeName(type.GetElementType()) + "[]";
            }
            else if (type.IsByRef)
            {
                return IrisTypeToCilTypeName(type.GetElementType()) + "&";
            }
            else if (type == IrisType.Void)
            {
                return "void";
            }

            return "_Unknown";
        }
 public void StoreElement(IrisType elementType)
 {
     if (elementType == IrisType.Integer)
         WriteInstruction("stelem.i4", null);
     else if (elementType == IrisType.Boolean)
         WriteInstruction("stelem.i1", null);
     else
         WriteInstruction("stelem.ref", null);
 }
 public void LoadElement(IrisType elementType)
 {
     if (elementType == IrisType.Integer)
         WriteInstruction("ldelem.i4", null);
     else if (elementType == IrisType.Boolean)
         WriteInstruction("ldelem.i1", null);
     else
         WriteInstruction("ldelem", IrisTypeToCilTypeName(elementType));
 }
Пример #39
0
 public void LoadElementAddress(IrisType elementType)
 {
     _textEmitter.LoadElementAddress(elementType);
 }
 public void StoreElement(IrisType elementType)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.StoreElem, elementType));
 }
Пример #41
0
 public void Load(IrisType type)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.Load, type));
 }
 public void LoadElementAddress(IrisType elementType)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.LoadElemA, elementType));
 }
Пример #43
0
 public void StoreElement(IrisType elementType)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.StoreElem, elementType));
 }
 public void Load(IrisType type)
 {
     _deferredInstructions.Add(new MethodInstruction(MethodOpCode.Load, type));
 }
Пример #45
0
 public void LoadElement(IrisType elementType)
 {
     _textEmitter.LoadElement(elementType);
 }
        public void BeginMethod(
            string name,
            IrisType returnType,
            Variable[] parameters,
            Variable[] locals,
            bool entryPoint,
            string methodFileName)
        {
            if (!_outputEnabled)
                return;

            _emitter.BeginMethod(name, returnType, parameters, locals.ToArray(), entryPoint);
            if (_emitDebugInfo)
                _emitter.EmitMethodLanguageInfo();

            _methodFileName = methodFileName;
        }
Пример #47
0
 public void BeginMethod(string name, IrisType returnType, Variable[] parameters, Variable[] locals, bool entryPoint)
 {
     _textEmitter.BeginMethod(name, returnType, parameters, locals, entryPoint);
 }
Пример #48
0
 public void StoreElement(IrisType elementType)
 {
     _textEmitter.StoreElement(elementType);
 }
Пример #49
0
 public void Store(IrisType type)
 {
     _textEmitter.Store(type);
 }
        public ImportedMethod TryFindMethod(string name, bool instance, IrisType returnType, IrisType[] paramTypes)
        {
            EnsureMethods();

            foreach (ImportedMethod method in _methods)
            {
                if (method.IsStatic == instance)
                    continue;

                if (method.ReturnType != returnType)
                    continue;

                if (!string.Equals(method.Name, name))
                    continue;

                Variable[] methodParams = method.GetParameters();
                if (methodParams.Length != paramTypes.Length)
                    continue;

                bool match = true;
                for (int i = 0; i < paramTypes.Length; i++)
                {
                    if (paramTypes[i] != methodParams[i].Type)
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                    return method; // Found
            }

            return null; // Not found
        }
        public void BeginMethod(string name, IrisType returnType, Variable[] parameters, Variable[] locals, bool entryPoint)
        {
            string cilName = string.Format(
                "{0} {1}({2})",
                IrisTypeToCilTypeName(returnType),
                name,
                string.Join(", ", parameters.Select(v => IrisVarToCilVar(v))));

            WriteIndentedText(string.Format(".method public hidebysig static {0} cil managed", cilName));
            WriteIndentedText("{");

            _indentLevel++;

            if (entryPoint)
            {
                WriteIndentedText(".entrypoint");
            }

            if (locals.Length > 0)
            {
                StringBuilder localsBuilder = new StringBuilder();
                localsBuilder.Append(".locals init (");

                int localIndex = 0;
                foreach (Variable var in locals)
                {
                    if (localIndex != 0)
                        localsBuilder.Append(", ");

                    localsBuilder.AppendFormat("[{0}] {1}", localIndex, IrisVarToCilVar(var));
                    localIndex++;
                }

                localsBuilder.Append(")");
                WriteIndentedText(localsBuilder.ToString());
            }
        }
 public void Add(string name, IrisType type)
 {
     _symbols.Add(new Tuple<string, IrisType>(name, type));
 }
 public void LoadElementAddress(IrisType elementType)
 {
     WriteInstruction("ldelema", IrisTypeToCilTypeName(elementType));
 }
        protected void ImportMethod(
            FilePosition fp,
            string symbolName,
            ImportedModule module,
            string declaringTypeName,
            string methodName,
            bool instance,
            IrisType returnType,
            IrisType[] paramTypes)
        {
            ImportedType declaringType = module.TryGetTypeByName(declaringTypeName);
            if (declaringType == null)
            {
                CompileErrors.Add(fp, String.Format("Cannot find imported type '{0}'.", declaringTypeName));
                return;
            }

            ImportedMethod importedMethod = declaringType.TryFindMethod(methodName, instance, returnType, paramTypes);
            if (importedMethod == null)
            {
                CompileErrors.Add(fp, String.Format("Cannot find imported function or procedure '{0}.{1}'.", declaringTypeName, methodName));
                return;
            }

            Method method = importedMethod.ConvertToIrisMethod();
            bool containsInvalidType = method.ReturnType == IrisType.Invalid;
            foreach (Variable param in method.GetParameters())
            {
                if (containsInvalidType)
                    break;

                if (param.Type == IrisType.Invalid)
                    containsInvalidType = true;
            }

            if (containsInvalidType)
                CompileErrors.Add(fp, String.Format("The function or procedure '{0}.{1}' contains types that are not supported by the language.", declaringTypeName, methodName));
            else
                SymbolTable.Add(symbolName, method, StorageClass.Global, importedMethod);
        }
 public void Store(IrisType type)
 {
     if (type == IrisType.Boolean)
         WriteInstruction("stind.i1", null);
     else if (type == IrisType.Integer)
         WriteInstruction("stind.i4", null);
     else
         WriteInstruction("stind.ref", null);
 }
        /// <summary>
        /// Add intrinsic methods and globals to the symbol table
        /// </summary>
        public void AddIntrinsics()
        {
            ImportedModule mscorlib = ReferenceMscorlib();
            ImportedModule runtime = ReferenceExternal("IrisRuntime.dll");

            IrisType tVoid = IrisType.Void;
            IrisType tString = IrisType.String;
            IrisType tInt = IrisType.Integer;
            IrisType[] noParams = new IrisType[0];

            FilePosition fp = FilePosition.Begin;

            if (mscorlib != null)
            {
                ImportGlobalField(fp, "$.emptystr", mscorlib, "System.String", "Empty");
                ImportMethod(fp, "concat", mscorlib, "System.String", "Concat", false, tString, new IrisType[] { tString, tString });
                ImportMethod(fp, "readln", mscorlib, "System.Console", "ReadLine", false, tString, noParams);
                ImportMethod(fp, "str", mscorlib, "System.Int32", "ToString", true, tString, noParams);
                ImportMethod(fp, "strcmp", mscorlib, "System.String", "Compare", false, tInt, new IrisType[] { tString, tString });
                ImportMethod(fp, "writeln", mscorlib, "System.Console", "WriteLine", false, tVoid, new IrisType[] { tString });
            }

            if (runtime != null)
            {
                ImportMethod(fp, "$.initstrarray", runtime, "IrisRuntime.CompilerServices", "InitStrArray", false, tVoid, new IrisType[] { IrisType.String.MakeArrayType() });
                ImportMethod(fp, "rand", runtime, "IrisRuntime.CompilerServices", "Rand", false, tInt, noParams);
            }
        }
        private static string TryGetFrameNameHelper(DkmInspectionContext inspectionContext, DkmStackWalkFrame frame, DkmVariableInfoFlags argumentFlags)
        {
            ImportedMethod currentMethod = TryGetCurrentMethod(inspectionContext, frame);

            if (currentMethod == null)
            {
                return(null);
            }

            string name = currentMethod.Name;

            if (string.Equals(name, "$.main", StringComparison.Ordinal))
            {
                return("<Main Block>");
            }

            if (argumentFlags == DkmVariableInfoFlags.None)
            {
                return(name);
            }

            Variable[] args = currentMethod.GetParameters();
            if (args.Length == 0)
            {
                return(name);
            }

            StringBuilder nameBuilder = new StringBuilder();

            nameBuilder.Append(name);
            nameBuilder.Append('(');

            bool first     = true;
            bool showTypes = argumentFlags.HasFlag(DkmVariableInfoFlags.Types);
            bool showNames = argumentFlags.HasFlag(DkmVariableInfoFlags.Names);

            foreach (Variable arg in args)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    nameBuilder.Append("; ");
                }

                IrisType argType = arg.Type;
                if (argType.IsByRef)
                {
                    nameBuilder.Append("var ");
                    argType = argType.GetElementType();
                }

                if (showNames)
                {
                    nameBuilder.Append(arg.Name);
                }

                if (showNames && showTypes)
                {
                    nameBuilder.Append(" : ");
                }

                if (showTypes)
                {
                    nameBuilder.Append(argType);
                }
            }

            nameBuilder.Append(')');
            return(nameBuilder.ToString());
        }
 public void LoadElementAddress(IrisType elementType)
 {
     _textEmitter.LoadElementAddress(elementType);
 }
Пример #59
0
 private static int dr(int M, int ii, int k, IrisType[] I)
 {
     if ((ii + 1 < dataList[M].Count) && (dataList[M][ii + 1].Name == I[k].Name))
     {
         ii++;
         ii = dr(M, ii, k, I);
     }
     return ii;
 }
 public void Store(IrisType type)
 {
     _textEmitter.Store(type);
 }