Skip to content

Commit

Permalink
core: use new Subcore/Supercore mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Mar 4, 2025
1 parent 54e5f8b commit 81907ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

14 changes: 9 additions & 5 deletions src/isa/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use core::fmt::{self, Debug, Formatter};

use aluvm::alu::{CoreExt, NoExt, Register};
use aluvm::alu::{CoreExt, NoExt, Register, Supercore};
use aluvm::{GfaCore, RegE};
use amplify::num::u256;

Expand Down Expand Up @@ -111,10 +111,14 @@ impl CoreExt for UsonicCore {
}
}

impl From<UsonicCore> for GfaCore {
fn from(core: UsonicCore) -> Self { core.gfa }
impl Supercore<GfaCore> for UsonicCore {
fn subcore(&self) -> GfaCore { self.gfa }

fn merge_subcore(&mut self, subcore: GfaCore) { self.gfa = subcore; }
}

impl From<UsonicCore> for NoExt {
fn from(_: UsonicCore) -> Self { NoExt }
impl Supercore<NoExt> for UsonicCore {
fn subcore(&self) -> NoExt { NoExt }

fn merge_subcore(&mut self, _subcore: NoExt) {}
}
14 changes: 7 additions & 7 deletions src/isa/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use std::collections::BTreeSet;

use aluvm::alu::regs::Status;
use aluvm::alu::{Core, CoreExt, ExecStep, Site, SiteId};
use aluvm::alu::{Core, CoreExt, ExecStep, Site, SiteId, Supercore};
use aluvm::isa::Instruction;
use aluvm::RegE;

Expand Down Expand Up @@ -152,22 +152,22 @@ impl<Id: SiteId> Instruction<Id> for Instr<Id> {
) -> ExecStep<Site<Id>> {
match self {
Instr::Ctrl(instr) => {
let mut subcore = Core::from(core.clone());
let mut subcore = core.subcore();
let step = instr.exec(site, &mut subcore, &mut ());
*core = subcore.extend(core.cx.clone());
core.merge_subcore(subcore);
step
}
Instr::Gfa(instr) => {
let mut subcore = Core::from(core.clone());
let mut subcore = core.subcore();
let step = instr.exec(site, &mut subcore, &mut ());
*core = subcore.extend(core.cx.clone());
core.merge_subcore(subcore);
step
}
Instr::Usonic(instr) => Instruction::<Id>::exec(instr, site, core, context),
Instr::Reserved(instr) => {
let mut subcore = Core::from(core.clone());
let mut subcore = core.subcore();
let step = instr.exec(site, &mut subcore, &mut ());
*core = subcore.extend(core.cx.clone());
core.merge_subcore(subcore);
step
}
}
Expand Down

0 comments on commit 81907ba

Please # to comment.