Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmindlin committed Jun 18, 2024
1 parent 2b3ba36 commit 7bdd99a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scout-interpreter/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum BuiltinKind {
Len,
Input,
Contains,
Type,
}

impl BuiltinKind {
Expand All @@ -43,6 +44,7 @@ impl BuiltinKind {
"len" => Some(Len),
"input" => Some(Input),
"contains" => Some(Contains),
"type" => Some(Type),
_ => None,
}
}
Expand All @@ -55,6 +57,10 @@ impl BuiltinKind {
) -> EvalResult {
use BuiltinKind::*;
match self {
Type => {
assert_param_len!(args, 1);
Ok(Arc::new(Object::Str(args[0].type_str().to_string())))
}
Print => {
for obj in args {
println!("{obj}");
Expand Down
16 changes: 16 additions & 0 deletions scout-interpreter/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ pub enum Object {
Fn(Vec<Identifier>, Block),
}

impl Object {
pub fn type_str(&self) -> &str {
use Object::*;
match self {
Null => "null",
Map(_) => "map",
Str(_) => "string",
Node(_) => "node",
List(_) => "list",
Boolean(_) => "bool",
Number(_) => "number",
Fn(_, _) => "fn",
}
}
}

impl PartialEq for Object {
fn eq(&self, other: &Self) -> bool {
use Object::*;
Expand Down

0 comments on commit 7bdd99a

Please sign in to comment.