Interfaces for errors, calling vasm, and generating source maps
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use vcore::{CPU, Word};
|
use vcore::{CPU, Word};
|
||||||
use vcore::memory::{PeekPoke, PeekPokeExt};
|
use vcore::memory::{PeekPoke, PeekPokeExt};
|
||||||
|
use vasm_core::parse_error::AssembleError;
|
||||||
|
use serde::{ Deserialize, Serialize };
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct NovaForth;
|
pub struct NovaForth;
|
||||||
@@ -20,6 +22,45 @@ impl NovaForth {
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct WasmCPU(CPU);
|
pub struct WasmCPU(CPU);
|
||||||
|
|
||||||
|
#[wasm_bindgen(inspectable, getter_with_clone)]
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct JsVasmError {
|
||||||
|
pub line_number: usize,
|
||||||
|
pub message: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AssembleError> for JsVasmError {
|
||||||
|
fn from(value: AssembleError) -> Self {
|
||||||
|
let line = match value.clone() {
|
||||||
|
AssembleError::ParseError(loc, _) => loc.line_num,
|
||||||
|
AssembleError::EquResolveError(loc, _, _) => loc.line_num,
|
||||||
|
AssembleError::EquDuplicateError(loc, _) => loc.line_num,
|
||||||
|
AssembleError::OrgResolveError(loc, _) => loc.line_num,
|
||||||
|
AssembleError::ArgError(loc, _) => loc.line_num,
|
||||||
|
AssembleError::NoCode => 0,
|
||||||
|
AssembleError::IncludeError(loc, _) => loc.line_num,
|
||||||
|
AssembleError::FileError(_) => 0,
|
||||||
|
AssembleError::MacroError(loc) => loc.line_num,
|
||||||
|
};
|
||||||
|
|
||||||
|
return JsVasmError {
|
||||||
|
line_number: line,
|
||||||
|
message: value.message()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn assemble_snippet(snippet: String) -> Result<Vec<u8>, JsVasmError> {
|
||||||
|
vasm_core::assemble_snippet(snippet.lines().map(String::from)).map_err(|err| JsVasmError::from(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn source_map(snippet: String) -> JsValue {
|
||||||
|
let source_map = vasm_core::snippet_source_map(snippet.lines().map(String::from)).map_err(|err| JsVasmError::from(err));
|
||||||
|
serde_wasm_bindgen::to_value(&source_map).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl WasmCPU {
|
impl WasmCPU {
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
|
|||||||
Reference in New Issue
Block a user