Jelajahi Sumber

make wasm build happy

Tamo 1 Minggu lalu
induk
melakukan
38e3bbbf34
3 mengubah file dengan 10 tambahan dan 8 penghapusan
  1. 5 2
      numbat-wasm/src/lib.rs
  2. 2 3
      numbat/src/ffi/plot.rs
  3. 3 3
      numbat/src/vm.rs

+ 5 - 2
numbat-wasm/src/lib.rs

@@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex};
 use wasm_bindgen::prelude::*;
 
 use numbat::buffered_writer::BufferedWriter;
-use numbat::diagnostic::ErrorDiagnostic;
+use numbat::diagnostic::{ErrorDiagnostic, ResolverDiagnostic};
 use numbat::help::help_markup;
 use numbat::html_formatter::{HtmlFormatter, HtmlWriter};
 use numbat::markup::Formatter;
@@ -143,7 +143,10 @@ impl Numbat {
                 | NameResolutionError::ReservedIdentifier(_)),
             )) => self.print_diagnostic(&e),
             Err(NumbatError::TypeCheckError(e)) => self.print_diagnostic(&e),
-            Err(NumbatError::RuntimeError(e)) => self.print_diagnostic(&e),
+            Err(NumbatError::RuntimeError(e)) => self.print_diagnostic(&ResolverDiagnostic {
+                resolver: self.ctx.resolver(),
+                error: &e,
+            }),
         }
     }
 

+ 2 - 3
numbat/src/ffi/plot.rs

@@ -1,7 +1,6 @@
 #[cfg(feature = "plotting")]
 use plotly::Plot;
 
-#[cfg(feature = "plotting")]
 use crate::interpreter::RuntimeErrorKind;
 
 #[cfg(feature = "plotting")]
@@ -124,8 +123,8 @@ pub fn show(args: Args) -> Result<Value, Box<RuntimeErrorKind>> {
 }
 
 #[cfg(not(feature = "plotting"))]
-pub fn show(_args: Args) -> Result<Value> {
-    return Err(Box::new(RuntimeError::UserError(
+pub fn show(_args: Args) -> Result<Value, Box<RuntimeErrorKind>> {
+    return Err(Box::new(RuntimeErrorKind::UserError(
         "Plotting is currently not supported on this platform.".into(),
     )));
 }

+ 3 - 3
numbat/src/vm.rs

@@ -391,7 +391,7 @@ impl Vm {
         let (bytecode, spans) = self.current_chunk_mut();
         bytecode.push(op as u8);
         Self::push_u16(bytecode, arg);
-        spans.extend(std::iter::repeat_n(span, 3));
+        spans.extend(std::iter::repeat(span).take(3));
     }
 
     pub(crate) fn add_op2(&mut self, op: Op, arg1: u16, arg2: u16, span: Span) {
@@ -399,7 +399,7 @@ impl Vm {
         bytecode.push(op as u8);
         Self::push_u16(bytecode, arg1);
         Self::push_u16(bytecode, arg2);
-        spans.extend(std::iter::repeat_n(span, 5));
+        spans.extend(std::iter::repeat(span).take(5));
     }
 
     pub(crate) fn add_op3(&mut self, op: Op, arg1: u16, arg2: u16, arg3: u16, span: Span) {
@@ -408,7 +408,7 @@ impl Vm {
         Self::push_u16(bytecode, arg1);
         Self::push_u16(bytecode, arg2);
         Self::push_u16(bytecode, arg3);
-        spans.extend(std::iter::repeat_n(span, 7));
+        spans.extend(std::iter::repeat(span).take(7));
     }
 
     pub fn current_offset(&self) -> u16 {