/// <summary>
        /// Reloads the modules from the interpreter.
        ///
        /// This method should be called on the analysis thread and is usually invoked
        /// when the interpreter signals that it's modules have changed.
        /// </summary>
        public async Task ReloadModulesAsync(CancellationToken token = default(CancellationToken))
        {
            if (!_reloadLock.Wait(0))
            {
                // If we don't lock immediately, wait for the current reload to
                // complete and then return.
                await _reloadLock.WaitAsync().ConfigureAwait(false);

                _reloadLock.Release();
                return;
            }

            try {
                // Cancel outstanding analysis
                Queue.Clear();
                // Tell factory to clear cached modules. This also clears the interpreter data.
                InterpreterFactory.NotifyImportNamesChanged();
                // Now initialize the interpreter
                Interpreter.Initialize(this);
                // Reload importable modules
                Modules.Reload();
                // Load known types from the selected interpreter
                await LoadKnownTypesAsync(token);

                // Re-initialize module variables
                foreach (var mod in ModulesByFilename.Values)
                {
                    mod.Clear();
                    mod.EnsureModuleVariables(this);
                }
            } finally {
                _reloadLock.Release();
            }
        }
        public InterpretationClient(ISyneryMemory memory)
        {
            Memory = memory;

            IInterpreterFactory factory = InterpreterFactory.GetDefaultInterpreterFactory();

            Controller = new InterpretationController(factory, memory);
        }
