mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
No commits in common. "cb0efd3dd4b2770f48b7338efefb74d32de95bbc" and "a0f30d19ef4f2e17bef92010c7556392b60a26aa" have entirely different histories.
cb0efd3dd4
...
a0f30d19ef
|
@ -17,26 +17,6 @@ pub enum Value {
|
||||||
Nil,
|
Nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Value {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Value::True => write!(f, "#t"),
|
|
||||||
Value::False => write!(f, "#f"),
|
|
||||||
Value::Int(i) => write!(f, "{}", i),
|
|
||||||
Value::Float(fl) => write!(f, "{}", fl),
|
|
||||||
Value::String(s) => write!(f, "{}", s),
|
|
||||||
Value::Symbol(s) => write!(f, "{}", s),
|
|
||||||
Value::List(car, cdr) => {
|
|
||||||
write!(f, "(")?;
|
|
||||||
write!(f, "{}", car)?;
|
|
||||||
for item in cdr.iter().cloned() { write!(f, " {}", item)?; }
|
|
||||||
write!(f, ")")
|
|
||||||
},
|
|
||||||
Value::Nil => write!(f, "nil"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Tree {
|
pub enum Tree {
|
||||||
Atom { atom: Value, quote: bool },
|
Atom { atom: Value, quote: bool },
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::{fs::{ read_to_string, File }, io::Write};
|
use std::fs::read_to_string;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
/// Arguments handler.
|
/// Arguments handler.
|
||||||
|
@ -20,12 +20,11 @@ fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
match args.options {
|
match args.options {
|
||||||
Options::Compile { input, ast } => {
|
Options::Compile { input, ast } => {
|
||||||
let code = read_to_string(&input).unwrap();
|
let code = read_to_string(input).unwrap();
|
||||||
let tree = parse(&code);
|
let tree = parse(&code);
|
||||||
match ast {
|
match ast {
|
||||||
true => for node in tree { println!("{:#?}", node) },
|
true => for node in tree { println!("{:#?}", node) },
|
||||||
false => {
|
false => {
|
||||||
// Check if the tree is valid
|
|
||||||
let mut checked_tree = Vec::new();
|
let mut checked_tree = Vec::new();
|
||||||
for node in tree {
|
for node in tree {
|
||||||
match node {
|
match node {
|
||||||
|
@ -34,13 +33,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate instructions
|
|
||||||
let instructions = generate_instructions(checked_tree.into_iter());
|
let instructions = generate_instructions(checked_tree.into_iter());
|
||||||
|
|
||||||
// Write instructions to file
|
|
||||||
let mut file = File::create(format!("{}.vyir" , input.file_stem().unwrap().to_str().unwrap())).unwrap();
|
|
||||||
for instruction in instructions {
|
for instruction in instructions {
|
||||||
file.write_all(instruction.to_string().as_bytes()).expect("Failed to write instructions to file");
|
println!("{:#?}", instruction);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::front::parser::Value;
|
use crate::front::parser::Value;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Instructions {
|
pub enum Instructions {
|
||||||
Store { value: Value, name: Box<str> },
|
Store { value: Value, name: Box<str> },
|
||||||
Push { value: Value },
|
Push { value: Value },
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Instructions {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Instructions::Store { value, name } => write!(f, "store {} {}", value, name),
|
|
||||||
Instructions::Push { value } => write!(f, "push {}", value),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue