Skip to content

Commit cd3ec2c

Browse files
committed
Add hook for implementing custom instruction behaviour
1 parent 0a44b19 commit cd3ec2c

File tree

8 files changed

+234
-110
lines changed

8 files changed

+234
-110
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ required-features = ["mlogv32"]
1818

1919
[dependencies]
2020
binrw = { version = "0.15.0", default-features = false, features = ["verbose-backtrace"] }
21+
derivative = { version = "2.2.0", features = ["use_core"] }
2122
enum_dispatch = "0.3.13"
2223
hashbrown = "0.15.5"
2324
indexmap = { version = "2.10.0", default-features = false }

src/logic/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn parse_and_serialize_ast(
4444
privileged: false,
4545
code: ast.clone().into_boxed_slice(),
4646
links: &[],
47+
instruction_hook: None,
4748
},
4849
&builder,
4950
));

src/logic/vm/buildings.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use crate::types::{
1313
content::{self, Block},
1414
};
1515
#[cfg(feature = "std")]
16-
use crate::{
17-
logic::LogicParser,
18-
types::{ProcessorConfig, schematics::SchematicTile},
19-
};
16+
use crate::types::{ProcessorConfig, schematics::SchematicTile};
2017

2118
pub const MICRO_PROCESSOR: &str = "micro-processor";
2219
pub const LOGIC_PROCESSOR: &str = "logic-processor";
@@ -75,7 +72,7 @@ impl Building {
7572
return Self::from_processor_config(
7673
name,
7774
position,
78-
&ProcessorBuilder::parse_config(config)?,
75+
&ProcessorConfig::parse(config)?,
7976
builder,
8077
);
8178
#[cfg(not(feature = "std"))]
@@ -129,36 +126,36 @@ impl Building {
129126
config: &ProcessorConfig,
130127
builder: &LogicVMBuilder,
131128
) -> VMLoadResult<Self> {
132-
let code = LogicParser::new()
133-
.parse(&config.code)
134-
// FIXME: hack
135-
.map_err(|e| VMLoadError::BadProcessorCode(e.to_string()))?
136-
.into_boxed_slice();
129+
let code = ProcessorBuilder::parse_code(&config.code)?;
137130

138131
let data = match name {
139132
MICRO_PROCESSOR => ProcessorBuilder {
140133
ipt: 2.,
141134
privileged: false,
142135
code,
143136
links: &config.links,
137+
instruction_hook: None,
144138
},
145139
LOGIC_PROCESSOR => ProcessorBuilder {
146140
ipt: 8.,
147141
privileged: false,
148142
code,
149143
links: &config.links,
144+
instruction_hook: None,
150145
},
151146
HYPER_PROCESSOR => ProcessorBuilder {
152147
ipt: 25.,
153148
privileged: false,
154149
code,
155150
links: &config.links,
151+
instruction_hook: None,
156152
},
157153
WORLD_PROCESSOR => ProcessorBuilder {
158154
ipt: 8.,
159155
privileged: true,
160156
code,
161157
links: &config.links,
158+
instruction_hook: None,
162159
},
163160
_ => {
164161
return Err(VMLoadError::BadBlockType {

0 commit comments

Comments
 (0)