private static Expression CompileExistence(Op op, Scope scope) { var p = scope.FreeVariable("ref"); var @ref = new Literal {Value = p.Name}; var fst = new Parens {Body = new Assign {Variable = @ref, Value = op.First}}; return Compile(new If {Condition = new Existence {Expression = fst}, Body = @ref, ElseBody = op.Second}, scope); }
public static Expression CompileLiteral(Literal node, Scope scope) { //TODO: need to determine if we are doing a value or a variable var value = node.Value; int i; if (int.TryParse(value, out i)) return Expression.Constant(i, ObjectType); long l; if (long.TryParse(value, out l)) return Expression.Constant(l, ObjectType); if ((value.StartsWith("'") && value.EndsWith("'")) || (value.StartsWith("\"") && value.EndsWith("\""))) { //de-quote value = value.Substring(1, value.Length - 2); return Expression.Constant(value, ObjectType); } //TODO: we should not be creating variables here. Only upon assignment. var p = scope.GetVariableExpression(value); if (p == null) { return RuntimeHelpers.CreateThrowExpression(typeof(MissingMemberException), "'" + value + "' is undefined."); } Helper.IsNotNull(p); return p; }