add option -r for forced repl

This commit is contained in:
Murphy 2024-09-04 12:03:25 -04:00
parent 4124346ba1
commit ab042c7956
Signed by: freya
GPG key ID: 744AB800E383AE52
2 changed files with 16 additions and 11 deletions

View file

@ -1,4 +1,4 @@
use std::{path::PathBuf, io::{self, Read, IsTerminal}, cell::RefCell, rc::Rc};
use std::{cell::RefCell, io::{self, IsTerminal, Read}, path::PathBuf, rc::Rc};
use clap::{Parser as ArgParser, ColorChoice};
use matrix_lang::prelude::*;
use repl::Repl;
@ -24,6 +24,10 @@ pub struct Args {
#[arg(short, long)]
debug: bool,
/// Force repl after running a file
#[arg(short, long)]
repl: bool,
/// Choses color
#[arg(long)]
color: Option<ColorChoice>,
@ -44,6 +48,7 @@ pub struct State<'a> {
compiler: Compiler<'a>,
vm: Rc<RefCell<Vm>>,
color: bool,
repl: bool,
}
pub fn error(err: Exception, state: &State) {
@ -83,10 +88,10 @@ impl<'a> State<'a> {
}
};
mode = Mode::Compile(buffer, path);
repl = false;
repl = args.repl;
} else if buffer.len() > 0 {
mode = Mode::Execute(buffer);
repl = false;
repl = args.repl;
} else {
mode = Mode::Repl;
repl = true;
@ -118,6 +123,7 @@ impl<'a> State<'a> {
vm: Rc::new(RefCell::new(vm)),
compiler,
color,
repl,
}, mode))
}
@ -156,6 +162,7 @@ fn handle_mode(state: &mut State, mode: Mode) -> Result<()> {
Mode::Repl => {
let mut repl = Repl::new(state);
repl.run()?;
state.repl = false;
},
Mode::Execute(buffer) => {
let fun = state.load_program(buffer)?;
@ -170,6 +177,12 @@ fn handle_mode(state: &mut State, mode: Mode) -> Result<()> {
Program::save(fun, &mut file)?;
}
};
if state.repl {
let mut repl = Repl::new(state);
repl.run()?;
}
Ok(())
}

View file

@ -1,8 +0,0 @@
let a = 3
{
a = 4;
const bees = \a => a*2;
let j = bees(3);
a = j;
}
let g = a + 'aaaa';