Move schala-specific stuff into its own module

This commit is contained in:
greg 2017-01-23 03:03:12 -08:00
parent 9d6bdf22da
commit 1a4bf24ab1
6 changed files with 13 additions and 37 deletions

View File

@ -7,7 +7,7 @@ fn paha(x, y, z) {
x * y * z x * y * z
} }
a = 0 a = 1
c = if a { c = if a {
10 10

View File

@ -7,17 +7,14 @@ use std::fs::File;
use std::io::Read; use std::io::Read;
use std::process; use std::process;
mod tokenizer; mod schala_lang;
mod parser; use schala_lang::eval::Evaluator;
use schala_lang::compilation::compilation_sequence;
use eval::Evaluator; use schala_lang::Schala;
mod eval;
use language::{ProgrammingLanguage, ParseError, TokenError}; use language::{ProgrammingLanguage, ParseError, TokenError};
mod language; mod language;
use compilation::{compilation_sequence, compile_ast};
mod compilation;
mod llvm_wrap; mod llvm_wrap;
fn main() { fn main() {
@ -57,7 +54,7 @@ fn program_options() -> getopts::Options {
options options
} }
fn run_noninteractive<'a, T: ProgrammingLanguage<eval::Evaluator<'a>>>(filename: &str, compile: bool, trace_evaluation: bool, language: &T) { fn run_noninteractive<'a, T: ProgrammingLanguage<Evaluator<'a>>>(filename: &str, compile: bool, trace_evaluation: bool, language: &T) {
let mut source_file = File::open(&Path::new(filename)).unwrap(); let mut source_file = File::open(&Path::new(filename)).unwrap();
let mut buffer = String::new(); let mut buffer = String::new();
source_file.read_to_string(&mut buffer).unwrap(); source_file.read_to_string(&mut buffer).unwrap();
@ -143,7 +140,7 @@ impl<'a> Repl<'a> {
self.input_handler_new(input, schala) self.input_handler_new(input, schala)
} }
fn input_handler_new<T: ProgrammingLanguage<eval::Evaluator<'a>>>(&mut self, input: &str, language: T) -> String { fn input_handler_new<T: ProgrammingLanguage<Evaluator<'a>>>(&mut self, input: &str, language: T) -> String {
let mut output = String::new(); let mut output = String::new();
let tokens = match T::tokenize(input) { let tokens = match T::tokenize(input) {
@ -233,24 +230,3 @@ impl<'a> Repl<'a> {
} }
} }
struct Schala { }
impl<'a> ProgrammingLanguage<eval::Evaluator<'a>> for Schala {
type Token = tokenizer::Token;
type AST = parser::AST;
fn tokenize(input: &str) -> Result<Vec<Self::Token>, TokenError> {
tokenizer::tokenize(input).map_err(|x| TokenError { msg: x.msg })
}
fn parse(input: Vec<Self::Token>) -> Result<Self::AST, ParseError> {
parser::parse(&input, &[]).map_err(|x| ParseError { msg: x.msg })
}
fn evaluate(ast: Self::AST, evaluator: &mut Evaluator) -> Vec<String> {
evaluator.run(ast)
}
fn compile(ast: Self::AST) -> String {
compile_ast(ast)
}
}

View File

@ -7,7 +7,7 @@ use std::io::Write;
use self::llvm_sys::prelude::*; use self::llvm_sys::prelude::*;
use self::llvm_sys::{LLVMIntPredicate, LLVMRealPredicate}; use self::llvm_sys::{LLVMIntPredicate, LLVMRealPredicate};
use parser::{AST, Statement, Function, Prototype, Expression, BinOp}; use schala_lang::parser::{AST, Statement, Function, Prototype, Expression, BinOp};
use llvm_wrap as LLVMWrap; use llvm_wrap as LLVMWrap;

View File

@ -2,13 +2,13 @@ extern crate take_mut;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use parser::{AST, Statement, Expression, Function, Callable, BinOp}; use schala_lang::parser::{AST, Statement, Expression, Function, Callable, BinOp};
use std::rc::Rc; use std::rc::Rc;
use std::io::{Write, Stdout, BufWriter}; use std::io::{Write, Stdout, BufWriter};
use std::convert::From; use std::convert::From;
use parser::Expression::*; use schala_lang::parser::Expression::*;
use parser::Statement::*; use schala_lang::parser::Statement::*;
type Reduction<T> = (T, Option<SideEffect>); type Reduction<T> = (T, Option<SideEffect>);

View File

@ -1,6 +1,6 @@
use std::fmt; use std::fmt;
use tokenizer::{Token, Kw, OpTok}; use schala_lang::tokenizer::{Token, Kw, OpTok};
use tokenizer::Token::*; use schala_lang::tokenizer::Token::*;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::rc::Rc; use std::rc::Rc;
use std::convert::From; use std::convert::From;