integrate assembler

This commit is contained in:
phyto 2023-05-06 11:25:11 +00:00
parent a542346b3d
commit 4534d8480a
Signed by: phyto
SSH Key Fingerprint: SHA256:FJdIUDW+Q/c/oLlaNI7vrxCrv0VMxMgT6usJ+7A/wo0
3 changed files with 63 additions and 58 deletions

View File

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ruxnasm = { git = "https://git.disroot.org/phyto/ruxnasm.git" }

View File

@ -3,7 +3,8 @@ fn main() {
braintal::bf::optimise::optimise(&mut bf);
let tal = braintal::uxn::from_ops(&bf);
dbg!(bf);
print!("{}", tal);
use std::io::Write;
std::io::stdout().write(&tal);
}
fn read_stdin() -> Vec<braintal::bf::Op> {

View File

@ -6,7 +6,7 @@
mod asm;
use crate::bf::Op;
pub fn from_ops(s: &[Op]) -> String {
pub fn from_ops(s: &[Op]) -> Vec<u8> {
let mut r = init();
let mut uxn_index = 0;
@ -19,7 +19,10 @@ pub fn from_ops(s: &[Op]) -> String {
r.push_str("#0f DEO");
r
dbg!(&r);
let (bin, _) = ruxnasm::assemble(r.as_bytes()).unwrap();
bin
}
fn match_op(s: &Op, bf_index: usize, uxn_index: usize) -> String {
@ -29,12 +32,12 @@ fn match_op(s: &Op, bf_index: usize, uxn_index: usize) -> String {
// - Have each whitespace-seperated word equate to 1 byte of uxn
// - Leave the stack in the same format it was found
match s {
Add(1) => prog.push_str("DUP2 LDAk INC ROT ROT STA"), //INC is slightly smaller
Add(1) => prog.push_str("DUP2 LDAk #01 ADD ROT ROT STA"), //INC is slightly smaller
Add(amt) if amt > &0 => prog.push_str(&format!("DUP2 LDAk LIT {:02} ADD ROT ROT STA", amt)),
Add(amt) if amt < &0 => {
prog.push_str(&format!("DUP2 LDAk LIT {:02} SUB ROT ROT STA", -amt))
}
Seek(-1) => prog.push_str("INC2"),
Seek(-1) => prog.push_str("#0001 ADD2"),
Seek(amt) if amt > &0 => prog.push_str(&format!("LIT 00 LIT {:02} SUB2", amt)),
Seek(amt) if amt < &0 => prog.push_str(&format!("LIT 00 LIT {:02} ADD2", -amt)),
LoopStart(adr) => prog.push_str(&format!(