public LingVariable(String Name, VarType Type) { label = Name; range = new List<double>(2); fs = new List<MembershipFunction>(); type = Type; }
private void FunRetForm_Load(object sender, EventArgs e) { // 读取这个函数的状态 List<string> args; string retType; core.getFunction(this.frname, out args, out retType); this.frtype = Consta.parseCTypeToVarType(retType); if (this.frtype == VarType.VOID) { this.radioButton2.Enabled = this.radioButton3.Enabled = this.radioButton4.Enabled = false; this.textBox2.Enabled = this.textBox1.Enabled = this.comboBox1.Enabled = false; this.radioButton1.Checked = true; } else { this.radioButton1.Enabled = false; this.radioButton2.Checked = true; this.textBox2.Enabled = true; this.textBox1.Enabled = this.comboBox1.Enabled = false; } // 加载全局变量表 List<string> globalVarList = core.getGlobalVar(); if (globalVarList.Count == 0) { this.radioButton4.Enabled = false; } else { foreach (string s in globalVarList) { this.comboBox1.Items.Add(s); } this.comboBox1.SelectedIndex = 0; } }
public Variable(string rawString) { if ("1234567890-+".Contains(rawString[0])) { Type = VarType.Number; Contents = Convert.ToInt32(rawString); } else if (rawString[0] == '"') { Type = VarType.String; Contents = rawString.Substring(1, rawString.Length - 2); } else { Contents = rawString.Substring(1, rawString.Length - 1); switch (rawString[0]) { case '$': Type = VarType.Local; break; case '^': Type = VarType.Obj; break; case '*': Type = VarType.Global; break; default: throw new Exception("Vartype not implemented: " + rawString[0]); } } }
public void InitializeConnection(BaseNode _node, DataDirection _direction, VarType _varType, int _num) { node = _node; dataDirection = _direction; varType = _varType; num = _num; }
public void Parse(ref string[] program) { string token = ParseUtils.GetToken(ref program); WooScript._Log.AddMsg("Found function, target \"" + token + "\""); WooScript._Log.Indent(); if (WooScript.IsFloatVariable(token)) { _ReturnType = VarType.varFloat; _Var = token; } else if (WooScript.IsVecVariable(token)) { _ReturnType = VarType.varVector; _Var = token; } else { throw new ParseException("Expected \"" + token + "\" to be a float or vector variable"); } string assignOp = ParseUtils.GetToken(ref program); _AssignOp = WooScript.GetAssignOp(assignOp); _Expression = ExpressionBuilder.Parse(ref program); if (_ReturnType == VarType.varVector && (_Expression.GetExpressionType() != VarType.varVector)) throw new ParseException("Target token is \"" + token + "\" which is a vector, expression isn't..."); if (_ReturnType == VarType.varFloat && (_Expression.GetExpressionType() != VarType.varFloat)) throw new ParseException("Target token is \"" + token + "\" which is a float, expression isn't..."); }
/// <summary> /// 以另一个函数的形式修改自己 /// </summary> /// <param name="other">待复制函数单元</param> /// <returns>返回更新后的自身</returns> public FunctionCell editSign(FunctionCell other) { this.callname = other.callname; this.returnType = other.returnType; this.paraList = new List<KagaVar>(other.paraList.ToArray()); return this; }
public bool AddValue(string key, VarType type, string v) { if (HaveKey(key)) return false; Value val = new Value(v, type); val.ConverToRealType(); _valueContainer[key] = val; return true; }
public VarTypeObject(VarType v) { this.ident = null; this.varType = v; if (v == VarType.ObjectStrict || v == VarType.Object) throw new Exception("TODO: Allow anonymous objects"); template = null; //TODO: Allow anonymous objects }
public CVarHeader(int type, int offset, int count, string name, string desc, string unit) { this.type = (VarType)type; this.offset = offset; this.count = count; this.name = name; this.desc = desc; this.unit = unit; }
public VarTypeObject(Ident i, bool isStrict = false, Template template = null) { this.ident = i; this.varType = isStrict ? VarType.ObjectStrict : VarType.Object; this.template = template; if(this.template == null && (this.ident.ReferencedObject is Interfaces.iTemplate)) { this.template = ((Interfaces.iTemplate)this.ident.ReferencedObject).TemplateObject; } }
//inserts array, true if successful, false if already in table public bool InsertArray(string identifier, int addr, VarType type) { if (Symbols.ContainsKey(identifier)) { return false; } else { Symbols.Add(identifier, addr); ArrayTypes.Add(identifier, type); SetType(identifier, VarType.Array); return true; } }
//allocates variable memory, returns address /numeric identifier //size gives us declaration size for arrays, //type gives us dword or byte public int AllocateVariableMemory(VarType type, int size=1) { //cheating and just putting a 'v' for variable and taking on the counter variableCounter++; if (type == VarType.Int){ dataBuffer.Add("v"+variableCounter +" dd " + ((size>1) ? size + "dup (?)" : "?")); } else { dataBuffer.Add("v"+variableCounter +" db " + ((size>1) ? size + "dup (?)" : "?")); } return variableCounter; }
protected CVar(String name, String defaultValue, VarType type, CFlags flags) { if (name == null) { throw new NullReferenceException("Name is null"); } m_name = name; m_defaultValue = defaultValue; m_type = type; m_flags = flags; SetValue(defaultValue); }
public bool BindConnections(VarPass outNode, VarPass inNode, VarType outType, VarType inType, int outNum, int inNum) { if (outType == VarType.IdWeightList) { Debug.Log("Binding..."); IOutputList<IdWeight> outIdWeightList = outNode.node as IOutputList<IdWeight>; if(outIdWeightList == null) return false; Debug.Log("got output interface..."); if(inNode.varType == VarType.IdWeightVar){ return false; } if (inNode.varType == VarType.IdWeightList){ Debug.Log("got list node..." + inNode.node.GetType().ToString()); IInputList<IdWeight> inIdWeightList = inNode.node as IInputList<IdWeight>; if(inIdWeightList == null) return false; inIdWeightList.inputList = outIdWeightList.outputList; if (outNode.oppositeConnections.Count == 0) outNode.oppositeConnections.Add(inNode); else{ outNode.oppositeConnections.Clear(); outNode.oppositeConnections.Add(inNode); } return true; } if (inNode.varType == VarType.IdWeightNestedList){ Debug.Log("got nested list node..." + inNode.node.GetType().ToString()); IInputMultyList<IdWeight> inIdWeightMultyList = inNode.node as IInputMultyList<IdWeight>; if(inIdWeightMultyList == null) return false; Debug.Log("got input Nested list interface..."); inIdWeightMultyList.inputLists[inNum] = outIdWeightList.outputList; if (outNode.oppositeConnections.Count == 0){ outNode.oppositeConnections.Add(inNode); inNode.oppositeConnections.Add(outNode); Debug.Log("Adding to empty new opposite connection"); } else{ outNode.oppositeConnections.Clear(); outNode.oppositeConnections.Add(inNode); inNode.oppositeConnections.Add(outNode); Debug.Log("Replacing new opposite connection"); } return true; } return false; } return false; }
//[string output] public ReportVariable this[VarType varType] { get { switch (varType) { case VarType.Index: return _index; break; case VarType.Content: break; default: break; } } set { this[varType].Content = value; } //get; set; }
//process output and input of vars and lists public void PassArgument(BaseNode from, BaseNode to, VarType fromType, VarType outType) { switch (fromType) { case VarType.FloatVar: IOutputVar<float> fromInterface = from as IOutputVar<float>; IInputVar<float> toInterface = to as IInputVar<float>; if(fromInterface != null && toInterface != null){ toInterface.inputVar = fromInterface.outputVar; } break; case VarType.IdWeightVar: IOutputVar<IdWeight> fromIdWeight = from as IOutputVar<IdWeight>; IInputVar<IdWeight> toIdWeight = to as IInputVar<IdWeight>; if(fromIdWeight != null && toIdWeight != null){ toIdWeight.inputVar = fromIdWeight.outputVar; } break; default: break; } }
public varType(string lex, Lexer.Symbol token, int dpth, VarType varT, int off) : base(lex, token, dpth) { TypeOfVariable = varT; Offset = off + getSize(varT); size = getSize(varT); }
public Loop(VarType bound, OpType operation, VarType step) { Operation = operation; Bound = bound; Step = step; }
public void AddLocalVar(string methodName, string varName, int length, VarType type) { MethodList.AddLocalVar(methodName, varName, length, type); }
public void AddGlobalVar(string name, int length, VarType type) { Vars.AddVar(name, globalCount++, length, type); }
public Access(Id a, Expr i, VarType p) : base(new Word("[]", Tag.INDEX), p) { Array = a; Index = i; }
private Val(VarType type, Var val) { _type = type; _val = val; }
public Val(VarType type) : this(type, Var.Create(type)) { }
public ArrayType(VarType varType) { VarType = varType; }
public ArrayType(Expression expression, VarType varType) { Expression = expression; VarType = varType; }
public EnumResultCode CreateItems(ValueQT valueQT) { //lock (m_lock) { try { // Retreive parent folder AddressSpaceElement parentFolder = GetParent(); ArrayList children = GetChildren(); uint itemCount = 0; VarType itemType = VarType.Unknown; string itemSet = String.Empty; bool isAnalogItem = false; DaAddressSpaceElement outParam = null; // get parameter values foreach (DaAddressSpaceElement param in children) { if (param == null) { continue; } ValueQT paramValue = null; param.GetCacheValue(ref paramValue); if (param.Name == ItemCountParam) { itemCount = (uint)paramValue.Data; } else if (param.Name == ItemTypeParam) { itemType = (VarType)((uint)paramValue.Data); } else if (param.Name == ItemSetIdParam) { outParam = param; } else if (param.Name == ItemIsAnalogParam) { isAnalogItem = (bool)paramValue.Data; } } // Check if all parameters are set if (itemCount != 0 && itemType != VarType.Unknown && outParam != null) { Type varType; switch (itemType) { case VarType.Uint8: varType = typeof(Byte); break; case VarType.Int8: varType = typeof(SByte); break; case VarType.Uint16: varType = typeof(UInt16); break; case VarType.Int16: varType = typeof(Int16); break; case VarType.Uint32: varType = typeof(UInt32); break; case VarType.Int32: varType = typeof(Int32); break; case VarType.Uint64: varType = typeof(UInt64); break; case VarType.Int64: varType = typeof(Int64); break; case VarType.Float: varType = typeof(Single); break; case VarType.Double: varType = typeof(Double); break; default: varType = typeof(Byte); break; } // Create the item set CreateItems(parentFolder, outParam, itemCount, varType, false, valueQT.Data.ToString(), isAnalogItem); } else { // Parameters not set correctly return(EnumResultCode.E_FAIL); } return(EnumResultCode.S_OK); } catch { return(EnumResultCode.E_FAIL); } } }
public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("Name", Name); var culture = new CultureInfo("en-US"); VarType type = VarType.Double; var valtype = Value.GetType(); if (valtype == typeof(double)) { type = VarType.Double; } else if (valtype == typeof(Complex)) { type = VarType.Complex; } else if (valtype == typeof(Fraction)) { type = VarType.Fraction; } else if (valtype == typeof(Matrix)) { type = VarType.Matrix; } else if (valtype == typeof(Vector)) { type = VarType.Vector; } else if (valtype == typeof(Set)) { type = VarType.Set; } else if (valtype == typeof(string)) { type = VarType.String; } else if (valtype == typeof(Time)) { type = VarType.Time; } writer.WriteAttributeString("Type", type.ToString()); string xml = null; var sb = new StringBuilder(); switch (type) { case VarType.Double: xml = (Convert.ToDouble(Value)).ToString("G17", culture); writer.WriteElementString("Content", xml); break; case VarType.Complex: var r = ((Complex)Value).Real.ToString("G17", culture); var i = ((Complex)Value).Imaginary.ToString("G17", culture); xml = string.Format("{0};{1}", r, i); writer.WriteElementString("Content", xml); break; case VarType.Fraction: var n = ((Fraction)Value).Numerator.ToString(culture); var d = ((Fraction)Value).Denominator.ToString(culture); xml = string.Format("{0};{1}", n, d); writer.WriteElementString("Content", xml); break; case VarType.Matrix: Matrix m = ((Matrix)Value); writer.WriteAttributeString("Rows", m.Rows.ToString()); writer.WriteAttributeString("Columns", m.Columns.ToString()); for (int row = 0; row < m.Rows; row++) { sb.Append("["); for (int column = 0; column < m.Columns; column++) { sb.AppendFormat("{0};", m[row, column].ToString("G17", culture)); } sb.Append("]\n"); } writer.WriteElementString("Content", sb.ToString()); break; case VarType.Vector: var v = (Vector)Value; writer.WriteAttributeString("Dimensions", v.Dimensions.ToString()); if (v.Dimensions == 2) { xml = string.Format("{0};{1}", v.X.ToString("G17", culture), v.Y.ToString("G17", culture)); } else { xml = string.Format("{0};{1};{2}", v.X.ToString("G17", culture), v.Y.ToString("G17", culture), ((double)v.Z).ToString("G17", culture)); } writer.WriteElementString("Content", xml); break; case VarType.Set: var s = (Set)Value; writer.WriteAttributeString("Items", s.Count.ToString()); sb.Clear(); foreach (var item in s) { sb.AppendFormat("{0};", item.ToString("G17", culture)); } writer.WriteElementString("Content", sb.ToString()); break; case VarType.String: writer.WriteElementString("Content", Value.ToString()); break; case VarType.Time: Time t = (Time)Value; xml = (Convert.ToDouble(t.TotalSeconds).ToString("G17", culture)); writer.WriteElementString("Content", xml); break; } }
/// <summary> /// Provides an simple string representation of the contained data and type. /// </summary> /// <returns></returns> public override string ToString() { return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}: {1}", Value, VarType.ToString())); }
public var(float o) { _type = VarType.FLOAT; _obj = o; }
public Val(VarType type, object val) : this(type, Var.Create(type, val)) { }
public object Read(DataType DataType, int DB, int StartByteAdr, VarType VarType, int VarCount) { byte[] bytes = null; int cntBytes = 0; switch (VarType) { case VarType.Byte: cntBytes = VarCount; if (cntBytes < 1) { cntBytes = 1; } bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(bytes[0]); } else { return(bytes); } case VarType.Word: cntBytes = VarCount * 2; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.Word.FromByteArray(bytes)); } else { return(Types.Word.ToArray(bytes)); } case VarType.Int: cntBytes = VarCount * 2; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.Int.FromByteArray(bytes)); } else { return(Types.Int.ToArray(bytes)); } case VarType.DWord: cntBytes = VarCount * 4; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.DWord.FromByteArray(bytes)); } else { return(Types.DWord.ToArray(bytes)); } case VarType.DInt: cntBytes = VarCount * 4; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.DInt.FromByteArray(bytes)); } else { return(Types.DInt.ToArray(bytes)); } case VarType.Real: cntBytes = VarCount * 4; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.Double.FromByteArray(bytes)); } else { return(Types.Double.ToArray(bytes)); } case VarType.String: cntBytes = VarCount; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } return(Types.String.FromByteArray(bytes)); case VarType.Timer: cntBytes = VarCount * 2; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.Timer.FromByteArray(bytes)); } else { return(Types.Timer.ToArray(bytes)); } case VarType.Counter: cntBytes = VarCount * 2; bytes = ReadBytes(DataType, DB, StartByteAdr, cntBytes); if (bytes == null) { return(null); } if (VarCount == 1) { return(Types.Counter.FromByteArray(bytes)); } else { return(Types.Counter.ToArray(bytes)); } default: return(null); } return(null); }
public static void Parse(string input, out DataType dataType, out int dbNumber, out VarType varType, out int address, out int bitNumber) { bitNumber = -1; dbNumber = 0; switch (input.Substring(0, 2)) { case "DB": string[] strings = input.Split(new char[] { '.' }); if (strings.Length < 2) { throw new InvalidAddressException("To few periods for DB address"); } dataType = DataType.DataBlock; dbNumber = int.Parse(strings[0].Substring(2)); address = int.Parse(strings[1].Substring(3)); string dbType = strings[1].Substring(0, 3); switch (dbType) { case "DBB": varType = VarType.Byte; return; case "DBW": varType = VarType.Word; return; case "DBD": varType = VarType.DWord; return; case "DBX": bitNumber = int.Parse(strings[2]); if (bitNumber > 7) { throw new InvalidAddressException("Bit can only be 0-7"); } varType = VarType.Bit; return; default: throw new InvalidAddressException(); } case "EB": // Input byte dataType = DataType.Input; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Byte; return; case "EW": // Input word dataType = DataType.Input; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Word; return; case "ED": // Input double-word dataType = DataType.Input; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.DWord; return; case "AB": // Output byte dataType = DataType.Output; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Byte; return; case "AW": // Output word dataType = DataType.Output; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Word; return; case "AD": // Output double-word dataType = DataType.Output; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.DWord; return; case "MB": // Memory byte dataType = DataType.Memory; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Byte; return; case "MW": // Memory word dataType = DataType.Memory; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.Word; return; case "MD": // Memory double-word dataType = DataType.Memory; dbNumber = 0; address = int.Parse(input.Substring(2)); varType = VarType.DWord; return; default: switch (input.Substring(0, 1)) { case "E": case "I": // Input dataType = DataType.Input; varType = VarType.Bit; break; case "A": case "O": // Output dataType = DataType.Output; varType = VarType.Bit; break; case "M": // Memory dataType = DataType.Memory; varType = VarType.Byte; break; case "T": // Timer dataType = DataType.Timer; dbNumber = 0; address = int.Parse(input.Substring(1)); varType = VarType.Timer; return; case "Z": case "C": // Counter dataType = DataType.Timer; dbNumber = 0; address = int.Parse(input.Substring(1)); varType = VarType.Counter; return; default: throw new InvalidAddressException(string.Format("{0} is not a valid address", input.Substring(0, 1))); } string txt2 = input.Substring(1); if (txt2.IndexOf(".") == -1) { throw new InvalidAddressException("To few periods for DB address"); } address = int.Parse(txt2.Substring(0, txt2.IndexOf("."))); bitNumber = int.Parse(txt2.Substring(txt2.IndexOf(".") + 1)); if (bitNumber > 7) { throw new InvalidAddressException("Bit can only be 0-7"); } return; } }
/// <summary> /// Parallelize the scheduled search plan to the branching factor, /// splitting it at the first loop into a header part and a body part /// </summary> public static void ParallelizeHeadBody(LGSPRulePattern rulePattern) { Debug.Assert(rulePattern.patternGraph.schedulesIncludingNegativesAndIndependents.Length == 1); ScheduledSearchPlan ssp = rulePattern.patternGraph.schedulesIncludingNegativesAndIndependents[0]; int indexToSplitAt = 0; for (int i = 0; i < ssp.Operations.Length; ++i) { SearchOperation so = ssp.Operations[i]; if (so.Type == SearchOperationType.Lookup || so.Type == SearchOperationType.Incident || so.Type == SearchOperationType.Incoming || so.Type == SearchOperationType.Outgoing || so.Type == SearchOperationType.PickFromStorage || so.Type == SearchOperationType.PickFromStorageDependent || so.Type == SearchOperationType.PickFromIndex || so.Type == SearchOperationType.PickFromIndexDependent) { indexToSplitAt = i; break; } } rulePattern.patternGraph.parallelizedSchedule = new ScheduledSearchPlan[2]; List <SearchOperation> headOperations = new List <SearchOperation>(); List <SearchOperation> bodyOperations = new List <SearchOperation>(); for (int i = 0; i < rulePattern.Inputs.Length; ++i) { if (rulePattern.Inputs[i] is VarType) // those don't appear in the schedule, they are only extracted into the search program { VarType varType = (VarType)rulePattern.Inputs[i]; String varName = rulePattern.InputNames[i]; PatternVariable dummy = new PatternVariable(varType, varName, varName, i, false, null); headOperations.Add(new SearchOperation(SearchOperationType.WriteParallelPresetVar, dummy, null, 0)); bodyOperations.Add(new SearchOperation(SearchOperationType.ParallelPresetVar, dummy, null, 0)); } } for (int i = 0; i < ssp.Operations.Length; ++i) { SearchOperation so = ssp.Operations[i]; if (i < indexToSplitAt) { SearchOperation clone = (SearchOperation)so.Clone(); clone.Isomorphy.Parallel = true; clone.Isomorphy.LockForAllThreads = true; headOperations.Add(clone); switch (so.Type) { // the target binding looping operations can't appear in the header, so we don't treat them here // the non-target binding operations are completely handled by just adding them, happended already above // the target binding non-looping operations are handled below, // by parallel preset writing in the header and reading in the body // with exception of def, its declaration and initializion is just re-executed in the body // some presets can't appear in an action header, they are thus not taken care of case SearchOperationType.ActionPreset: case SearchOperationType.MapWithStorage: case SearchOperationType.MapWithStorageDependent: case SearchOperationType.Cast: case SearchOperationType.Assign: case SearchOperationType.Identity: case SearchOperationType.ImplicitSource: case SearchOperationType.ImplicitTarget: case SearchOperationType.Implicit: headOperations.Add(new SearchOperation(SearchOperationType.WriteParallelPreset, (SearchPlanNode)so.Element, so.SourceSPNode, 0)); bodyOperations.Add(new SearchOperation(SearchOperationType.ParallelPreset, (SearchPlanNode)so.Element, so.SourceSPNode, 0)); break; case SearchOperationType.AssignVar: headOperations.Add(new SearchOperation(SearchOperationType.WriteParallelPresetVar, (PatternVariable)so.Element, so.SourceSPNode, 0)); bodyOperations.Add(new SearchOperation(SearchOperationType.ParallelPresetVar, (PatternVariable)so.Element, so.SourceSPNode, 0)); break; case SearchOperationType.DefToBeYieldedTo: bodyOperations.Add((SearchOperation)so.Clone()); break; } } else if (i == indexToSplitAt) { SearchOperation cloneHead; SearchOperation cloneBody; switch (so.Type) { case SearchOperationType.Lookup: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelLookup); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelLookup); break; case SearchOperationType.Incident: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelIncident); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelIncident); break; case SearchOperationType.Incoming: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelIncoming); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelIncoming); break; case SearchOperationType.Outgoing: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelOutgoing); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelOutgoing); break; case SearchOperationType.PickFromStorage: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelPickFromStorage); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelPickFromStorage); break; case SearchOperationType.PickFromStorageDependent: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelPickFromStorageDependent); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelPickFromStorageDependent); break; case SearchOperationType.PickFromIndex: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelPickFromIndex); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelPickFromIndex); break; case SearchOperationType.PickFromIndexDependent: cloneHead = (SearchOperation)so.Clone(SearchOperationType.SetupParallelPickFromIndexDependent); cloneBody = (SearchOperation)so.Clone(SearchOperationType.ParallelPickFromIndexDependent); break; default: // failure, operation at this index cannot be parallelized/parallelization not supported cloneHead = null; cloneBody = null; break; } headOperations.Add(cloneHead); cloneBody.Isomorphy.Parallel = true; bodyOperations.Add(cloneBody); } else { SearchOperation clone = (SearchOperation)so.Clone(); clone.Isomorphy.Parallel = true; bodyOperations.Add(clone); if (clone.Element is PatternCondition) { SetNeedForParallelizedVersion((clone.Element as PatternCondition).ConditionExpression); } } } ScheduledSearchPlan headSsp = new ScheduledSearchPlan( rulePattern.patternGraph, headOperations.ToArray(), headOperations.Count > 0 ? headOperations[0].CostToEnd : 0); rulePattern.patternGraph.parallelizedSchedule[0] = headSsp; ScheduledSearchPlan bodySsp = new ScheduledSearchPlan( rulePattern.patternGraph, bodyOperations.ToArray(), bodyOperations.Count > 0 ? bodyOperations[0].CostToEnd : 0); rulePattern.patternGraph.parallelizedSchedule[1] = bodySsp; ParallelizeNegativeIndependent(bodySsp); ParallelizeAlternativeIterated(rulePattern.patternGraph); ParallelizeYielding(rulePattern.patternGraph); }
public Id(Word id, VarType p, int b) : base(id, p) { Offset = b; }
public void AddMethod(string name, VarType type) { MethodList.AddMethod(name, type); }
private Var(VarDictionary data) : this() { this.type = VarType.Dictionary; this.asDictionary = data; }
/// <summary> /// Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format. /// </summary> /// <param name="varType"></param> /// <param name="bytes"></param> /// <param name="varCount"></param> /// <param name="bitAdr"></param> /// <returns></returns> private object?ParseBytes(VarType varType, byte[] bytes, int varCount, byte bitAdr = 0) { if (bytes == null || bytes.Length == 0) { return(null); } switch (varType) { case VarType.Byte: if (varCount == 1) { return(bytes[0]); } else { return(bytes); } case VarType.Word: if (varCount == 1) { return(Word.FromByteArray(bytes)); } else { return(Word.ToArray(bytes)); } case VarType.Int: if (varCount == 1) { return(Int.FromByteArray(bytes)); } else { return(Int.ToArray(bytes)); } case VarType.DWord: if (varCount == 1) { return(DWord.FromByteArray(bytes)); } else { return(DWord.ToArray(bytes)); } case VarType.DInt: if (varCount == 1) { return(DInt.FromByteArray(bytes)); } else { return(DInt.ToArray(bytes)); } case VarType.Real: if (varCount == 1) { return(Types.Real.FromByteArray(bytes)); } else { return(Types.Real.ToArray(bytes)); } case VarType.LReal: if (varCount == 1) { return(Types.LReal.FromByteArray(bytes)); } else { return(Types.LReal.ToArray(bytes)); } case VarType.String: return(Types.String.FromByteArray(bytes)); case VarType.S7String: return(S7String.FromByteArray(bytes)); case VarType.S7WString: return(S7WString.FromByteArray(bytes)); case VarType.Timer: if (varCount == 1) { return(Timer.FromByteArray(bytes)); } else { return(Timer.ToArray(bytes)); } case VarType.Counter: if (varCount == 1) { return(Counter.FromByteArray(bytes)); } else { return(Counter.ToArray(bytes)); } case VarType.Bit: if (varCount == 1) { if (bitAdr > 7) { return(null); } else { return(Bit.FromByte(bytes[0], bitAdr)); } } else { return(Bit.ToBitArray(bytes, varCount)); } case VarType.DateTime: if (varCount == 1) { return(DateTime.FromByteArray(bytes)); } else { return(DateTime.ToArray(bytes)); } case VarType.DateTimeLong: if (varCount == 1) { return(DateTimeLong.FromByteArray(bytes)); } else { return(DateTimeLong.ToArray(bytes)); } default: return(null); } }
public var() { _type = VarType.UNDEFINED; _obj = null; }
//inserts into symbol table after going through checks public void insert(string lex, Lexer.Symbol token, int dpth, EntryType et, VarType vt, LinkedList <parameterType> p = null, constantType c = null) { int key = hash(lex); bool found = false; foreach (var i in symTable) { if (i != null) { foreach (var j in i) { if (j.Lexeme == lex && j.depth == dpth) { found = true; } } } } if (found) { Console.WriteLine($"Error Found: {lex} already exits at depth: {dpth}"); Console.ReadLine(); Environment.Exit(0); } else { if (symTable[key] == null) { symTable[key] = new LinkedList <symTableRecord>(); } switch (et) { case EntryType.varEntry: symTable[key].AddFirst(new varType(lex, token, dpth, vt, calcVarOffset(dpth))); break; case EntryType.constEntry: symTable[key].AddFirst(new constantType(lex, token, dpth, c)); break; case EntryType.functionEntry: symTable[key].AddFirst(new functionType(lex, token, dpth, vt, p)); break; case EntryType.parameterEntry: int totalOffset = 0; for (int i = 0; i < TableSize; i++) { if (symTable[i] != null) { var TsymTable = new LinkedList <symTableRecord>(symTable[i]); foreach (parameterType item in TsymTable.OfType <parameterType>()) { if (item.depth == dpth) { totalOffset = item.Size + totalOffset; } } } } symTable[key].AddFirst(new parameterType(lex, dpth, vt, totalOffset)); break; } } }
public var(SByte o) { _type = VarType.UBYTE; _obj = o; }
public var(ushort o) { _type = VarType.USHORT; _obj = o; }
public var(uint o) { _type = VarType.UINT; _obj = o; }
/// <summary> /// Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format. /// </summary> /// <param name="varType"></param> /// <param name="bytes"></param> /// <param name="varCount"></param> /// <returns></returns> private object ParseBytes(VarType varType, byte[] bytes, int varCount) { if (bytes == null) return null; switch (varType) { case VarType.Byte: if (varCount == 1) return bytes[0]; else return bytes; case VarType.Word: if (varCount == 1) return Types.Word.FromByteArray(bytes); else return Types.Word.ToArray(bytes); case VarType.Int: if (varCount == 1) return Types.Int.FromByteArray(bytes); else return Types.Int.ToArray(bytes); case VarType.DWord: if (varCount == 1) return Types.DWord.FromByteArray(bytes); else return Types.DWord.ToArray(bytes); case VarType.DInt: if (varCount == 1) return Types.DInt.FromByteArray(bytes); else return Types.DInt.ToArray(bytes); case VarType.Real: if (varCount == 1) return Types.Double.FromByteArray(bytes); else return Types.Double.ToArray(bytes); case VarType.String: return Types.String.FromByteArray(bytes); case VarType.Timer: if (varCount == 1) return Types.Timer.FromByteArray(bytes); else return Types.Timer.ToArray(bytes); case VarType.Counter: if (varCount == 1) return Types.Counter.FromByteArray(bytes); else return Types.Counter.ToArray(bytes); case VarType.Bit: return null; //TODO default: return null; } }
public VariableStorer(VarType v, uint loc) { Type = v; Location = loc; }
unsafe void Parse(SR1_Reader reader, Event scriptEvent, ScriptType type, SR1_PrimativeArray <short> scriptData) { if ((reader.File._ImportFlags & SR1_File.ImportFlags.LogScripts) != 0) { try { string script = ""; short[] opCodes = new short[scriptData.Count]; int c = 0; foreach (short code in scriptData) { opCodes[c] = code; c++; } List <VarType> stack = new List <VarType>(); fixed(short *codeStreamStart = opCodes) { short *codeStream = codeStreamStart; c = 0; while (c < opCodes.Length) { PCode opcode = (PCode)(*codeStream - 1); int mathOp = _PCodes[(int)opcode].mathOp; int additionalBytes = 0; script += "\t\t"; if (mathOp > -1) { Operation operation = GetCompareOperationFromID(stack[stack.Count - 1], _PCodes[(int)opcode].mathOp, stack, codeStream); VarType param0VarType = stack[stack.Count - 2]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2); VarType param1VarType = stack[stack.Count - 1]; string param1 = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1); string result = "(" + _VarTypes[(int)operation.t] + ")"; script += "object var" + stack.Count + " = " + result + operation.n + "(" + param0 + ", " + param1 + ")"; stack.Add(operation.t); } else if (opcode == PCode.AddObjectToStack) { int param = *(codeStream + 1); EventBaseObject scriptEventInstance = (EventBaseObject)scriptEvent.instances[param]; VarType param0Type = GetVarType_AddObjectToStack(scriptEventInstance, stack, codeStream); string param0 = "(" + _VarTypes[(int)param0Type] + ")instances[" + param.ToString() + "]"; script += "object var" + stack.Count + " = " + param0; stack.Add(param0Type); } else if (opcode == PCode.AddPlayerObjectToStack) { int param = *(codeStream + 1); VarType param0Type = VarType.InstanceObject; string param0 = "(" + _VarTypes[(int)param0Type] + ")gameTrackerX.playerInstance"; script += "object var" + stack.Count + " = " + param0; stack.Add(param0Type); } else if (opcode == PCode.ModifyObjectToStackWithAttribute) { int param = *(codeStream + 1); Operation operation = GetTranformOperationFromID(stack[stack.Count - 1], param, stack, codeStream); VarType param0VarType = stack[stack.Count - 1]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 1); string result = "(" + _VarTypes[(int)operation.t] + ")"; if (operation.t != VarType.None) { script += "var" + (stack.Count - 1) + " = " + result; } if (param0VarType == VarType.EventObject) { // SavedEvent and SavedEventSmallVars both inherit from SavedBasic. // Hopefully the opcodes don't care where these come from and behave the same as local events. if (operation.p == 1) { string param1 = (*(codeStream + 2)).ToString(); script += operation.n + "(" + param0 + ", " + param1 + ")"; additionalBytes++; } else { script += operation.n + "(" + param0 + ")"; } } else { script += operation.n + "(" + param0 + ")"; } if (operation.t != VarType.None) { stack[stack.Count - 1] = operation.t; } } else if (opcode == PCode.AddNumberToStack) { int param = *(codeStream + 1); VarType param0Type = VarType.Number; string param0 = "(" + _VarTypes[(int)param0Type] + ")" + param.ToString(); script += "object var" + stack.Count + " = " + param0; stack.Add(VarType.Number); } else if (opcode == PCode.DoStackOperationEquals) { VarType param0VarType = stack[stack.Count - 2]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2); VarType param1VarType = stack[stack.Count - 1]; string param1 = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1); script += _PCodes[*codeStream - 1].n + "(" + param0 + ", " + param1 + ")"; } else if (opcode == PCode.Execute) { script += _PCodes[*codeStream - 1].n + "()"; stack.Clear(); } else { script += _PCodes[*codeStream - 1].n + "()"; } script += ";\r\n"; codeStream += _PCodes[*codeStream - 1].l; codeStream += additionalBytes; c += _PCodes[opCodes[c] - 1].l; c += additionalBytes; if (c < opCodes.Length && (opcode == PCode.Execute || opcode == PCode.EndConditional || opcode == PCode.EndAction || opcode == PCode.EndOfLine2)) { script += "\r\n"; } } reader.LogScript(script); } } catch { reader.LogScript("\t\t// Error reading " + type.ToString() + " script.\r\n"); } } }
public static int getSize(VarType type) { switch (type) { case VarType.UNDEFINED: return 0; case VarType.BYTE: case VarType.INDEX: return 1; case VarType.UBYTE: return 1; case VarType.SHORT: return 2; case VarType.USHORT: return 2; case VarType.INT: return 4; case VarType.UINT: return 4; case VarType.LONG: return 8; case VarType.FLOAT: return 4; case VarType.DOUBLE: return 8; default: throw new RunnerError(ErrorCode.BAD_VAR_TYPE); } }
public object Read(DataType dataType, int db, int startByteAdr, VarType varType, int varCount) { byte[] bytes = null; int cntBytes = 0; switch (varType) { case VarType.Byte: cntBytes = varCount; if (cntBytes < 1) cntBytes = 1; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return bytes[0]; else return bytes; case VarType.Word: cntBytes = varCount * 2; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.Word.FromByteArray(bytes); else return Types.Word.ToArray(bytes); case VarType.Int: cntBytes = varCount * 2; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.Int.FromByteArray(bytes); else return Types.Int.ToArray(bytes); case VarType.DWord: cntBytes = varCount * 4; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.DWord.FromByteArray(bytes); else return Types.DWord.ToArray(bytes); case VarType.DInt: cntBytes = varCount * 4; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.DInt.FromByteArray(bytes); else return Types.DInt.ToArray(bytes); case VarType.Real: cntBytes = varCount * 4; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.Double.FromByteArray(bytes); else return Types.Double.ToArray(bytes); case VarType.String: cntBytes = varCount; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; return Types.String.FromByteArray(bytes); case VarType.Timer: cntBytes = varCount * 2; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.Timer.FromByteArray(bytes); else return Types.Timer.ToArray(bytes); case VarType.Counter: cntBytes = varCount * 2; bytes = ReadBytes(dataType, db, startByteAdr, cntBytes); if (bytes == null) return null; if (varCount == 1) return Types.Counter.FromByteArray(bytes); else return Types.Counter.ToArray(bytes); default: return null; } }
public void CreateNode(NodeGraph GraphObj, NodeType nT, VarType pT, object subType, int nodeCount = 2) { NodeBase node = null; switch (nT) { case NodeType.Math: node = NodeUtilities.CreateNode(GraphObj, NodeType.Math, subType, pT, mouseLoc, nodeCount); break; case NodeType.Event: node = NodeUtilities.CreateNode(GraphObj, nT, subType, mouseLoc); break; case NodeType.Fetch: break; case NodeType.Control: //Debug.Log("I control the world"); if ((ControlNode.ControlType)subType != ControlNode.ControlType.Cast) { node = NodeUtilities.CreateNode(GraphObj, nT, subType, mouseLoc); } break; case NodeType.Function: node = NodeUtilities.CreateNode(GraphObj, nT, subType, pT, mouseLoc, nodeCount); break; } //Debug.Log(node); // establish connection between selected pin and first input/output of matching type // e.g. float to float if (pinToAttach != null) { if (!pinToAttach.isInput) { foreach (InputPin ip in node.InPins) { if (ip.varType == pinToAttach.varType) { graph.ConnectPins(ip, (OutputPin)pinToAttach); break; } } } else { foreach (OutputPin op in node.OutPins) { if (op.varType == pinToAttach.varType) { graph.ConnectPins((InputPin)pinToAttach, op); break; } } } } Destroy(false); }
public void parse(VarType type, Byte[] data) { switch (type) { case VarType.UNDEFINED: _obj = null; break; case VarType.BYTE: _obj = (byte)data[0]; break; case VarType.UBYTE: _obj = (sbyte)data[0]; break; case VarType.SHORT: _obj = BitConverter.ToInt16(data, 0); break; case VarType.USHORT: _obj = BitConverter.ToUInt16(data, 0); break; case VarType.INT: _obj = BitConverter.ToInt32(data, 0); break; case VarType.UINT: _obj = BitConverter.ToUInt32(data, 0); break; case VarType.LONG: _obj = BitConverter.ToUInt64(data, 0); break; case VarType.FLOAT: _obj = BitConverter.ToSingle(data, 0); break; case VarType.DOUBLE: _obj = BitConverter.ToDouble(data, 0); break; default: throw new RunnerError(ErrorCode.BAD_VAR_TYPE); } _type = type; }
void OnGUI() { GUILayout.Space(10); _name = EditorGUILayout.TextField("Name:", _name); GUILayout.Space(10); _varType = (VarType)EditorGUILayout.EnumPopup(_varType); GUILayout.Space(10); switch (_varType) { case VarType.INT: case VarType.FLOAT: case VarType.STRING: _var = EditorGUILayout.TextField("Value:", _var); break; case VarType.BOOL: if (string.IsNullOrEmpty(_var)) { _var = bool.TrueString; } try { _var = EditorGUILayout.Toggle(bool.Parse(_var)).ToString(); } catch (System.Exception) { _var = bool.TrueString; } break; } GUILayout.Space(10); if (GUILayout.Button("Add", ResourcesManager.GetInstance.skin.button, GUILayout.Height(25))) { if (_container.HaveKey(_name)) { EditorUtility.DisplayDialog("Error!", "The name already exist! ", "OK"); return; } Value value = null; switch (_varType) { case VarType.INT: int result; if (int.TryParse(_var, out result)) { value = new Value(result); } break; case VarType.FLOAT: float resultF; if (float.TryParse(_var, out resultF)) { value = new Value(resultF); } break; case VarType.BOOL: value = new Value(bool.Parse(_var)); break; case VarType.STRING: value = new Value(_var); break; } if (value == null) { EditorUtility.DisplayDialog("Error!", "Value Type Was Wrong! ", "OK"); return; } _container.AddValue(_name, value); Close(); } }
public var(Byte o) { _type = VarType.BYTE; _obj = o; }
public ValueOutputPin(NodeBase n, VarType t) : base(n, t) { }
public var(short o) { _type = VarType.SHORT; _obj = o; }
public static void AddType(FlatBufferBuilder builder, VarType type) { builder.AddSbyte(2, (sbyte)type, 0); }
public var(int o) { _type = VarType.INT; _obj = o; }
/// <summary> /// Read and decode a certain number of bytes of the "VarType" provided. /// This can be used to read multiple consecutive variables of the same type (Word, DWord, Int, etc). /// If the read was not successful, check LastErrorCode or LastErrorString. /// </summary> /// <param name="dataType">Data type of the memory area, can be DB, Timer, Counter, Merker(Memory), Input, Output.</param> /// <param name="db">Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc.</param> /// <param name="startByteAdr">Start byte address. If you want to read DB1.DBW200, this is 200.</param> /// <param name="varType">Type of the variable/s that you are reading</param> /// <param name="bitAdr">Address of bit. If you want to read DB1.DBX200.6, set 6 to this parameter.</param> /// <param name="varCount"></param> public async Task <object> ReadAsync(DataType dataType, int db, int startByteAdr, VarType varType, int varCount, byte bitAdr = 0) { int cntBytes = VarTypeToByteLength(varType, varCount); byte[] bytes = await ReadBytesAsync(dataType, db, startByteAdr, cntBytes); return(ParseBytes(varType, bytes, varCount, bitAdr)); }
public var(long o) { _type = VarType.LONG; _obj = o; }
public void AddMethod(string name, VarType type) { methods.Add(new Method(name, type)); }
public var(double o) { _type = VarType.DOUBLE; _obj = o; }
public void AddLocalVar(string methodName, string varName, int length, VarType type) { methods.FirstOrDefault((x) => x.Name == methodName).AddLocalVar(varName, length, type); }