Add custom arithmetic functions, created md5.jas
This commit is contained in:
@@ -15,8 +15,9 @@ bonus = ["bonus:network", "bonus:heap"]
|
||||
"bonus:network" = []
|
||||
"bonus:heap" = []
|
||||
|
||||
extra = ["extra:sleep"]
|
||||
extra = ["extra:sleep", "extra:arithmetic"]
|
||||
"extra:sleep" = []
|
||||
"extra:arithmetic" = []
|
||||
|
||||
debug = ["debug:instr", "debug:frame", "debug:gc"]
|
||||
"debug:instr" = []
|
||||
|
||||
BIN
files/custom/md5.ijvm
Normal file
BIN
files/custom/md5.ijvm
Normal file
Binary file not shown.
1602
files/custom/md5.jas
Normal file
1602
files/custom/md5.jas
Normal file
File diff suppressed because it is too large
Load Diff
46
ijvm.config
46
ijvm.config
@@ -1,27 +1,38 @@
|
||||
0x00 NOP
|
||||
|
||||
0x10 BIPUSH byte
|
||||
0x13 LDC_W constant
|
||||
0x15 ILOAD var
|
||||
|
||||
0x36 ISTORE var
|
||||
|
||||
0x57 POP
|
||||
0x59 DUP
|
||||
0xA7 GOTO label
|
||||
0x5F SWAP
|
||||
|
||||
0x60 IADD
|
||||
0x64 ISUB
|
||||
|
||||
0x70 SHL
|
||||
0x71 SHR
|
||||
0x72 IMUL
|
||||
0x73 IDIV
|
||||
|
||||
0x7E IAND
|
||||
|
||||
0x84 IINC var byte
|
||||
|
||||
0x99 IFEQ label
|
||||
0x9B IFLT label
|
||||
0x9F IF_ICMPEQ label
|
||||
0x84 IINC var byte
|
||||
0x15 ILOAD var
|
||||
0xB6 INVOKEVIRTUAL method
|
||||
0xB0 IOR
|
||||
|
||||
0xA7 GOTO label
|
||||
0xAC IRETURN
|
||||
0x36 ISTORE var
|
||||
0x64 ISUB
|
||||
0x13 LDC_W constant
|
||||
0x00 NOP
|
||||
0x57 POP
|
||||
0x5F SWAP
|
||||
|
||||
0xB0 IOR
|
||||
0xB6 INVOKEVIRTUAL method
|
||||
|
||||
0xC4 WIDE
|
||||
0xFF HALT
|
||||
0xFE ERR
|
||||
0xFD OUT
|
||||
0xFC IN
|
||||
|
||||
0xD1 NEWARRAY
|
||||
0xD2 IALOAD
|
||||
@@ -34,4 +45,7 @@
|
||||
0xE4 NETOUT
|
||||
0xE5 NETCLOSE
|
||||
|
||||
0xF0 SLP byte
|
||||
0xFC IN
|
||||
0xFD OUT
|
||||
0xFE ERR
|
||||
0xFF HALT
|
||||
|
||||
@@ -48,10 +48,8 @@ impl Heaps {
|
||||
}
|
||||
|
||||
pub fn gc(&mut self) {
|
||||
println!("GC PRE : {} weaks", self.len());
|
||||
for i in 0..self.len() {
|
||||
println!("\theap: {} = {:?}", i, self.get(i));
|
||||
}
|
||||
println!("GC POST: {} weaks", self.len());
|
||||
self.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ impl NetStack {
|
||||
}
|
||||
|
||||
pub fn connect(&mut self, host: u32, port: u16) -> Result<()> {
|
||||
let h1 = (host & (0xFF << 24)) >> 24 as u8;
|
||||
let h2 = (host & (0xFF << 16)) >> 16 as u8;
|
||||
let h3 = (host & (0xFF << 8)) >> 8 as u8;
|
||||
let h4 = (host & 0xFF) >> 0 as u8;
|
||||
let h1 = ((host >> 24) & 0xFF) as u8;
|
||||
let h2 = ((host >> 16) & 0xFF) as u8;
|
||||
let h3 = ((host >> 8) & 0xFF) as u8;
|
||||
let h4 = ((host >> 0) & 0xFF) as u8;
|
||||
let addr: String = format!("{}.{}.{}.{}:{}", h1, h2, h3, h4, port);
|
||||
|
||||
if let Ok(stream) = TcpStream::connect(addr) {
|
||||
|
||||
111
src/ops.rs
111
src/ops.rs
@@ -31,33 +31,49 @@ lazy_static! {
|
||||
let mut m = vec![Operation::Invalid; 0xFF + 1];
|
||||
|
||||
m[0x00] = Operation::Op("NOP", nop, vec![]);
|
||||
|
||||
m[0x10] = Operation::Op("BIPUSH", bipush, vec![Args::Byte]);
|
||||
m[0x13] = Operation::Op("LDC_W", ldc_w, vec![Args::Constant]);
|
||||
m[0x15] = Operation::Op("ILOAD", iload, vec![Args::Var]);
|
||||
|
||||
m[0x36] = Operation::Op("ISTORE", istore, vec![Args::Var]);
|
||||
|
||||
m[0x57] = Operation::Op("POP", pop, vec![]);
|
||||
m[0x59] = Operation::Op("DUP", dup, vec![]);
|
||||
m[0x5F] = Operation::Op("SWAP", swap, vec![]);
|
||||
|
||||
m[0x60] = Operation::Op("IADD", iadd, vec![]);
|
||||
m[0x64] = Operation::Op("ISUB", isub, vec![]);
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
{
|
||||
m[0x70] = Operation::Op("SHL", shl, vec![]);
|
||||
m[0x71] = Operation::Op("SHR", shr, vec![]);
|
||||
m[0x72] = Operation::Op("IMUL", imul, vec![]);
|
||||
m[0x73] = Operation::Op("IDIV", idiv, vec![]);
|
||||
}
|
||||
m[0x7E] = Operation::Op("IAND", iand, vec![]);
|
||||
m[0xB0] = Operation::Op("IOR", ior, vec![]);
|
||||
|
||||
m[0x84] = Operation::Op("IINC", iinc, vec![Args::Var, Args::Byte]);
|
||||
|
||||
m[0x99] = Operation::Op("IFEQ", ifeq, vec![Args::Label]);
|
||||
m[0x9b] = Operation::Op("IFLT", iflt, vec![Args::Label]);
|
||||
m[0x9F] = Operation::Op("IF_ICMPEQ", if_icmpeq, vec![Args::Label]);
|
||||
|
||||
m[0xA7] = Operation::Op("GOTO", goto, vec![Args::Label]);
|
||||
m[0xAC] = Operation::Op("IRETURN", ireturn, vec![]);
|
||||
m[0xB6] = Operation::Op("INVOKEVIRTUAL", invokevirtual, vec![Args::Constant]);
|
||||
m[0xC4] = Operation::Op("WIDE", wide, vec![]);
|
||||
m[0xFC] = Operation::Op("IN", _in, vec![]);
|
||||
m[0xFD] = Operation::Op("OUT", out, vec![]);
|
||||
m[0xFE] = Operation::Op("ERR", err, vec![]);
|
||||
m[0xFF] = Operation::Op("HALT", halt, vec![]);
|
||||
|
||||
#[cfg(feature = "extra:sleep")]
|
||||
m[0xB0] = Operation::Op("IOR", ior, vec![]);
|
||||
m[0xB6] = Operation::Op("INVOKEVIRTUAL", invokevirtual, vec![Args::Constant]);
|
||||
|
||||
m[0xC4] = Operation::Op("WIDE", wide, vec![]);
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
{
|
||||
m[0xF0] = Operation::Op("SLP", slp, vec![Args::Byte]);
|
||||
m[0xD1] = Operation::Op("NEWARRAY", newarray, vec![]);
|
||||
m[0xD2] = Operation::Op("IALOAD", iaload, vec![]);
|
||||
m[0xD3] = Operation::Op("IASTORE", iastore, vec![]);
|
||||
m[0xD4] = Operation::Op("GC", gc, vec![]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
@@ -69,13 +85,14 @@ lazy_static! {
|
||||
m[0xE5] = Operation::Op("NETCLOSE", netclose, vec![]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:heap")]
|
||||
#[cfg(feature = "extra:sleep")]
|
||||
{
|
||||
m[0xD1] = Operation::Op("NEWARRAY", newarray, vec![]);
|
||||
m[0xD2] = Operation::Op("IALOAD", iaload, vec![]);
|
||||
m[0xD3] = Operation::Op("IASTORE", iastore, vec![]);
|
||||
m[0xD4] = Operation::Op("GC", gc, vec![]);
|
||||
m[0xF0] = Operation::Op("SLP", slp, vec![Args::Byte]);
|
||||
}
|
||||
m[0xFC] = Operation::Op("IN", _in, vec![]);
|
||||
m[0xFD] = Operation::Op("OUT", out, vec![]);
|
||||
m[0xFE] = Operation::Op("ERR", err, vec![]);
|
||||
m[0xFF] = Operation::Op("HALT", halt, vec![]);
|
||||
|
||||
m
|
||||
};
|
||||
@@ -293,18 +310,34 @@ fn slp(machine: &mut Machine) -> Result<()> {
|
||||
#[cfg(feature = "bonus:network")]
|
||||
fn netbind(machine: &mut Machine) -> Result<()> {
|
||||
let port: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
machine.net.bind(port as u16)
|
||||
|
||||
let result = match machine.net.bind(port as u16) {
|
||||
Ok(_) => 1,
|
||||
Err(_) => 0,
|
||||
};
|
||||
machine.cur_stack().push(Value::Int(result));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
fn netconnect(machine: &mut Machine) -> Result<()> {
|
||||
let port: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let host: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
machine.net.connect(host as u32, port as u16)
|
||||
let result = match machine.net.connect(host as u32, port as u16) {
|
||||
Ok(_) => 1,
|
||||
Err(_) => 0,
|
||||
};
|
||||
machine.cur_stack().push(Value::Int(result));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
fn netin(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
return Err("Invalid netref to netin");
|
||||
}
|
||||
|
||||
let byte = i32::from(machine.net.read_byte()?);
|
||||
machine.cur_stack().push(Value::Int(byte));
|
||||
Ok(())
|
||||
@@ -312,12 +345,21 @@ fn netin(machine: &mut Machine) -> Result<()> {
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
fn netout(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
return Err("Invalid netref to netout");
|
||||
}
|
||||
|
||||
let val: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
machine.net.write_byte(val as u8)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
fn netclose(machine: &mut Machine) -> Result<()> {
|
||||
let netref: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
if netref != 1 {
|
||||
return Err("Invalid netref to netclose");
|
||||
}
|
||||
machine.net.close()
|
||||
}
|
||||
|
||||
@@ -367,3 +409,40 @@ fn gc(machine: &mut Machine) -> Result<()> {
|
||||
machine.heap.gc();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
fn shl(machine: &mut Machine) -> Result<()> {
|
||||
let shift: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
machine.cur_stack().push(Value::Int(value << shift));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
fn shr(machine: &mut Machine) -> Result<()> {
|
||||
let shift: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
let result: u32 = (value as u32) >> (shift as u32);
|
||||
machine.cur_stack().push(Value::Int(result as i32));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
fn imul(machine: &mut Machine) -> Result<()> {
|
||||
let a: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let b: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
machine.cur_stack().push(Value::Int(a * b));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "extra:arithmetic")]
|
||||
fn idiv(machine: &mut Machine) -> Result<()> {
|
||||
let divisor: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
let value: i32 = machine.cur_stack().pop()?.try_into()?;
|
||||
|
||||
machine.cur_stack().push(Value::Int(value / divisor));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user