Skip to content

Commit

Permalink
Fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebaz committed May 18, 2019
1 parent 520f285 commit c799038
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
9 changes: 6 additions & 3 deletions examples/break.lcore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(loop 'i 3 '[
(if (= i 1) '[
(break)
(loop 'x 4 '[
(prin "X: ")(print x)
(loop 'y 4 '[
(prin "Y: ")(print y)
(if (= y 2) '[(break)])
])
(if (= x 2) '[(break)])
])
Binary file added examples/gold/break.output
Binary file not shown.
Binary file added examples/gold/bug-ret.output
Binary file not shown.
Binary file added examples/output/break.output
Binary file not shown.
Binary file added examples/output/bug-ret.output
Binary file not shown.
Binary file modified examples/output/print.output
Binary file not shown.
Binary file modified examples/output/ret.output
Binary file not shown.
21 changes: 16 additions & 5 deletions src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub fn lcore_loop(
args: &mut Value,
symbol_table: &mut Environment,
) -> Result<Value, LCoreError> {
symbol_table.push();
let mut args = args.as_array().iter();

let quote = args
Expand All @@ -218,17 +219,18 @@ pub fn lcore_loop(

if let Err(err) = lcore_interpret(&mut loop_body, symbol_table) {
match err {
LCoreError::LambdaCoreError(s) => println!("{}", s),
LCoreError::IndexError(s) => println!("{}", s),
LCoreError::ArgumentError(s) => println!("{}", s),
LCoreError::NameError(s) => println!("{}", s),
LCoreError::LambdaCoreError(..) => return Err(err),
LCoreError::IndexError(..) => return Err(err),
LCoreError::ArgumentError(..) => return Err(err),
LCoreError::NameError(..) => return Err(err),
//LCoreError::ReturnError(v) => println!("CANNOT RETURN FROM FOR LOOP"),
LCoreError::ReturnError => println!("CANNOT RETURN FROM FOR LOOP"),
LCoreError::ReturnError => return Err(err),
LCoreError::BreakError => break
}
}
}

symbol_table.pop();
Ok(Value::Null)
}

Expand Down Expand Up @@ -929,6 +931,14 @@ pub fn lcore_return(
}


pub fn lcore_break(
args: &mut Value,
symbol_table: &mut Environment,
) -> Result<Value, LCoreError> {
LCoreError::Break()
}


pub fn import_builtins(symbol_table: &mut Environment) {
symbol_table.insert("print".to_string(), Value::Func { f: lcore_print });
symbol_table.insert("prin".to_string(), Value::Func { f: lcore_prin });
Expand Down Expand Up @@ -978,4 +988,5 @@ pub fn import_builtins(symbol_table: &mut Environment) {
symbol_table.insert("if".to_string(), Value::Func { f: lcore_if });
symbol_table.insert("sel".to_string(), Value::Func { f: lcore_sel });
symbol_table.insert("ret".to_string(), Value::Func { f: lcore_return });
symbol_table.insert("break".to_string(), Value::Func { f: lcore_break });
}
2 changes: 1 addition & 1 deletion src/lcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ pub fn lcore_interpret_expression(
match err {
//LCoreError::ReturnError(v) => return Err(err.clone()),
LCoreError::ReturnError => return Err(err.clone()),
LCoreError::BreakError => println!("NOT IMPLEMENTED!"),
LCoreError::BreakError => return Err(err.clone()),

_ => return Err(err.clone())
}
Expand Down

0 comments on commit c799038

Please sign in to comment.