Exemplo n.º 1
0
 public static HassiumDictionary getAttributes(VirtualMachine vm, params HassiumObject[] args)
 {
     HassiumDictionary dict = new HassiumDictionary(new List<HassiumKeyValuePair>());
     foreach (var pair in args[0].Attributes)
         dict.add(vm, new HassiumString(pair.Key), pair.Value);
     return dict;
 }
Exemplo n.º 2
0
        public static HassiumList map(VirtualMachine vm, params HassiumObject[] args)
        {
            HassiumList list = args[0].ToList(vm) as HassiumList;
            HassiumList result = new HassiumList(new HassiumObject[0]);

            for (int i = 0; i < list.List.Count; i++)
                result.add(vm, args[1].Invoke(vm, list.List[i]));

            return result;
        }
Exemplo n.º 3
0
 public static HassiumString format(VirtualMachine vm, params HassiumObject[] args)
 {
     object[] elements = new object[args.Length - 1];
     for (int i = 0; i < elements.Length; i++)
     {
         if (args[i + 1] is HassiumInt)
             elements[i] = args[i + 1].ToInt(vm).Int;
         else if (args[i + 1] is HassiumFloat)
             elements[i] = args[i + 1].ToFloat(vm).Float;
         else
             elements[i] = args[i + 1].ToString(vm).String;
     }
     return new HassiumString(string.Format(args[0].ToString(vm).String, elements));
 }
Exemplo n.º 4
0
 public static HassiumString input(VirtualMachine vm, params HassiumObject[] args)
 {
     return new HassiumString(Console.ReadLine());
 }
Exemplo n.º 5
0
 public static HassiumBool hasAttribute(VirtualMachine vm, params HassiumObject[] args)
 {
     return new HassiumBool(args[0].Attributes.ContainsKey(args[1].ToString(vm).String));
 }
Exemplo n.º 6
0
 public static HassiumObject getAttribute(VirtualMachine vm, params HassiumObject[] args)
 {
     return args[0].Attributes[args[1].ToString(vm).String];
 }
Exemplo n.º 7
0
 public static HassiumList range(VirtualMachine vm, params HassiumObject[] args)
 {
     int start, end;
     switch (args.Length)
     {
         case 1:
             start = 0;
             end = (int)args[0].ToInt(vm).Int;
             break;
         default:
             start = (int)args[0].ToInt(vm).Int;
             end = (int)args[1].ToInt(vm).Int;
             break;
     }
     HassiumList result = new HassiumList(new HassiumObject[0]);
     while (start < end)
         result.add(vm, new HassiumInt(start++));
     return result;
 }
Exemplo n.º 8
0
 public static HassiumNull printf(VirtualMachine vm, params HassiumObject[] args)
 {
     Console.Write(format(vm, args).ToString(vm).String);
     return HassiumObject.Null;
 }
Exemplo n.º 9
0
 public static HassiumTypeDefinition type(VirtualMachine vm, params HassiumObject[] args)
 {
     return args[0].Type();
 }
Exemplo n.º 10
0
 public static HassiumNull sleep(VirtualMachine vm, params HassiumObject[] args)
 {
     Thread.Sleep((int)args[0].ToInt(vm).Int);
     return HassiumObject.Null;
 }
Exemplo n.º 11
0
 public static HassiumObject setAttribute(VirtualMachine vm, params HassiumObject[] args)
 {
     string attrib = args[1].ToString(vm).String;
     if (args[0].Attributes.ContainsKey(attrib))
         args[0].Attributes.Remove(attrib);
     args[0].Attributes.Add(attrib, args[2]);
     return args[0];
 }
Exemplo n.º 12
0
 public static HassiumObject removeAttribute(VirtualMachine vm, params HassiumObject[] args)
 {
     args[0].Attributes.Remove(args[1].ToString(vm).String);
     return args[0];
 }
Exemplo n.º 13
0
 public static HassiumChar readKey(VirtualMachine vm, params HassiumObject[] args)
 {
     return new HassiumChar((char)Console.ReadKey(args.Length == 1 ? args[0].ToBool(vm).Bool : false).KeyChar);
 }
Exemplo n.º 14
0
 public static HassiumChar readChar(VirtualMachine vm, params HassiumObject[] args)
 {
     return new HassiumChar((char)Console.Read());
 }
Exemplo n.º 15
0
 public static HassiumList types(VirtualMachine vm, params HassiumObject[] args)
 {
     return new HassiumList(args[0].Types.ToArray());
 }
Exemplo n.º 16
0
 public static HassiumNull print(VirtualMachine vm, params HassiumObject[] args)
 {
     foreach (var arg in args)
         Console.Write(arg.ToString(vm).String);
     return HassiumObject.Null;
 }
Exemplo n.º 17
0
 public static HassiumObject clone(VirtualMachine vm, params HassiumObject[] args)
 {
     return args[0].Clone() as HassiumObject;
 }
Exemplo n.º 18
0
 public HassiumObject GetVariable(VirtualMachine vm, int index)
 {
     if (Frames.Peek().ContainsVariable(index))
         return Frames.Peek().GetVariable(index);
     throw new InternalException(vm, "Variable was not found inside the stack frame! Index " + index);
 }
Exemplo n.º 19
0
 public InternalException(VirtualMachine vm, string messageFormat, params object[] args)
 {
     Message = string.Format(messageFormat, args);
     VM = vm;
 }