Browse Source

hacky ECL???

master
eta 4 months ago
parent
commit
f280d24db2
  1. 45
      nest/cmds.c
  2. 3
      nest/config.Y
  3. 28
      sysdep/unix/main.c

45
nest/cmds.c

@ -15,6 +15,7 @@
#include "lib/string.h"
#include "lib/resource.h"
#include "filter/filter.h"
#include <ecl/ecl.h>
extern int shutting_down;
extern int configuring;
@ -109,3 +110,47 @@ cmd_eval(const struct f_line *expr)
cli_msg(23, "%s", buf.start);
}
char* ecl_get_string_for(cl_object obj) {
cl_object formatted = cl_princ_to_string(obj);
assert(ECL_STRINGP(formatted));
if (!ecl_fits_in_base_string(formatted)) {
return NULL; // sad
}
cl_object base = si_coerce_to_base_string(formatted);
char* ret = base->base_string.self;
return ret;
}
void
cmd_cl_eval(char *obj)
{
cl_env_ptr env = ecl_process_env();
cl_object form = ecl_read_from_cstring_safe(obj, ECL_NIL);
if (ecl_eql(form, ECL_NIL)) {
cli_msg(8041, "nil form or error in reader");
return;
}
cl_object result = ECL_NIL;
ECL_HANDLER_CASE_BEGIN(env, ecl_list1(ECL_T)) {
result = cl_eval(form);
} ECL_HANDLER_CASE(1, condition) {
char* err = ecl_get_string_for(condition);
cli_msg(8041, "runtime error: %s", err ? err : "wat");
return;
} ECL_HANDLER_CASE_END;
char* disp = ecl_get_string_for(result);
if (!disp) {
cli_msg(8043, "unicode what");
return;
}
char* newline = "\n";
char* line = strtok(disp, newline);
while (line != NULL) {
char* next = strtok(NULL, newline);
int errcode = next == NULL ? 44 : -8044;
cli_msg(errcode, line);
line = next;
}
}

3
nest/config.Y

@ -805,6 +805,9 @@ CF_CLI(DUMP FILTER ALL,,, [[Dump all filters in linearized form]])
CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
{ cmd_eval(f_linearize($2)); } ;
CF_CLI(CLEVAL, text, <string>, [[Evaluate Common Lisp code]])
{ cmd_cl_eval($2); } ;
CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug|trace|info|remote|warning|error|auth [, ...] }) [<buffer-size>], [[Control echoing of log messages]]) {
cli_set_log_echo(this_cli, $2, $3);

28
sysdep/unix/main.c

@ -22,6 +22,7 @@
#include <sys/stat.h>
#include <sys/utsname.h>
#include <libgen.h>
#include <ecl/ecl.h>
#include "nest/bird.h"
#include "lib/lists.h"
@ -852,6 +853,21 @@ parse_args(int argc, char **argv)
}
}
#define ecls(x) ecl_make_simple_base_string(x,-1)
#define eclcs(x) ecl_make_constant_base_string(x,-1)
cl_object
clbird_version()
{
return eclcs(BIRD_VERSION);
}
void
init_ecl_functions()
{
cl_object package = ecl_make_package(eclcs("BIRD"), ECL_NIL, ECL_NIL, ECL_NIL);
ecl_def_c_function(_ecl_intern("version", package), clbird_version, 0);
}
/*
* Hic Est main()
*/
@ -923,6 +939,18 @@ main(int argc, char **argv)
write_pid_file();
log(L_INFO "Booting ECL");
ecl_set_option(ECL_OPT_TRAP_SIGSEGV, FALSE);
ecl_set_option(ECL_OPT_TRAP_SIGFPE, FALSE);
ecl_set_option(ECL_OPT_TRAP_SIGINT, FALSE);
ecl_set_option(ECL_OPT_TRAP_SIGILL, FALSE);
ecl_set_option(ECL_OPT_TRAP_INTERRUPT_SIGNAL, FALSE);
cl_boot(argc, argv);
init_ecl_functions();
log(L_INFO "ECL interpreter booted");
signal_init();
config_commit(conf, RECONFIG_HARD, 0);

Loading…
Cancel
Save