-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0901ac0
commit e3e874c
Showing
12 changed files
with
766 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use r_derive::*; | ||
|
||
use crate::callable::core::*; | ||
use crate::formals; | ||
use crate::lang::*; | ||
use crate::object::*; | ||
|
||
#[doc(alias = "typeof")] | ||
#[builtin(sym = "typeof")] | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct PrimitiveTypeOf; | ||
|
||
formals!(PrimitiveTypeOf, "(x,)"); | ||
|
||
impl Callable for PrimitiveTypeOf { | ||
fn call_matched(&self, args: List, _ellipsis: List, stack: &mut CallStack) -> EvalResult { | ||
let mut args = Obj::List(args); | ||
let x = args.try_get_named("x")?.force(stack)?; | ||
|
||
let t = match x { | ||
Obj::Null => "null", | ||
Obj::Vector(v) => match v { | ||
Vector::Character(_) => "character", | ||
Vector::Integer(_) => "integer", | ||
Vector::Double(_) => "double", | ||
Vector::Logical(_) => "logical", | ||
}, | ||
Obj::List(_) => "list", | ||
Obj::Expr(_) => "expression", | ||
Obj::Promise(..) => "promise", | ||
Obj::Function(..) => "function", | ||
Obj::Environment(..) => "environment", | ||
}; | ||
EvalResult::Ok(Obj::Vector(Vector::Character(vec![t.to_string()].into()))) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
||
mod tests { | ||
use crate::{r, r_expect}; | ||
#[test] | ||
fn character() { | ||
r_expect!(typeof("a") == "character") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.