Ejemplo n.º 3
0
        public StoreActionTests()
        {
            // https://xunit.net/docs/shared-context

            _interpreter = InterpreterFactory.CreateWithDefaults();
            _interpreter.AddCoreLibrary();
            _storeWord = _interpreter.GetWord("!");
        }
        public SyneryFunctionDeclarationInterpretationClient(ISyneryMemory memory, IAntlrErrorListener <int> lexerErrorListener = null, IAntlrErrorListener <IToken> parserErrorListener = null)
        {
            Memory              = memory;
            LexerErrorListener  = lexerErrorListener;
            ParserErrorListener = parserErrorListener;

            IInterpreterFactory factory = InterpreterFactory.GetDefaultInterpreterFactory();

            factory.SetInterpreter(new SyneryFunctionBlockInterpreter());

            Controller = new InterpretationController(factory, memory);
        }
        public ExpressionExtractorTests()
        {
            var currencyService = new TestCurrencyService();

            var tokenQueueFactory   = new TokenQueueFactory();
            var coinMarketCapClient = new TestCoinMarketCapClient();
            var fixerClient         = new TestFixerClient();
            var currencyConverter   = new CurrencyConverter(coinMarketCapClient, fixerClient);
            var tokenConverter      = new TokenConverter(currencyConverter, currencyService, coinMarketCapClient, fixerClient);
            var interpreterFactory  = new InterpreterFactory(tokenConverter, currencyService, tokenQueueFactory);

            this.expressionExtractor = new ExpressionExtractor(interpreterFactory);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates an instance of the file interpreter.
        /// </summary>
        /// <param name="terminal">The terminal implementation that will be used for I/O.</param>
        public ExecutionContext(IRuntimeEnvironment environment,
                                ITerminal terminal,
                                IDataSegmentAccessor dataSegment,
                                RegisterManager regMgr,
                                TextSegmentAccessor textSegment)
        {
            m_Environment    = environment;
            m_Terminal       = terminal;
            m_InterpreterFac = new InterpreterFactory(environment, terminal);

            m_Ctx = new RuntimeContext(environment, dataSegment, regMgr);

            m_TextSegment = textSegment;
        }
Ejemplo n.º 7
0
        public UnitTest1()
        {
            var settings = new TestBotSettings();
            var connectionStringFactory = new TestConnectionStringFactory();
            var coinmarkcapClient       = new CoinMarketCapClientCachingDecorator(new CoinMarketCapClient());
            var fixerClient             = new FixerClientCachingDecorator(new FixerClient());
            var currencyConverter       = new CurrencyConverter(coinmarkcapClient, fixerClient);
            var redditClientFactory     = new RedditClientFactory();

            this.currencyService      = new CurrencyService(connectionStringFactory);
            this.remindRequestService = new RemindRequestService(connectionStringFactory);
            var tokenConverter      = new TokenConverter(currencyConverter, currencyService, coinmarkcapClient, fixerClient);
            var tokenQueueFactory   = new TokenQueueFactory();
            var interpreterFactory  = new InterpreterFactory(tokenConverter, currencyService, tokenQueueFactory);
            var expressionExtractor = new ExpressionExtractor(interpreterFactory);

            this.unreadMessageReader  = new RedditUnreadMessagesReader(settings, remindRequestService, expressionExtractor, redditClientFactory);
            this.remindRequestHandler = new RemindRequestHandler(settings, remindRequestService, interpreterFactory, redditClientFactory);
        }
Ejemplo n.º 8
0
 public CommaActionTests()
 {
     _interpreter = InterpreterFactory.CreateWithDefaults();
     _interpreter.AddCoreLibrary();
     _commaWord = _interpreter.GetWord(",");
 }
Ejemplo n.º 9
0
 public WithinWordTests()
 {
     _interpreter = InterpreterFactory.CreateWithDefaults();
     _interpreter.AddCoreExtLibrary();
     _withinWord = _interpreter.GetWord("WITHIN");
 }
Ejemplo n.º 10
0
 public PlusStoreActionTests()
 {
     _interpreter = InterpreterFactory.CreateWithDefaults();
     _interpreter.AddCoreLibrary();
     _plusStoreWord = _interpreter.GetWord("+!");
 }
Ejemplo n.º 11
0
 public SlashModWordTests()
 {
     _interpreter = InterpreterFactory.CreateWithDefaults();
     _interpreter.AddCoreLibrary();
     _slashModWord = _interpreter.GetWord("/MOD");
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var interpreter = InterpreterFactory.CreateWithDefaults();

            interpreter.Output = new ConsoleWriter();
            interpreter
            .AddCoreLibrary()
            .AddCoreExtLibrary()
            .AddExceptionLibrary()
            .AddDoubleLibrary()
            .AddDoubleExtLibrary()
            .AddFloatingLibrary()
            .AddFloatingExtLibrary()
            .AddObjectLibrary()
            .AddStringLibrary()
            .AddToolsLibrary()
            .AddToolsExtLibrary();

            interpreter.AddPrimitiveWord("TRACE", () =>
            {
                interpreter.StackExpect(1);

                _tracing = interpreter.Pop() != 0;

                return(1);
            });

            interpreter.ExecutingWord += Interpreter_ExecutingWord;

            while (true)
            {
                try
                {
                    // Show a prompt.
                    Console.Write(interpreter.IsCompiling ? ":> " : "-> ");

                    // Interpret.
                    interpreter.Evaluate(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    Console.WriteLine(ex.Message);
                }

                // TODO: Breaking state.

                if (interpreter.InterpreterState == InterpreterStateCode.Terminating)
                {
                    Console.WriteLine();
                    Console.WriteLine("Bye!");

                    break;
                }
            }

            //WordsListTest();


            //Console.WriteLine(Marshal.SizeOf(typeof(EfrtValue)));

            //var ds = new DataStack();

            //ds.Push(123);
            //Console.WriteLine(ds.Pop().Int);

            //ds.Push((short)11, 12);
            //var s = ds.Pop();
            //Console.WriteLine(s.Short + " " + s.Short2);
            //s.Short2 = 33;
            //Console.WriteLine(s.Short + " " + s.Short2);
        }
 public RemindRequestHandler(IBotSettings botSettings, IRemindRequestService remindRequestService, InterpreterFactory interpreterFactory, RedditClientFactory clientFactory)
 {
     this.client = clientFactory.Create(botSettings);
     this.remindRequestService = remindRequestService;
     this.interpreterFactory   = interpreterFactory;
 }
Ejemplo n.º 14
0
 public InterpreterHeapExtensionsTests()
 {
     _interpreter = InterpreterFactory.CreateWithDefaults();
 }
 public ExpressionExtractor(InterpreterFactory interpreterFactory)
 {
     this.interpreterFactory = interpreterFactory;
 }