protected static MemberInfo MemberInfoRoundtrip(MemberInfo m) { var ts = new TypeSpace(); var its = new InvertedTypeSpace(); return(MemberInfoRoundtrip(m, ts, its)); }
/// <summary> /// Instantiates an expression to expression slim converter with a given typespace and slim expression factory. /// </summary> /// <param name="typeSpace">The type space.</param> /// <param name="factory">The slim expression factory.</param> public ExpressionToExpressionSlimConverter(TypeSpace typeSpace, IExpressionSlimFactory factory) { TypeSpace = typeSpace ?? throw new ArgumentNullException(nameof(typeSpace)); _factory = factory ?? throw new ArgumentNullException(nameof(factory)); _parameters = new Dictionary <ParameterExpression, ParameterExpressionSlim>(); _labels = new Dictionary <LabelTarget, LabelTargetSlim>(); }
protected static Type TypeRoundtrip(Type t) { var ts = new TypeSpace(); var its = new InvertedTypeSpace(); return(TypeRoundtrip(t, ts, its)); }
/// <summary> /// Pushes a new frame, e.g. when starting to process a lambda expression or a block expression. /// </summary> /// <param name="json">JSON representation of the serialization frame.</param> /// <param name="types">Type space used to lookup parameter types.</param> /// <returns>Frame containing mappings for the specified parameters.</returns> public DeserializationFrame PushFrame(Json.Expression json, TypeSpace types) { var frame = new DeserializationFrame(json, types); _environment.Push(frame); return(frame); }
/// <summary> /// Creates a new expression tree serialization context with the given tracking objects. /// </summary> /// <param name="typeSpace">Type space for tracking of types in the expression tree being (de)serialized.</param> /// <param name="scope">Scope tracking facility for parameters in lambda expressions and block expressions.</param> /// <param name="heap">Heap serialization facility, typically used for closures.</param> /// <param name="labels">Label serialization facility, used for statement trees.</param> private ExpressionJsonSerializationContext(TypeSpace typeSpace, Scope scope, Heap heap, Labels labels) { Types = typeSpace; Scope = scope; Heap = heap; Labels = labels; }
public void TypeSpace_Resolve() { var ts = new TypeSpace(); var longSlim = ts.ConvertType(typeof(long)); ts.MapType(typeof(int), longSlim); Assert.AreEqual(ts.ConvertType(typeof(int)), longSlim); }
/// <summary> /// Reconstructors a label registration from a JSON representation. /// </summary> /// <param name="label">JSON representation of a label registration.</param> /// <param name="types">Type space to look up label types.</param> /// <returns>Label registration corresponding to the JSON representation.</returns> public static LabelTarget FromJson(Json.Expression label, TypeSpace types) { var jo = (Json.ObjectExpression)label; var type = types.Lookup(TypeRef.FromJson(jo.Members["Type"])); var name = (string)((Json.ConstantExpression)jo.Members["Name"]).Value; return(Expression.Label(type, name)); }
/// <summary> /// Reconstructs a label tracking instance from the given JSON representation. /// </summary> /// <param name="json">JSON representation of a label tracking instance.</param> /// <param name="types">Type space to lookup label types.</param> /// <returns>Label tracking instance corresponding to the given JSON representation.</returns> public static Labels FromJson(Json.Expression json, TypeSpace types) { var labels = (Json.ArrayExpression)json; return(new Labels(labels.Elements .Select((label, i) => (Label: LabelRegistration.FromJson(label, types), Id: i)) .ToDictionary(x => x.Id, x => x.Label) )); }
/// <summary> /// Gets the JSON representation of the scope tracking information. /// </summary> /// <param name="types">Type space used to register referenced types.</param> /// <returns>JSON representation of the scope tracking information.</returns> public Json.Expression ToJson(TypeSpace types) { if (Serialization == null) { throw new InvalidOperationException("Type map constructed for serialization only."); } return(Serialization.ToJson(types)); }
static void Main(string[] args) { VariablePool pool = RuntimeEngine.VariablePool; TypeSpace space = TypeEngine.RuntimeTypes; ICASMInterpreter.LoadAndExecute(@"G:\test2.icasm"); var stack = ICASMInterpreter.MemoryStack; Console.ReadKey(); return; }
public void TypeSpace_ArgumentChecks() { var ts = new TypeSpace(); AssertEx.ThrowsException <ArgumentNullException>(() => ts.GetMember(member: null), ex => Assert.AreEqual(ex.ParamName, "member")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.GetConstructor(constructor: null), ex => Assert.AreEqual(ex.ParamName, "constructor")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.GetField(field: null), ex => Assert.AreEqual(ex.ParamName, "field")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.GetMethod(method: null), ex => Assert.AreEqual(ex.ParamName, "method")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.GetProperty(property: null), ex => Assert.AreEqual(ex.ParamName, "property")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.ConvertType(type: null), ex => Assert.AreEqual(ex.ParamName, "type")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.MapType(type: null, typeSlim: null), ex => Assert.AreEqual(ex.ParamName, "type")); AssertEx.ThrowsException <ArgumentNullException>(() => ts.MapType(typeof(int), typeSlim: null), ex => Assert.AreEqual(ex.ParamName, "typeSlim")); }
/// <summary> /// Registers a label target for serialization. /// This method can only be used during serialization. /// </summary> /// <param name="target">Target label.</param> /// <param name="types">type space to lookup label types.</param> /// <returns>Label registration JSON representation.</returns> public Json.Expression RegisterLabel(LabelTarget target, TypeSpace types) { if (!_serializationLabelIds.TryGetValue(target, out int id)) { id = _serializationLabelIds.Count; var type = types.Register(target.Type).ToJson(); _serializationLabels[target] = new LabelRegistration(target, type); _serializationLabelIds[target] = id; } return(Json.Expression.Number(id.ToString(CultureInfo.InvariantCulture))); }
/// <summary> /// Gets the JSON representation of the frame. /// </summary> /// <param name="types">Type space to register parameter types in.</param> /// <returns>JSON representation of the frame.</returns> public Json.Expression ToJson(TypeSpace types) { // // Note: keep in sync with DeserializationFrame::.ctor code. // return(Json.Expression.Array( from p in _parameters select(Json.Expression) Json.Expression.Object( new Dictionary <string, Json.Expression> { { "Name", Json.Expression.String(_mapping[p]) }, { "FriendlyName", Json.Expression.String(p.Name) }, { "Type", types.Register(p.Type).ToJson() } }) )); }
/// <summary> /// Creates a deserialization frame from the given JSON representation. /// </summary> /// <param name="json">JSON representation of a frame.</param> /// <param name="types">Type space used to lookup parameter types.</param> public DeserializationFrame(Json.Expression json, TypeSpace types) { _parameters = new List <ParameterExpression>(); _mapping = new Dictionary <string, ParameterExpression>(); foreach (Json.ObjectExpression p in ((Json.ArrayExpression)json).Elements) { // // Note: keep in sync with SerializationFrame::ToJson code. // Add( (string)((Json.ConstantExpression)p.Members["Name"]).Value, types.Lookup(TypeRef.FromJson(p.Members["Type"])), (string)((Json.ConstantExpression)p.Members["FriendlyName"]).Value ); } }
public static TypeSpace GetTypeSpace(Address _typespace_address) { string[] _nodes = _typespace_address.FullPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); TypeSpace typespace = TypeEngine.RuntimeTypes; int i = 0; if (_nodes.Length >= 1) { if (_nodes[0].Equals("$SYSTEM$_Runtime.TypeSpace@" + typeof(TypeEngine).Name)) { i = 1; } } for (; i < _nodes.Length; i++) { typespace = typespace.GetTypeSpace(_nodes[i]); } return(typespace); }
public void InvertedTypeSpace_MapType_Success() { var ts = new TypeSpace(); var its = new InvertedTypeSpace(); var fooSlim = ts.ConvertType(typeof(Foo)); its.MapType(fooSlim, typeof(Qux)); var fooCtor = typeof(Foo).GetConstructors().Single(); var quxCtor = typeof(Qux).GetConstructors().Single(); Assert.AreEqual(quxCtor, MemberInfoRoundtrip(fooCtor, ts, its)); var fooField = typeof(Foo).GetField("baz"); var quxField = typeof(Qux).GetField("baz"); Assert.AreEqual(quxField, MemberInfoRoundtrip(fooField, ts, its)); var fooProp = typeof(Foo).GetProperty("Bar"); var quxProp = typeof(Qux).GetProperty("Bar"); Assert.AreEqual(quxProp, MemberInfoRoundtrip(fooProp, ts, its)); var fooIdxProp = typeof(Foo).GetProperty("Item"); var quxIdxProp = typeof(Qux).GetProperty("Item"); Assert.AreEqual(quxIdxProp, MemberInfoRoundtrip(fooIdxProp, ts, its)); var fooSimple = typeof(Foo).GetMethod("Qux1"); var quxSimple = typeof(Qux).GetMethod("Qux1"); Assert.AreEqual(quxSimple, MemberInfoRoundtrip(fooSimple, ts, its)); var fooGenericDef = typeof(Foo).GetMethod("Qux2"); var quxGenericDef = typeof(Qux).GetMethod("Qux2"); Assert.AreEqual(quxGenericDef, MemberInfoRoundtrip(fooGenericDef, ts, its)); var fooGeneric = fooGenericDef.MakeGenericMethod(new[] { typeof(int) }); var quxGeneric = quxGenericDef.MakeGenericMethod(new[] { typeof(int) }); Assert.AreEqual(quxGeneric, MemberInfoRoundtrip(fooGeneric, ts, its)); }
/// <summary> /// Visits a member assignment slim tree node to produce a member assignment, /// taking implicit conversions for primitive data model types into account. /// </summary> /// <param name="node">Slim expression representation of the assignment.</param> /// <param name="expression">Expression assigned to the member, obtained from recursive conversion steps.</param> /// <returns>Member assignment node.</returns> protected override MemberAssignment MakeMemberAssignment(MemberAssignmentSlim node, Expression expression) { var member = TypeSpace.GetMember(node.Member); var lhsType = GetMemberAssignmentMemberType(member); var rhsType = expression.Type; // This case occurs when an enum is used in a known type and the underlying type of the enum // is used during anonymization. For example: // // xs.Select(x => new Person { Sex = Sex.Male, Age = x }) // // Erasure of the enum results in the following anonymized expression: // // xs.Select(x => new <>__Record { entity://person/sex = 1, entity://person/age = x }) // // Upon unification and reconstruction of the expression, the record type is unified against // the Person type, and an assignment incompatibility occurs for Sex = 1. // // A similar case exists during recursive rewriting of a subexpression whose type, declared // on a known type, is an enum. For example: // // xs.Select(x => new Person { Sex = x.Sex, Age = 21 }) // // Erasure of the enum results in the following anonymized expression: // // xs.Select(x => new <>__Record { entity://person/sex = x.entity://ape/sex, entity://person/age = 21 }) // // This time around, as the type of "x" gets resolved, the x.entity://ape/sex subexpression is // turned into x.Sex on the known type, which is an enum. Assignment to the record type's int // property now fails because of lack of conversion. if (lhsType != rhsType && (IsEnumAssignableToUnderlyingType(lhsType, rhsType) || IsEnumAssignableToUnderlyingType(rhsType, lhsType))) { expression = Expression.Convert(expression, lhsType); } return(base.MakeMemberAssignment(node, expression)); }
/// <summary> /// Restores an expression tree serialization context, used for deserialization, from the given JSON representation. /// </summary> /// <param name="expression">JSON representation of an expression tree serialization context.</param> /// <param name="typeResolutionService">Type resolution service. Can be null.</param> /// <returns>Expression tree serialization context used for deserialization.</returns> public static ExpressionJsonSerializationContext FromJson(Json.Expression expression, ITypeResolutionService typeResolutionService) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var ctx = (Json.ObjectExpression)expression; // // Important! The type space needs to be rehydrated first because of its use by scope // tracking and label serialization. // var typeSpace = TypeSpace.FromJson(ctx.Members["Types"], typeResolutionService); var heap = default(Heap); if (ctx.Members.TryGetValue("Heap", out Json.Expression heapJson)) { heap = Heap.FromJson(heapJson); } var scope = default(Scope); if (ctx.Members.TryGetValue("Globals", out Json.Expression globals)) { scope = Scope.FromJson(globals, typeSpace); } var labels = default(Labels); if (ctx.Members.TryGetValue("Labels", out Json.Expression labelsJson)) { labels = Labels.FromJson(labelsJson, typeSpace); } return(new ExpressionJsonSerializationContext(typeSpace, scope, heap, labels)); }
public void InvertedTypeSpace_MemberRoundtrip_BadMapping_ThrowsInvalidOperation() { var ts = new TypeSpace(); var its = new InvertedTypeSpace(); var fooSlim = ts.ConvertType(typeof(Foo)); its.MapType(fooSlim, typeof(Bar)); var ctor = typeof(Foo).GetConstructors().Single(); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(ctor, ts, its)); var field = typeof(Foo).GetField("baz"); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(field, ts, its)); var prop = typeof(Foo).GetProperty("Bar"); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(prop, ts, its)); var idxProp = typeof(Foo).GetProperty("Item"); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(idxProp, ts, its)); var simple = typeof(Foo).GetMethod("Qux1"); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(simple, ts, its)); var genericDef = typeof(Foo).GetMethod("Qux2"); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(genericDef, ts, its)); var generic = genericDef.MakeGenericMethod(new[] { typeof(int) }); Assert.ThrowsException <InvalidOperationException>(() => MemberInfoRoundtrip(generic, ts, its)); }
/// <summary> /// Creates a new deserialization state object. /// </summary> /// <param name="globals">JSON representation of globals to make available.</param> /// <param name="types">Type space for lookup of types.</param> public DeserializationState(Json.Expression globals, TypeSpace types) { _environment = new Stack <DeserializationFrame>(); _globals = new DeserializationFrame(globals, types); }
/// <summary> /// Restores scope tracking information from the given JSON representation. /// </summary> /// <param name="json">JSON representation of scope tracking information.</param> /// <param name="types">Type space used to lookup referenced types.</param> /// <returns>Scope tracking instance used during deserialization.</returns> public static Scope FromJson(Json.Expression json, TypeSpace types) { var state = new DeserializationState(json, types); return(new Scope(state)); }
protected static Type TypeRoundtrip(Type t, TypeSpace ts, InvertedTypeSpace its) { return(its.ConvertType(ts.ConvertType(t))); }
protected static MemberInfo MemberInfoRoundtrip(MemberInfo m, TypeSpace ts, InvertedTypeSpace its) { return(its.GetMember(ts.GetMember(m))); }
public static void CreateTypeSpace(Address _typespace_address) { TypeSpace typespace = GetTypeSpace(_typespace_address); typespace.CreateTypeSpace(_typespace_address.Name); }
/// <summary> /// Instantiates an expression to expression slim converter with a given typespace. /// </summary> /// <param name="typeSpace">The type space.</param> public ExpressionToExpressionSlimConverter(TypeSpace typeSpace) : this(typeSpace, ExpressionSlimFactory.Instance) { }
public static void AddType(Address _type_address, Infinity.Engine.Data.Type type) { TypeSpace typespace = GetTypeSpace(_type_address.Parent); typespace.Put(type.Address.Name, type); }
public static void CreateType(Address _type_address, string igml_code) { TypeSpace typespace = GetTypeSpace(_type_address); typespace.Create(_type_address.Name, igml_code); }
public static Infinity.Engine.Data.Type GetType(Address _type_address) { TypeSpace typespace = GetTypeSpace(_type_address.Parent); return(typespace.Get(_type_address.Name)); }
/// <summary> /// Gets the JSON representation of the scope tracking serialization state. /// </summary> /// <param name="types">Type space to register and lookup parameter types.</param> /// <returns>JSON representation of the scope tracking serialization state.</returns> public Json.Expression ToJson(TypeSpace types) { return(_globals.ToJson(types)); }
public static ICASMExecutionResult Execute(Scope _currentScope, ICASMDirectiveType type, ICASMTagType tag, ICASMDirectiveParameters parameters) { ICASMExecutionResult result = new ICASMExecutionResult() { Success = true }; ICASMValue varname, varvalue, varscope, vartype; Variable variable; Address address; string _ideoutput = ""; switch (type) { #region VariableAddDirective case ICASMDirectiveType.VariableAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tVariableAddDirective, usage - \n\t+var <name> <?scope> <?type> <?value>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); vartype = null; varvalue = new ICASMValue(ICASMValueType.Normal, null); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); if (parameters.Count > 2) { vartype = parameters[2].Check(ICASMValueType.Address); if (parameters.Count > 3) { varvalue = parameters[3].Check(ICASMValueType.Address, ICASMValueType.ExecutableResult, ICASMValueType.Identifier, ICASMValueType.Normal); } } } Data.Type varType = null; if (vartype != null) { varType = TypeEngine.GetType(Address.FromScope(new Scripting.Scope((string)vartype.Value))); } else { varType = ICASMValue.GetTypeFromPrimitiveType(varvalue.PrimitiveType); } string[] memberCreation = varType.MemberCreationQueue.ToArray(); variable = new Variable(varvalue.Value, varType); for (int i = 0; i < memberCreation.Length; i++) { ICASMDirective _temp_directive_function_member = ICASMInterpreter.ParseDirective(_currentScope, memberCreation[i]); if (_temp_directive_function_member.Type == ICASMDirectiveType.VariableAddDirective) { _temp_directive_function_member.SetTag(ICASMTagType.AppendTuple); string varscopestr = (string)varscope.Value; if (!varscopestr.Equals("/")) { varscopestr = varscopestr + "/"; } _temp_directive_function_member.Parameters.Insert(1, new ICASMValue(ICASMValueType.Address, varscopestr + (string)varname.Value)); ICASMExecutionResult res = Execute(_currentScope, _temp_directive_function_member); variable.TupleAddresses.Add((string)_temp_directive_function_member.Parameters[0].Value, (Address)res.Data["VariableAddDirective"]); } } address = Address.FromScope(new Scripting.Scope((string)varscope.Value + "/" + (string)varname.Value)); if (tag == ICASMTagType.Suppress) { RuntimeEngine.CreatePool(address.Parent); if (RuntimeEngine.GetPool(address.Parent).HasVariable(address.Name)) { RuntimeEngine.GetPool(address.Parent).Pull(address.Name); } } else if (tag == ICASMTagType.AppendTuple) { address = Address.FromScope(new Scripting.Scope((string)varscope.Value + "." + (string)varname.Value)); } RuntimeEngine.PutVariable(address, variable); result.Success = true; result.Data.Add(type.ToString(), address); break; #endregion #region VariableRemoveDirective case ICASMDirectiveType.VariableRemoveDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tVariableRemoveDirective, usage - \n\t-var <name> <?scope>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } VariablePool pool = RuntimeEngine.GetPool(Address.FromScope(new Scope((string)varscope.Value))); variable = pool.Pull((string)varname.Value); if (variable != null) { result.Success = true; result.Data.Add(type.ToString(), new Address((string)varscope.Value, (string)varname.Value, AddressType.Variable)); } break; #endregion #region VariablePoolAddDirective case ICASMDirectiveType.VariablePoolAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tVariablePoolAddDirective, usage - \n\t+pool <name> <?scope>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } address = Address.FromScope(new Scope((string)varscope.Value + "/" + (string)varname.Value)); RuntimeEngine.CreatePool(address); result.Success = true; result.Data.Add(type.ToString(), address); break; #endregion #region VariablePoolRemoveDirective case ICASMDirectiveType.VariablePoolRemoveDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tVariablePoolRemoveDirective, usage - \n\t-pool <name> <?scope>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } address = Address.FromScope(new Scope((string)varscope.Value + "/" + (string)varname.Value)); RuntimeEngine.GetPool(address.Parent).PullPool(address.Name); result.Success = true; result.Data.Add(type.ToString(), address); break; #endregion #region CallDirective case ICASMDirectiveType.CallDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tCallDirective, usage - \n\tcall <type> <function name> <?parameters>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0]; if (varname.Type == ICASMValueType.Identifier && varname.Value.Equals("type(stack)")) { varname.Value = MemoryStack.Peek(); } else { varname = varname.Check(ICASMValueType.Address); } varscope = parameters[1]; if ((string)varscope.Value == "/") { varscope.Type = ICASMValueType.FunctionIdentifier; } varscope = varscope.Check(ICASMValueType.FunctionIdentifier, ICASMValueType.Identifier); if (parameters.Count > 2) { Address[] _addresses = new Address[parameters.Count - 2]; for (int i = 2; i < parameters.Count; i++) { if (parameters[i].Type == ICASMValueType.Normal) { Data.Type ttt = ICASMValue.GetTypeFromPrimitiveType(parameters[i].PrimitiveType); variable = new Variable(parameters[i].Value, ttt); RuntimeEngine.PutVariable("/$SYSTEM$_temp" + (_temps), variable); _addresses[i - 2] = "/$SYSTEM$_temp" + _temps; MemoryStack.Push(_addresses[i - 2]); _temps++; } else if (parameters[i].Type == ICASMValueType.Address) { _addresses[i - 2] = (string)parameters[i].Value; } else if (parameters[i].Type == ICASMValueType.Identifier) { _addresses[i - 2] = "/" + (string)parameters[i].Value; } } address = (string)varname.Value; string temp_address = "/$SYSTEM$_temp" + (_temps); _executingFunction = true; TypeEngine.GetType(address).ExecuteFunction(temp_address, (string)varscope.Value, _addresses); MemoryStack.Push(temp_address); address = temp_address; result.Success = true; result.Data.Add(type.ToString(), (Address)temp_address); _temps++; } break; #endregion #region AssignDirective case ICASMDirectiveType.AssignDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tAssignDirective, usage - \n\tassign <value> <address of variable>\n\t\t<value> - can be any primitive value, address, identifier or another nested <?call> or <?ewfc>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0]; varscope = parameters[1].Check(ICASMValueType.Identifier, ICASMValueType.Address); address = (string)varscope.Value; variable = new Variable(); Address addr = null; if (varname.Type == ICASMValueType.Normal) { Data.Type ttt = ICASMValue.GetTypeFromPrimitiveType(varname.PrimitiveType); variable = new Variable(varname.Value, ttt); } else if (varname.Type == ICASMValueType.Identifier) { addr = "/" + (string)varname.Value; variable = RuntimeEngine.GetVariable(addr); } else if (varname.Type == ICASMValueType.Address) { addr = (string)varname.Value; variable = RuntimeEngine.GetVariable(addr); } if (tag == ICASMTagType.Suppress) { RuntimeEngine.CreatePool(address.Parent); VariablePool variablep = RuntimeEngine.GetPool(address.Parent); if (variablep.HasVariable(address.Name)) { variablep.Pull(address.Name); } RuntimeEngine.PutVariable(address, variable); } RuntimeEngine.SetVariable(address, variable); result.Success = true; result.Data.Add(type.ToString(), address); break; #endregion #region FunctionAddDirective case ICASMDirectiveType.FunctionAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tFunctionAddDirective, usage - \n\t+function <name> <type address> <function type> <?parameter type addresses>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.FunctionIdentifier, ICASMValueType.Identifier); if (varname == null && parameters[0].Value.Equals("/")) { varname = parameters[0]; } varscope = parameters[1].Check(ICASMValueType.Address); vartype = parameters[2].Check(ICASMValueType.Identifier); List <Address> parametertypes = new List <Address>(); int j = 3; while (j < parameters.Count && parameters[j].Type == ICASMValueType.Address) { parametertypes.Add((string)parameters[j].Value); j++; } FunctionType _newFunctionType = (FunctionType)Enum.Parse(typeof(FunctionType), (string)vartype.Value); ICASMFunction new_function = new ICASMFunction((string)varname.Value, (string)varname.Value, _newFunctionType, (string)varscope.Value, parametertypes.ToArray()); _mode = ICASMInterpreterMode.Function; currentFunction = new_function; break; #endregion #region FunctionRemoveDirective case ICASMDirectiveType.FunctionRemoveDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tFunctionRemoveDirective, usage - \n\t+function <name> <type address>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } //To-do break; #endregion #region FieldsAddDirective case ICASMDirectiveType.FieldsAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tFieldsAddDirective, usage - \n\t+fields <type address>\n\t\t<... var add statements>\n\tend+"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Address); currentType = TypeEngine.GetType((string)varname.Value); _mode = ICASMInterpreterMode.Fields; break; #endregion #region TypeAddDirective case ICASMDirectiveType.TypeAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tTypeAddDirective, usage - \n\t+type <name> <typespace address>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } Data.Type t = new Data.Type((string)varname.Value, (string)varscope.Value); TypeEngine.AddType(t.Address, t); break; #endregion #region TypeRemoveDirective case ICASMDirectiveType.TypeRemoveDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tTypeRemoveDirective, usage - \n\t-type <name> <typespace address>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } TypeSpace from = TypeEngine.GetTypeSpace((string)varscope.Value); if (from.HasType((string)varname.Value)) { from.Pull((string)varname.Value); } break; #endregion #region TypespaceAddDirective case ICASMDirectiveType.TypespaceAddDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tTypespaceAddDirective, usage - \n\t+typespace <name> <?typespace parent>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } TypeSpace _toCreateTypespaceIn = TypeEngine.GetTypeSpace((string)varscope.Value); _toCreateTypespaceIn.CreateTypeSpace((string)varname.Value); break; #endregion #region TypespaceRemoveDirective case ICASMDirectiveType.TypespaceRemoveDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tTypespaceRemoveDirective, usage - \n\t-typespace <name> <?typespace parent>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Identifier); varscope = new ICASMValue(ICASMValueType.Address, "/"); if (parameters.Count > 1) { varscope = parameters[1].Check(ICASMValueType.Address); } TypeSpace _toRemoveTypespaceFrom = TypeEngine.GetTypeSpace((string)varscope.Value); _toRemoveTypespaceFrom.PullTypeSpace((string)varname.Value); break; #endregion #region ReturnDirective case ICASMDirectiveType.ReturnDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tReturnDirective, usage - \n\treturn <identifier/address/value>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } address = null; varname = parameters[0].Check(ICASMValueType.Address, ICASMValueType.Identifier, ICASMValueType.Normal); if (varname.Type == ICASMValueType.Address) { address = (string)varname.Value; } else if (varname.Type == ICASMValueType.Identifier) { address = "/" + (string)varname.Value; } else if (varname.Type == ICASMValueType.Normal) { Data.Type ttt = ICASMValue.GetTypeFromPrimitiveType(varname.PrimitiveType); variable = new Variable(varname.Value, ttt); RuntimeEngine.PutVariable("/$SYSTEM$_temp" + (_temps), variable); address = "/$SYSTEM$_temp" + _temps; MemoryStack.Push(address); _temps++; } if (address != null) { result.Success = true; result.Data.Add(type.ToString(), address); } _functionReturned = true; _executingFunction = false; break; #endregion #region TypeAddDirective case ICASMDirectiveType.ImportDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tTypeAddDirective, usage - \n\timport <librarypath/filepath>\n\t\t-path - for importing a file"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Normal); string _importPath = (string)varname.Value; LoadAndExecute(_importPath.Trim()); break; #endregion #region EwfcDirective case ICASMDirectiveType.EwfcDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tEwfcDirective, usage - \n\tewfc <.net namespace> <function name> <?parameters>"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varscope = parameters[0].Check(ICASMValueType.Address); varname = parameters[1].Check(ICASMValueType.Identifier); _importPath = (string)varscope.Value; string _importMethodName = (string)varname.Value; _importPath = _importPath.Replace('/', '.').Trim('.'); object[] _parametersToCallingFunction = new object[parameters.Count - 2]; System.Type[] _parameterTypesToCallingFunction = new System.Type[parameters.Count - 2]; variable = new Variable(); for (int i = 2; i < parameters.Count; i++) { if (parameters[i].Type == ICASMValueType.Normal) { Data.Type ttt = ICASMValue.GetTypeFromPrimitiveType(parameters[i].PrimitiveType); variable = new Variable(parameters[i].Value, ttt); } else if (parameters[i].Type == ICASMValueType.Address) { variable = RuntimeEngine.GetVariable((string)parameters[i].Value); } else if (parameters[i].Type == ICASMValueType.Identifier) { variable = RuntimeEngine.GetVariable("/" + (string)parameters[i].Value); } if (variable.Value == null) { continue; } _parametersToCallingFunction[i - 2] = variable.Value; _parameterTypesToCallingFunction[i - 2] = variable.Value.GetType(); } System.Type _typeOfCallingMethod = System.Type.GetType(_importPath); MethodInfo _callingMethodInfo = _typeOfCallingMethod.GetMethod(_importMethodName, _parameterTypesToCallingFunction); object _methodCallResult = _callingMethodInfo.Invoke(null, _parametersToCallingFunction); if (_methodCallResult != null) { string _methodResultValue = _methodCallResult.ToString(); ICASMValue icasm_methodReturnedValue = null; Variable _methodCallResultVariable = null; if ((icasm_methodReturnedValue = ICASMValue.ParseValue(_methodResultValue)) != null) { Data.Type ttt = ICASMValue.GetTypeFromPrimitiveType(icasm_methodReturnedValue.PrimitiveType); _methodCallResultVariable = new Variable(icasm_methodReturnedValue.Value, ttt); } else { _methodCallResultVariable = new Variable(_methodCallResult, new Data.Type("Object", "/")); } address = "/$SYSTEM$_temp" + _temps; RuntimeEngine.PutVariable(address, _methodCallResultVariable); result.Success = true; result.Data.Add(ICASMDirectiveType.CallDirective.ToString(), address); MemoryStack.Push(address); _temps++; } break; #endregion #region ReflectDirective case ICASMDirectiveType.ReflectDirective: if (tag == ICASMTagType.Help) { _ideoutput = "\n\tReflectDirective, usage - \n\treflect <address>\n\t\t-variable - reflect variable\n\t\t-pool - reflect variable pool\n\t\t-typespace - reflect typespace\n\t\t-type - reflect type"; result.Data.Add("$IDE_OUTPUT$", _ideoutput); break; } varname = parameters[0].Check(ICASMValueType.Address); if (tag == ICASMTagType.Variable) { Variable _reflectVariable = RuntimeEngine.GetVariable((string)varname.Value); _ideoutput = "\n\tReflect options - " + tag + ", " + _reflectVariable.Address; _ideoutput += "\n\tVariable Address - " + _reflectVariable.Address; _ideoutput += "\n\tVariable Value - " + _reflectVariable.Value; if (_reflectVariable.Type != null) { _ideoutput += "\n\tVariable Type - " + _reflectVariable.Type.Address + "\n\tTuples - "; } foreach (Address _reflectVariableTuple in _reflectVariable.TupleAddresses.Values) { _ideoutput += "\n\t\t" + _reflectVariableTuple; } result.Data.Add("$IDE_OUTPUT$", _ideoutput); } else if (tag == ICASMTagType.Pool) { VariablePool _reflectPool = RuntimeEngine.GetPool((string)varname.Value); _ideoutput = "\n\tReflect options - " + tag + ", " + _reflectPool.Address; _ideoutput += "\n\tVariable Address - " + _reflectPool.Address; _ideoutput += "\n\tVariablePools - " + _reflectPool.VariablePoolCount; foreach (VariablePool _pool in _reflectPool.VariablePools.Values) { _ideoutput += "\n\t\t" + _pool.Address; } _ideoutput += "\n\tVariables - " + _reflectPool.VariableCount; foreach (Variable _var in _reflectPool.Variables.Values) { _ideoutput += "\n\t\t" + _var.Address; } result.Data.Add("$IDE_OUTPUT$", _ideoutput); } else if (tag == ICASMTagType.Type) { Data.Type _reflectType = TypeEngine.GetType((string)varname.Value); _ideoutput = "\n\tReflect options - " + tag + ", " + _reflectType.Address; _ideoutput += "\n\tFunctions - " + _reflectType.FunctionCount; foreach (FunctionOverloads f in _reflectType.Functions.Values) { _ideoutput += "\n\t\t" + f.AccessKey + " (overloads " + f.Overloads.Count + ")"; for (int i = 0; i < f.Overloads.Count; i++) { _ideoutput += "\n\t\t\t" + i + " - "; foreach (Address typse in f.Overloads[i].Parameters) { _ideoutput += "[" + typse.FullPath + "] "; } } } result.Data.Add("$IDE_OUTPUT$", _ideoutput); } else if (tag == ICASMTagType.Typespace) { } break; #endregion #region JumpDirective case ICASMDirectiveType.JumpDirective: varname = parameters[0]; int step = (int)varname.Value; result.Success = true; result.Data.Add(ICASMDirectiveType.JumpDirective.ToString(), step); break; #endregion } if (!_executingFunction) { while (MemoryStack.Count != 0) { Address addr = MemoryStack.Pop(); if (result.Data.ContainsKey("CallDirective")) { Address addr_c1 = (Address)result.Data["CallDirective"]; if (addr_c1.Equals(addr)) { continue; } } else if (result.Data.ContainsKey("ReturnDirective")) { if (result.Data["ReturnDirective"].Equals(addr.FullPath)) { continue; } } VariablePool pool = RuntimeEngine.VariablePool; RuntimeEngine.GetPool(addr.Parent).Pull(addr.Name, true); } } return(result); }