Skip to content

Commit

Permalink
Move main typecheck to typechecking rather than runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Lafon committed Sep 9, 2023
1 parent 00872a7 commit be392d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 7 additions & 0 deletions brilirs/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,13 @@ fn type_check_instruction<'a>(
}

fn type_check_func(bbfunc: &BBFunction, bbprog: &BBProgram) -> Result<(), PositionalInterpError> {
if bbfunc.name == "main" {
if bbfunc.return_type.is_some() {
return Err(InterpError::NonEmptyRetForFunc(bbfunc.name.clone()))
.map_err(|e| e.add_pos(bbfunc.pos.clone()));
}
}

let mut env: FxHashMap<&str, &Type> =
FxHashMap::with_capacity_and_hasher(20, fxhash::FxBuildHasher::default());
bbfunc.args.iter().for_each(|a| {
Expand Down
5 changes: 0 additions & 5 deletions brilirs/src/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,6 @@ pub fn execute_main<T: std::io::Write, U: std::io::Write>(
.map(|i| prog.get(i).unwrap())
.ok_or(InterpError::NoMainFunction)?;

if main_func.return_type.is_some() {
return Err(InterpError::NonEmptyRetForFunc(main_func.name.clone()))
.map_err(|e| e.add_pos(main_func.pos.clone()));
}

let mut env = Environment::new(main_func.num_of_vars);
let heap = Heap::default();

Expand Down

0 comments on commit be392d4

Please sign in to comment.