#ifndef __CODE_H #define __CODE_H #include "thunk.h" enum CodeType { CT_VAR, CT_VAR_STRICT, CT_APP, CT_APP_DYN, CT_SELECT, CT_IF, CT_THUNK }; struct Code { CodeType type : 3; unsigned int nr_args : 5; // used in AppEntry unsigned int nr_cases : 5; // used in SelectEntry unsigned int strict : 1; // used in VarEntry }; struct ThunkEntry { struct Code base; struct Thunk thunk; }; struct VarEntry { struct Code base; int index; // index on the stack }; struct AppEntry { struct Code base; union { struct VarEntry var; struct Desc* f; }; struct Code* args[]; }; #define SC_CONS 1 #define SC_LIT 2 #define SC_DEFAULT 3 struct SelectCaseEntry { int type; struct Code* body; union { struct ADTEntry* cons; struct ThunkEntry* lit; }; }; struct SelectEntry { struct Code base; struct Code* expr; struct SelectCaseEntry cases[]; }; struct IfEntry { struct Code base; struct Code* cond; struct Code* texpr; struct Code* fexpr; }; void exec(Code* expr, int frame_ptr, int root_frame_ptr, int root_frame_ptr_b); struct Thunk* eval(Thunk* thunk); #endif // __CODE_H