public ActionResult DeleteConfirmed(int id) { WItem item = db.WItems.Find(id); db.WItems.Remove(item); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Item/Create public ActionResult Create() { var item = new WItem(); var categories = new List <Category>(); PopulateCategories(item); return(View()); }
public ActionResult Edit([Bind(Include = "Id,Name,Quantity,Price,DiscountPercentage")] WItem item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
// Pop from the current execution stack in use public WItem pop_exec() { // We then get the stack and pop the top value WItem item = exec_stack.pop(); if (item != null) { return(item); } return(null); }
public ActionResult Create([Bind(Include = "Id,Name,Quantity,Price,DiscountPercentage")] WItem item) { if (ModelState.IsValid) { db.WItems.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
// GET: Item/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WItem item = db.WItems.Find(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
private void func_return() { this.state.func_depth--; // First get the return value, by poping it from the exec stack WItem return_value = this.exec_stack.pop(); // Then restore the state of the core FuncFrame previous_frame = this.func_stack.pop(); this.pc = previous_frame.pc; this.locals = previous_frame.locals; this.exec_stack = previous_frame.exec_stack; this.bytecode = previous_frame.bytecode; this.state.opcode_count = this.bytecode.Length; // Then push the returned value to the exec stack this.exec_stack.push(return_value); }
private void PopulateCategories(WItem item) { var allCategories = db.Categories; var itemCategories = new HashSet <int>(item.Categories.Select(c => c.Id)); var categoryData = new List <AssignedCategories>(); foreach (var cat in allCategories) { categoryData.Add(new AssignedCategories { CategoryID = cat.Id, Name = cat.Name, Assigned = itemCategories.Contains(cat.Id) }); } ViewBag.Categories = categoryData; }
public static WItem Create(string message, LogLevel level) => WItem.CreateItem(message, level);
// We expect a WavyItem to be a WavyObject private dynamic expect_wobject(WItem item) { ASSERT_ERR(!(item is WObject), CoreErrorType.UNEXPECTED_TYPE, "Expected WavyObject, but got: " + item.GetType()); return(item); }
// We expect a WavyItem to be a WavyFunction private dynamic expect_wfunc(WItem item) { ASSERT_ERR(!(item is WFunction), CoreErrorType.UNEXPECTED_TYPE, "Expected WavyFunction, but got: " + item.GetType()); return(item); }
public void assign_item(Core core, int id, WItem item) { this.m_bank.set(id, item); }
// Pop from the current execution stack in use public void push_exec(WItem item) { exec_stack.push(item); }
public void add(int id, WItem item) { this.bank_dict.Add(id, item); }
public void set(int id, WItem item) { this.bank_dict[id] = item; }
public static WItem Create(string message, LogLevel level, string group) => WItem.CreateItem(message, level, group);
public static WItem Create(string startMessage, string endMessage, LogLevel level, string group) => WItem.CreateItem(startMessage, endMessage, level, group);
// We expect a WavyItem to be an int private dynamic expect_int(WItem item) { ASSERT_ERR(item is Wint, CoreErrorType.UNEXPECTED_TYPE, "Expected int, but got: " + item.GetType()); return((Wint)item); }
// Main fde cycle public void evaluate_sequence() { // Initialise the state of the multi_core_state this.state.multi_core_state = MultiCoreState.RUNNING; // Check we have not reached the end while (!end()) { // Only execute if the core has not been suspended if (this.state.multi_core_state != MultiCoreState.SUSPENDED) { Int32 op = get_next(); #if CORE_INSTR_DEBUG Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("op: " + (Opcode)op); Console.ForegroundColor = ConsoleColor.Yellow; #endif // Surround the execute phase in a try catch, this is so the vm can return safely to the error handling // without breaking other vm components try { switch ((Opcode)op) { case Opcode.PRINT: { Console.ForegroundColor = ConsoleColor.Green; #if VM_MULTI_CORE Console.WriteLine("{core " + this.state.id + "} " + peek_exec()); #else Console.WriteLine(peek_exec()); #endif Console.ForegroundColor = ConsoleColor.Yellow; goto_next(); break; } case Opcode.END: { // Return an END state this.state.currently_interpreting = false; break; } case Opcode.NOP: { goto_next(); break; } case Opcode.POP_EXEC: { pop_exec(); goto_next(); break; } case Opcode.LD_CONST: { Int32 id = get_arg(); push_exec(this.vm.bank_manager.request_c_item(this, id)); this.vm.bank_manager.release_c_item(this, id); goto_next(); break; } case Opcode.LD_VAR: { Int32 id = get_arg(); push_exec(this.vm.bank_manager.request_m_item(this, id)); this.vm.bank_manager.release_m_item(this, id); goto_next(); break; } case Opcode.LD_LOC: { // Check if we are actually in a function ASSERT_ERR(this.state.func_depth > 0, CoreErrorType.INVALID_LOCAL, "Cannot load local from non-function state!"); Int32 index = get_arg(); // Check if we have a valid local index ASSERT_ERR(index > this.locals.Length - 1, CoreErrorType.INVALID_LOCAL, "Local index is larger than locals size!"); push_exec(this.locals[index]); goto_next(); break; } case Opcode.BANK_VAR: { Int32 id = get_arg(); this.vm.bank_manager.request_m_item(this, id); this.vm.bank_manager.assign_item(this, id, pop_exec()); this.vm.bank_manager.request_m_item(this, id); goto_next(); break; } case Opcode.BANK_ASSIGN: { goto_next(); break; } case Opcode.LOCAL_ASSIGN: { goto_next(); break; } case Opcode.MAKE_CLASS: { break; } case Opcode.MAKE_FUNC: { break; } case Opcode.NEW: { break; } case Opcode.INVOKE_FUNC: { WFunction func = expect_wfunc(pop_exec()); #if CORE_TRACE_DEBUG func_call_trace(func); #else func_call(func); #endif break; } case Opcode.RETURN: { func_return(); goto_next(); break; } case Opcode.GOTO: { this.pc += get_arg(); break; } case Opcode.IF_ZERO: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) == 0) { goto_next(); break; } this.pc += arg; break; } case Opcode.IF_NZERO: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) != 0) { goto_next(); break; } this.pc += arg; break; } case Opcode.IF_GRT: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) > expect_numeric(pop_exec())) { goto_next(); break; } this.pc += arg; break; } case Opcode.IF_GRTE: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) >= expect_numeric(pop_exec())) { goto_next(); break; } this.pc += arg; break; } case Opcode.IF_LT: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) < expect_numeric(pop_exec())) { goto_next(); break; } this.pc += arg; break; } case Opcode.IF_LTE: { Int32 arg = get_arg(); if (expect_numeric(pop_exec()) <= expect_numeric(pop_exec())) { goto_next(); break; } this.pc += arg; break; } case Opcode.INCREMENT: { WItem num = expect_numeric(peek_exec()); num.value = num.value + 1; goto_next(); break; } case Opcode.DECREMENT: { WItem num = expect_numeric(peek_exec()); num.value = num.value - 1; goto_next(); break; } case Opcode.PSH_ZERO: { push_exec((Wint)0); goto_next(); break; } case Opcode.PSH_NULL: { push_exec((Wnull)null); goto_next(); break; } default: { // We have an invalid opcode push_err(CoreErrorType.INVALID_OP, "op: " + op); break; } } // Program counter is out of range ASSERT_ERR(pc <0 || pc> MAX_PC, CoreErrorType.INVALID_PC_RANGE); } catch (CoreErrException e) { if (e.err.is_fatal()) { this.vm.core_manager.isolate(this.state.id); } this.state.err_handler.say_latest(); break; } } } close(); }
public static WItem Create(string message) => WItem.CreateItem(message);
public static WItem Create(LogLevel level) => WItem.CreateItem(level);
public static WItem Create() => WItem.CreateItem();
public static WItem Create(string startMessage, string endMessage) => WItem.CreateItem(startMessage, endMessage);
// We expect a WavyItem to be a numeric private dynamic expect_numeric(WItem item) { ASSERT_ERR(!(item is Wint) && !(item is Wdouble), CoreErrorType.UNEXPECTED_TYPE, "Expected numeric, but got: " + item.GetType()); return(item); }