repl: initial working version with new crate structure

This commit is contained in:
Brian Carroll 2022-01-30 09:04:48 +00:00
parent 0f206121bd
commit f098c6cb99
13 changed files with 120 additions and 25 deletions

39
Cargo.lock generated
View file

@ -3351,6 +3351,7 @@ dependencies = [
"roc_parse",
"roc_problem",
"roc_region",
"roc_repl_cli",
"roc_reporting",
"roc_solve",
"roc_target",
@ -3672,6 +3673,44 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "roc_repl_cli"
version = "0.1.0"
dependencies = [
"bumpalo",
"const_format",
"roc_mono",
"roc_parse",
"roc_repl_eval",
"rustyline",
"rustyline-derive",
"target-lexicon",
]
[[package]]
name = "roc_repl_eval"
version = "0.1.0"
dependencies = [
"bumpalo",
"inkwell 0.1.0",
"libloading 0.7.1",
"roc_build",
"roc_builtins",
"roc_can",
"roc_collections",
"roc_fmt",
"roc_gen_llvm",
"roc_load",
"roc_module",
"roc_mono",
"roc_parse",
"roc_region",
"roc_reporting",
"roc_target",
"roc_types",
"target-lexicon",
]
[[package]]
name = "roc_reporting"
version = "0.1.0"

View file

@ -33,6 +33,8 @@ members = [
"code_markup",
"error_macros",
"reporting",
"repl_cli",
"repl_eval",
"roc_std",
"test_utils",
"utils",

View file

@ -66,6 +66,7 @@ roc_reporting = { path = "../reporting" }
roc_error_macros = { path = "../error_macros" }
roc_editor = { path = "../editor", optional = true }
roc_linker = { path = "../linker" }
roc_repl_cli = { path = "../repl_cli" }
clap = { version = "= 3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] }
const_format = "0.2.22"
rustyline = { git = "https://github.com/rtfeldman/rustyline", tag = "v9.1.1" }

View file

@ -18,7 +18,6 @@ use target_lexicon::{Architecture, OperatingSystem, Triple, X86_32Architecture};
pub mod build;
mod format;
pub mod repl;
pub use format::format;
pub const CMD_BUILD: &str = "build";

View file

@ -1,9 +1,10 @@
use roc_cli::build::check_file;
use roc_cli::{
build_app, docs, format, repl, BuildConfig, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT,
CMD_FORMAT, CMD_REPL, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_TIME, ROC_FILE,
build_app, docs, format, BuildConfig, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT, CMD_FORMAT,
CMD_REPL, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_TIME, ROC_FILE,
};
use roc_load::file::LoadingProblem;
use roc_repl_cli;
use std::fs::{self, FileType};
use std::io;
use std::path::{Path, PathBuf};
@ -63,7 +64,7 @@ fn main() -> io::Result<()> {
}
}
Some((CMD_REPL, _)) => {
repl::main()?;
roc_repl_cli::main()?;
// Exit 0 if the repl exited normally
Ok(0)

21
repl_cli/Cargo.toml Normal file
View file

@ -0,0 +1,21 @@
[package]
edition = "2021"
name = "roc_repl_cli"
version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bumpalo = {version = "3.8.0", features = ["collections"]}
const_format = "0.2.22"
rustyline = {git = "https://github.com/rtfeldman/rustyline", tag = "v9.1.1"}
rustyline-derive = {git = "https://github.com/rtfeldman/rustyline", tag = "v9.1.1"}
target-lexicon = "0.12.2"
roc_mono = {path = "../compiler/mono"}
roc_parse = {path = "../compiler/parse"}
roc_repl_eval = {path = "../repl_eval"}
[lib]
name = "roc_repl_cli"
path = "src/lib.rs"

View file

@ -1,13 +1,13 @@
use const_format::concatcp;
#[cfg(feature = "llvm")]
use gen::{gen_and_eval, ReplOutput};
use roc_parse::parser::{EExpr, ELambda, SyntaxError};
use rustyline::highlight::{Highlighter, PromptInfo};
use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
use rustyline_derive::{Completer, Helper, Hinter};
use std::borrow::Cow;
use std::io;
use roc_parse::parser::{EExpr, ELambda, SyntaxError};
use roc_repl_eval::gen::{gen_and_eval, ReplOutput};
const BLUE: &str = "\u{001b}[36m";
const PINK: &str = "\u{001b}[35m";
const END_COL: &str = "\u{001b}[0m";
@ -27,11 +27,11 @@ pub const INSTRUCTIONS: &str = "Enter an expression, or :help, or :exit/:q.\n";
pub const PROMPT: &str = concatcp!("\n", BLUE, "»", END_COL, " ");
pub const CONT_PROMPT: &str = concatcp!(BLUE, "", END_COL, " ");
mod app_memory;
#[cfg(feature = "llvm")]
mod eval;
#[cfg(feature = "llvm")]
mod gen;
// mod app_memory;
// #[cfg(feature = "llvm")]
// mod eval;
// #[cfg(feature = "llvm")]
// mod gen;
#[derive(Completer, Helper, Hinter)]
struct ReplHelper {
@ -108,12 +108,6 @@ impl Validator for InputValidator {
}
}
#[cfg(not(feature = "llvm"))]
pub fn main() -> io::Result<()> {
panic!("The REPL currently requires being built with LLVM.");
}
#[cfg(feature = "llvm")]
pub fn main() -> io::Result<()> {
use rustyline::error::ReadlineError;
use rustyline::Editor;
@ -236,7 +230,6 @@ fn report_parse_error(fail: SyntaxError) {
println!("TODO Gracefully report parse error in repl: {:?}", fail);
}
#[cfg(feature = "llvm")]
fn eval_and_format<'a>(src: &str) -> Result<String, SyntaxError<'a>> {
use roc_mono::ir::OptLevel;
use target_lexicon::Triple;

27
repl_eval/Cargo.toml Normal file
View file

@ -0,0 +1,27 @@
[package]
edition = "2021"
name = "roc_repl_eval"
version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bumpalo = {version = "3.8.0", features = ["collections"]}
inkwell = {path = "../vendor/inkwell"}# TODO
libloading = "0.7.1" # TODO
target-lexicon = "0.12.2"
roc_build = {path = "../compiler/build", default-features = false, features = ["llvm"]}# TODO
roc_builtins = {path = "../compiler/builtins"}
roc_can = {path = "../compiler/can"}
roc_collections = {path = "../compiler/collections"}
roc_fmt = {path = "../compiler/fmt"}
roc_gen_llvm = {path = "../compiler/gen_llvm"}# TODO
roc_load = {path = "../compiler/load"}
roc_module = {path = "../compiler/module"}
roc_mono = {path = "../compiler/mono"}
roc_parse = {path = "../compiler/parse"}
roc_region = {path = "../compiler/region"}
roc_reporting = {path = "../reporting"}
roc_target = {path = "../compiler/roc_target"}
roc_types = {path = "../compiler/types"}

View file

@ -1,10 +1,9 @@
use crate::repl::app_memory::AppMemoryInternal;
use crate::repl::eval;
use crate::app_memory::AppMemoryInternal;
use crate::eval;
use bumpalo::Bump;
use inkwell::context::Context;
use inkwell::module::Linkage;
use roc_build::link::module_to_dylib;
use roc_build::program::FunctionIterator;
use inkwell::context::Context; // TODO
use inkwell::module::Linkage; // TODO
use roc_build::{link::module_to_dylib, program::FunctionIterator};
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::{MutMap, MutSet};
use roc_fmt::annotation::Formattable;
@ -167,6 +166,10 @@ pub fn gen_and_eval<'a>(
}
};
/*--------------------------------------------------------------------
START OF LLVM-SPECIFIC STUFF
--------------------------------------------------------------------*/
let module = arena.alloc(module);
let (module_pass, function_pass) =
roc_gen_llvm::llvm::build::construct_optimization_passes(module, opt_level);
@ -228,6 +231,11 @@ pub fn gen_and_eval<'a>(
let lib = module_to_dylib(env.module, &target, opt_level)
.expect("Error loading compiled dylib for test");
/*--------------------------------------------------------------------
END OF LLVM-SPECIFIC STUFF
--------------------------------------------------------------------*/
let res_answer = unsafe {
eval::jit_to_ast(
&arena,

4
repl_eval/src/lib.rs Normal file
View file

@ -0,0 +1,4 @@
mod app_memory;
// mod debug; TODO: Is this in the right place? Seems to be specifically for solve.rs
mod eval;
pub mod gen;