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:
Vincent Ambo 2021-01-17 12:13:52 +03:00 committed by tazjin
parent 052f8976bb
commit f8b3e2a100
7 changed files with 9 additions and 8 deletions

View file

@ -1,25 +0,0 @@
use std::fmt;
use std::time::{SystemTime, UNIX_EPOCH};
use crate::errors::Error;
use crate::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)))
}
}