summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--matrix-bin/src/main.rs19
-rw-r--r--test.mat8
2 files changed, 16 insertions, 11 deletions
diff --git a/matrix-bin/src/main.rs b/matrix-bin/src/main.rs
index 8321796..2b00a6a 100644
--- a/matrix-bin/src/main.rs
+++ b/matrix-bin/src/main.rs
@@ -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(())
}
diff --git a/test.mat b/test.mat
deleted file mode 100644
index 71a04dd..0000000
--- a/test.mat
+++ /dev/null
@@ -1,8 +0,0 @@
-let a = 3
-{
- a = 4;
- const bees = \a => a*2;
- let j = bees(3);
- a = j;
-}
-let g = a + 'aaaa';