added 'dup'
This commit is contained in:
parent
6ac45cfcb7
commit
a88e4efff0
|
@ -106,6 +106,16 @@ pub fn compile(tokens: Vec<Operator>, args: Args) -> Result<()>{
|
|||
writeln!(writer, " call print")?;
|
||||
ti += 1;
|
||||
},
|
||||
|
||||
OpType::Dup => {
|
||||
writeln!(writer, " ; -- DUP")?;
|
||||
writeln!(writer, " pop rax")?;
|
||||
writeln!(writer, " push rax")?;
|
||||
writeln!(writer, " push rax")?;
|
||||
|
||||
ti += 1;
|
||||
},
|
||||
|
||||
OpType::If => {
|
||||
writeln!(writer, " ; -- IF")?;
|
||||
writeln!(writer, " pop rax")?;
|
||||
|
|
|
@ -10,6 +10,7 @@ pub enum OpType {
|
|||
If,
|
||||
Else,
|
||||
End,
|
||||
Dup,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,12 @@ pub fn run(tokens: Vec<crate::constants::Operator>) -> Result<(), &'static str>{
|
|||
// let _ = io::stdout().flush();
|
||||
ti += 1;
|
||||
},
|
||||
|
||||
OpType::Dup => {
|
||||
let a = stack_pop(&mut stack)?;
|
||||
stack.push(a);
|
||||
stack.push(a);
|
||||
},
|
||||
OpType::If => {
|
||||
let a = stack_pop(&mut stack)?;
|
||||
if a == 0 {
|
||||
|
|
|
@ -70,6 +70,7 @@ impl Parser {
|
|||
"if" => tokens.push(Operator::new(OpType::If, 0, token.file.clone(), token.line, token.col)),
|
||||
"else" => tokens.push(Operator::new(OpType::Else, 0, token.file.clone(), token.line, token.col)),
|
||||
"end" => tokens.push(Operator::new(OpType::End, 0, token.file.clone(), token.line, token.col)),
|
||||
"dup" => tokens.push(Operator::new(OpType::Dup, 0, token.file.clone(), token.line, token.col)),
|
||||
|
||||
|
||||
t => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user