PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Backend/Runtime/Module.cs

https://bitbucket.org/AdamMil/boaold
C# | 65 lines | 35 code | 10 blank | 20 comment | 4 complexity | 394d4db0c8e1c534dbe394083b751809 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. Boa is the reference implementation for a language similar to Python,
  3. also called Boa. This implementation is both interpreted and compiled,
  4. targeting the Microsoft .NET Framework.
  5. http://www.adammil.net/
  6. Copyright (C) 2004-2005 Adam Milazzo
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. using System;
  20. using System.Collections;
  21. using System.Collections.Specialized;
  22. using System.Reflection;
  23. namespace Boa.Runtime
  24. {
  25. [BoaType("module")]
  26. public class Module : Boa.AST.Snippet, IHasAttributes, IRepresentable
  27. { public const string FieldName = "__module";
  28. public Module() { __dict__ = new Dict(); }
  29. public Module(IDictionary dict) { __dict__ = dict; }
  30. public override void Run(Frame frame) { throw new NotImplementedException("Run() not implemented!"); }
  31. public string __repr__()
  32. { object name = __dict__["__name__"];
  33. return name==null ? "<module>" : string.Format("<module {0}>", Ops.Repr(name));
  34. }
  35. public override string ToString() { return __repr__(); }
  36. #region IHasAttributes Members
  37. public List __attrs__() { return new List(__dict__.Keys); }
  38. public void __delattr__(string key)
  39. { if(!Ops.DelDescriptor(__dict__[key], null)) __dict__.Remove(key);
  40. }
  41. public object __getattr__(string name)
  42. { object obj = __dict__[name];
  43. if(obj!=null || __dict__.Contains(name)) return Ops.GetDescriptor(obj, null);
  44. return builtins.__getattr__(name);
  45. }
  46. public void __setattr__(string key, object value)
  47. { if(!Ops.SetDescriptor(__dict__[key], null, value)) __dict__[key] = value;
  48. }
  49. #endregion
  50. public readonly IDictionary __dict__;
  51. static readonly ReflectedType builtins = ReflectedType.FromType(typeof(Boa.Modules.__builtin__));
  52. }
  53. } // namespace Boa.Runtime