Example #1
0
 internal void DefineGlobalVar(string name, InjectionValue value)
 {
     vars[name] = new Var {
         Value = value, IsGlobal = true
     };
     globalVars[name] = vars[name];
 }
Example #2
0
 public ForScope(string variableName, InjectionValue range, int statementIndex, InjectionValue step)
 {
     VariableName   = variableName;
     Range          = range;
     StatementIndex = statementIndex;
     Step           = step;
 }
        public static InjectionValue GetArrayLength(InjectionValue arg)
        {
            if (arg.Kind == InjectionValueKind.Array)
            {
                return(new InjectionValue(arg.Array.Length));
            }

            return(InjectionValue.Zero);
        }
Example #4
0
 internal void SetVar(string name, InjectionValue value)
 {
     if (vars.ContainsKey(name))
     {
         vars[name].Value = value;
     }
     else
     {
         throw new StatementFailedException($"Variable {name} is not declared.");
     }
 }
Example #5
0
        internal void DefineDim(string name, int limit)
        {
            var dim = new InjectionValue[limit + 1];

            for (int i = 0; i < limit + 1; i++)
            {
                dim[i] = InjectionValue.Unit;
            }

            CurrentScope.DefineVar(name, new InjectionValue(dim));
        }
Example #6
0
            internal bool TryGetValue(string name, out InjectionValue value)
            {
                if (vars.TryGetValue(name, out var var))
                {
                    value = var.Value;
                    return(true);
                }

                value = InjectionValue.Unit;
                return(false);
            }
Example #7
0
        public static int ToInt(InjectionValue value)
        {
            switch (value.Kind)
            {
            case InjectionValueKind.Integer:
                return(value.Integer);

            case InjectionValueKind.String:
                return(ToInt(value.String));

            default:
                throw new NotImplementedException($"InjectionValueKind {value.Kind}");
            }
        }
        private int ConvertContainer(InjectionValue containerId)
        {
            switch (containerId.Kind)
            {
            case InjectionValueKind.String:
                return(ConvertContainer(containerId.String));

            case InjectionValueKind.Integer:
                return(containerId.Integer);

            default:
                throw new NotImplementedException($"Conversion for {containerId.Kind})");
            }
        }
Example #9
0
 public void SetDim(string name, int index, InjectionValue value)
 {
     if (CurrentScope.TryGetValue(name, out var dim))
     {
         if (dim.Kind == InjectionValueKind.Array)
         {
             dim.Array[index] = value;
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        public NativeSubrutineDefinition(string name, Delegate subrutine)
        {
            Name = name;

            this.subrutine = subrutine;

            if (!InjectionValue.IsSupported(subrutine.Method.ReturnType))
            {
                throw new ArgumentException($"The retrun type {subrutine.Method.ReturnType} of {subrutine} is not compatible with native subrutine.");
            }

            var parameterTypes = this.subrutine.Method
                                 .GetParameters();

            foreach (var param in parameterTypes)
            {
                if (!InjectionValue.IsSupported(param.ParameterType))
                {
                    throw new ArgumentException($"The type {param.ParameterType} of {param.Name} ({subrutine}) is not compatible with native subrutine.");
                }
            }

            parameterKinds = parameterTypes.Select(x => InjectionValue.GetKind(x.ParameterType)).ToArray();
        }
Example #11
0
 public InjectionValue File(InjectionValue fileName) => new InjectionValue(FileObject.Create((string)fileName));
Example #12
0
 public int Count(InjectionValue type, InjectionValue color, InjectionValue container) =>
 bridge.Count(NumberConversions.ToInt(type), NumberConversions.ToInt(color), ConvertContainer(container));
Example #13
0
 public void FindType(InjectionValue type, InjectionValue color, InjectionValue containerId, InjectionValue range)
 => bridge.FindType(NumberConversions.ToInt(type),
                    NumberConversions.ToInt(color),
                    ConvertContainer(containerId),
                    NumberConversions.ToInt(range));
Example #14
0
 public void SetVar(string name, InjectionValue value) => CurrentScope.SetVar(name, value);
Example #15
0
 internal void DefineVar(string name, InjectionValue value) => vars[name] = new Var
 {
     Value = value, IsGlobal = false
 };
Example #16
0
 public bool TryGetVar(string name, out InjectionValue value)
 => CurrentScope.TryGetValue(name, out value);
Example #17
0
 internal void DefineVar(string name, InjectionValue value) => CurrentScope.DefineVar(name, value);