| CODENOTIFIER | HelpYou are not signed inSign in |
Project: IronRuby
Revision: 133
Author: jlam
Date: 18 Aug 2008 12:14:41
Changes:Sync TFS
Files:| ... | ...@@ -1 +0,0 @@ | |
| 0 | This is a test |
| ... | ...@@ -24,17 +24,17 @@ | |
| 24 | 24 | public partial class RescueExpression : Expression { |
| 25 | 25 | private readonly SourceSpan _rescueSpan; |
| 26 | 26 | private readonly Expression/*!*/ _guardedExpression; |
| 27 | private readonly Statement/*!*/ _rescueClauseStatement; | |
| 27 | private readonly Expression/*!*/ _rescueClauseStatement; | |
| 28 | 28 | |
| 29 | 29 | public Expression/*!*/ GuardedExpression { |
| 30 | 30 | get { return _guardedExpression; } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | public Statement/*!*/ RescueClauseStatement { | |
| 33 | public Expression/*!*/ RescueClauseStatement { | |
| 34 | 34 | get { return _rescueClauseStatement; } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | public RescueExpression(Expression/*!*/ guardedExpression, Statement/*!*/ rescueClauseStatement, SourceSpan rescueSpan, SourceSpan location) | |
| 37 | public RescueExpression(Expression/*!*/ guardedExpression, Expression/*!*/ rescueClauseStatement, SourceSpan rescueSpan, SourceSpan location) | |
| 38 | 38 | : base(location) { |
| 39 | 39 | ContractUtils.RequiresNotNull(guardedExpression, "guardedExpression"); |
| 40 | 40 | ContractUtils.RequiresNotNull(rescueClauseStatement, "rescueClauseStatement"); |
| ... | ...@@ -46,9 +46,9 @@ | |
| 46 | 46 | |
| 47 | 47 | internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) { |
| 48 | 48 | return new Body( |
| 49 | CollectionUtils.MakeList<Statement>(new ExpressionStatement(_guardedExpression)), | |
| 49 | CollectionUtils.MakeList<Expression>(_guardedExpression), | |
| 50 | 50 | CollectionUtils.MakeList( |
| 51 | new RescueClause(CollectionUtils.MakeList<Statement>(_rescueClauseStatement), _rescueSpan) | |
| 51 | new RescueClause(CollectionUtils.MakeList<Expression>(_rescueClauseStatement), _rescueSpan) | |
| 52 | 52 | ), |
| 53 | 53 | null, null, Location).TransformToExpression(gen); |
| 54 | 54 | } |
| ... | ...@@ -137,8 +137,6 @@ | |
| 137 | 137 | public virtual void Exit(AliasStatement/*!*/ node) { } |
| 138 | 138 | public virtual bool Enter(ConditionalStatement/*!*/ node) { return true; } |
| 139 | 139 | public virtual void Exit(ConditionalStatement/*!*/ node) { } |
| 140 | public virtual bool Enter(ExpressionStatement/*!*/ node) { return true; } | |
| 141 | public virtual void Exit(ExpressionStatement/*!*/ node) { } | |
| 142 | 140 | public virtual bool Enter(Finalizer/*!*/ node) { return true; } |
| 143 | 141 | public virtual void Exit(Finalizer/*!*/ node) { } |
| 144 | 142 | public virtual bool Enter(Initializer/*!*/ node) { return true; } |
| ... | ...@@ -249,29 +249,29 @@ | |
| 249 | 249 | Tokenizer.ReportError(Errors.MatchGroupReferenceReadOnly, matchRef.VariableName); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | private Statement/*!*/ MakeGlobalAlias(SymbolId newVar, SymbolId/*!*/ existingVar, SourceSpan location) { | |
| 252 | private AliasStatement/*!*/ MakeGlobalAlias(SymbolId newVar, SymbolId/*!*/ existingVar, SourceSpan location) { | |
| 253 | 253 | return new AliasStatement(false, newVar, existingVar, location); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | private Statement/*!*/ MakeGlobalAlias(SymbolId newVar, RegexMatchReference/*!*/ existingVar, SourceSpan location) { | |
| 256 | private Expression/*!*/ MakeGlobalAlias(SymbolId newVar, RegexMatchReference/*!*/ existingVar, SourceSpan location) { | |
| 257 | 257 | if (existingVar.CanAlias) { |
| 258 | 258 | return new AliasStatement(false, newVar, existingVar.VariableSymbol, location); |
| 259 | 259 | } else { |
| 260 | 260 | _tokenizer.ReportError(Errors.CannotAliasGroupMatchVariable); |
| 261 | return new ExpressionStatement(new ErrorExpression(location)); | |
| 261 | return new ErrorExpression(location); | |
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | private Statement/*!*/ MakeGlobalAlias(RegexMatchReference/*!*/ newVar, SymbolId existingVar, SourceSpan location) { | |
| 265 | private AliasStatement/*!*/ MakeGlobalAlias(RegexMatchReference/*!*/ newVar, SymbolId existingVar, SourceSpan location) { | |
| 266 | 266 | return new AliasStatement(false, newVar.VariableSymbol, existingVar, location); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | private Statement/*!*/ MakeGlobalAlias(RegexMatchReference/*!*/ newVar, RegexMatchReference/*!*/ existingVar, SourceSpan location) { | |
| 269 | private Expression/*!*/ MakeGlobalAlias(RegexMatchReference/*!*/ newVar, RegexMatchReference/*!*/ existingVar, SourceSpan location) { | |
| 270 | 270 | if (existingVar.CanAlias) { |
| 271 | 271 | return new AliasStatement(false, newVar.VariableSymbol, existingVar.VariableSymbol, location); |
| 272 | 272 | } else { |
| 273 | 273 | _tokenizer.ReportError(Errors.CannotAliasGroupMatchVariable); |
| 274 | return new ExpressionStatement(new ErrorExpression(location)); | |
| 274 | return new ErrorExpression(location); | |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| ... | ...@@ -283,7 +283,7 @@ | |
| 283 | 283 | return result; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | private IfExpression/*!*/ MakeIfExpression(Expression/*!*/ condition, List<Statement>/*!*/ body, List<ElseIfClause>/*!*/ elseIfClauses, SourceSpan location) { | |
| 286 | private IfExpression/*!*/ MakeIfExpression(Expression/*!*/ condition, List<Expression>/*!*/ body, List<ElseIfClause>/*!*/ elseIfClauses, SourceSpan location) { | |
| 287 | 287 | // last else-if/else clause is the first one in the list: |
| 288 | 288 | elseIfClauses.Reverse(); |
| 289 | 289 | return new IfExpression(condition, body, elseIfClauses, location); |
| ... | ...@@ -327,12 +327,8 @@ | |
| 327 | 327 | return arguments; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | private Statement/*!*/ MakeLoopStatement(Statement/*!*/ statement, Expression/*!*/ condition, bool isWhileLoop, SourceSpan location) { | |
| 331 | ExpressionStatement exprStmt; | |
| 332 | BlockExpression blockExpr; | |
| 333 | ||
| 334 | bool isPostTest = ((exprStmt = statement as ExpressionStatement) != null && (blockExpr = exprStmt.Expression as BlockExpression) != null); | |
| 335 | return new WhileLoopStatement(CurrentScope, condition, isPostTest, isWhileLoop, statement, location); | |
| 330 | private Expression/*!*/ MakeLoopStatement(Expression/*!*/ statement, Expression/*!*/ condition, bool isWhileLoop, SourceSpan location) { | |
| 331 | return new WhileLoopStatement(condition, isWhileLoop, statement, location); | |
| 336 | 332 | } |
| 337 | 333 | |
| 338 | 334 | public static string/*!*/ TerminalToString(int terminal) { |
| ... | ...@@ -20,24 +20,24 @@ | |
| 20 | 20 | namespace Ruby.Compiler.Ast { |
| 21 | 21 | |
| 22 | 22 | // statement rescue statement |
| 23 | public partial class RescueStatement : Statement { | |
| 23 | public partial class RescueStatement : Expression { | |
| 24 | 24 | private readonly SourceSpan _rescueSpan; |
| 25 | private readonly Statement/*!*/ _guardedStatement; | |
| 26 | private readonly Statement/*!*/ _rescueClauseStatement; | |
| 25 | private readonly Expression/*!*/ _guardedStatement; | |
| 26 | private readonly Expression/*!*/ _rescueClauseStatement; | |
| 27 | 27 | |
| 28 | 28 | public SourceSpan RescueSpan { |
| 29 | 29 | get { return _rescueSpan; } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | public Statement/*!*/ GuardedStatement { | |
| 32 | public Expression/*!*/ GuardedStatement { | |
| 33 | 33 | get { return _guardedStatement; } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | public Statement/*!*/ RescueClauseStatement { | |
| 36 | public Expression/*!*/ RescueClauseStatement { | |
| 37 | 37 | get { return _rescueClauseStatement; } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | public RescueStatement(Statement/*!*/ guardedStatement, Statement/*!*/ rescueClauseStatement, SourceSpan rescueSpan, SourceSpan location) | |
| 40 | public RescueStatement(Expression/*!*/ guardedStatement, Expression/*!*/ rescueClauseStatement, SourceSpan rescueSpan, SourceSpan location) | |
| 41 | 41 | : base(location) { |
| 42 | 42 | ContractUtils.RequiresNotNull(guardedStatement, "guardedStatement"); |
| 43 | 43 | ContractUtils.RequiresNotNull(rescueClauseStatement, "rescueClauseStatement"); |
| ... | ...@@ -622,7 +622,7 @@ | |
| 622 | 622 | return result; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | internal MSA.Expression/*!*/ TransformStatements(List<Statement>/*!*/ statements, ResultOperation resultOperation) { | |
| 625 | internal MSA.Expression/*!*/ TransformStatements(List<Expression>/*!*/ statements, ResultOperation resultOperation) { | |
| 626 | 626 | Assert.NotNullItems(statements); |
| 627 | 627 | |
| 628 | 628 | if (statements.Count > 0) { |
| ... | ...@@ -651,7 +651,7 @@ | |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | internal MSA.Expression/*!*/ TransformStatementsToExpression(List<Statement> statements) { | |
| 654 | internal MSA.Expression/*!*/ TransformStatementsToExpression(List<Expression> statements) { | |
| 655 | 655 | if (statements == null || statements.Count == 0) { |
| 656 | 656 | return Ast.Null(); |
| 657 | 657 | } |
| ... | ...@@ -660,7 +660,7 @@ | |
| 660 | 660 | return statements[0].TransformRead(this); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | MSA.Expression[] result = new MSA.Expression[statements.Count]; | |
| 663 | var result = new MSA.Expression[statements.Count]; | |
| 664 | 664 | for (int i = 0; i < result.Length - 1; i++) { |
| 665 | 665 | result[i] = statements[i].Transform(this); |
| 666 | 666 | } |
| ... | ...@@ -66,7 +66,6 @@ | |
| 66 | 66 | GetMetaObjectRule(binding, GetReturnType(typeof(T)), siteExpr), |
| 67 | 67 | "<rule>" |
| 68 | 68 | ), |
| 69 | null, | |
| 70 | 69 | new ReadOnlyCollection<ParameterExpression>(pes.AddFirst(siteExpr)) |
| 71 | 70 | ); |
| 72 | 71 | } |
| ... | ...@@ -1,46 +0,0 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System; | |
| 17 | using System.Collections.Generic; | |
| 18 | ||
| 19 | namespace Microsoft.Scripting.Actions { | |
| 20 | internal sealed class RuleValidator { | |
| 21 | private readonly Func<bool>[] _validators; | |
| 22 | ||
| 23 | private RuleValidator(Func<bool>[] validators) { | |
| 24 | _validators = validators; | |
| 25 | } | |
| 26 | ||
| 27 | private bool Valid() { | |
| 28 | foreach (Func<bool> f in _validators) { | |
| 29 | if (!f()) { | |
| 30 | return false; | |
| 31 | } | |
| 32 | } | |
| 33 | return true; | |
| 34 | } | |
| 35 | ||
| 36 | internal static Func<bool> Create(List<Func<bool>> validators) { | |
| 37 | if (validators == null || validators.Count == 0) { | |
| 38 | return null; | |
| 39 | } else if (validators.Count == 1) { | |
| 40 | return validators[0]; | |
| 41 | } else { | |
| 42 | return new RuleValidator(validators.ToArray()).Valid; | |
| 43 | } | |
| 44 | } | |
| 45 | } | |
| 46 | } |
| ... | ...@@ -21,19 +21,19 @@ | |
| 21 | 21 | |
| 22 | 22 | namespace Ruby.Compiler.Ast { |
| 23 | 23 | |
| 24 | public partial class Initializer : Statement { | |
| 24 | public partial class Initializer : Expression { | |
| 25 | 25 | // BEGIN { body } |
| 26 | 26 | |
| 27 | 27 | private readonly LexicalScope/*!*/ _definedScope; |
| 28 | 28 | |
| 29 | 29 | // TODO: |
| 30 | private readonly List<Statement> _statements; | |
| 30 | private readonly List<Expression> _statements; | |
| 31 | 31 | |
| 32 | public List<Statement> Statements { | |
| 32 | public List<Expression> Statements { | |
| 33 | 33 | get { return _statements; } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | public Initializer(LexicalScope/*!*/ definedScope, List<Statement> statements, SourceSpan location) | |
| 36 | public Initializer(LexicalScope/*!*/ definedScope, List<Expression> statements, SourceSpan location) | |
| 37 | 37 | : base(location) { |
| 38 | 38 | Assert.NotNull(definedScope); |
| 39 | 39 |
| ... | ...@@ -21,19 +21,19 @@ | |
| 21 | 21 | |
| 22 | 22 | namespace Ruby.Compiler.Ast { |
| 23 | 23 | |
| 24 | public partial class Finalizer : Statement { | |
| 24 | public partial class Finalizer : Expression { | |
| 25 | 25 | // END { body } |
| 26 | 26 | |
| 27 | 27 | private readonly LexicalScope/*!*/ _definedScope; |
| 28 | 28 | |
| 29 | 29 | // TODO: |
| 30 | private readonly List<Statement> _statements; | |
| 30 | private readonly List<Expression> _statements; | |
| 31 | 31 | |
| 32 | public List<Statement> Statements { | |
| 32 | public List<Expression> Statements { | |
| 33 | 33 | get { return _statements; } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | public Finalizer(LexicalScope/*!*/ definedScope, List<Statement> statements, SourceSpan location) | |
| 36 | public Finalizer(LexicalScope/*!*/ definedScope, List<Expression> statements, SourceSpan location) | |
| 37 | 37 | : base(location) { |
| 38 | 38 | Assert.NotNull(definedScope); |
| 39 | 39 |
| ... | ...@@ -42,7 +42,6 @@ | |
| 42 | 42 | internal Expression[] _parameters; // the parameters which the rule is processing |
| 43 | 43 | internal Expression[] _parametersMinusSite; // the parameters which the rule is processing minus the CallSite parameter |
| 44 | 44 | internal Expression[] _allParameters; // The parameters, including CodeContext, if any. |
| 45 | internal List<Func<bool>> _validators; // the list of validates which indicate when the rule is no longer valid | |
| 46 | 45 | private bool _error; // true if the rule represents an error |
| 47 | 46 | internal List<VariableExpression> _temps; // temporaries allocated by the rule |
| 48 | 47 | |
| ... | ...@@ -78,21 +77,6 @@ | |
| 78 | 77 | } |
| 79 | 78 | |
| 80 | 79 | /// <summary> |
| 81 | /// Adds a validation delegate which determines if the rule is still valid. | |
| 82 | /// | |
| 83 | /// A validator provides a dynamic test that can invalidate a rule at runtime. | |
| 84 | /// The definition of an invalid rule is one whose Test will always return false. | |
| 85 | /// In theory a set of validators is not needed as this could be encoded in the | |
| 86 | /// test itself; however, in practice it is much simpler to include these helpers. | |
| 87 | /// | |
| 88 | /// The validator returns true if the rule should still be considered valid. | |
| 89 | /// </summary> | |
| 90 | public void AddValidator(Func<bool> validator) { | |
| 91 | if (_validators == null) _validators = new List<Func<bool>>(); | |
| 92 | _validators.Add(validator); | |
| 93 | } | |
| 94 | ||
| 95 | /// <summary> | |
| 96 | 80 | /// Gets the logical parameters to the dynamic site in the form of Expressions. |
| 97 | 81 | /// </summary> |
| 98 | 82 | public IList<Expression> Parameters { |
| ... | ...@@ -333,7 +317,6 @@ | |
| 333 | 317 | "<rule>", |
| 334 | 318 | _temps != null ? _temps.ToArray() : new VariableExpression[0] |
| 335 | 319 | ), |
| 336 | RuleValidator.Create(_validators), | |
| 337 | 320 | new ReadOnlyCollection<ParameterExpression>(_paramVariables) |
| 338 | 321 | ); |
| 339 | 322 | } |
| ... | ...@@ -1,40 +0,0 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System.Diagnostics; | |
| 17 | using MSA = System.Linq.Expressions; | |
| 18 | ||
| 19 | namespace Ruby.Compiler.Ast { | |
| 20 | ||
| 21 | public partial class ExpressionStatement : Statement { | |
| 22 | private readonly Expression/*!*/ _expression; | |
| 23 | ||
| 24 | public Expression/*!*/ Expression { | |
| 25 | get { return _expression; } | |
| 26 | } | |
| 27 | ||
| 28 | public ExpressionStatement(Expression/*!*/ expression) | |
| 29 | : base(expression.Location) { | |
| 30 | Debug.Assert(expression != null); | |
| 31 | ||
| 32 | _expression = expression; | |
| 33 | } | |
| 34 | ||
| 35 | internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) { | |
| 36 | return _expression.TransformRead(gen); | |
| 37 | } | |
| 38 | } | |
| 39 | } | |
| 40 |
| ... | ...@@ -20,23 +20,20 @@ | |
| 20 | 20 | |
| 21 | 21 | namespace Ruby.Compiler.Ast { |
| 22 | 22 | |
| 23 | public partial class WhileLoopStatement : Statement { | |
| 24 | // until cond | |
| 25 | // body | |
| 26 | // end | |
| 27 | ||
| 23 | // <statement> while <expression> | |
| 24 | // <statement> until <expression> | |
| 25 | // <block-expression> while <expression> | |
| 26 | // <block-expression> until <expression> | |
| 27 | public partial class WhileLoopStatement : Expression { | |
| 28 | 28 | private readonly Expression/*!*/ _condition; |
| 29 | private readonly Statement _statements; // optional | |
| 29 | private readonly Expression _statements; // optional | |
| 30 | 30 | private readonly bool _isWhileLoop; |
| 31 | private readonly bool _isPostTest; | |
| 32 | ||
| 33 | private readonly LexicalScope/*!*/ _parentScope; | |
| 34 | 31 | |
| 35 | 32 | public Expression/*!*/ Condition { |
| 36 | 33 | get { return _condition; } |
| 37 | 34 | } |
| 38 | 35 | |
| 39 | public Statement Statements { | |
| 36 | public Expression Statements { | |
| 40 | 37 | get { return _statements; } |
| 41 | 38 | } |
| 42 | 39 | |
| ... | ...@@ -44,28 +41,22 @@ | |
| 44 | 41 | get { return _isWhileLoop; } |
| 45 | 42 | } |
| 46 | 43 | |
| 47 | public bool IsPostTest { | |
| 48 | get { return _isPostTest; } | |
| 49 | } | |
| 50 | ||
| 51 | public WhileLoopStatement(LexicalScope/*!*/ parentScope, Expression/*!*/ condition, bool isPostTest, bool isWhileLoop, | |
| 52 | Statement/*!*/ body, SourceSpan location) | |
| 44 | public WhileLoopStatement(Expression/*!*/ condition, bool isWhileLoop, | |
| 45 | Expression/*!*/ body, SourceSpan location) | |
| 53 | 46 | : base(location) { |
| 54 | Assert.NotNull(parentScope, condition); | |
| 47 | Assert.NotNull(condition); | |
| 55 | 48 | |
| 56 | _parentScope = parentScope; | |
| 57 | 49 | _condition = condition; |
| 58 | 50 | _isWhileLoop = isWhileLoop; |
| 59 | 51 | _statements = body; |
| 60 | _isPostTest = isPostTest; | |
| 61 | 52 | } |
| 62 | 53 | |
| 63 | 54 | internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) { |
| 64 | List<Statement> stmt = new List<Statement>(1); | |
| 55 | List<Expression> stmt = new List<Expression>(1); | |
| 65 | 56 | if (_statements != null) { |
| 66 | 57 | stmt.Add(_statements); |
| 67 | 58 | } |
| 68 | return new WhileLoopExpression(_parentScope, _condition, _isWhileLoop, stmt, Location).TransformRead(gen); | |
| 59 | return new WhileLoopExpression(_condition, _isWhileLoop, stmt, Location).TransformRead(gen); | |
| 69 | 60 | } |
| 70 | 61 | } |
| 71 | 62 | } |
| ... | ...@@ -73,13 +73,6 @@ | |
| 73 | 73 | |
| 74 | 74 | #endregion |
| 75 | 75 | |
| 76 | public static MSA.Expression/*!*/ Result(MSA.Expression/*!*/ resultVariable, MSA.Expression/*!*/ statement) { | |
| 77 | return Ast.Comma( | |
| 78 | statement, | |
| 79 | resultVariable | |
| 80 | ); | |
| 81 | } | |
| 82 | ||
| 83 | 76 | public static MSA.Expression/*!*/ Infinite(MSA.LabelTarget/*!*/ label, params MSA.Expression[]/*!*/ body) { |
| 84 | 77 | return AstUtils.Infinite(Ast.Block(body), label); |
| 85 | 78 | } |
| ... | ...@@ -61,7 +61,7 @@ | |
| 61 | 61 | // or we are further generalizing an existing rule. We need to re-write the incoming tree |
| 62 | 62 | // to be templated over the necessary constants and return the new rule bound to the template. |
| 63 | 63 | |
| 64 | return new Rule<T>(newBody, to.Validator, null, new TemplateData<T>(), to.Parameters); | |
| 64 | return new Rule<T>(newBody, null, new TemplateData<T>(), to.Parameters); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // we have compatible templated rules, we can just swap out the constant pool and |
| ... | ...@@ -80,7 +80,7 @@ | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // create a new rule which is bound to the new delegate w/ the expression tree from the old code. |
| 83 | return new Rule<T>(newBody, to.Validator, dlg, from.Template, to.Parameters); | |
| 83 | return new Rule<T>(newBody, dlg, from.Template, to.Parameters); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | private static Rule<T> FindCompatibleRuleForTemplate<T>(Rule<T> from, Rule<T> to, out List<ConstantExpression> newConstants, out bool tooSpecific) where T : class { |
| ... | ...@@ -13,6 +13,7 @@ | |
| 13 | 13 | * |
| 14 | 14 | * ***************************************************************************/ |
| 15 | 15 | |
| 16 | using System; | |
| 16 | 17 | using System.Collections.Generic; |
| 17 | 18 | using System.Diagnostics; |
| 18 | 19 | using System.Scripting; |
| ... | ...@@ -23,27 +24,26 @@ | |
| 23 | 24 | using Ruby.Runtime; |
| 24 | 25 | using Ruby.Runtime.Calls; |
| 25 | 26 | using MSA = System.Linq.Expressions; |
| 27 | using AstUtils = Microsoft.Scripting.Ast.Utils; | |
| 26 | 28 | |
| 27 | 29 | namespace Ruby.Compiler.Ast { |
| 28 | 30 | using Ast = System.Linq.Expressions.Expression; |
| 29 | using AstUtils = Microsoft.Scripting.Ast.Utils; | |
| 30 | using System; | |
| 31 | 31 | |
| 32 | 32 | public partial class SourceUnitTree : Node { |
| 33 | 33 | |
| 34 | 34 | private readonly LexicalScope/*!*/ _definedScope; |
| 35 | 35 | private readonly List<Initializer> _initializers; |
| 36 | private readonly List<Statement> _statements; | |
| 36 | private readonly List<Expression> _statements; | |
| 37 | 37 | |
| 38 | 38 | public List<Initializer> Initializers { |
| 39 | 39 | get { return _initializers; } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | public List<Statement> Statements { | |
| 42 | public List<Expression> Statements { | |
| 43 | 43 | get { return _statements; } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | public SourceUnitTree(LexicalScope/*!*/ definedScope, List<Statement> statements, List<Initializer> initializers, SourceSpan location) | |
| 46 | public SourceUnitTree(LexicalScope/*!*/ definedScope, List<Expression> statements, List<Initializer> initializers, SourceSpan location) | |
| 47 | 47 | : base(location) { |
| 48 | 48 | ContractUtils.RequiresNotNull(definedScope, "scope"); |
| 49 | 49 |
| ... | ...@@ -201,7 +201,15 @@ | |
| 201 | 201 | |
| 202 | 202 | public virtual string[] GetFiles(string path, string searchPattern) { |
| 203 | 203 | #if !SILVERLIGHT |
| 204 | return Directory.GetFiles(path, searchPattern); | |
| 204 | return Directory.GetFiles(path, searchPattern); | |
| 205 | #else | |
| 206 | throw new NotImplementedException(); | |
| 207 | #endif | |
| 208 | } | |
| 209 | ||
| 210 | public virtual string[] GetDirectories(string path, string searchPattern) { | |
| 211 | #if !SILVERLIGHT | |
| 212 | return Directory.GetDirectories(path, searchPattern); | |
| 205 | 213 | #else |
| 206 | 214 | throw new NotImplementedException(); |
| 207 | 215 | #endif |
| ... | ...@@ -29,7 +29,7 @@ | |
| 29 | 29 | |
| 30 | 30 | private readonly List<Expression> _types; // optional |
| 31 | 31 | private readonly LeftValue _target; // optional |
| 32 | private readonly List<Statement> _statements; // optional | |
| 32 | private readonly List<Expression> _statements; // optional | |
| 33 | 33 | |
| 34 | 34 | public List<Expression> Types { |
| 35 | 35 | get { return _types; } |
| ... | ...@@ -39,16 +39,16 @@ | |
| 39 | 39 | get { return _target; } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | public List<Statement> Statements { | |
| 42 | public List<Expression> Statements { | |
| 43 | 43 | get { return _statements; } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | public RescueClause(List<Statement> statements, SourceSpan location) | |
| 46 | public RescueClause(List<Expression> statements, SourceSpan location) | |
| 47 | 47 | : base(location) { |
| 48 | 48 | _statements = statements; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | public RescueClause(List<Expression> types, LeftValue target, List<Statement> statements, SourceSpan location) | |
| 51 | public RescueClause(List<Expression> types, LeftValue target, List<Expression> statements, SourceSpan location) | |
| 52 | 52 | : base(location) { |
| 53 | 53 | _types = types; |
| 54 | 54 | _target = target; |
| ... | ...@@ -161,7 +161,6 @@ | |
| 161 | 161 | |
| 162 | 162 | public partial class AliasStatement { public override NodeTypes NodeType { get { return NodeTypes.AliasStatement; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } |
| 163 | 163 | public partial class ConditionalStatement { public override NodeTypes NodeType { get { return NodeTypes.ConditionalStatement; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } |
| 164 | public partial class ExpressionStatement { public override NodeTypes NodeType { get { return NodeTypes.ExpressionStatement; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } | |
| 165 | 164 | public partial class Finalizer { public override NodeTypes NodeType { get { return NodeTypes.Finalizer; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } |
| 166 | 165 | public partial class Initializer { public override NodeTypes NodeType { get { return NodeTypes.Initializer; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } |
| 167 | 166 | public partial class RescueStatement { public override NodeTypes NodeType { get { return NodeTypes.RescueStatement; } } internal protected override void Walk(Walker/*!*/ walker) { walker.Walk(this); } } |
| ... | ...@@ -20,7 +20,7 @@ | |
| 20 | 20 | namespace Ruby.Compiler.Ast { |
| 21 | 21 | using Ast = System.Linq.Expressions.Expression; |
| 22 | 22 | |
| 23 | public abstract class JumpStatement : Statement { | |
| 23 | public abstract class JumpStatement : Expression { | |
| 24 | 24 | private readonly LexicalScope/*!*/ _scope; |
| 25 | 25 | private readonly Arguments _arguments; |
| 26 | 26 |
| ... | ...@@ -167,10 +167,6 @@ | |
| 167 | 167 | originalMonomorphicRule = rule; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | if (!rule.IsValid) { | |
| 171 | continue; | |
| 172 | } | |
| 173 | ||
| 174 | 170 | mm.Reset(); |
| 175 | 171 | |
| 176 | 172 | // |
| ... | ...@@ -202,7 +198,7 @@ | |
| 202 | 198 | // Level 2 cache lookup |
| 203 | 199 | // |
| 204 | 200 | Type[] argTypes = TypeUtils.GetTypesForBinding(args); |
| 205 | applicable = _cache.FindApplicableRules(_binder, argTypes, startingTarget); | |
| 201 | applicable = _cache.FindApplicableRules(_binder, argTypes); | |
| 206 | 202 | |
| 207 | 203 | // |
| 208 | 204 | // Any applicable rules in level 2 cache? |
| ... | ...@@ -320,9 +316,7 @@ | |
| 320 | 316 | return new CallSite<T>(binder); |
| 321 | 317 | } |
| 322 | 318 | |
| 323 | // TODO: Make internal and create friendly UnitTests | |
| 324 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] | |
| 325 | public static void ClearRuleCache() { | |
| 319 | private static void ClearRuleCache() { | |
| 326 | 320 | _cache.Clear(); |
| 327 | 321 | } |
| 328 | 322 | } |
| ... | ...@@ -37,36 +37,29 @@ | |
| 37 | 37 | private readonly Expression _binding; |
| 38 | 38 | |
| 39 | 39 | /// <summary> |
| 40 | /// The validator to indicate when the rule is no longer valid | |
| 41 | /// </summary> | |
| 42 | private readonly Func<bool> _validator; | |
| 43 | ||
| 44 | /// <summary> | |
| 45 | 40 | /// Template data - null for methods which aren't templated. Non-null for methods which |
| 46 | 41 | /// have been templated. The same template data is shared across all templated rules with |
| 47 | 42 | /// the same target method. |
| 48 | 43 | /// </summary> |
| 49 | 44 | private readonly TemplateData<T> _template; |
| 50 | 45 | |
| 51 | public Rule(Expression binding, Func<bool> validator, params ParameterExpression[] parameters) | |
| 52 | : this(binding, validator, (IEnumerable<ParameterExpression>)parameters) { | |
| 46 | public Rule(Expression binding, params ParameterExpression[] parameters) | |
| 47 | : this(binding, (IEnumerable<ParameterExpression>)parameters) { | |
| 53 | 48 | } |
| 54 | 49 | |
| 55 | public Rule(Expression binding, Func<bool> validator, IEnumerable<ParameterExpression> parameters) { | |
| 50 | public Rule(Expression binding, IEnumerable<ParameterExpression> parameters) { | |
| 56 | 51 | var @params = parameters.ToReadOnly(); |
| 57 | 52 | ValidateRuleParameters(typeof(T), @params); |
| 58 | 53 | |
| 59 | 54 | _binding = binding; |
| 60 | _validator = validator; | |
| 61 | 55 | _parameters = @params; |
| 62 | 56 | _mySet = new SmallRuleSet<T>(new[] { this }); |
| 63 | 57 | } |
| 64 | 58 | |
| 65 | internal Rule(Expression binding, Func<bool> validator, T target, TemplateData<T> template, ReadOnlyCollection<ParameterExpression> parameters) { | |
| 59 | internal Rule(Expression binding, T target, TemplateData<T> template, ReadOnlyCollection<ParameterExpression> parameters) { | |
| 66 | 60 | ValidateRuleParameters(typeof(T), parameters); |
| 67 | 61 | |
| 68 | 62 | _binding = binding; |
| 69 | _validator = validator; | |
| 70 | 63 | _parameters = parameters; |
| 71 | 64 | _mySet = new SmallRuleSet<T>(target, new Rule<T>[] { this }); |
| 72 | 65 | _template = template; |
| ... | ...@@ -96,23 +89,6 @@ | |
| 96 | 89 | get { return _binding; } |
| 97 | 90 | } |
| 98 | 91 | |
| 99 | /// <summary> | |
| 100 | /// If not valid, this indicates that the given Test can never return true and therefore | |
| 101 | /// this rule should be removed from any RuleSets when convenient in order to | |
| 102 | /// reduce memory usage and the number of active rules. | |
| 103 | /// </summary> | |
| 104 | public bool IsValid { | |
| 105 | get { | |
| 106 | return _validator != null ? _validator() : true; | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | internal Func<bool> Validator { | |
| 111 | get { | |
| 112 | return _validator; | |
| 113 | } | |
| 114 | } | |
| 115 | ||
| 116 | 92 | internal TemplateData<T> Template { |
| 117 | 93 | get { |
| 118 | 94 | return _template; |
| ... | ...@@ -1,50 +0,0 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System.Collections.Generic; | |
| 17 | using System.Scripting; | |
| 18 | using AstUtils = Microsoft.Scripting.Ast.Utils; | |
| 19 | using MSA = System.Linq.Expressions; | |
| 20 | ||
| 21 | namespace Ruby.Compiler.Ast { | |
| 22 | using Ast = System.Linq.Expressions.Expression; | |
| 23 | ||
| 24 | public abstract class Statement : Node { | |
| 25 | internal static readonly List<Statement>/*!*/ EmptyList = new List<Statement>(); | |
| 26 | ||
| 27 | protected Statement(SourceSpan location) | |
| 28 | : base(location) { | |
| 29 | } | |
| 30 | ||
| 31 | internal virtual MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) { | |
| 32 | return AstUtils.Comma(Location, TransformRead(gen)); | |
| 33 | } | |
| 34 | ||
| 35 | internal virtual MSA.Expression/*!*/ TransformResult(AstGenerator/*!*/ gen, ResultOperation resultOperation) { | |
| 36 | MSA.Expression resultExpression = TransformRead(gen); | |
| 37 | MSA.Expression statement; | |
| 38 | ||
| 39 | if (resultOperation.Variable != null) { | |
| 40 | statement = Ast.Assign(resultOperation.Variable, Ast.Convert(resultExpression, resultOperation.Variable.Type)); | |
| 41 | } else { | |
| 42 | statement = Ast.Return(resultExpression); | |
| 43 | } | |
| 44 | ||
| 45 | return AstUtils.Comma(Location, statement); | |
| 46 | } | |
| 47 | ||
| 48 | internal abstract MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen); | |
| 49 | } | |
| 50 | } |
| ... | ...@@ -170,7 +170,6 @@ |