PageRenderTime 180ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/Clojure/Clojure/CljCompiler/Ast/TheVarExpr.cs

https://github.com/christianblunden/clojure-clr
C# | 91 lines | 56 code | 23 blank | 12 comment | 2 complexity | 5770fbf823e9e502b447fbb26b2cd800 MD5 | raw file
  1. /**
  2. * Copyright (c) Rich Hickey. All rights reserved.
  3. * The use and distribution terms for this software are covered by the
  4. * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5. * which can be found in the file epl-v10.html at the root of this distribution.
  6. * By using this software in any fashion, you are agreeing to be bound by
  7. * the terms of this license.
  8. * You must not remove this notice, or any other, from this software.
  9. **/
  10. /**
  11. * Author: David Miller
  12. **/
  13. using System;
  14. #if CLR2
  15. using Microsoft.Scripting.Ast;
  16. #else
  17. using System.Linq.Expressions;
  18. #endif
  19. namespace clojure.lang.CljCompiler.Ast
  20. {
  21. class TheVarExpr : Expr
  22. {
  23. #region Data
  24. readonly Var _var;
  25. #endregion
  26. #region Ctors
  27. public TheVarExpr(Var var)
  28. {
  29. _var = var;
  30. }
  31. #endregion
  32. #region Type mangling
  33. public bool HasClrType
  34. {
  35. get { return true; }
  36. }
  37. public Type ClrType
  38. {
  39. get { return typeof(Var); }
  40. }
  41. #endregion
  42. #region Parsing
  43. public sealed class Parser : IParser
  44. {
  45. public Expr Parse(ParserContext pcon, object form)
  46. {
  47. Symbol sym = (Symbol)RT.second(form);
  48. Var v = Compiler.LookupVar(sym, false);
  49. if (v != null)
  50. return new TheVarExpr(v);
  51. throw new Exception(string.Format("Unable to resolve var: {0} in this context", sym));
  52. }
  53. }
  54. #endregion
  55. #region eval
  56. public object Eval()
  57. {
  58. return _var;
  59. }
  60. #endregion
  61. #region Code generation
  62. public Expression GenCode(RHC rhc, ObjExpr objx, GenContext context)
  63. {
  64. return objx.GenVar(context,_var);
  65. }
  66. #endregion
  67. }
  68. }