Skip to content

Commit

Permalink
Refactoring / Addressing comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaheba committed Apr 6, 2017
1 parent dbc5911 commit d7548f3
Show file tree
Hide file tree
Showing 9 changed files with 471 additions and 236 deletions.
197 changes: 197 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ maplit = "*"
kaktus = "0.1.2"
log = "0.3"
env_logger = "0.3"
frunk = "0.1.22"
frunk_core = "0.0.11"
boolinator = "2.4.0"
40 changes: 40 additions & 0 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


#[derive(Debug, Clone, Copy)]
pub enum Comp {
Eq,
Lt,
Le,
Gt,
Ge,
}


#[derive(Debug, Clone)]
pub enum Instruction {
Call(String),
Return,

Add,
Cmp(Comp),

Jump(usize),
JumpIfTrue(usize),
JumpIfFalse(usize),

Load(usize),
Store(usize),
Const(usize),

Array(usize),
ArrayGet,
Push,

Loop,
Break,

// intrinsics
Len,
Print,
Clone,
}
21 changes: 3 additions & 18 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl AsMut<Vec<usize>> for Value {
}


// usize
impl From<Value> for usize {
fn from(val: Value) -> Self {
match val {
Expand All @@ -60,36 +59,22 @@ impl From<usize> for Value {
}


// impl<'a> From<&'a Instruction> for TraceInstruction {
impl From<Instruction> for TraceInstruction {
fn from(instr: Instruction) -> TraceInstruction {
impl<'a> From<&'a Instruction> for TraceInstruction {
fn from(instr: &Instruction) -> TraceInstruction {
use Instruction as I;
use TraceInstruction as TI;

match instr {
match *instr {
I::Add => TI::Add,
I::Cmp(c) => TI::Cmp(c),
I::Const(c) => TI::Const(c),

I::Len => TI::Len,
I::Print => TI::Print,
I::Clone => TI::Clone,

I::Array(u) => TI::Array(u),
I::ArrayGet => TI::ArrayGet,

_ => panic!("can not convert {:?}", instr),
}
}
}


impl<'a> From<&'a Func> for FuncInfo {
fn from(func: &Func) -> Self {
FuncInfo {
name: func.name.clone(),
args: func.args,
locals: func.locals,
}
}
}
Loading

0 comments on commit d7548f3

Please sign in to comment.