From 1a4bf24ab1749ed87658f716e54e0924424ea9c9 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 23 Jan 2017 03:03:12 -0800 Subject: [PATCH] Move schala-specific stuff into its own module --- compile.schala | 2 +- src/main.rs | 36 +++++----------------------- src/{ => schala_lang}/compilation.rs | 2 +- src/{ => schala_lang}/eval.rs | 6 ++--- src/{ => schala_lang}/parser.rs | 4 ++-- src/{ => schala_lang}/tokenizer.rs | 0 6 files changed, 13 insertions(+), 37 deletions(-) rename src/{ => schala_lang}/compilation.rs (99%) rename src/{ => schala_lang}/eval.rs (98%) rename src/{ => schala_lang}/parser.rs (99%) rename src/{ => schala_lang}/tokenizer.rs (100%) diff --git a/compile.schala b/compile.schala index c51175f..23cd053 100644 --- a/compile.schala +++ b/compile.schala @@ -7,7 +7,7 @@ fn paha(x, y, z) { x * y * z } -a = 0 +a = 1 c = if a { 10 diff --git a/src/main.rs b/src/main.rs index 7ba7fab..ee3202b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,17 +7,14 @@ use std::fs::File; use std::io::Read; use std::process; -mod tokenizer; -mod parser; - -use eval::Evaluator; -mod eval; +mod schala_lang; +use schala_lang::eval::Evaluator; +use schala_lang::compilation::compilation_sequence; +use schala_lang::Schala; use language::{ProgrammingLanguage, ParseError, TokenError}; mod language; -use compilation::{compilation_sequence, compile_ast}; -mod compilation; mod llvm_wrap; fn main() { @@ -57,7 +54,7 @@ fn program_options() -> getopts::Options { options } -fn run_noninteractive<'a, T: ProgrammingLanguage>>(filename: &str, compile: bool, trace_evaluation: bool, language: &T) { +fn run_noninteractive<'a, T: ProgrammingLanguage>>(filename: &str, compile: bool, trace_evaluation: bool, language: &T) { let mut source_file = File::open(&Path::new(filename)).unwrap(); let mut buffer = String::new(); source_file.read_to_string(&mut buffer).unwrap(); @@ -143,7 +140,7 @@ impl<'a> Repl<'a> { self.input_handler_new(input, schala) } - fn input_handler_new>>(&mut self, input: &str, language: T) -> String { + fn input_handler_new>>(&mut self, input: &str, language: T) -> String { let mut output = String::new(); let tokens = match T::tokenize(input) { @@ -233,24 +230,3 @@ impl<'a> Repl<'a> { } } -struct Schala { } - -impl<'a> ProgrammingLanguage> for Schala { - type Token = tokenizer::Token; - type AST = parser::AST; - - fn tokenize(input: &str) -> Result, TokenError> { - tokenizer::tokenize(input).map_err(|x| TokenError { msg: x.msg }) - } - - fn parse(input: Vec) -> Result { - parser::parse(&input, &[]).map_err(|x| ParseError { msg: x.msg }) - } - fn evaluate(ast: Self::AST, evaluator: &mut Evaluator) -> Vec { - evaluator.run(ast) - } - fn compile(ast: Self::AST) -> String { - compile_ast(ast) - } -} - diff --git a/src/compilation.rs b/src/schala_lang/compilation.rs similarity index 99% rename from src/compilation.rs rename to src/schala_lang/compilation.rs index 65dc903..1ffb6ed 100644 --- a/src/compilation.rs +++ b/src/schala_lang/compilation.rs @@ -7,7 +7,7 @@ use std::io::Write; use self::llvm_sys::prelude::*; 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; diff --git a/src/eval.rs b/src/schala_lang/eval.rs similarity index 98% rename from src/eval.rs rename to src/schala_lang/eval.rs index 48049ba..cb1b3ae 100644 --- a/src/eval.rs +++ b/src/schala_lang/eval.rs @@ -2,13 +2,13 @@ extern crate take_mut; use std::collections::HashMap; 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::io::{Write, Stdout, BufWriter}; use std::convert::From; -use parser::Expression::*; -use parser::Statement::*; +use schala_lang::parser::Expression::*; +use schala_lang::parser::Statement::*; type Reduction = (T, Option); diff --git a/src/parser.rs b/src/schala_lang/parser.rs similarity index 99% rename from src/parser.rs rename to src/schala_lang/parser.rs index 9ca57c4..7935200 100644 --- a/src/parser.rs +++ b/src/schala_lang/parser.rs @@ -1,6 +1,6 @@ use std::fmt; -use tokenizer::{Token, Kw, OpTok}; -use tokenizer::Token::*; +use schala_lang::tokenizer::{Token, Kw, OpTok}; +use schala_lang::tokenizer::Token::*; use std::collections::VecDeque; use std::rc::Rc; use std::convert::From; diff --git a/src/tokenizer.rs b/src/schala_lang/tokenizer.rs similarity index 100% rename from src/tokenizer.rs rename to src/schala_lang/tokenizer.rs