mirror of
https://github.com/guilhermewerner/machine
synced 2025-06-16 21:24:18 +00:00
Working...
This commit is contained in:
27
Examples/Assembler.rs
Normal file
27
Examples/Assembler.rs
Normal file
@ -0,0 +1,27 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use ::Machine::*;
|
||||
use bincode::Options;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let assembly = Assembly {
|
||||
name: "Serialization Example".into(),
|
||||
version: 1,
|
||||
source: AssemblySource {
|
||||
text: include_bytes!("Bytecode.bin").to_vec(),
|
||||
data: Vec::new(),
|
||||
},
|
||||
};
|
||||
|
||||
let options = bincode::options()
|
||||
.with_big_endian()
|
||||
.with_fixint_encoding()
|
||||
.allow_trailing_bytes();
|
||||
|
||||
let encoded: Vec<u8> = options.serialize(&assembly).unwrap();
|
||||
fs::write("Examples/Assembly.bin", &encoded).unwrap();
|
||||
|
||||
//let decoded: Assembly = bincode::deserialize(&encoded[..]).unwrap();
|
||||
//assert_eq!(assembly, decoded);
|
||||
}
|
BIN
Examples/Assembly.bin
Normal file
BIN
Examples/Assembly.bin
Normal file
Binary file not shown.
21
Examples/Loader.rs
Normal file
21
Examples/Loader.rs
Normal file
@ -0,0 +1,21 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use ::Machine::*;
|
||||
use bincode::Options;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let encoded: Vec<u8> = fs::read("Examples/Assembly.bin").unwrap();
|
||||
|
||||
let options = bincode::options()
|
||||
.with_big_endian()
|
||||
.with_fixint_encoding()
|
||||
.allow_trailing_bytes();
|
||||
|
||||
let assembly: Assembly = options.deserialize(&encoded[..]).unwrap();
|
||||
|
||||
let mut vm = Machine::New([0, 0, 0, 0]);
|
||||
|
||||
vm.LoadProgram(&assembly.source.text);
|
||||
vm.Execute();
|
||||
}
|
Reference in New Issue
Block a user