Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WIP] Add a proper REPL #464

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ color-backtrace = { version = "0.4", default-features = false, optional = true }
counter = "0.4"
atty = { version = "0.2", default-features = false, optional = true }
git-testament = { version = "0.1", optional = true }
rustyline = { version = "6.1.2", optional = true }
rustyline-derive = { version = "0.3.1", optional = true }

[dev-dependencies]
env_logger = { version = "0.7", default-features = false }
Expand All @@ -48,19 +50,25 @@ proptest = "^0.9.6"
proptest-derive = "0.1"

[features]
default = ["cc", "codegen", "color-backtrace"]
default = ["cc", "codegen", "color-backtrace", "repl"]
# The `swcc` binary
cc = ["ansi_term", "git-testament", "tempfile", "pico-args", "codegen", "atty"]
codegen = ["cranelift", "cranelift-module", "cranelift-object"]
jit = ["codegen", "cranelift-simplejit"]
repl = ["rustyline", "rustyline-derive", "jit"]
# for internal use
_test_headers = []

[[bin]]
name = "swcc"
path = "src/main.rs"
path = "src/bin/swcc.rs"
required-features = ["cc"]

[[bin]]
name = "swcci"
path = "src/bin/swcci.rs"
required-features = ["repl"]

[[bench]]
name = "examples"
harness = false
Expand Down
1 change: 0 additions & 1 deletion src/analyze/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,6 @@ impl Qualifiers {
#[cfg(test)]
mod test {
use super::*;
use crate::analyze::test::analyze;
use crate::analyze::*;
pub(crate) fn expr(input: &str) -> CompileResult<Expr> {
analyze(input, Parser::expr, PureAnalyzer::expr)
Expand Down
45 changes: 23 additions & 22 deletions src/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use counter::Counter;

use crate::data::{error::Warning, hir::*, lex::Keyword, *};
use crate::intern::InternedStr;
use crate::parse::{Lexer, Parser};
use crate::lex::PreProcessor;
use crate::parse::{parser, Lexer, Parser};
use crate::RecursionGuard;

pub(crate) type TagScope = Scope<InternedStr, TagEntry>;
Expand Down Expand Up @@ -1343,33 +1344,33 @@ impl UnitSpecifier {
}
}

/// Analyzes the given input using the given parser, and analyze function.
pub fn analyze<'c, 'input: 'c, P, A, R, S, E>(
input: &'input str,
parse_func: P,
analyze_func: A,
) -> CompileResult<R>
where
P: Fn(&mut Parser<PreProcessor<'c>>) -> Result<S, E>,
A: Fn(&mut PureAnalyzer, S) -> R,
CompileError: From<E>,
{
let mut p = parser(input);
let ast = parse_func(&mut p)?;
let mut a = PureAnalyzer::new();
let e = analyze_func(&mut a, ast);
if let Some(err) = a.error_handler.pop_front() {
return Err(err);
}
Ok(e)
}

#[cfg(test)]
pub(crate) mod test {
use super::{Error, *};
use crate::data::types::{ArrayType, FunctionType, Type::*};
use crate::lex::PreProcessor;
use crate::parse::test::*;

pub(crate) fn analyze<'c, 'input: 'c, P, A, R, S, E>(
input: &'input str,
parse_func: P,
analyze_func: A,
) -> CompileResult<R>
where
P: Fn(&mut Parser<PreProcessor<'c>>) -> Result<S, E>,
A: Fn(&mut PureAnalyzer, S) -> R,
CompileError: From<E>,
{
let mut p = parser(input);
let ast = parse_func(&mut p)?;
let mut a = PureAnalyzer::new();
let e = analyze_func(&mut a, ast);
if let Some(err) = a.error_handler.pop_front() {
return Err(err);
}
Ok(e)
}

fn maybe_decl(s: &str) -> Option<CompileResult<Declaration>> {
decls(s).into_iter().next()
}
Expand Down
2 changes: 1 addition & 1 deletion src/analyze/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl FunctionAnalyzer<'_> {
#[cfg(test)]
mod tests {
use super::*;
use crate::analyze::test::{analyze, analyze_expr};
use crate::analyze::FunctionData;
use crate::analyze::{analyze, test::analyze_expr};
use crate::data::*;
use crate::Parser;

Expand Down
Loading