1use sim_kernel::Symbol;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum ClLiteFormRole {
6 Binding,
8 Control,
10 Dispatch,
12 Namespace,
14 Mutation,
16}
17
18#[derive(Clone, Debug, PartialEq, Eq)]
20pub struct ClLiteFormSpec {
21 pub symbol: Symbol,
23 pub role: ClLiteFormRole,
25 pub organ: Symbol,
27 pub doc: &'static str,
29}
30
31pub fn cl_lite_form_specs() -> Vec<ClLiteFormSpec> {
33 vec![
34 binding_form(
35 "defun",
36 "Define a function through the shared binding organ.",
37 ),
38 binding_form(
39 "defmacro",
40 "Define a macro function through the binding organ.",
41 ),
42 binding_form(
43 "let",
44 "Enter a lexical binding frame through the binding organ.",
45 ),
46 mutation_form("setq", "Update a CL-lite variable through a mutation cell."),
47 control_form(
48 "handler-case",
49 "Signal to the nearest condition handler through the control organ.",
50 ),
51 control_form(
52 "restart-case",
53 "Expose and invoke restarts through the control organ.",
54 ),
55 dispatch_form(
56 "defgeneric",
57 "Declare a generic function backed by the dispatch organ.",
58 ),
59 dispatch_form(
60 "defmethod",
61 "Attach a primary method through the dispatch organ.",
62 ),
63 namespace_form(
64 "defpackage",
65 "Create a package through the namespace organ.",
66 ),
67 namespace_form(
68 "in-package",
69 "Resolve the current package through the namespace organ.",
70 ),
71 mutation_form(
72 "setf",
73 "Update generalized places through the mutation organ.",
74 ),
75 ]
76}
77
78fn binding_form(name: &'static str, doc: &'static str) -> ClLiteFormSpec {
79 ClLiteFormSpec {
80 symbol: Symbol::qualified("cl", name),
81 role: ClLiteFormRole::Binding,
82 organ: sim_lib_binding::binding_organ_symbol(),
83 doc,
84 }
85}
86
87fn control_form(name: &'static str, doc: &'static str) -> ClLiteFormSpec {
88 ClLiteFormSpec {
89 symbol: Symbol::qualified("cl", name),
90 role: ClLiteFormRole::Control,
91 organ: sim_lib_control::control_organ_symbol(),
92 doc,
93 }
94}
95
96fn dispatch_form(name: &'static str, doc: &'static str) -> ClLiteFormSpec {
97 ClLiteFormSpec {
98 symbol: Symbol::qualified("cl", name),
99 role: ClLiteFormRole::Dispatch,
100 organ: sim_lib_dispatch::dispatch_organ_symbol(),
101 doc,
102 }
103}
104
105fn namespace_form(name: &'static str, doc: &'static str) -> ClLiteFormSpec {
106 ClLiteFormSpec {
107 symbol: Symbol::qualified("cl", name),
108 role: ClLiteFormRole::Namespace,
109 organ: sim_lib_namespace::namespace_organ_symbol(),
110 doc,
111 }
112}
113
114fn mutation_form(name: &'static str, doc: &'static str) -> ClLiteFormSpec {
115 ClLiteFormSpec {
116 symbol: Symbol::qualified("cl", name),
117 role: ClLiteFormRole::Mutation,
118 organ: sim_lib_mutation::mutation_organ_symbol(),
119 doc,
120 }
121}