mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
repl: Create dumy Wasm implementations of SystemTime and Duration
This commit is contained in:
parent
8e370a32b6
commit
a0ccae2865
3 changed files with 50 additions and 1 deletions
|
@ -43,9 +43,13 @@ use std::iter;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::from_utf8_unchecked;
|
use std::str::from_utf8_unchecked;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime};
|
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
use std::time::{Duration, SystemTime};
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
use wasm_system_time::{Duration, SystemTime};
|
||||||
|
|
||||||
/// Default name for the binary generated for an app, if an invalid one was specified.
|
/// Default name for the binary generated for an app, if an invalid one was specified.
|
||||||
const DEFAULT_APP_OUTPUT_PATH: &str = "app";
|
const DEFAULT_APP_OUTPUT_PATH: &str = "app";
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,6 @@
|
||||||
#![allow(clippy::large_enum_variant)]
|
#![allow(clippy::large_enum_variant)]
|
||||||
pub mod docs;
|
pub mod docs;
|
||||||
pub mod file;
|
pub mod file;
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
mod wasm_system_time;
|
||||||
|
|
42
compiler/load/src/wasm_system_time.rs
Normal file
42
compiler/load/src/wasm_system_time.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#![cfg(target_family = "wasm")]
|
||||||
|
/*
|
||||||
|
For the Web REPL (repl_www), we build the compiler as a Wasm module.
|
||||||
|
SystemTime is the only thing in the compiler that would need a special implementation for this.
|
||||||
|
There is a WASI implementation for it, but we are targeting the browser, not WASI!
|
||||||
|
It's possible to write browser versions of WASI's low-level ABI but we'd rather avoid it.
|
||||||
|
Instead we use these dummy implementations, which should just disappear at compile time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct SystemTime;
|
||||||
|
|
||||||
|
impl SystemTime {
|
||||||
|
fn now() -> Self {
|
||||||
|
SystemTime
|
||||||
|
}
|
||||||
|
fn duration_since(&self, _: SystemTime) -> Result<Duration, String> {
|
||||||
|
Ok(Duration)
|
||||||
|
}
|
||||||
|
fn elapsed(&self) -> Result<Duration, String> {
|
||||||
|
Ok(Duration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct Duration;
|
||||||
|
|
||||||
|
impl Duration {
|
||||||
|
fn checked_sub(&self, _: Duration) -> Option<Duration> {
|
||||||
|
Some(Duration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Duration {
|
||||||
|
fn default() -> Self {
|
||||||
|
Duration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::AddAssign for Duration {
|
||||||
|
fn add_assign(&mut self, _: Duration) {}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue