void Start() { codeList.TrashSlots.Add(trashSlot); // Create an instruction block for each opcode for (OpCategory opCategory = 0; opCategory < OpCategory._SIZE; ++opCategory) { GameObject header = Instantiate(headerPrefab, instructionList, false); TextMeshProUGUI headerTM = header.GetComponent <TextMeshProUGUI>(); RectTransform headerRT = header.GetComponent <RectTransform>(); headerTM.text = opCategory.ToString(); headerRT.sizeDelta = new Vector2(headerTM.preferredWidth, headerRT.sizeDelta.y); List <OpCode> opCodes = InstructionMaps.opCategoryOpCodesMap[opCategory]; foreach (OpCode opCode in opCodes) { CreateInstructionBlock(opCode); } } // Create local register tokens for (int regNum = 0; regNum < VirtualMachine.NUM_LOCAL_REGS; ++regNum) { Argument arg = new Argument(Argument.Type.REGISTER, regNum); CreateToken(arg, localRegTokenList); } // Create shared register tokens for (int regNum = VirtualMachine.NUM_LOCAL_REGS; regNum < VirtualMachine.NUM_SHARED_REGS + VirtualMachine.NUM_LOCAL_REGS; ++regNum) { Argument arg = new Argument(Argument.Type.REGISTER, regNum); CreateToken(arg, sharedRegTokenList); } }
static InstructionMaps() { for (OpCategory opCategory = 0; opCategory < OpCategory._SIZE; ++opCategory) { // Init opCategoryOpCodesMap opCategoryOpCodesMap[opCategory] = new List <OpCode>(); } for (OpCode opCode = 0; opCode < OpCode._SIZE; ++opCode) { // Init nameOpMap nameOpMap.Add(opCode.ToString(), opCode); // Init opCategoryOpCodesMap opCategoryOpCodesMap[opCodeOpCategoryMap[opCode]].Add(opCode); // Validate opArgSpecMap is filled out int numArgs = opArgNumMap[opCode]; Debug.Assert(opArgSpecMap[opCode].Length == numArgs); } // Validate sizes of maps Debug.Assert(opArgNumMap.Count == (int)OpCode._SIZE); Debug.Assert(opArgSpecMap.Count == (int)OpCode._SIZE); Debug.Assert(opCodeOpCategoryMap.Count == (int)OpCode._SIZE); Debug.Assert(opCategoryOpCodesMap.Count == (int)OpCategory._SIZE); }
void Start() { Globals.trashSlots.Add(trashSlot); // Create an instruction block for each opcode for (OpCategory opCategory = 0; opCategory < OpCategory._SIZE; ++opCategory) { GameObject header = Instantiate(headerPrefab, instructionList, false); header.GetComponent <TextMeshProUGUI>().text = opCategory.ToString(); List <OpCode> opCodes = InstructionMaps.opCategoryOpCodesMap[opCategory]; foreach (OpCode opCode in opCodes) { CreateInstructionBlock(opCode); } } for (int regNum = 0; regNum < VirtualMachine.NUM_REGS; ++regNum) { Argument arg = new Argument(Argument.Type.REGISTER, regNum); CreateToken(arg, regTokenList); } ResetBranchLabelList(); ResetConstLabelList(); Globals.program.OnBranchLabelChange += ResetBranchLabelList; Globals.program.OnConstLabelChange += ResetConstLabelList; }
// lineNumber == -1 signifies no line number public void Init(int lineNumber, Instruction instruction, Divider myDivider, CodeList codeList) { base.Init(myDivider, codeList); this.lineNumber = lineNumber; this.instruction = instruction; draggable.onDragSuccess = (Draggable.Slot slot) => { Insert(slot); // Reset frontend Destroy(gameObject); codeList.Program.BroadcastInstructionChange(); }; draggable.onDragTrash = (Draggable.Slot slot) => { if (lineNumber != -1) { Remove(); codeList.Program.BroadcastInstructionChange(); } Destroy(gameObject); }; // Configure text opCodeTM.text = instruction.opCode.ToString(); // Configure color OpCategory category = InstructionMaps.opCodeOpCategoryMap[instruction.opCode]; bg.color = opCategoryColorMap.map[category]; // Configure tips string buffer; InstructionMaps.opDescriptiveNameMap.TryGetValue(instruction.opCode, out buffer); GetComponent <DisplaysTips>().Init(buffer); // Create argument fields ArgumentSpec[] argSpecs = InstructionMaps.opArgSpecMap[instruction.opCode]; for (int argNum = 0; argNum < instruction.args.Length; ++argNum) { GameObject field; Argument arg = instruction.args[argNum]; if (argSpecs[argNum].regOnly || argSpecs[argNum].presets != null) { field = Instantiate(dropdownFieldPrefab, transform); field.GetComponent <DropdownField>().Init(argSpecs[argNum], arg, codeList); } else { field = Instantiate(slotFieldPrefab, transform); field.GetComponent <SlotField>().Init(arg, codeList); } field.GetComponent <DisplaysTips>().Init(argSpecs[argNum].name); } }
// lineNumber == -1 signifies no line number public void Init(int lineNumber, Instruction instruction, Divider myDivider) { base.Init(myDivider); this.lineNumber = lineNumber; this.instruction = instruction; draggable.onDragSuccess = (Draggable.Slot slot) => { Insert(slot); // Reset frontend Destroy(gameObject); Globals.program.BroadcastInstructionChange(); }; draggable.onDragTrash = (Draggable.Slot slot) => { if (lineNumber != -1) { Remove(); Globals.program.BroadcastInstructionChange(); } Destroy(gameObject); }; // Configure text opCodeTM.text = instruction.opCode.ToString(); // Configure color OpCategory category = InstructionMaps.opCodeOpCategoryMap[instruction.opCode]; bg.color = opCategoryColorMap.map[category]; // Create argument fields ArgumentSpec[] argSpecs = InstructionMaps.opArgSpecMap[instruction.opCode]; for (int argNum = 0; argNum < instruction.args.Length; ++argNum) { GameObject field; Argument arg = instruction.args[argNum]; if (argSpecs[argNum].regOnly || argSpecs[argNum].presets != null) { field = Instantiate(dropdownFieldPrefab, transform); field.GetComponent <DropdownField>().Init(argSpecs[argNum], arg); } else { field = Instantiate(slotFieldPrefab, transform); field.GetComponent <SlotField>().Init(arg); } // Add header // GameObject header = Instantiate(headerPrefab, field.transform); // header.GetComponent<TextMeshProUGUI>().text = argSpecs[argNum].name; } }
/* Returns the category of binary operation */ private OpCategory getCategory(BinaryOp.ArithOp op, bool overflow, bool unsigned) { OpCategory category = OpCategory.InvalidOp; if (!overflow) { if ((op == BinaryOp.ArithOp.ADD || op == BinaryOp.ArithOp.DIV || op == BinaryOp.ArithOp.MUL || op == BinaryOp.ArithOp.REM || op == BinaryOp.ArithOp.SUB) && !unsigned) { category = OpCategory.NumericOp; } else if (op == BinaryOp.ArithOp.CEQ && !unsigned || op == BinaryOp.ArithOp.CGT || op == BinaryOp.ArithOp.CLT) { category = OpCategory.ComparisonOp; } else if (op == BinaryOp.ArithOp.AND && !unsigned || op == BinaryOp.ArithOp.DIV && unsigned || op == BinaryOp.ArithOp.OR && !unsigned || op == BinaryOp.ArithOp.REM && unsigned || op == BinaryOp.ArithOp.XOR && !unsigned) { category = OpCategory.IntegerOp; } else if (op == BinaryOp.ArithOp.SHL && !unsigned || op == BinaryOp.ArithOp.SHR) { category = OpCategory.ShiftOp; } } else if (op == BinaryOp.ArithOp.ADD || op == BinaryOp.ArithOp.MUL || op == BinaryOp.ArithOp.SUB) { category = OpCategory.OverflowOp; } return(category); }
static InstructionMaps() { for (OpCategory opCategory = 0; opCategory < OpCategory._SIZE; ++opCategory) { // Init opCategoryOpCodesMap opCategoryOpCodesMap[opCategory] = new List <OpCode>(); } for (OpCode opCode = 0; opCode < OpCode._SIZE; ++opCode) { // Init nameOpMap nameOpMap.Add(opCode.ToString(), opCode); // Init opCategoryOpCodesMap opCategoryOpCodesMap[opCodeOpCategoryMap[opCode]].Add(opCode); } // Validate sizes of maps Debug.Assert(opDescriptiveNameMap.Count == (int)OpCode._SIZE); Debug.Assert(opArgSpecMap.Count == (int)OpCode._SIZE); Debug.Assert(opCodeOpCategoryMap.Count == (int)OpCode._SIZE); Debug.Assert(opCategoryOpCodesMap.Count == (int)OpCategory._SIZE); }
/// <summary> /// 根据ID获取手卫生依从性调查评分 数据分析表 /// </summary> /// <param name="iFilter"></param> /// <param name="HANDID"></param> public Tuple <List <HandHygieneGroupAnalysis>, List <HandHygieneDczs>, List <HandHygieneOpModel> > GetHandHygiAnalysisSourceList(CommonFilter iFilter, string HANDID) { string filter = "1=1"; filter += iFilter.GetQueryString(); Func <string, int> funcSort = v => { var sort = 0; switch (v) { case "护士": sort = 1; break; case "医技": sort = 2; break; case "医生": sort = 3; break; case "工人": sort = 4; break; } return(sort); }; List <BUS_HANDHYGIENE_SOURCE> handHygiSource = EntityOperate <BUS_HANDHYGIENE_SOURCE> .GetEntityList(filter + (string.IsNullOrWhiteSpace(HANDID) == true ? "" : " and HANDID='" + HANDID + "'")); var handHygieneGroupList = handHygiSource.GroupBy(p => p.ZY).Select(g => new HandHygieneGroupAnalysis { handhygiene_source = g, zy = g.Key, sort = funcSort(g.Key), currentSum = g.Count() }).OrderBy(g => g.sort).ToList(); //调查总数 #region var dczsSql = string.Format(@" select * from (select count(jcbrq) jcbrq ,zy from bus_handhygiene_source where jcbrq != '正确' and handid ={0} group by zy ) pivot ( sum(jcbrq) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) ) union all select * from (select count(JCBRH) JCBRH ,zy from bus_handhygiene_source where JCBRH != '正确' and handid ={0} group by zy ) pivot ( sum(JCBRH) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) ) union all select * from (select count(JCWJWPQ) JCWJWPQ ,zy from bus_handhygiene_source where JCWJWPQ != '正确' and handid ={0} group by zy ) pivot ( sum(JCWJWPQ) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) ) union all select * from (select count(JCBRHJH) JCBRHJH ,zy from bus_handhygiene_source where JCBRHJH != '正确' and handid = {0} group by zy ) pivot ( sum(JCBRHJH) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) ) union all select * from (select count(JCWWH) JCWWH ,zy from bus_handhygiene_source where JCWWH != '正确' and handid = {0} group by zy ) pivot ( sum(JCWWH) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) ) union all select * from (select count(PCQ) PCQ ,zy from bus_handhygiene_source where PCQ != '正确' and handid = {0} group by zy ) pivot ( sum(PCQ) for zy in ('医生' ys,'护士' hs,'医技' yj,'工人' gr) )", HANDID); #endregion var dczsListSource = EntityOperate <HandHygieneDczs> .GetEntityListBySQL(dczsSql); var ysOpCount = dczsListSource.Sum(p => p.ys); //医生操作总数 var hsOpCount = dczsListSource.Sum(p => p.hs); //护士操作总数 var yjOpCount = dczsListSource.Sum(p => p.yj); //医技操作总数 var grOpCount = dczsListSource.Sum(p => p.gr); //工人操作总数 dczsListSource.Add(new HandHygieneDczs { ys = ysOpCount, hs = hsOpCount, yj = yjOpCount, gr = grOpCount }); // List<HandHygieneDczs> dczsList = new List<HandHygieneDczs>(); // string[] itemArr = { "接触病人前", "接触病人后", "无菌操作前", "接触病人周围环境后", "接触污物(摘手套)后", "配餐前", "总数" }; var opModelList = new List <HandHygieneOpModel>(); string[] zyArr = { "医生", "护士", "医技", "工人" }; foreach (var zyItem in zyArr) { //获取操作列表sql var getOpList = string.Format(@"select sum(case jcbrq when '消' then 1 else 0 end) x,sum(case jcbrq when '洗' then 1 else 0 end) xx, sum(case jcbrq when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}' and handid = {1} union all --医生接触病人前 select sum(case JCBRH when '消' then 1 else 0 end) x,sum(case JCBRH when '洗' then 1 else 0 end) xx, sum(case JCBRH when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}' and handid = {1} union all --接触病人后 select sum(case JCWJWPQ when '消' then 1 else 0 end) x,sum(case JCWJWPQ when '洗' then 1 else 0 end) xx, sum(case JCWJWPQ when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}' and handid = {1} union all --接触无菌物品前 select sum(case JCBRHJH when '消' then 1 else 0 end) x,sum(case JCBRHJH when '洗' then 1 else 0 end) xx, sum(case JCBRHJH when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}' and handid = {1} union all --接触病人周围环境后 select sum(case JCWWH when '消' then 1 else 0 end) x,sum(case JCWWH when '洗' then 1 else 0 end) xx, sum(case JCWWH when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}' and handid = {1} union all --接触污物(摘手套)后 select sum(case PCQ when '消' then 1 else 0 end) x,sum(case PCQ when '洗' then 1 else 0 end) xx, sum(case PCQ when '未' then 1 else 0 end) w from bus_handhygiene_source where zy = '{0}'and handid = {1} --配餐前", zyItem, HANDID); HandHygieneOpModel opModel = new HandHygieneOpModel(); var opList = EntityOperate <OpCategory> .GetEntityListBySQL(getOpList); opModel.zyName = zyItem; opModel.opList = opList; var opCategoryModel = new OpCategory { x = opList.Select(p => p.x).Sum(), xx = opList.Select(p => p.xx).Sum(), w = opList.Select(p => p.w).Sum() }; opModel.opList.Add(opCategoryModel); opModelList.Add(opModel); } return(new Tuple <List <HandHygieneGroupAnalysis>, List <HandHygieneDczs>, List <HandHygieneOpModel> >(handHygieneGroupList, dczsListSource, opModelList)); }
/* Performs binary operation on two values on top of the stack * (corresponds to CILPE.CFG.BinaryOp class) */ public void Perform_BinaryOp(BinaryOp.ArithOp op, bool overflow, bool unsigned, out Exception exc) { exc = null; /* Determining category of binary operation */ OpCategory category = getCategory(op, overflow, unsigned); if (category == OpCategory.InvalidOp) { throw new InvalidBinaryOpException(); } /* Getting operands from stack */ Value val1, val2; val2 = Pop(); val1 = Pop(); /* Performing binary operation */ object res = null; if (val1 is StructValue && val2 is StructValue) { StructValue.TypeIndex typeA = (val1 as StructValue).getTypeIndex(), typeB = (val2 as StructValue).getTypeIndex(); if (typeA == StructValue.TypeIndex.INVALID || typeB == StructValue.TypeIndex.INVALID) { throw new InvalidOperandException(); } ValueType a = (val1 as StructValue).Obj, b = (val2 as StructValue).Obj; int operandsKind = 0; bool success = true; if (category == OpCategory.ShiftOp) /* shl, shr, shr_un */ { if (typeA == StructValue.TypeIndex.FLOAT64 || typeB == StructValue.TypeIndex.FLOAT64 || typeB == StructValue.TypeIndex.INT64) { throw new InvalidOperandException(); } operandsKind = ((typeB == StructValue.TypeIndex.INT32) ? 0 : 3) + (int)typeA; DataModelUtils.ShiftOp((int)op, unsigned, a, b, operandsKind, out res); } else { if (typeA == typeB) { operandsKind = (int)typeA; } else if (typeA == StructValue.TypeIndex.INT32 && typeB == StructValue.TypeIndex.NATIVEINT) { operandsKind = 4; } else if (typeA == StructValue.TypeIndex.NATIVEINT && typeB == StructValue.TypeIndex.INT32) { operandsKind = 5; } else { throw new InvalidOperandException(); } switch (category) { case OpCategory.NumericOp: /* add, div, mul, rem, sub */ success = DataModelUtils.NumericOp((int)op, a, b, operandsKind, out res); break; case OpCategory.ComparisonOp: /* ceq, cgt, cgt.un, clt, clt.un */ DataModelUtils.ComparisonOp((int)op, unsigned, a, b, operandsKind, out res); break; case OpCategory.IntegerOp: /* and, div.un, or, rem.un, xor */ case OpCategory.OverflowOp: /* add.ovf, add.ovf.un, mul.ovf, mul.ovf.un, sub.ovf, sub.ovf.un */ if (operandsKind == 3) { throw new InvalidOperandException(); } success = DataModelUtils.IntOvfOp((int)op, unsigned, a, b, operandsKind, out res); break; } } if (!success) { exc = res as Exception; res = null; } } else if (op == BinaryOp.ArithOp.CEQ) { if ((val1 is NullValue || val1 is ObjectReferenceValue) && (val2 is NullValue || val2 is ObjectReferenceValue) || (val1 is NullValue || val1 is PointerValue) && (val2 is NullValue || val2 is PointerValue)) { res = Equals(val1, val2) ? (Int32)1 : (Int32)0; } else { throw new InvalidOperandException(); } } else if (op == BinaryOp.ArithOp.CGT) { if (val1 is ObjectReferenceValue && val2 is NullValue && unsigned) { res = (Int32)1; } else if (val1 is NullValue && val2 is NullValue) { res = (Int32)0; } else if (val1 is PointerValue && val2 is NullValue) { res = (Int32)1; } else { throw new InvalidOperandException(); } } else if (op == BinaryOp.ArithOp.CLT) { if (val1 is NullValue && val2 is ObjectReferenceValue && unsigned) { res = (Int32)1; } else if (val1 is NullValue && val2 is NullValue) { res = (Int32)0; } else if (val1 is NullValue && val2 is PointerValue) { res = (Int32)1; } else { throw new InvalidOperandException(); } } else { throw new InvalidOperandException(); } if (res != null) { push(new StructValue(res as ValueType)); } }