refactor(tazjin/rlox): Move treewalk interpreter into subdirectory
Change-Id: I9163f75db5a1ff75e1b1f81bad78fd9d8ddb104a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2409 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
This commit is contained in:
parent
052f8976bb
commit
f8b3e2a100
7 changed files with 9 additions and 8 deletions
25
users/tazjin/rlox/src/treewalk/interpreter/builtins.rs
Normal file
25
users/tazjin/rlox/src/treewalk/interpreter/builtins.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::fmt;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::errors::Error;
|
||||
use crate::treewalk::interpreter::Value;
|
||||
use crate::parser::Literal;
|
||||
|
||||
pub trait Builtin: fmt::Debug {
|
||||
fn arity(&self) -> usize;
|
||||
fn call(&self, args: Vec<Value>) -> Result<Value, Error>;
|
||||
}
|
||||
|
||||
// Builtin to return the current timestamp.
|
||||
#[derive(Debug)]
|
||||
pub struct Clock {}
|
||||
impl Builtin for Clock {
|
||||
fn arity(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn call(&self, _args: Vec<Value>) -> Result<Value, Error> {
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
Ok(Value::Literal(Literal::Number(now.as_secs() as f64)))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue