refactor: function

This commit is contained in:
2025-05-10 20:01:56 +08:00
parent fa3193ea50
commit 046b03c60e
8 changed files with 293 additions and 277 deletions

View File

@@ -1,15 +1,15 @@
use ecow::EcoString;
use crate::ty::internal::Const;
use crate::ty::internal::{Const, Func};
type Slice<T> = Box<[T]>;
pub type ThunkIdx = usize;
pub type ConstIdx = usize;
pub type SymIdx = usize;
pub type FuncIdx = usize;
pub type OpCodes = Slice<OpCode>;
pub type Consts = Slice<Const>;
pub type Thunks = Slice<Thunk>;
pub type Funcs = Slice<Func>;
#[derive(Debug, Clone)]
pub struct Thunk {
@@ -34,16 +34,6 @@ pub enum OpCode {
Call { arity: usize },
/// make a function
Func { idx: ThunkIdx },
/// push param `sym` into TOS
PushIdentParam { sym: EcoString },
/// push formal param `sym` into TOS
PushFormalParam { sym: EcoString },
/// push default formal param with thunkidx `idx` into TOS
PushDefaultParam { idx: ThunkIdx },
/// TODO:
SetEllipsis,
/// TODO:
SetAlias { sym: EcoString },
/// consume 1 element, assert TOS is true
Assert,
@@ -118,4 +108,5 @@ pub enum UnOp {
pub struct Program {
pub top_level: OpCodes,
pub thunks: Thunks,
pub funcs: Box<[Func]>
}