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
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