Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryex committed Apr 30, 2024
2 parents 0391c55 + e39a317 commit 4c53dcc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
<!-- insertion marker -->
## [v0.2.3] - 2024-04-30

<small>[Compare with v0.2.2](https://github.com/Ryex/ic10emu/compare/v0.2.2...v0.2.3)</small>

Small bugfix release

### Bug Fixes

- fix bitwise operaitons ([ed8cdb](https://github.com/Ryex/ic10emu/commit/ed8cdb575c19cf9c042b4c60cd8c73b1859ab3fe) by Emil Gardström).
- fix `mod` instruction ([a6af24](https://github.com/Ryex/ic10emu/commit/a6af244080d05a7cac31e419a2b8058325c8c99b) by Emil Gardström).
## [v0.2.2] - 2024-04-28

<small>[Compare with v0.2.1](https://github.com/Ryex/ic10emu/compare/v0.2.1...v0.2.2)</small>

### Features

- better slot UI ([c87d3f8](https://github.com/Ryex/ic10emu/commit/c87d3f8bd88a64ad421e5999d7a040de205d4e03) by Rachel Powers).
- much better slot occupant card ([1790715](https://github.com/Ryex/ic10emu/commit/17907151b34bb6efdbd4370cd449e21dcc8eed54) by Rachel Powers).

### Bug Fixes

- device id change UI event chain fixed; changing the Active IC's ID no longer breaks the UI ([4ac823a](https://github.com/Ryex/ic10emu/commit/4ac823a1bc9d3b572de713ac59a5aabd5f0ff599) by Rachel Powers).

### Performance Improvements

- performance improvments ([cfa240c](https://github.com/Ryex/ic10emu/commit/cfa240c5794817ce4221cdac8be2e96e320edf5c) by Rachel Powers). Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
- vastly improve load speed ([6cc2189](https://github.com/Ryex/ic10emu/commit/6cc21899214296f51e93b70a3f9f67c39ba243d3) by Rachel Powers). Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
- improve slot UI + device search speedup ([eb4463c](https://github.com/Ryex/ic10emu/commit/eb4463c8ab318e8093e93c1ecaac139cf6dbb74d) by Rachel Powers). Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>

## [v0.2.1] - 2024-04-22

<small>[Compare with v0.2.0](https://github.com/Ryex/ic10emu/compare/v0.2.0...v0.2.1)</small>

## [v0.2.0] - 2024-04-21

<small>[Compare with first commit](https://github.com/Ryex/ic10emu/compare/de8503b74501d5f51eef24e55e7c0fa7b43a5e28...v0.2.0)</small>

### Bug Fixes

- slotType serial + feaures ([b60cc44](https://github.com/Ryex/ic10emu/commit/b60cc4458099043725a776aa5bc0c9ce748b56d8) by Rachel Powers).


## [0.2.2] - 2024-04-28

Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["ic10lsp_wasm", "ic10emu_wasm", "ic10emu", "xtask"]
resolver = "2"

[workspace.package]
version = "0.2.2"
version = "0.2.3"
edition = "2021"

[profile.release]
Expand Down
11 changes: 5 additions & 6 deletions ic10emu/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl Operand {
index: u32,
) -> Result<i64, interpreter::ICError> {
match self {
Self::Number(num) => Ok(num.value_i64()),
Self::Number(num) => Ok(num.value_i64(signed)),
_ => {
let val = self.as_value(ic, inst, index)?;
if val < -9.223_372_036_854_776E18 {
Expand All @@ -445,15 +445,15 @@ impl Operand {
}
}
}

pub fn as_value_i32(
&self,
ic: &interpreter::IC,
signed: bool,
inst: InstructionOp,
index: u32,
) -> Result<i32, interpreter::ICError> {
match self {
Self::Number(num) => Ok(num.value_i64() as i32),
Self::Number(num) => Ok(num.value_i64(signed) as i32),
_ => {
let val = self.as_value(ic, inst, index)?;
if val < -2147483648.0 {
Expand Down Expand Up @@ -1079,9 +1079,9 @@ impl Number {
Number::String(s) => const_crc32::crc32(s.as_bytes()) as i32 as f64,
}
}
pub fn value_i64(&self) -> i64 {
pub fn value_i64(&self, signed: bool) -> i64 {
match self {
Number::Enum(val) | Number::Float(val) | Number::Constant(val) => *val as i64,
Number::Enum(val) | Number::Float(val) | Number::Constant(val) => interpreter::f64_to_i64(*val, signed),
Number::Binary(val) | Number::Hexadecimal(val) => *val,
Number::String(s) => const_crc32::crc32(s.as_bytes()) as i32 as i64,
}
Expand Down Expand Up @@ -1471,7 +1471,6 @@ mod tests {
test_roundtrip("%1001");
}


#[test]
fn all_generated_enums_have_value() {
use strum::IntoEnumIterator;
Expand Down
47 changes: 28 additions & 19 deletions ic10emu/src/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use core::f64;
use serde::{Deserialize, Serialize};
use std::{cell::{Cell, RefCell}, ops::Deref, string::ToString};
use std::{
cell::{Cell, RefCell},
ops::Deref,
string::ToString,
};
use std::{
collections::{BTreeMap, HashSet},
error::Error,
Expand All @@ -13,7 +17,9 @@ use itertools::Itertools;
use time::format_description;

use crate::{
device::SlotType, grammar::{self, LogicType, ParseError, SlotLogicType}, vm::VM
device::SlotType,
grammar::{self, LogicType, ParseError, SlotLogicType},
vm::VM,
};

use serde_with::serde_as;
Expand Down Expand Up @@ -434,12 +440,7 @@ impl IC {
}

/// sets a register thorough, recursing through provided indirection, returns value previously
pub fn set_register(
&self,
indirection: u32,
target: u32,
val: f64,
) -> Result<f64, ICError> {
pub fn set_register(&self, indirection: u32, target: u32, val: f64) -> Result<f64, ICError> {
let t = self.get_real_target(indirection, target)?;
let mut registers = self.registers.borrow_mut();
let old_val = registers
Expand Down Expand Up @@ -525,7 +526,11 @@ impl IC {
if let Some(device) = vm.devices.get(&self.device) {
let mut device_ref = device.borrow_mut();
let _ = device_ref.set_field(LogicType::LineNumber, self.ip.get() as f64, vm, true);
if let Some(slot) = device_ref.slots.iter_mut().find(|slot| slot.typ == SlotType::ProgrammableChip) {
if let Some(slot) = device_ref
.slots
.iter_mut()
.find(|slot| slot.typ == SlotType::ProgrammableChip)
{
let _ = slot.set_field(SlotLogicType::LineNumber, self.ip.get() as f64, true);
}
}
Expand Down Expand Up @@ -1745,7 +1750,11 @@ impl IC {
} = reg.as_register(this, inst, 1)?;
let a = a.as_value(this, inst, 2)?;
let b = b.as_value(this, inst, 1)?;
this.set_register(indirection, target, ((a % b) + b) % b)?;
let mut m = a % b;
if m < 0.0 {
m += b;
}
this.set_register(indirection, target, m)?;
Ok(())
}
oprs => Err(ICError::mismatch_operands(oprs.len(), 3)),
Expand Down Expand Up @@ -1980,7 +1989,7 @@ impl IC {
target,
} = reg.as_register(this, inst, 1)?;
let a = a.as_value_i64(this, true, inst, 2)?;
let b = b.as_value_i32(this, inst, 3)?;
let b = b.as_value_i32(this, true, inst, 3)?;
this.set_register(indirection, target, i64_to_f64(a << b))?;
Ok(())
}
Expand All @@ -1993,7 +2002,7 @@ impl IC {
target,
} = reg.as_register(this, inst, 1)?;
let a = a.as_value_i64(this, false, inst, 2)?;
let b = b.as_value_i32(this, inst, 3)?;
let b = b.as_value_i32(this, true, inst, 3)?;
this.set_register(indirection, target, i64_to_f64((a as u64 >> b) as i64))?;
Ok(())
}
Expand All @@ -2006,7 +2015,7 @@ impl IC {
target,
} = reg.as_register(this, inst, 1)?;
let a = a.as_value_i64(this, true, inst, 2)?;
let b = b.as_value_i32(this, inst, 3)?;
let b = b.as_value_i32(this, true, inst, 3)?;
this.set_register(indirection, target, i64_to_f64(a >> b))?;
Ok(())
}
Expand Down Expand Up @@ -2599,18 +2608,18 @@ impl LogicTypeExt for grammar::LogicType {
}

pub fn f64_to_i64(f: f64, signed: bool) -> i64 {
let mut num: i64 = (f % 9007199254740992.0) as i64;
let mut num: i64 = (f % (1i64 << 53) as f64) as i64;
if !signed {
num &= 18014398509481983_i64;
num &= (1i64 << 54) - 1;
}
num
}

pub fn i64_to_f64(i: i64) -> f64 {
let flag: bool = (i & 9007199254740992_i64) != 0;
let mut i = i & 9007199254740991_i64;
const MASK: i64 = 1 << 53;
let flag: bool = (i & MASK) != 0;
let mut i = i & (MASK - 1);
if flag {
i &= -9007199254740992_i64;
i |= -MASK;
}
i as f64
}
Expand Down
2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ic10emu",
"version": "0.2.2",
"version": "0.2.3",
"description": "an IC10 emulator for IC10 mips from Stationeers",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4c53dcc

Please sign in to comment.