cao_lang/vm/runtime/
cao_lang_function.rs1use std::ptr::NonNull;
2
3use crate::{prelude::Handle, value::Value};
4
5use super::cao_lang_object::CaoLangObject;
6
7#[derive(Debug)]
8pub struct CaoLangFunction {
9 pub handle: Handle,
10 pub arity: u32,
11}
12
13#[derive(Debug)]
14pub struct CaoLangNativeFunction {
15 pub handle: Handle,
16}
17
18pub struct CaoLangClosure {
19 pub function: CaoLangFunction,
20 pub upvalues: Vec<NonNull<CaoLangObject>>,
21}
22
23impl std::fmt::Debug for CaoLangClosure {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 f.debug_struct("CaoLangClosure")
26 .field("function", &self.function)
27 .field(
28 "upvalues",
29 &self
30 .upvalues
31 .iter()
32 .map(|u| unsafe { (u, u.as_ref()) })
33 .collect::<Vec<_>>(),
34 )
35 .finish()
36 }
37}
38
39#[derive(Debug)]
40pub struct CaoLangUpvalue {
41 pub location: *mut Value,
42 pub value: Value,
43 pub next: *mut CaoLangObject,
44}