Пример #1
0
 private object CallInternal(RuntimeState state, object instance,
     object[] parameterValues, bool wantRefParams,
     out bool[] refParams)
 {
     if (wantRefParams)
         refParams = RefParams;
     else
         refParams = null;
     
     if (parameterValues.Length != parameters.Count)
         throw new Exception("TODO Incorrect number of parameters, "
             + "expecting " + parameters.Count + " got "
             + parameterValues.Length);
     
     MethodScope methodScope = new MethodScope(
         state.Scope,
         instance);
     
     for (int n = 0; n < parameters.Count; n++)
         methodScope.SetName(parameters[n], parameterValues[n]);
     
     state.Scope = methodScope;
     object returned = codeTree.Run(state);
     state.Scope = methodScope.Parent;
     
     for (int n = 0; n < parameters.Count; n++)
         parameterValues[n] = methodScope.GetName(parameters[n]);
     
     if (state.Returning == methodScope)
         state.Returning = null;
     
     return returned;
 }
Пример #2
0
 public object Call(RuntimeState state, object[] parameters,
     bool wantRefParams, out bool[] refParams)
 {
     if (isInstance)
         throw new Exception();
     
     return CallInternal(state, null, parameters, wantRefParams,
         out refParams);
 }
Пример #3
0
        public object Call(RuntimeState state, object instance,
                           object[] parameters, bool wantRefParams, out bool[] refParams)
        {
            if (!isInstance)
            {
                throw new Exception();
            }

            return(CallInternal(state, instance, parameters, wantRefParams,
                                out refParams));
        }
Пример #4
0
        private object CallInternal(RuntimeState state, object instance,
                                    object[] parameterValues, bool wantRefParams,
                                    out bool[] refParams)
        {
            if (wantRefParams)
            {
                refParams = RefParams;
            }
            else
            {
                refParams = null;
            }

            if (parameterValues.Length != parameters.Count)
            {
                throw new Exception("TODO Incorrect number of parameters, "
                                    + "expecting " + parameters.Count + " got "
                                    + parameterValues.Length);
            }

            MethodScope methodScope = new MethodScope(
                state.Scope,
                instance);

            for (int n = 0; n < parameters.Count; n++)
            {
                methodScope.SetName(parameters[n], parameterValues[n]);
            }

            state.Scope = methodScope;
            object returned = codeTree.Run(state);

            state.Scope = methodScope.Parent;

            for (int n = 0; n < parameters.Count; n++)
            {
                parameterValues[n] = methodScope.GetName(parameters[n]);
            }

            if (state.Returning == methodScope)
            {
                state.Returning = null;
            }

            return(returned);
        }
 public object Call(RuntimeState state, object[] parameterValues,
     bool wantRefParams, out bool[] refParams)
 {
     int extra;
     
     if (passState)
         extra = 1;
     else
         extra = 0;
     
     object[] actualParameterValues =
         new object[extra + parameterValues.Length];
     
     if (passState)
         actualParameterValues[0] = state;
     
     for (int n = 0; n < parameterValues.Length; n++)
         actualParameterValues[extra + n] = parameterValues[n];
     
     if (wantRefParams)
     {
         refParams = GetRefParams(method);
         
         if ((refParams != null) && passState)
         {
             bool[] newRefParams = new bool[refParams.Length - 1];
             
             for (int n = 0; n < newRefParams.Length; n++)
                 newRefParams[n] = refParams[n + 1];
             
             refParams = newRefParams;
         }
     }
     else
     {
         refParams = null;
     }
     
     object returnValue = method.Invoke(obj, actualParameterValues);
     
     for (int n = 0; n < parameterValues.Length; n++)
         parameterValues[n] = actualParameterValues[extra + n];
     
     return returnValue;
 }
Пример #6
0
 public void Whitespace(RuntimeState runtimeState)
 {
     //while (Peek().ToString().Trim().Length == 0)
     //    Read();
     
     if (!handleWhitespace)
         return;
     
     if (position >= length)
         return;
     
     if (whitespace == null)
         return;
     
     ParserState state = new ParserState(runtimeState);
 
     bool previousHandleWhitespace = handleWhitespace;
     handleWhitespace = false;
 
     whitespace.Parse(this, state);
     
     handleWhitespace = previousHandleWhitespace;
 }
