Debian Codegraph @

src/c/cinit.d

raw
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * cinit.d - lisp initialization
6 *
7 * Copyright (c) 1990 Giuseppe Attardi
8 * Copyright (c) 2001 Juan Jose Garcia Ripoll
9 *
10 * See file 'LICENSE' for the copyright details.
11 *
12 */
13
14 #include <stdio.h>
15 #include <ecl/ecl.h>
16 #include <ecl/internal.h>
17
18 /*
19 * HOOKS.
20 *
21 * The following functions are only used to bootstrap ECL. They divert
22 * the calls to the interpreted code which is loaded by bare.lsp. Once
23 * the whole of ECL is built, the file cinit.o will be replaced by the
24 * actual initialization code, and the compiled function will be
25 * called instead.
26 */
27
28 extern cl_object
29 cl_upgraded_array_element_type(cl_narg narg, cl_object type, ...)
30 {
31 return _ecl_funcall2(@'upgraded-array-element-type', type);
32 }
33
34 extern cl_object
35 si_safe_eval(cl_narg narg, cl_object form, cl_object env, ...)
36 {
37 if (narg == 3) {
38 cl_object err_value;
39 va_list args; va_start(args, env);
40 err_value = va_arg(args, cl_object);
41 va_end(args);
42 return _ecl_funcall4(@'ext::safe-eval', form, env, err_value);
43 }
44 return _ecl_funcall3(@'ext::safe-eval', form, env);
45 }
46
47 extern cl_object
48 cl_slot_value(cl_object instance, cl_object name)
49 {
50 return _ecl_funcall3(@'slot-value', instance, name);
51 }
52
53 extern cl_object
54 clos_slot_value_set(cl_object value, cl_object instance, cl_object name)
55 {
56 return _ecl_funcall4(@'clos::slot-value-set', value, instance, name);
57 }
58
59 extern cl_object
60 clos_std_compute_applicable_methods(cl_object gf, cl_object arglist)
61 {
62 return _ecl_funcall3(@'clos::std-compute-applicable-methods', gf, arglist);
63 }
64
65 extern cl_object
66 si_bind_simple_restarts(cl_object tag, cl_object names)
67 {
68 if (ECL_FBOUNDP(@'si::bind-simple-restarts'))
69 return _ecl_funcall3(@'si::bind-simple-restarts', tag, names);
70 else
71 return ECL_SYM_VAL(ecl_process_env(), @'si::*restart-clusters*');
72 }
73
74 extern cl_object
75 si_bind_simple_handlers(cl_object tag, cl_object names)
76 {
77 if (ECL_FBOUNDP(@'si::bind-simple-handlers'))
78 return _ecl_funcall3(@'si::bind-simple-handlers', tag, names);
79 else
80 return ECL_SYM_VAL(ecl_process_env(), @'si::*handler-clusters*');
81 }
82
83 extern cl_object
84 clos_std_compute_effective_method(cl_object gf, cl_object combination, cl_object methods_list)
85 {
86 return _ecl_funcall4(@'clos::std-compute-effective-method', gf, combination, methods_list);
87 }
88
89 extern cl_object
90 clos_compute_effective_method_function(cl_object gf, cl_object combination, cl_object methods_list)
91 {
92 return _ecl_funcall4(@'clos::compute-effective-method-function', gf, combination, methods_list);
93 }
94
95 extern cl_object
96 si_string_to_object(cl_narg narg, cl_object string, ...)
97 {
98 if (narg == 2) {
99 cl_object err_value;
100 va_list args; va_start(args, string);
101 err_value = va_arg(args, cl_object);
102 va_end(args);
103 return _ecl_funcall3(@'si::string-to-object', string, err_value);
104 }
105 return _ecl_funcall2(@'si::string-to-object', string);
106 }
107
108 extern cl_object
109 si_signal_simple_error(cl_narg narg, cl_object condition, cl_object continuable, cl_object format, cl_object format_args, ...)
110 {
111 ecl_va_list args;
112 cl_object rest;
113 ecl_va_start(args, format_args, narg, 4);
114 rest = cl_grab_rest_args(args);
115 ecl_va_end(args);
116 return cl_apply(6, @'si::signal-simple-error', condition, continuable,
117 format, format_args, rest);
118 }
119
120 extern cl_object
121 cl_set_difference(cl_narg narg, cl_object l1, cl_object l2, ...)
122 {
123 @(return l1);
124 }
125
126 extern cl_object
127 cl_array_dimensions(cl_object array)
128 {
129 return _ecl_funcall2(@'ARRAY-DIMENSIONS', array);
130 }
131
132 extern cl_object
133 si_wrong_type_argument(cl_narg narg, cl_object object, cl_object type, ...)
134 {
135 return _ecl_funcall3(@'si::wrong-type-argument', object, type);
136 }
137
138 static cl_object si_simple_toplevel ()
139 {
140 cl_env_ptr env = ecl_process_env();
141 cl_object output = cl_core.standard_output;
142 cl_object sentence;
143 int i;
144
145 /* Simple minded top level loop */
146 ECL_CATCH_ALL_BEGIN(env) {
147 writestr_stream(";*** Lisp core booted ****\n"
148 "ECL (Embeddable Common Lisp)\n",
149 output);
150 ecl_force_output(output);
151 for (i = 1; i<ecl_fixnum(si_argc()); i++) {
152 cl_object arg = si_argv(ecl_make_fixnum(i));
153 cl_load(1, arg);
154 }
155 while (1) {
156 writestr_stream("\n> ", output);
157 sentence = @read(3, ECL_NIL, ECL_NIL, OBJNULL);
158 if (sentence == OBJNULL) {
159 @(return);
160 }
161 sentence = si_eval_with_env(1, sentence);
162 ecl_prin1(sentence, output);
163 }
164 } ECL_CATCH_ALL_END;
165 @(return);
166 }
167
168 int
169 main(int argc, char **args)
170 {
171 cl_object top_level, features;
172
173 /* This should be always the first call */
174 cl_boot(argc, args);
175
176 /* We are computing unnormalized numbers at some point */
177 si_trap_fpe(ECL_T, ECL_NIL);
178
179 #ifdef ECL_CMU_FORMAT
180 ECL_SET(@'*load-verbose*', ECL_NIL);
181 #endif
182 ECL_SET(@'*package*', cl_core.system_package);
183
184 features = ecl_symbol_value(@'*features*');
185 features = CONS(ecl_make_keyword("ECL-MIN"), features);
186 #ifdef HAVE_UNAME
187 features = CONS(ecl_make_keyword("UNAME"), features);
188 #endif
189 ECL_SET(@'*features*', features);
190 top_level = _ecl_intern("TOP-LEVEL", cl_core.system_package);
191 ecl_def_c_function(top_level, (cl_objectfn_fixed)si_simple_toplevel, 0);
192 _ecl_funcall1(top_level);
193 return(0);
194 }
195
196 #ifdef __cplusplus
197 extern "C" void init_lib_LSP(cl_object);
198 #endif
199
200 void init_lib_LSP(cl_object o) {}