From e1efd41abe6177b3daf1c02053767a70b71f1b2c Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 18 Aug 2020 09:36:19 +0200 Subject: [PATCH] core: builtins: MES_MINI. * include/mes/mes.h (g_mini): New global. * src/mes.c (init): Initialize it with environment variable MES_MINI. * src/builtins.c (mes_builtins): Register a minimal set of builtins when g_mini. --- include/mes/mes.h | 1 + src/builtins.c | 22 +++++++++++++++++++--- src/mes.c | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/mes/mes.h b/include/mes/mes.h index 11df1a35..dee7d31f 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -59,6 +59,7 @@ char *g_buf; SCM g_continuations; SCM g_symbols; SCM g_symbol_max; +int g_mini; /* a/env */ SCM R0; diff --git a/src/builtins.c b/src/builtins.c index dae42312..4c0747ad 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -109,11 +109,27 @@ init_builtin (SCM builtin_type, char const *name, int arity, FUNCTION function, SCM mes_builtins (SCM a) /*:((internal)) */ { - // TODO minimal: cons, car, cdr, list, null_p, eq_p minus, plus - // display_, display_error_, getenv - SCM builtin_type = make_builtin_type (); + if (g_mini != 0) + { + a = init_builtin (builtin_type, "cons", 2, &cons, a); + a = init_builtin (builtin_type, "car", 1, &car, a); + a = init_builtin (builtin_type, "list", -1, &list, a); + a = init_builtin (builtin_type, "eq?", 2, &eq_p, a); + a = init_builtin (builtin_type, "-", -1, &minus, a); + a = init_builtin (builtin_type, "+", -1, &plus, a); + a = init_builtin (builtin_type, "core:display", 1, &display_, a); + a = init_builtin (builtin_type, "core:write", 1, &write_, a); + a = init_builtin (builtin_type, "core:display-error", 1, &display_error_, a); + a = init_builtin (builtin_type, "getenv", 1, &getenv_, a); + a = init_builtin (builtin_type, "gc", 0, &gc, a); + a = init_builtin (builtin_type, ">", -1, &greater_p, a); + a = init_builtin (builtin_type, "<", -1, &less_p, a); + a = init_builtin (builtin_type, "make-vector", -1, &make_vector, a); + return a; + } + /* src/builtins.c */ a = init_builtin (builtin_type, "make-builtin", 4, &make_builtin, a); a = init_builtin (builtin_type, "builtin-name", 1, &builtin_name, a); diff --git a/src/mes.c b/src/mes.c index 90831590..927b5eb1 100644 --- a/src/mes.c +++ b/src/mes.c @@ -177,6 +177,7 @@ init (char **envp) char *p; if (p = getenv ("MES_DEBUG")) g_debug = atoi (p); + g_mini = getenv ("MES_MINI"); open_boot (); gc_init (); }