public Expr Parse(ParserContext pcon, object form) { int argCount = RT.count(form) - 1; if (argCount != 1) { IPersistentMap exData = new PersistentArrayMap(new Object[] { FormKey, form }); throw new ExceptionInfo("Wrong number of args (" + argCount + ") passed to quote", exData); } object v = RT.second(form); if (v == null) { return(Compiler.NilExprInstance); } else if (v is Boolean) { if ((bool)v) { return(Compiler.TrueExprInstance); } else { return(Compiler.FalseExprInstance); } } else if (Util.IsNumeric(v)) { return(NumberExpr.Parse(v)); } else if (v is string) { return(new StringExpr((String)v)); } else if (v is IPersistentCollection && ((IPersistentCollection)v).count() == 0) { return(new EmptyExpr(v)); } else { return(new ConstantExpr(v)); } }
public Expr Parse(ParserContext pcon, object form) { object v = RT.second(form); if (v == null) { return(Compiler.NilExprInstance); } else if (v is Boolean) { if ((bool)v) { return(Compiler.TrueExprInstance); } else { return(Compiler.FalseExprInstance); } } else if (Util.IsNumeric(v)) { return(NumberExpr.Parse(v)); } else if (v is string) { return(new StringExpr((String)v)); } else if (v is IPersistentCollection && ((IPersistentCollection)v).count() == 0) { return(new EmptyExpr(v)); } else { return(new ConstantExpr(v)); } }
//(case* expr shift mask default map<minhash, [test then]> table-type test-type skip-check?) //prepared by case macro and presumed correct //case macro binds actual expr in let so expr is always a local, //no need to worry about multiple evaluation public Expr Parse(ParserContext pcon, object frm) { ISeq form = (ISeq)frm; if (pcon.Rhc == RHC.Eval) { return(Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FnOnceSym, PersistentVector.EMPTY, form)), "case__" + RT.nextID())); } IPersistentVector args = LazilyPersistentVector.create(form.next()); object exprForm = args.nth(0); int shift = Util.ConvertToInt(args.nth(1)); int mask = Util.ConvertToInt(args.nth(2)); object defaultForm = args.nth(3); IPersistentMap caseMap = (IPersistentMap)args.nth(4); Keyword switchType = (Keyword)args.nth(5); Keyword testType = (Keyword)args.nth(6); IPersistentSet skipCheck = RT.count(args) < 8 ? null : (IPersistentSet)args.nth(7); ISeq keys = RT.keys(caseMap); int low = Util.ConvertToInt(RT.first(keys)); int high = Util.ConvertToInt(RT.nth(keys, RT.count(keys) - 1)); LocalBindingExpr testexpr = (LocalBindingExpr)Compiler.Analyze(pcon.SetRhc(RHC.Expression), exprForm); SortedDictionary <int, Expr> tests = new SortedDictionary <int, Expr>(); Dictionary <int, Expr> thens = new Dictionary <int, Expr>(); foreach (IMapEntry me in caseMap) { int minhash = Util.ConvertToInt(me.key()); object pair = me.val(); // [test-val then-expr] object first = RT.first(pair); Expr testExpr = testType == _intKey ? NumberExpr.Parse(Util.ConvertToInt(first)) : (first == null ? Compiler.NilExprInstance : new ConstantExpr(first)); tests[minhash] = testExpr; Expr thenExpr; thenExpr = Compiler.Analyze(pcon, RT.second(pair)); thens[minhash] = thenExpr; } Expr defaultExpr; defaultExpr = Compiler.Analyze(pcon, defaultForm); return(new CaseExpr( (IPersistentMap)Compiler.SourceSpanVar.deref(), testexpr, shift, mask, low, high, defaultExpr, tests, thens, switchType, testType, skipCheck)); }