device component with event to update state
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
@@ -79,14 +79,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.as_ref().borrow().ip)
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "instructionCount")]
|
||||
@@ -95,14 +94,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.as_ref().borrow().ic)
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "stack")]
|
||||
@@ -111,14 +109,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| Stack(ic.as_ref().borrow().stack))
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "registers")]
|
||||
@@ -127,14 +124,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| Registers(ic.as_ref().borrow().registers))
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "aliases", skip_typescript)]
|
||||
@@ -145,14 +141,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.as_ref().borrow().aliases.clone())
|
||||
})
|
||||
.flatten(),
|
||||
}),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@@ -165,14 +160,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.as_ref().borrow().defines.clone())
|
||||
})
|
||||
.flatten(),
|
||||
}),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@@ -185,14 +179,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.as_ref().borrow().pins)
|
||||
})
|
||||
.flatten(),
|
||||
}),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@@ -203,18 +196,17 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.borrow().state.clone())
|
||||
})
|
||||
.flatten()
|
||||
.map(|state| state.to_string())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "program")]
|
||||
#[wasm_bindgen(getter, js_name = "program", skip_typescript)]
|
||||
pub fn ic_program(&self) -> JsValue {
|
||||
serde_wasm_bindgen::to_value(
|
||||
&self
|
||||
@@ -222,14 +214,13 @@ impl DeviceRef {
|
||||
.borrow()
|
||||
.ic
|
||||
.as_ref()
|
||||
.map(|ic| {
|
||||
.and_then(|ic| {
|
||||
self.vm
|
||||
.borrow()
|
||||
.ics
|
||||
.get(ic)
|
||||
.map(|ic| ic.borrow().program.clone())
|
||||
})
|
||||
.flatten(),
|
||||
}),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@@ -306,6 +297,7 @@ impl DeviceRef {
|
||||
pub struct VM {
|
||||
vm: Rc<RefCell<ic10emu::VM>>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl VM {
|
||||
#[wasm_bindgen(constructor)]
|
||||
@@ -372,6 +364,18 @@ impl VM {
|
||||
pub fn ics(&self) -> Vec<u16> {
|
||||
self.vm.borrow().ics.keys().copied().collect_vec()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "lastOperationModified")]
|
||||
pub fn last_operation_modified(&self) -> Vec<u16> {
|
||||
self.vm.borrow().last_operation_modified()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Default for VM {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
||||
@@ -1,36 +1,120 @@
|
||||
type FieldType = 'Read' | 'Write' | 'ReadWrite';
|
||||
export type FieldType = "Read" | "Write" | "ReadWrite";
|
||||
|
||||
interface LogicField {
|
||||
field_type: FieldType,
|
||||
value: number,
|
||||
export interface LogicField {
|
||||
field_type: FieldType;
|
||||
value: number;
|
||||
}
|
||||
type Fields = Map<string, LogicField>;
|
||||
export type Fields = Map<string, LogicField>;
|
||||
|
||||
type SlotType = 'AccessCard' | 'Appliance' | 'Back' | 'Battery' | 'Blocked' | 'Bottle' | 'Cartridge' | 'Circuitboard' | 'CreditCard' | 'DataDisk' | 'DrillHead' | 'Egg' | 'Entity' | 'Flare' | 'GasCanister' | 'GasFilter' | 'Helmet' | 'Ingot' | 'LiquidBottle' | 'LiquidCanister' | 'Magazine' | 'Ore' | 'Organ' | 'Plant' | 'ProgramableChip' | 'ScanningHead' | 'SensorProcessingUnit' | 'SoundCartridge' | 'Suit' | 'Tool' | 'Torpedo' | 'None';
|
||||
|
||||
interface Slot {
|
||||
typ: SlotType,
|
||||
fields: Fields,
|
||||
export type SlotType =
|
||||
| "AccessCard"
|
||||
| "Appliance"
|
||||
| "Back"
|
||||
| "Battery"
|
||||
| "Blocked"
|
||||
| "Bottle"
|
||||
| "Cartridge"
|
||||
| "Circuitboard"
|
||||
| "CreditCard"
|
||||
| "DataDisk"
|
||||
| "DrillHead"
|
||||
| "Egg"
|
||||
| "Entity"
|
||||
| "Flare"
|
||||
| "GasCanister"
|
||||
| "GasFilter"
|
||||
| "Helmet"
|
||||
| "Ingot"
|
||||
| "LiquidBottle"
|
||||
| "LiquidCanister"
|
||||
| "Magazine"
|
||||
| "Ore"
|
||||
| "Organ"
|
||||
| "Plant"
|
||||
| "ProgramableChip"
|
||||
| "ScanningHead"
|
||||
| "SensorProcessingUnit"
|
||||
| "SoundCartridge"
|
||||
| "Suit"
|
||||
| "Tool"
|
||||
| "Torpedo"
|
||||
| "None";
|
||||
|
||||
export interface Slot {
|
||||
typ: SlotType;
|
||||
fields: Fields;
|
||||
}
|
||||
|
||||
type Reagents = Map<string, Map<number, number>>;
|
||||
export type Reagents = Map<string, Map<number, number>>;
|
||||
|
||||
type Connection = { CableNetwork: number } | 'Other' ;
|
||||
export type Connection = { CableNetwork: number } | "Other";
|
||||
|
||||
type Alias = { RegisterSpec: {indirection: number, target: number} } | { DeviceSpec: { device: "Db" | { Numbered: number } | { Indirect: { indirection: number, target: number } } }, connection: number | undefined };
|
||||
export type Alias =
|
||||
| { RegisterSpec: { indirection: number; target: number } }
|
||||
| {
|
||||
DeviceSpec: {
|
||||
device:
|
||||
| "Db"
|
||||
| { Numbered: number }
|
||||
| { Indirect: { indirection: number; target: number } };
|
||||
};
|
||||
connection: number | undefined;
|
||||
};
|
||||
|
||||
type Aliases = Map<string, Alias>;
|
||||
export type Aliases = Map<string, Alias>;
|
||||
|
||||
type Defines = Map<string, number>;
|
||||
export type Defines = Map<string, number>;
|
||||
|
||||
type Pins = (number | undefined)[]
|
||||
export type Pins = (number | undefined)[];
|
||||
|
||||
export type Operand =
|
||||
| { RegisterSpec: { indirection: number; target: number } }
|
||||
| {
|
||||
DeviceSpec: {
|
||||
device:
|
||||
| "Db"
|
||||
| { Numbered: number }
|
||||
| { Indirect: { indirection: number; target: number } };
|
||||
};
|
||||
connection: number | undefined;
|
||||
}
|
||||
| {
|
||||
Number:
|
||||
| { Float: number }
|
||||
| { Binary: number }
|
||||
| { Hexadecimal: number }
|
||||
| { Constant: number }
|
||||
| { String: string }
|
||||
| { Enum: number };
|
||||
}
|
||||
| { LogicType: string }
|
||||
| { SlotLogicType: string }
|
||||
| { BatchMode: string }
|
||||
| { ReagentMode: string }
|
||||
| { Identifier: { name: string } };
|
||||
|
||||
export interface Instruction {
|
||||
instruction: string;
|
||||
operands: Operand[];
|
||||
}
|
||||
|
||||
export type ICError = {
|
||||
ParseError: { line: number; start: number; end: number; msg: string };
|
||||
};
|
||||
|
||||
export interface Program {
|
||||
instructions: Instruction[];
|
||||
errors: ICError[];
|
||||
labels: Map<string, number>;
|
||||
}
|
||||
|
||||
export interface DeviceRef {
|
||||
readonly fields: Fields;
|
||||
readonly slots: Slot[];
|
||||
readonly reagents: Reagents;
|
||||
readonly connections: Connection[];
|
||||
readonly aliases?: Aliases | undefined;
|
||||
readonly defines?: Defines | undefined;
|
||||
readonly pins?: Pins;
|
||||
readonly fields: Fields;
|
||||
readonly slots: Slot[];
|
||||
readonly reagents: Reagents;
|
||||
readonly connections: Connection[];
|
||||
readonly aliases?: Aliases | undefined;
|
||||
readonly defines?: Defines | undefined;
|
||||
readonly pins?: Pins;
|
||||
readonly program?: Program;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user