nexus_lib/evaluator/
objects.rs1use std::fmt::Display;
2
3use crate::{
4 evaluator::builtins::BuiltinFunc,
5 lexer::tokens::Literal,
6 parser::ast::{BlockStmt, Ident, OptionallyTypedIdent},
7};
8
9use super::util;
10
11#[derive(Debug, Clone)]
12pub enum Object {
13 Lit(Literal),
14 None,
15 Err,
17 Use,
19 Ret(Box<Object>),
21 Br(Ident),
23 Func(FuncObj),
24 BuiltinFunc(BuiltinFunc),
25 Range,
27 Type,
28 List,
29}
30
31#[derive(Debug, Clone)]
32pub struct FuncObj {
33 pub args: Vec<OptionallyTypedIdent>,
34 pub block: BlockStmt,
35}
36
37#[derive(Debug, PartialEq, PartialOrd)]
38pub enum Comparable {
39 Lit(Literal),
40 None,
41}
42
43impl Display for Object {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 write!(
46 f,
47 "{}",
48 match self {
49 Object::Lit(lit) => lit.to_string(),
50 Object::None => "none".into(),
51 Object::Err => todo!(),
52 Object::Use => todo!(),
53 Object::Ret(_) => todo!(),
54 Object::Br(_) => todo!(),
55 Object::Func(func) => format!(
56 "func({}) {{\n{}\n}}",
57 util::typed_vec_to_string(&func.args),
58 util::block_to_string(&func.block)
59 ),
60 Object::BuiltinFunc(func) => match func.get_ret_val() {
61 Some(func) => func.to_string(),
62 None => todo!(),
63 },
64 Object::Range => todo!(),
65 Object::Type => todo!(),
66 Object::List => todo!(),
67 }
68 )
69 }
70}