Compare commits

..

No commits in common. "17eaeb1a2f5e91b8e29af6f807cced3595596ed5" and "30b608e5aa8a449a688fab408715d1afb60050ce" have entirely different histories.

4 changed files with 38 additions and 380 deletions

View file

@ -31,8 +31,8 @@ pub enum Arg {
impl assembler::ToCode for Arg {
fn to_code(&self) -> String {
match self {
Arg::Char(x) => format!("'{}'", x.escape_default()),
Arg::String(x) => format!("\"{}\"", x.escape_default()),
Arg::Char(x) => format!("'{}'", x),
Arg::String(x) => format!("\"{}\"", x),
Arg::Number(x) => x.to_string(),
Arg::Variable(x) => x.clone(),
Arg::BinaryExpression { left, right, op } => {

View file

@ -1 +1,13 @@
random . cr
asm"
.std_get MEM_ALLOC_PTR
tls
dbg
pop
"
3 cells allot
asm"
.std_get MEM_ALLOC_PTR
tls
dbg
pop
"

View file

@ -128,7 +128,7 @@ impl Data {
hence::parser::ast::Node::MacroCall {
name: "define".to_string(),
args: vec![
hence::arg::Arg::Variable("MEM_LOOP_I".to_string()),
hence::arg::Arg::Variable("MEM_ALLOC_PTR".to_string()),
hence::arg::Arg::BinaryExpression {
left: Box::new(hence::arg::Arg::Variable("CORE_MEM_MEM".to_string())),
right: Box::new(hence::arg::Arg::Number(16)),
@ -136,28 +136,6 @@ impl Data {
},
],
},
hence::parser::ast::Node::MacroCall {
name: "define".to_string(),
args: vec![
hence::arg::Arg::Variable("MEM_LOOP_J".to_string()),
hence::arg::Arg::BinaryExpression {
left: Box::new(hence::arg::Arg::Variable("MEM_LOOP_I".to_string())),
right: Box::new(hence::arg::Arg::Number(1)),
op: hence::arg::BinaryExpressionOperator::Add,
},
],
},
hence::parser::ast::Node::MacroCall {
name: "define".to_string(),
args: vec![
hence::arg::Arg::Variable("MEM_ALLOC_PTR".to_string()),
hence::arg::Arg::BinaryExpression {
left: Box::new(hence::arg::Arg::Variable("MEM_LOOP_J".to_string())),
right: Box::new(hence::arg::Arg::Number(1)),
op: hence::arg::BinaryExpressionOperator::Add,
},
],
},
// macros
// stack_transfer_alu
hence::parser::ast::Node::MacroCall {

View file

@ -53,7 +53,6 @@ pub enum Instruction {
Max,
Boolean,
Invert,
Random,
Plus,
OnePlus,
TwoPlus,
@ -122,7 +121,6 @@ impl Instruction {
"max" => Some(Instruction::Max),
"boolean" => Some(Instruction::Boolean),
"invert" => Some(Instruction::Invert),
"random" => Some(Instruction::Random),
"+" => Some(Instruction::Plus),
"1+" => Some(Instruction::OnePlus),
"2+" => Some(Instruction::TwoPlus),
@ -363,26 +361,8 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
arg: None,
},
]),
Instruction::I => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_get".to_string(),
args: vec![hence::arg::Arg::Variable("MEM_LOOP_I".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::J => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_get".to_string(),
args: vec![hence::arg::Arg::Variable("MEM_LOOP_J".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::I => Ok(vec![]),
Instruction::J => Ok(vec![]),
Instruction::Tuck => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_ld".to_string(),
@ -631,7 +611,7 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
name: "std_rset".to_string(),
args: vec![
hence::arg::Arg::Variable("CORE_REG_A".to_string()),
hence::arg::Arg::Char(' '),
hence::arg::Arg::Char('\n'),
],
},
hence::parser::ast::Node::MacroCall {
@ -645,7 +625,7 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
name: "std_rset".to_string(),
args: vec![
hence::arg::Arg::Variable("CORE_REG_A".to_string()),
hence::arg::Arg::Char('\n'),
hence::arg::Arg::Number(0x0a),
],
},
hence::parser::ast::Node::MacroCall {
@ -720,314 +700,26 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
])
}
Instruction::Count => Ok(vec![]),
Instruction::Not => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_ld".to_string(),
args: vec![],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_NOT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::And => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_AND".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Nand => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_AND".to_string())],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_NOT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Or => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_OR".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Nor => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_OR".to_string())],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_NOT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Xor => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_XOR".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Xnor => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_XOR".to_string())],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_NOT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Lsh => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_LSH".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Rsh => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_RSH".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Compare => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_CMP".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Eq => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_EQ".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Neq => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_EQ".to_string())],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_INV".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Lt => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_LT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Leq => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_LEQ".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Gt => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_GT".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Geq => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
args: vec![],
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_GEQ".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Not => Ok(vec![]),
Instruction::And => Ok(vec![]),
Instruction::Nand => Ok(vec![]),
Instruction::Or => Ok(vec![]),
Instruction::Nor => Ok(vec![]),
Instruction::Xor => Ok(vec![]),
Instruction::Xnor => Ok(vec![]),
Instruction::Lsh => Ok(vec![]),
Instruction::Rsh => Ok(vec![]),
Instruction::Compare => Ok(vec![]),
Instruction::Eq => Ok(vec![]),
Instruction::Neq => Ok(vec![]),
Instruction::Lt => Ok(vec![]),
Instruction::Leq => Ok(vec![]),
Instruction::Gt => Ok(vec![]),
Instruction::Geq => Ok(vec![]),
Instruction::Min => Ok(vec![]),
Instruction::Max => Ok(vec![]),
Instruction::Boolean => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_ld".to_string(),
args: vec![],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_BOL".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Invert => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_ld".to_string(),
args: vec![],
},
hence::parser::ast::Node::Call {
name: "tlr".to_string(),
arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())),
},
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_INV".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Random => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "std_alu".to_string(),
args: vec![hence::arg::Arg::Variable("CORE_ALU_RND".to_string())],
},
hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
},
]),
Instruction::Boolean => Ok(vec![]),
Instruction::Invert => Ok(vec![]),
Instruction::Plus => Ok(vec![
hence::parser::ast::Node::MacroCall {
name: "stack_transfer_alu".to_string(),
@ -1353,30 +1045,6 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
}],
]
.concat()),
Instruction::I | Instruction::J => Ok([
instruction.compile(data)?,
[hence::parser::ast::Node::Call {
name: "tls".to_string(),
arg: None,
}]
.into_iter()
.cycle()
.take(count - 1)
.collect(),
]
.concat()),
Instruction::Space | Instruction::Cr => Ok([
instruction.compile(data)?,
[hence::parser::ast::Node::Call {
name: "set".to_string(),
arg: None,
}]
.into_iter()
.cycle()
.take(count - 1)
.collect(),
]
.concat()),
_ => {
let compiled = instruction.compile(data)?;
let len = compiled.len() * count;