Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from mica-lang/lists
Fix REPL segfaulting on `Gc.collect`
- Loading branch information
Showing
8 changed files
with
124 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#![doc = include_str!("lib.md")] | ||
|
||
mod tests; | ||
|
||
pub use mica_hl::*; | ||
pub use mica_std as std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![allow(unused)] | ||
|
||
use mica_hl::{Engine, Error, Value}; | ||
|
||
fn engine() -> Result<Engine, Error> { | ||
let mut engine = Engine::new(mica_std::lib()); | ||
mica_std::load(&mut engine)?; | ||
Ok(engine) | ||
} | ||
|
||
fn interpret<'e>( | ||
engine: &'e mut Engine, | ||
filename: &str, | ||
input: &str, | ||
) -> Result<impl Iterator<Item = Result<Value, Error>> + 'e, Error> { | ||
let mut fiber = match engine.start(filename, input) { | ||
Ok(fiber) => fiber, | ||
Err(error) => { | ||
eprintln!("{error}"); | ||
return Ok(None.into_iter().flatten()); | ||
} | ||
}; | ||
Ok(Some(std::iter::from_fn(move || match fiber.resume() { | ||
Ok(Some(value)) => Some(Ok(value)), | ||
Ok(None) => None, | ||
Err(error) => { | ||
eprintln!("{error}"); | ||
Some(Err(error)) | ||
} | ||
})) | ||
.into_iter() | ||
.flatten()) | ||
} | ||
|
||
#[test] | ||
fn gc_collect_shouldnt_cause_use_after_free() -> Result<(), Error> { | ||
let mut engine = engine()?; | ||
|
||
for result in interpret(&mut engine, "(repl)", "[]")? { | ||
println!("< {result:?}"); | ||
println!(); | ||
} | ||
for result in interpret(&mut engine, "(repl)", "[]")? { | ||
println!("< {result:?}"); | ||
println!(); | ||
} | ||
for result in interpret(&mut engine, "(repl)", "Gc.collect")? { | ||
println!("< {result:?}"); | ||
println!(); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Deleting the global variables defined for built-ins should work. | ||
|
||
Nil = nil | ||
Boolean = nil | ||
Number = nil | ||
String = nil | ||
List = nil | ||
|
||
"a" | ||
"a" | ||
|
||
Gc.collect | ||
|
||
assert("a".cat("b") == "ab") | ||
"b" | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters