PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Backend/Modules/sys.cs

https://bitbucket.org/AdamMil/boaold
C# | 116 lines | 72 code | 24 blank | 20 comment | 6 complexity | ed7433c36539cbf1d38cf464b048219a 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.Reflection;
  22. using Boa.AST;
  23. using Boa.Runtime;
  24. namespace Boa.Modules
  25. {
  26. [BoaType("module")]
  27. public sealed class sys
  28. { sys() { }
  29. static sys()
  30. { modules["__builtin__"] = Importer.Import("__builtin__");
  31. Assembly ass;
  32. if(Options.Interactive) path.append("");
  33. else
  34. { ass = Assembly.GetEntryAssembly();
  35. if(ass!=null) path.append(System.IO.Path.GetDirectoryName(ass.Location));
  36. }
  37. string lib = Environment.GetEnvironmentVariable("BOA_LIB_PATH");
  38. if(lib!=null && lib!="") path.append(lib);
  39. ass = Assembly.GetExecutingAssembly();
  40. if(ass!=null)
  41. path.append(System.IO.Path.GetDirectoryName(ass.Location) + System.IO.Path.DirectorySeparatorChar + "lib");
  42. }
  43. public static string __repr__() { return "<module 'sys' (built-in)>"; }
  44. public static string __str__() { return __repr__(); }
  45. public static void exit() { exit(0); }
  46. public static void exit(object obj) { throw new SystemExitException(obj); }
  47. public static void loadAssemblyByName(string name) { ReflectedPackage.LoadAssemblyByName(name); }
  48. public static void loadAssemblyFromFile(string filename) { ReflectedPackage.LoadAssemblyFromFile(filename); }
  49. public static readonly object __displayhook__ =
  50. Ops.GenerateFunction("displayhook", new Parameter[] { new Parameter("value") }, new CallTargetN(display));
  51. public static readonly object __excepthook__; // TODO: implement this
  52. public static readonly object __stdin__ = new BoaFile(Console.OpenStandardInput());
  53. public static readonly object __stdout__ = new BoaFile(Console.OpenStandardOutput());
  54. public static readonly object __stderr__ = new BoaFile(Console.OpenStandardError());
  55. public static readonly List argv = new List();
  56. public static readonly Tuple builtin_module_names =
  57. new Tuple("__builtin__", "binascii", "bisect", "codecs", "dotnet", "dotnetpath", "math", "md5",
  58. "operator", "os", "random", "re", "socket", "string", "struct", "sys", "time", "types");
  59. public static string byteorder = BitConverter.IsLittleEndian ? "little" : "big";
  60. public static string copyright = "Boa, Copyright 2004-2005 Adam Milazzo\nPortions of the standard library are copyright their respective authors.";
  61. public static object displayhook = __displayhook__;
  62. public static object excepthook = __excepthook__;
  63. public static string executable; // TODO: implement this
  64. public static object exitfunc;
  65. public static int hexversion = 0x00020000; // 0.2.0.0 (remember to update 'version', below)
  66. public static int maxint = int.MaxValue;
  67. public static int maxunicode = (int)char.MaxValue;
  68. public static readonly Dict modules = new Dict();
  69. public static readonly List path = new List();
  70. public static string platform = Environment.OSVersion.Platform.ToString();
  71. public static string ps1 = ">>> ";
  72. public static string ps2 = "... ";
  73. public static object stdin = __stdin__;
  74. public static object stdout = __stdout__;
  75. public static object stderr = __stderr__;
  76. public static List warnoptions = new List(); // TODO: populate this list on startup
  77. public static int recursionlimit = 1000; // TODO: make this take effect
  78. public static int tracebacklimit = 1000; // TODO: make this take effect
  79. public static string version = "0.2.0"; // remember to update 'hexversion', above
  80. public static Tuple version_info = new Tuple(0, 2, 0, "devel");
  81. internal static Stack Exceptions = new Stack();
  82. static object display(params object[] values) // TODO: optimize this and use CallTarget1 or something
  83. { if(values[0]!=null)
  84. { Console.WriteLine(Ops.Repr(values[0]));
  85. __builtin__._ = values[0];
  86. }
  87. return null;
  88. }
  89. }
  90. } // namespace Boa.Modules