/// <summary>
 /// Create and return a parser capable of parsing methods and initializers.
 /// </summary>
 /// <remarks>
 /// The parser returned here is capable of parsing interchange chunks containg methods and initializers 
 /// that follow the interchange version standard that this version service is supporting.
 /// </remarks>
 /// <returns>Parser for parsing method and initilizers.</returns>
 protected virtual Parser GetFunctionParser()
 {
     Parser parser = new Parser();
     return parser;
 }
Esempio n. 2
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;
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        private void btnParseMethod_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;
            MethodNode node = parser.ParseMethod(reader);

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