Commit 60da6e54 authored by psf's avatar psf
Browse files

fix collision betweeen opcode and large literals

parent bd55267c
......@@ -59,8 +59,8 @@ impl Core {
fn step(&mut self) {
let opcode = self.load(self.ip);
self.ip = self.ip.wrapping_add(2);
if opcode >= 0xfff0 {
PRIMITIVES[(opcode - 0xfff0) as usize](self);
if (opcode >= 0xffe0) && (opcode & 1 == 0) {
PRIMITIVES[((opcode - 0xffe0) >> 1) as usize](self);
}
else if (opcode & 1) == 1 {
// Literal
......@@ -77,10 +77,10 @@ impl Core {
type Primitive = fn(&mut Core);
enum Op {
RET = 0xfff0, TOR = 0xfff1, RTO = 0xfff2, LD = 0xfff3,
ST = 0xfff4, DUP = 0xfff5, SWP = 0xfff6, DRP = 0xfff7,
Q = 0xfff8, ADD = 0xfff9, SFT = 0xfffa, OR = 0xfffb,
INV = 0xfffc, OUT = 0xfffd, IN = 0xfffe, NOP = 0xffff,
RET = 0xffe0, TOR = 0xffe2, RTO = 0xffe4, LD = 0xffe6,
ST = 0xffe8, DUP = 0xffea, SWP = 0xffec, DRP = 0xffee,
Q = 0xfff0, ADD = 0xfff2, SFT = 0xfff4, OR = 0xfff6,
INV = 0xfff8, OUT = 0xfffa, IN = 0xfffc, NOP = 0xfffe,
}
const PRIMITIVES: [Primitive; 16] = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment