internal void DefineGlobalVar(string name, InjectionValue value) { vars[name] = new Var { Value = value, IsGlobal = true }; globalVars[name] = vars[name]; }
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); }
internal void SetVar(string name, InjectionValue value) { if (vars.ContainsKey(name)) { vars[name].Value = value; } else { throw new StatementFailedException($"Variable {name} is not declared."); } }
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)); }
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); }
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})"); } }
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(); }
public InjectionValue File(InjectionValue fileName) => new InjectionValue(FileObject.Create((string)fileName));
public int Count(InjectionValue type, InjectionValue color, InjectionValue container) => bridge.Count(NumberConversions.ToInt(type), NumberConversions.ToInt(color), ConvertContainer(container));
public void FindType(InjectionValue type, InjectionValue color, InjectionValue containerId, InjectionValue range) => bridge.FindType(NumberConversions.ToInt(type), NumberConversions.ToInt(color), ConvertContainer(containerId), NumberConversions.ToInt(range));
public void SetVar(string name, InjectionValue value) => CurrentScope.SetVar(name, value);
internal void DefineVar(string name, InjectionValue value) => vars[name] = new Var { Value = value, IsGlobal = false };
public bool TryGetVar(string name, out InjectionValue value) => CurrentScope.TryGetValue(name, out value);
internal void DefineVar(string name, InjectionValue value) => CurrentScope.DefineVar(name, value);