boaold /Backend/Modules/sys.cs

Language C# Lines 116
MD5 Hash ed7433c36539cbf1d38cf464b048219a Estimated Cost $1,705 (why?)
Repository https://bitbucket.org/AdamMil/boaold View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Boa is the reference implementation for a language similar to Python,
also called Boa. This implementation is both interpreted and compiled,
targeting the Microsoft .NET Framework.

http://www.adammil.net/
Copyright (C) 2004-2005 Adam Milazzo

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

using System;
using System.Collections;
using System.Reflection;
using Boa.AST;
using Boa.Runtime;

namespace Boa.Modules
{

[BoaType("module")]
public sealed class sys
{ sys() { }
  static sys()
  { modules["__builtin__"] = Importer.Import("__builtin__");
    Assembly ass;

    if(Options.Interactive) path.append("");
    else
    { ass = Assembly.GetEntryAssembly();
      if(ass!=null) path.append(System.IO.Path.GetDirectoryName(ass.Location));
    }

    string lib = Environment.GetEnvironmentVariable("BOA_LIB_PATH");
    if(lib!=null && lib!="") path.append(lib);

    ass = Assembly.GetExecutingAssembly();
    if(ass!=null)
      path.append(System.IO.Path.GetDirectoryName(ass.Location) + System.IO.Path.DirectorySeparatorChar + "lib");
  }

  public static string __repr__() { return "<module 'sys' (built-in)>"; }
  public static string __str__() { return __repr__(); }

  public static void exit() { exit(0); }
  public static void exit(object obj) { throw new SystemExitException(obj); }
  
  public static void loadAssemblyByName(string name) { ReflectedPackage.LoadAssemblyByName(name); }
  public static void loadAssemblyFromFile(string filename) { ReflectedPackage.LoadAssemblyFromFile(filename); }

  public static readonly object __displayhook__ =
    Ops.GenerateFunction("displayhook", new Parameter[] { new Parameter("value") }, new CallTargetN(display));
  public static readonly object __excepthook__; // TODO: implement this
  public static readonly object __stdin__  = new BoaFile(Console.OpenStandardInput());
  public static readonly object __stdout__ = new BoaFile(Console.OpenStandardOutput());
  public static readonly object __stderr__ = new BoaFile(Console.OpenStandardError());

  public static readonly List argv = new List();

  public static readonly Tuple builtin_module_names =
    new Tuple("__builtin__", "binascii", "bisect", "codecs", "dotnet", "dotnetpath", "math", "md5",
              "operator", "os", "random", "re", "socket", "string", "struct", "sys", "time", "types");

  public static string byteorder = BitConverter.IsLittleEndian ? "little" : "big";
  
  public static string copyright = "Boa, Copyright 2004-2005 Adam Milazzo\nPortions of the standard library are copyright their respective authors.";

  public static object displayhook = __displayhook__;
  public static object excepthook = __excepthook__;
  public static string executable; // TODO: implement this
  public static object exitfunc;
  
  public static int hexversion = 0x00020000; // 0.2.0.0 (remember to update 'version', below)
  public static int maxint = int.MaxValue;
  public static int maxunicode = (int)char.MaxValue;

  public static readonly Dict modules = new Dict();
  public static readonly List path    = new List();
  public static string platform = Environment.OSVersion.Platform.ToString();
  public static string ps1 = ">>> ";
  public static string ps2 = "... ";
  
  public static object stdin  = __stdin__;
  public static object stdout = __stdout__;
  public static object stderr = __stderr__;
  
  public static List warnoptions = new List(); // TODO: populate this list on startup

  public static int recursionlimit = 1000; // TODO: make this take effect
  public static int tracebacklimit = 1000; // TODO: make this take effect

  public static string version = "0.2.0"; // remember to update 'hexversion', above
  public static Tuple version_info = new Tuple(0, 2, 0, "devel");

  internal static Stack Exceptions = new Stack();

  static object display(params object[] values) // TODO: optimize this and use CallTarget1 or something
  { if(values[0]!=null)
    { Console.WriteLine(Ops.Repr(values[0]));
      __builtin__._ = values[0];
    }
    return null;
  }
}

} // namespace Boa.Modules
Back to Top