Exemplo n.º 1
0
 void s_set(IList <string> args)
 {
     for (int i = 1; i < args.Count; i++)
     {
         Ram.Add(args[i], "True");
     }
 }
Exemplo n.º 2
0
        private void HandleToRam(string generator)
        {
            var dst1  = generator.Split(':');
            var name  = dst1.ElementAtOrDefault(0); //Name
            var value = dst1.ElementAtOrDefault(1); //Value
            var type  = dst1.ElementAtOrDefault(2); //Type

            //Remove if exsists the variable from ram
            if (Ram.Any((s) => s.Name == name))
            {
                Ram.Remove(Ram.First((s) => s.Name == name));
            }
            //The variable is not in ram and has to be created
            var actual_type = Type.GetType(type) ?? TypeAliasContainer.GetFromAlias(type);

            if (actual_type == null)
            {
                throw new InvalidVariableTypeException(string.Format("The type {0} is not a valid .Net or SelfLanguage type", type));
            }
            var convert = Conversion.GetConversion(actual_type);
            var obj     = GetVariableOfType(actual_type);

            if (convert.Any(s => s == PossibleConversion.IStringable))
            {
                dynamic o = obj;
                Ram.Add(new Variable(o.FromString(value), name));
            }
            else if (convert.Any(s => s == PossibleConversion.IConvertible))
            {
                var o = Convert.ChangeType(value, obj.GetType());
                Ram.Add(new Variable(o, name));
            }
            else if (convert.Any(s => s == PossibleConversion.Constructor))
            {
                var o = obj.GetType().GetConstructors().First((s) => s.GetParameters().Length == 1 && s.GetParameters().First().GetType() == typeof(string));
                Ram.Add(new Variable(o, name));
            }
            else if (convert.Any(s => s == PossibleConversion.FromStringImplicit))  //is the type implicitally convertible from string
            {
                obj = value;
                Ram.Add(new Variable(obj, name));
            }
            else if (convert.Any(s => s == PossibleConversion.FromStringExplicit))
            {
                obj = value; //TODO
            }
            else if (obj.GetType() is object)
            {
                obj = value;
                Ram.Add(new Variable(obj, name));
            }
            else
            {
                throw new InvalidVariableTypeException("The type {0} is not castable or convertible from string, and it does not have a constructor using one string argument");
            }
        }
Exemplo n.º 3
0
 void s_inc(IList <string> args)
 {
     if (args.Count == 2)
     {
         Ram.Add(args[1], (float.Parse(Ram.GetValue(args[1])) + 1).ToString());
     }
     else if (args.Count == 3)
     {
         Ram.Add(args[1], (float.Parse(Ram.GetValue(args[1])) + float.Parse(args[2])).ToString());
     }
     else
     {
         throw new Exception("Error in ~inc");
     }
 }
Exemplo n.º 4
0
 /* dvar [dvar_name] [value]
  * declares a dvar
  * stores a value to dvar
  */
 void s_dvar(IList <string> args)
 {
     try { Ram.Add(args[1], Args2Str(args, 2)); }
     catch { WriteLine("Error in " + Args2Str(args, 0)); }
 }