Skip to content

Commit

Permalink
update: bytecode def
Browse files Browse the repository at this point in the history
  • Loading branch information
DrEden33773 committed Dec 4, 2023
1 parent d55af03 commit 9c21c81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
43 changes: 42 additions & 1 deletion src/bytecode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
#[derive(Debug, Clone, Copy)]
pub enum ByteCode {}
pub enum UnaryOpCode {
SetPositive,
SetNegative,
}

#[derive(Debug, Clone, Copy)]
pub enum BinaryOpCode {
// arithmetic
Add,
Sub,
Mul,
Div,
// comparative
CmpEq,
CmpNe,
CmpGt,
CmpGe,
CmpLt,
CmpLe,
// assign
Assign,
}

#[derive(Debug, Clone, Copy)]
pub enum OpCode {
Unary(UnaryOpCode),
Binary(BinaryOpCode),
}

#[derive(Debug, Clone, Copy)]
pub enum ByteCode {
LoadConst { constant: i64 },
Operation { op_code: OpCode },
LoadVar { layer_dif: usize, offset: usize },
SetVar { layer_dif: usize, offset: usize },
Call { layer_dif: usize, offset: usize },
IncreaseSp { increment: usize },
JumpTo { offset: usize },
JumpIf { offset: usize },
ReadToVar { layer_dif: usize, offset: usize },
WriteTop,
}
20 changes: 1 addition & 19 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use self::token_def::Token;
use crate::error::{compile_error::CompileError, error_builder::CompileErrorBuilder};
use crate::error::error_builder::CompileErrorBuilder;
use std::{iter::Peekable, str::Chars};

#[cfg(not(feature = "debug"))]
use std::process::exit;

pub mod methods;
pub mod token_def;

Expand Down Expand Up @@ -44,21 +41,6 @@ impl<'a> LexerIterator for Lexer<'a> {
}
}

impl<'a> Lexer<'a> {
#[deprecated]
#[allow(dead_code)]
pub(super) fn panic_compile_error(
&mut self,
mut error_template: CompileError,
message: String,
) -> ! {
error_template.line = self.line_num;
error_template.col = self.col_num;
error_template.info = message;
panic!("{}", error_template);
}
}

impl<'a> Lexer<'a> {
fn ascii_char_handler(&mut self, c: char) -> Result<char, Token> {
if c.is_ascii() {
Expand Down
1 change: 0 additions & 1 deletion src/parser/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ impl<'a> Parser<'a> {
.build();
eprintln!("{}", err);
self.lexer.next();

None
}
}
Expand Down

0 comments on commit 9c21c81

Please sign in to comment.