Skip to content

Commit

Permalink
fix #21: add convenience string assembling function
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Jan 22, 2020
1 parent a242524 commit d195785
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/diagn/report.rs
Original file line number Diff line number Diff line change
@@ -350,6 +350,12 @@ impl RcReport
{
RcReport { report: Rc::new(RefCell::new(Report::new())) }
}


pub fn into_inner(self) -> Report
{
Rc::try_unwrap(self.report).ok().unwrap().into_inner()
}


pub fn error<S>(&self, descr: S)
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -20,8 +20,34 @@ mod test;


pub use self::diagn::Report;
pub use self::diagn::RcReport;
pub use self::asm::AssemblerState;
pub use self::util::FileServer;
pub use self::util::FileServerMock;
pub use self::util::FileServerReal;
pub use self::driver::drive;
pub use self::driver::drive;


pub fn assemble_str_to_binary(src: &str) -> (Option<Vec<u8>>, Report)
{
let mut fileserver = FileServerMock::new();
fileserver.add("str", src.clone());

let assemble = |report: diagn::RcReport, fileserver: &FileServerMock, filename: &str| -> Result<Vec<u8>, ()>
{
let mut asm = AssemblerState::new();
asm.process_file(report.clone(), fileserver, filename)?;
asm.wrapup(report)?;

let output = asm.get_binary_output();
Ok(output.generate_binary(0, output.len()))
};

let report = diagn::RcReport::new();

match assemble(report.clone(), &fileserver, "str")
{
Ok(output) => (Some(output), report.into_inner()),
Err(_) => (None, report.into_inner())
}
}
Binary file modified web/customasm.gc.wasm
Binary file not shown.

0 comments on commit d195785

Please sign in to comment.