Example #1
0
        public bool Evaluate()
        {
            string txt = this.Client.EvaluateSourceCode;
            StringReader reader = new StringReader(txt);

            ErrorSink errorSink = new ErrorSink(this.Client);
            Parser parser = new Parser();
            parser.ErrorSink = errorSink;
            InitializerNode node = parser.ParseInitializer(reader);
            if (errorSink.HadErrors)
                return false;

            Expression<Func<SmalltalkRuntime, object, object>> lambda;
            try
            {
                AstIntermediateInitializerCode code = new AstIntermediateInitializerCode(node);
                var compilationResult = code.CompileGlobalInitializer(this.Environment.Runtime);
                if (compilationResult == null)
                    return false;
                lambda = compilationResult.ExecutableCode;
                if (lambda == null)
                    return false;
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkDefinitionException ex)
            {
                if (this.Client != null)
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                return false;
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkRuntimeException ex)
            {
                if (this.Client != null)
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                return false;
            }

            try
            {
                var function = lambda.Compile();
                this.LastResult = function(this.Environment.Runtime, null);
            }
            catch (Exception ex)
            {
                if (this.Client != null)
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                return false;
            }
            this.PrintResult(this.LastResult);

            //dynamic rt = this.Environment.Runtime;
            //string x = rt.GetTestString();
            //dynamic x = this.LastResult;
            //dynamic y = x.PrintString();
            //y = x.PrintString;
            //int z = x.Hash();

            return true;
        }
Example #2
0
        private Expression<Func<SmalltalkRuntime, object, object>> JitExpression()
        {
            if (this.Environment == null)
            {
                MessageBox.Show("First, create the environment.");
                return null;
            }

            Properties.Settings.Default.LastWorkspaceInstallSource = this.textInstall.Text;
            Properties.Settings.Default.LastWorkspaceEvalSource = this.textEvaluate.Text;
            Properties.Settings.Default.Save();

            this.textResultEvaluate.Text = null;

            string txt = this.textEvaluate.SelectedText;
            if (String.IsNullOrEmpty(txt))
                txt = this.textEvaluate.Text;
            StringReader reader = new StringReader(txt);

            ErrorSink errorSink = new ErrorSink(this.textResultEvaluate);
            Parser parser = new Parser();
            parser.ErrorSink = errorSink;
            InitializerNode node = parser.ParseInitializer(reader);
            if (errorSink.HadErrors)
                return null;

            AstIntermediateInitializerCode code = new AstIntermediateInitializerCode(node);
            var compilationResult = code.CompileGlobalInitializer(this.Environment.Runtime);
            if (compilationResult == null)
                return null;
            return compilationResult.ExecutableCode;
        }
Example #3
0
        private void btnParseInitializer_Click(object sender, EventArgs e)
        {
            this.treeParseNodes.Nodes.Clear();
            this.listProperties.Items.Clear();

            string txt = this.txtSource.SelectedText;
            if (String.IsNullOrEmpty(txt))
                txt = this.txtSource.Text;
            StringReader reader = new StringReader(txt);

            parser = new VseCompatibleParser();
            this.Errors = new Dictionary<object, List<string>>();
            parser.ErrorSink = this;
            InitializerNode node = parser.ParseInitializer(reader);

            this.VisitNode(node, null, null);
        }