Пример #7
0
 public ParserState(RuntimeState runtimeState)
 {
     this.runtimeState = runtimeState;
 }
Пример #8
0
 public object Call(RuntimeState state, object[] parameterValues,
                    bool wantRefParams, out bool[] refParams)
 {
     return(method.Call(state, instance, parameterValues,
                        wantRefParams, out refParams));
 }
Пример #9
0
 public ParserState(RuntimeState runtimeState)
 {
     this.runtimeState = runtimeState;
 }
Пример #10
0
 public void Import(string fileName)
 {
     if (!hasBeenSetUp)
         throw new Exception();
     
     fileName = pathResolver.Resolve(fileName);
     
     string absoluteFileName = Path.GetFullPath(fileName);
     
     if (imported.Contains(absoluteFileName))
         return;
     
     if (verbose)
         Console.WriteLine("importing " + fileName);
     
     imported.Add(absoluteFileName);
     
     if (Path.GetExtension(fileName).ToLower() == ".dll")
     {
         Assembly.LoadFrom(fileName);
     }
     else
     {
         pathResolver.PushDirectory(fileName);
     
         Lexer lexer = new Lexer(parseTrace, fileName);
         RuntimeState runtimeState = new RuntimeState(this, rootModule);
     
         currentLexer = lexer;
         
         Pattern oldRoot = grammar.RootPattern;
         
         try
         {
             string extension = Path.GetExtension(fileName).ToLower();
             
             if ((extension != "") && (extension != ".kat"))
             {
                 IDictionary languages = (IDictionary) rootModule.GetName("languages");
                 object callable = languages[extension];
                 Type rootType = (Type) CallNode.Call(runtimeState, callable, null);
                     
                 grammar.RootPattern = Pattern.PatternForType(rootType);
             }
             
             grammar.Parse(lexer, runtimeState);
         }
         catch (Exception exception)
         {
             if (runtimeState.RunningSource != null)
                 Console.WriteLine(runtimeState.RunningSource);
             
             throw exception;
         }
         finally
         {
             grammar.RootPattern = oldRoot;
         }
         
         pathResolver.PopDirectory();
     }
 }
Пример #11
0
        public void Import(string fileName)
        {
            if (!hasBeenSetUp)
            {
                throw new Exception();
            }

            fileName = pathResolver.Resolve(fileName);

            string absoluteFileName = Path.GetFullPath(fileName);

            if (imported.Contains(absoluteFileName))
            {
                return;
            }

            if (verbose)
            {
                Console.WriteLine("importing " + fileName);
            }

            imported.Add(absoluteFileName);

            if (Path.GetExtension(fileName).ToLower() == ".dll")
            {
                Assembly.LoadFrom(fileName);
            }
            else
            {
                pathResolver.PushDirectory(fileName);

                Lexer        lexer        = new Lexer(parseTrace, fileName);
                RuntimeState runtimeState = new RuntimeState(this, rootModule);

                currentLexer = lexer;

                Pattern oldRoot = grammar.RootPattern;

                try
                {
                    string extension = Path.GetExtension(fileName).ToLower();

                    if ((extension != "") && (extension != ".kat"))
                    {
                        IDictionary languages = (IDictionary)rootModule.GetName("languages");
                        object      callable  = languages[extension];
                        Type        rootType  = (Type)CallNode.Call(runtimeState, callable, null);

                        grammar.RootPattern = Pattern.PatternForType(rootType);
                    }

                    grammar.Parse(lexer, runtimeState);
                }
                catch (Exception exception)
                {
                    if (runtimeState.RunningSource != null)
                    {
                        Console.WriteLine(runtimeState.RunningSource);
                    }

                    throw exception;
                }
                finally
                {
                    grammar.RootPattern = oldRoot;
                }

                pathResolver.PopDirectory();
            }
        }
Пример #12
0
 public object Call(RuntimeState state, object[] parameterValues,
     bool wantRefParams, out bool[] refParams)
 {
     return method.Call(state, instance, parameterValues,
         wantRefParams, out refParams);
 }