2016-10-17 17:26:07 +01:00
|
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 13:24:36 +01:00
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2019-03-02 13:36:22 +00:00
|
|
|
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-05-28 15:39:44 +01:00
|
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
|
* This file is part of GNU Mes.
|
2016-05-28 15:39:44 +01:00
|
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2016-05-28 15:39:44 +01:00
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2016-05-28 15:39:44 +01:00
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-22 13:24:36 +01:00
|
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-28 15:39:44 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
|
#include "mes/lib.h"
|
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
2017-05-02 22:30:46 +01:00
|
|
|
|
#include <assert.h>
|
2019-03-02 13:36:22 +00:00
|
|
|
|
#include <fcntl.h>
|
2017-05-02 22:30:46 +01:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2019-03-02 13:36:22 +00:00
|
|
|
|
#include <string.h>
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
|
char g_datadir[1024];
|
|
|
|
|
int g_debug;
|
|
|
|
|
char *g_buf;
|
|
|
|
|
SCM g_continuations;
|
|
|
|
|
SCM g_symbols;
|
|
|
|
|
SCM g_symbol_max;
|
2018-12-30 05:56:06 +00:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// a/env
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM r0;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// param 1
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM r1;
|
2018-12-20 15:47:56 +00:00
|
|
|
|
// save 2
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM r2;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// continuation
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM r3;
|
2018-10-14 08:10:30 +01:00
|
|
|
|
// current-module
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM m0;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
// macro
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM g_macros;
|
|
|
|
|
SCM g_ports;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
2019-01-04 08:28:46 +00:00
|
|
|
|
#if __MESC__
|
|
|
|
|
typedef long function0_t;
|
|
|
|
|
typedef long function1_t;
|
|
|
|
|
typedef long function2_t;
|
|
|
|
|
typedef long function3_t;
|
|
|
|
|
typedef long functionn_t;
|
|
|
|
|
#else // !__MESC__
|
2018-08-12 15:53:21 +01:00
|
|
|
|
typedef SCM (*function0_t) (void);
|
|
|
|
|
typedef SCM (*function1_t) (SCM);
|
|
|
|
|
typedef SCM (*function2_t) (SCM, SCM);
|
|
|
|
|
typedef SCM (*function3_t) (SCM, SCM, SCM);
|
|
|
|
|
typedef SCM (*functionn_t) (SCM);
|
2019-01-04 08:28:46 +00:00
|
|
|
|
#endif // !__MESC__
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
2018-08-11 10:42:30 +01:00
|
|
|
|
alloc (long n)
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
SCM x = g_free;
|
|
|
|
|
g_free += n;
|
2018-11-11 09:01:49 +00:00
|
|
|
|
if (g_free > ARENA_SIZE)
|
|
|
|
|
assert (!"alloc: out of memory");
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return x;
|
|
|
|
|
}
|
2016-10-27 15:44:09 +01:00
|
|
|
|
|
2016-12-23 17:05:45 +00:00
|
|
|
|
SCM
|
2018-08-11 10:42:30 +01:00
|
|
|
|
make_cell__ (long type, SCM car, SCM cdr)
|
2016-12-23 17:05:45 +00:00
|
|
|
|
{
|
2018-04-14 07:15:49 +01:00
|
|
|
|
SCM x = alloc (1);
|
|
|
|
|
TYPE (x) = type;
|
|
|
|
|
CAR (x) = car;
|
|
|
|
|
CDR (x) = cdr;
|
|
|
|
|
return x;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
make_cell_ (SCM type, SCM car, SCM cdr)
|
2016-11-21 08:28:34 +00:00
|
|
|
|
{
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
assert (TYPE (type) == TNUMBER);
|
2018-08-11 10:42:30 +01:00
|
|
|
|
long t = VALUE (type);
|
2018-04-14 07:15:49 +01:00
|
|
|
|
if (t == TCHAR || t == TNUMBER)
|
|
|
|
|
return make_cell__ (t, car ? CAR (car) : 0, cdr ? CDR (cdr) : 0);
|
|
|
|
|
return make_cell__ (t, car, cdr);
|
2016-10-26 18:44:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 21:38:19 +01:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
assoc_string (SCM x, SCM a) ///((internal))
|
2018-10-19 21:38:19 +01:00
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
while (a != cell_nil && (TYPE (CAAR (a)) != TSTRING || string_equal_p (x, CAAR (a)) == cell_f))
|
2018-10-19 21:38:19 +01:00
|
|
|
|
a = CDR (a);
|
|
|
|
|
return a != cell_nil ? CAR (a) : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM
|
|
|
|
|
type_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return MAKE_NUMBER (TYPE (x));
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 15:25:36 +00:00
|
|
|
|
// SCM
|
|
|
|
|
// car_to_cell_ (SCM x)
|
|
|
|
|
// {
|
|
|
|
|
// return CAR (x);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// SCM
|
|
|
|
|
// cdr_to_cell_ (SCM x)
|
|
|
|
|
// {
|
|
|
|
|
// return CDR (x);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// SCM
|
|
|
|
|
// car_to_number_ (SCM x)
|
|
|
|
|
// {
|
|
|
|
|
// return MAKE_NUMBER (CAR (x));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// SCM
|
|
|
|
|
// cdr_to_number_ (SCM x)
|
|
|
|
|
// {
|
|
|
|
|
// return MAKE_NUMBER (CDR (x));
|
|
|
|
|
// }
|
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM
|
|
|
|
|
car_ (SCM x)
|
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
return (TYPE (x) != TCONTINUATION && (TYPE (CAR (x)) == TPAIR // FIXME: this is weird
|
|
|
|
|
|| TYPE (CAR (x)) == TREF
|
|
|
|
|
|| TYPE (CAR (x)) == TSPECIAL
|
|
|
|
|
|| TYPE (CAR (x)) == TSYMBOL
|
|
|
|
|
|| TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x));
|
2017-03-25 14:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr_ (SCM x)
|
|
|
|
|
{
|
2018-04-09 06:12:38 +01:00
|
|
|
|
return (TYPE (x) != TCHAR
|
|
|
|
|
&& TYPE (x) != TNUMBER
|
2018-10-15 11:28:02 +01:00
|
|
|
|
&& TYPE (x) != TPORT
|
2018-04-09 06:12:38 +01:00
|
|
|
|
&& (TYPE (CDR (x)) == TPAIR
|
|
|
|
|
|| TYPE (CDR (x)) == TREF
|
|
|
|
|
|| TYPE (CDR (x)) == TSPECIAL
|
2019-02-16 11:27:42 +00:00
|
|
|
|
|| TYPE (CDR (x)) == TSYMBOL || TYPE (CDR (x)) == TSTRING)) ? CDR (x) : MAKE_NUMBER (CDR (x));
|
2017-03-25 14:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
cons (SCM x, SCM y)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2018-04-14 07:15:49 +01:00
|
|
|
|
return make_cell__ (TPAIR, x, y);
|
2016-05-28 15:39:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
|
|
|
|
car (SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CAR (x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr (SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CDR (x);
|
|
|
|
|
}
|
2017-01-18 06:38:45 +00:00
|
|
|
|
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
list (SCM x) ///((arity . n))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
{
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
|
|
|
|
null_p (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return x == cell_nil ? cell_t : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
SCM
|
|
|
|
|
eq_p (SCM x, SCM y)
|
|
|
|
|
{
|
|
|
|
|
return (x == y
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|| ((TYPE (x) == TKEYWORD && TYPE (y) == TKEYWORD
|
2018-11-11 15:25:36 +00:00
|
|
|
|
&& string_equal_p (x, y) == cell_t))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|| (TYPE (x) == TCHAR && TYPE (y) == TCHAR
|
2017-01-04 07:16:14 +00:00
|
|
|
|
&& VALUE (x) == VALUE (y))
|
2019-02-16 11:27:42 +00:00
|
|
|
|
|| (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER && VALUE (x) == VALUE (y))) ? cell_t : cell_f;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
}
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|
2016-12-23 17:05:45 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
values (SCM x) ///((arity . n))
|
2016-12-23 17:05:45 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM v = cons (0, x);
|
|
|
|
|
TYPE (v) = TVALUES;
|
|
|
|
|
return v;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
acons (SCM key, SCM value, SCM alist)
|
2016-12-23 17:05:45 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return cons (cons (key, value), alist);
|
2016-07-10 12:47:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-11 10:42:30 +01:00
|
|
|
|
long
|
2019-02-16 11:27:42 +00:00
|
|
|
|
length__ (SCM x) ///((internal))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
{
|
2018-08-11 10:42:30 +01:00
|
|
|
|
long n = 0;
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
n++;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
2018-04-14 07:15:49 +01:00
|
|
|
|
return -1;
|
2017-04-12 20:27:59 +01:00
|
|
|
|
x = CDR (x);
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
}
|
2018-04-14 07:15:49 +01:00
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
length (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return MAKE_NUMBER (length__ (x));
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
error (SCM key, SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM throw;
|
2018-10-14 07:30:18 +01:00
|
|
|
|
if ((throw = module_ref (r0, cell_symbol_throw)) != cell_undefined)
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
return apply (throw, cons (key, cons (x, cell_nil)), r0);
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2017-03-25 14:58:44 +00:00
|
|
|
|
display_error_ (key);
|
2017-03-26 21:12:24 +01:00
|
|
|
|
eputs (": ");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (x);
|
2017-03-26 21:12:24 +01:00
|
|
|
|
eputs ("\n");
|
2018-10-19 22:01:59 +01:00
|
|
|
|
assert (0);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
exit (1);
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// extra lib
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
assert_defined (SCM x, SCM e) ///((internal))
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (e == cell_undefined)
|
|
|
|
|
return error (cell_symbol_unbound_variable, x);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
check_formals (SCM f, SCM formals, SCM args) ///((internal))
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
2018-08-11 10:42:30 +01:00
|
|
|
|
long flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : length__ (formals);
|
|
|
|
|
long alen = length__ (args);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
if (alen != flen && alen != -1 && flen != -1)
|
|
|
|
|
{
|
|
|
|
|
char *s = "apply: wrong number of arguments; expected: ";
|
|
|
|
|
eputs (s);
|
|
|
|
|
eputs (itoa (flen));
|
|
|
|
|
eputs (", got: ");
|
|
|
|
|
eputs (itoa (alen));
|
|
|
|
|
eputs ("\n");
|
2018-04-09 06:12:38 +01:00
|
|
|
|
write_error_ (f);
|
2018-11-11 15:25:36 +00:00
|
|
|
|
SCM e = MAKE_STRING0 (s);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return error (cell_symbol_wrong_number_of_args, cons (e, f));
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
check_apply (SCM f, SCM e) ///((internal))
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
char *type = 0;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (f == cell_f || f == cell_t)
|
|
|
|
|
type = "bool";
|
|
|
|
|
if (f == cell_nil)
|
|
|
|
|
type = "nil";
|
|
|
|
|
if (f == cell_unspecified)
|
|
|
|
|
type = "*unspecified*";
|
|
|
|
|
if (f == cell_undefined)
|
|
|
|
|
type = "*undefined*";
|
|
|
|
|
if (TYPE (f) == TCHAR)
|
|
|
|
|
type = "char";
|
|
|
|
|
if (TYPE (f) == TNUMBER)
|
|
|
|
|
type = "number";
|
|
|
|
|
if (TYPE (f) == TSTRING)
|
|
|
|
|
type = "string";
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (TYPE (f) == TSTRUCT && builtin_p (f) == cell_f)
|
2018-10-13 16:34:27 +01:00
|
|
|
|
type = "#<...>";
|
2018-04-21 12:31:12 +01:00
|
|
|
|
if (TYPE (f) == TBROKEN_HEART)
|
|
|
|
|
type = "<3";
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
|
{
|
|
|
|
|
char *s = "cannot apply: ";
|
|
|
|
|
eputs (s);
|
|
|
|
|
eputs (type);
|
|
|
|
|
eputs ("[");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (e);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("]\n");
|
2018-11-11 15:25:36 +00:00
|
|
|
|
SCM e = MAKE_STRING0 (s);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return error (cell_symbol_wrong_type_arg, cons (e, f));
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
append2 (SCM x, SCM y)
|
2016-07-10 12:47:56 +01:00
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (x == cell_nil)
|
|
|
|
|
return y;
|
|
|
|
|
if (TYPE (x) != TPAIR)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("append2")));
|
2018-04-20 13:38:24 +01:00
|
|
|
|
SCM r = cell_nil;
|
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
r = cons (CAR (x), r);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
return reverse_x_ (r, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
append_reverse (SCM x, SCM y)
|
|
|
|
|
{
|
|
|
|
|
if (x == cell_nil)
|
|
|
|
|
return y;
|
|
|
|
|
if (TYPE (x) != TPAIR)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("append-reverse")));
|
2018-04-20 13:38:24 +01:00
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
y = cons (CAR (x), y);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
reverse_x_ (SCM x, SCM t)
|
|
|
|
|
{
|
2018-04-29 17:14:01 +01:00
|
|
|
|
if (x != cell_nil && TYPE (x) != TPAIR)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("core:reverse!")));
|
2018-04-20 13:38:24 +01:00
|
|
|
|
SCM r = t;
|
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
t = CDR (x);
|
|
|
|
|
CDR (x) = r;
|
|
|
|
|
r = x;
|
|
|
|
|
x = t;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
2016-07-10 09:43:26 +01:00
|
|
|
|
}
|
2016-05-28 15:39:44 +01:00
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
pairlis (SCM x, SCM y, SCM a)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_nil)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
return a;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
2016-07-08 17:02:06 +01:00
|
|
|
|
return cons (cons (x, y), a);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
return cons (cons (car (x), car (y)), pairlis (cdr (x), cdr (y), a));
|
2016-05-28 15:39:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
assq (SCM x, SCM a)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2018-04-29 15:17:07 +01:00
|
|
|
|
if (TYPE (a) != TPAIR)
|
|
|
|
|
return cell_f;
|
2018-08-12 15:53:21 +01:00
|
|
|
|
int t = TYPE (x);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (t == TSYMBOL || t == TSPECIAL)
|
2018-10-18 17:50:09 +01:00
|
|
|
|
while (a != cell_nil && x != CAAR (a))
|
|
|
|
|
a = CDR (a);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (t == TCHAR || t == TNUMBER)
|
|
|
|
|
{
|
|
|
|
|
SCM v = VALUE (x);
|
|
|
|
|
while (a != cell_nil && v != VALUE (CAAR (a)))
|
|
|
|
|
a = CDR (a);
|
|
|
|
|
}
|
2018-10-18 17:50:09 +01:00
|
|
|
|
else if (t == TKEYWORD)
|
|
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
|
while (a != cell_nil && string_equal_p (x, CAAR (a)) == cell_f)
|
2018-10-18 17:50:09 +01:00
|
|
|
|
a = CDR (a);
|
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
else
|
2018-10-18 17:50:09 +01:00
|
|
|
|
/* pointer equality, e.g. on strings. */
|
2018-08-12 15:53:21 +01:00
|
|
|
|
while (a != cell_nil && x != CAAR (a))
|
|
|
|
|
a = CDR (a);
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return a != cell_nil ? CAR (a) : cell_f;
|
2016-10-19 23:11:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 21:38:19 +01:00
|
|
|
|
SCM
|
|
|
|
|
assoc (SCM x, SCM a)
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (x) == TSTRING)
|
|
|
|
|
return assoc_string (x, a);
|
|
|
|
|
while (a != cell_nil && equal2_p (x, CAAR (a)) == cell_f)
|
|
|
|
|
a = CDR (a);
|
|
|
|
|
return a != cell_nil ? CAR (a) : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
|
|
|
|
set_car_x (SCM x, SCM e)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("set-car!")));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
CAR (x) = e;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
set_cdr_x (SCM x, SCM e)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("set-cdr!")));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
CDR (x) = e;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
set_env_x (SCM x, SCM e, SCM a)
|
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM p;
|
|
|
|
|
if (TYPE (x) == TVARIABLE)
|
|
|
|
|
p = VARIABLE (x);
|
|
|
|
|
else
|
2018-10-14 07:30:18 +01:00
|
|
|
|
p = assert_defined (x, module_variable (a, x));
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (p) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (p, x));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
return set_cdr_x (p, e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal))
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM cl = cons (cons (cell_closure, x), x);
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
r1 = e;
|
|
|
|
|
r0 = cl;
|
2016-12-22 15:50:51 +00:00
|
|
|
|
return cell_unspecified;
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
make_closure_ (SCM args, SCM body, SCM a) ///((internal))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
{
|
2018-10-20 17:27:13 +01:00
|
|
|
|
return make_cell__ (TCLOSURE, cell_f, cons (cons (cell_circular, a), cons (args, body)));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
make_variable_ (SCM var) ///((internal))
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
2018-04-21 12:19:54 +01:00
|
|
|
|
return make_cell__ (TVARIABLE, var, 0);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
2018-10-18 17:50:09 +01:00
|
|
|
|
macro_get_handle (SCM name)
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
{
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 06:55:28 +01:00
|
|
|
|
if (TYPE (name) == TSYMBOL)
|
2018-10-18 17:50:09 +01:00
|
|
|
|
return hashq_get_handle (g_macros, name, cell_nil);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 06:55:28 +01:00
|
|
|
|
return cell_f;
|
2018-10-15 13:13:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
get_macro (SCM name) ///((internal))
|
2018-10-15 13:13:51 +01:00
|
|
|
|
{
|
2018-10-18 17:50:09 +01:00
|
|
|
|
SCM m = macro_get_handle (name);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (m != cell_f)
|
|
|
|
|
return MACRO (CDR (m));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
return cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 13:13:51 +01:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
macro_set_x (SCM name, SCM value) ///((internal))
|
2018-10-15 13:13:51 +01:00
|
|
|
|
{
|
2018-10-18 17:50:09 +01:00
|
|
|
|
return hashq_set_x (g_macros, name, value);
|
2018-10-15 13:13:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal))
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
SCM x = r3;
|
|
|
|
|
r3 = c;
|
|
|
|
|
r2 = p2;
|
|
|
|
|
gc_push_frame ();
|
|
|
|
|
r1 = p1;
|
2018-10-20 17:27:13 +01:00
|
|
|
|
r0 = a;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
r3 = x;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM
|
|
|
|
|
add_formals (SCM formals, SCM x)
|
|
|
|
|
{
|
|
|
|
|
while (TYPE (x) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
formals = cons (CAR (x), formals);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
if (TYPE (x) == TSYMBOL)
|
|
|
|
|
formals = cons (x, formals);
|
|
|
|
|
return formals;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2019-02-16 11:27:42 +00:00
|
|
|
|
formal_p (SCM x, SCM formals) /// ((internal))
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (TYPE (formals) == TSYMBOL)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (x == formals)
|
|
|
|
|
return x;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else
|
|
|
|
|
return cell_f;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
|
|
|
|
while (TYPE (formals) == TPAIR && CAR (formals) != x)
|
|
|
|
|
formals = CDR (formals);
|
|
|
|
|
if (TYPE (formals) == TSYMBOL)
|
|
|
|
|
return formals == x;
|
|
|
|
|
return TYPE (formals) == TPAIR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
expand_variable_ (SCM x, SCM formals, int top_p) ///((internal))
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
|
|
|
|
while (TYPE (x) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (CAR (x)) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (x) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CAR (CDAR (x));
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (CAAR (x) == cell_symbol_define || CAAR (x) == cell_symbol_define_macro)
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
|
|
|
|
SCM f = CAR (CDAR (x));
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
}
|
|
|
|
|
if (CAAR (x) != cell_symbol_quote)
|
|
|
|
|
expand_variable_ (CAR (x), formals, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CAR (x) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CADR (x);
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (CAR (x) == cell_symbol_define || CAR (x) == cell_symbol_define_macro)
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
|
|
|
|
SCM f = CADR (x);
|
|
|
|
|
if (top_p && TYPE (f) == TPAIR)
|
|
|
|
|
f = CDR (f);
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
else if (CAR (x) == cell_symbol_quote)
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
else if (TYPE (CAR (x)) == TSYMBOL
|
2018-10-15 09:44:47 +01:00
|
|
|
|
&& CAR (x) != cell_symbol_boot_module
|
2017-12-09 07:33:50 +00:00
|
|
|
|
&& CAR (x) != cell_symbol_current_module
|
2019-02-16 11:27:42 +00:00
|
|
|
|
&& CAR (x) != cell_symbol_primitive_load && !formal_p (CAR (x), formals))
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
2018-10-14 07:30:18 +01:00
|
|
|
|
SCM v = module_variable (r0, CAR (x));
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (v != cell_f)
|
2018-04-21 12:19:54 +01:00
|
|
|
|
CAR (x) = make_variable_ (v);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
top_p = 0;
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
expand_variable (SCM x, SCM formals) ///((internal))
|
2017-12-09 07:33:50 +00:00
|
|
|
|
{
|
|
|
|
|
return expand_variable_ (x, formals, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-12-22 15:34:28 +00:00
|
|
|
|
eval_apply ()
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
SCM aa;
|
|
|
|
|
SCM args;
|
|
|
|
|
SCM body;
|
|
|
|
|
SCM cl;
|
|
|
|
|
SCM entry;
|
|
|
|
|
SCM expanders;
|
|
|
|
|
SCM formals;
|
|
|
|
|
SCM input;
|
|
|
|
|
SCM name;
|
|
|
|
|
SCM macro;
|
|
|
|
|
SCM p;
|
|
|
|
|
SCM program;
|
|
|
|
|
SCM sc_expand;
|
2017-12-14 06:05:53 +00:00
|
|
|
|
SCM v;
|
2018-04-12 06:07:24 +01:00
|
|
|
|
SCM x;
|
|
|
|
|
int global_p;
|
|
|
|
|
int macro_p;
|
2018-08-12 15:53:21 +01:00
|
|
|
|
int t;
|
2018-10-04 20:43:45 +01:00
|
|
|
|
long c;
|
2018-04-12 06:07:24 +01:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
eval_apply:
|
|
|
|
|
if (r3 == cell_vm_evlis2)
|
|
|
|
|
goto evlis2;
|
|
|
|
|
else if (r3 == cell_vm_evlis3)
|
|
|
|
|
goto evlis3;
|
|
|
|
|
else if (r3 == cell_vm_eval_check_func)
|
|
|
|
|
goto eval_check_func;
|
|
|
|
|
else if (r3 == cell_vm_eval2)
|
|
|
|
|
goto eval2;
|
|
|
|
|
else if (r3 == cell_vm_apply2)
|
|
|
|
|
goto apply2;
|
|
|
|
|
else if (r3 == cell_vm_if_expr)
|
|
|
|
|
goto if_expr;
|
|
|
|
|
else if (r3 == cell_vm_begin_eval)
|
|
|
|
|
goto begin_eval;
|
|
|
|
|
else if (r3 == cell_vm_eval_set_x)
|
|
|
|
|
goto eval_set_x;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_car)
|
|
|
|
|
goto macro_expand_car;
|
|
|
|
|
else if (r3 == cell_vm_return)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_cdr)
|
|
|
|
|
goto macro_expand_cdr;
|
|
|
|
|
else if (r3 == cell_vm_eval_define)
|
|
|
|
|
goto eval_define;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand)
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_lambda)
|
|
|
|
|
goto macro_expand_lambda;
|
|
|
|
|
else if (r3 == cell_vm_eval_pmatch_car)
|
|
|
|
|
goto eval_pmatch_car;
|
|
|
|
|
else if (r3 == cell_vm_begin_expand_macro)
|
|
|
|
|
goto begin_expand_macro;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_define)
|
|
|
|
|
goto macro_expand_define;
|
|
|
|
|
else if (r3 == cell_vm_begin_expand_eval)
|
|
|
|
|
goto begin_expand_eval;
|
|
|
|
|
else if (r3 == cell_vm_call_with_current_continuation2)
|
|
|
|
|
goto call_with_current_continuation2;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_set_x)
|
|
|
|
|
goto macro_expand_set_x;
|
|
|
|
|
else if (r3 == cell_vm_eval_pmatch_cdr)
|
|
|
|
|
goto eval_pmatch_cdr;
|
|
|
|
|
else if (r3 == cell_vm_macro_expand_define_macro)
|
|
|
|
|
goto macro_expand_define_macro;
|
|
|
|
|
else if (r3 == cell_vm_begin_primitive_load)
|
|
|
|
|
goto begin_primitive_load;
|
|
|
|
|
|
|
|
|
|
else if (r3 == cell_vm_evlis)
|
|
|
|
|
goto evlis;
|
|
|
|
|
else if (r3 == cell_vm_apply)
|
|
|
|
|
goto apply;
|
|
|
|
|
else if (r3 == cell_vm_eval)
|
|
|
|
|
goto eval;
|
|
|
|
|
else if (r3 == cell_vm_eval_macro_expand_eval)
|
|
|
|
|
goto eval_macro_expand_eval;
|
|
|
|
|
else if (r3 == cell_vm_eval_macro_expand_expand)
|
|
|
|
|
goto eval_macro_expand_expand;
|
|
|
|
|
else if (r3 == cell_vm_begin)
|
|
|
|
|
goto begin;
|
|
|
|
|
else if (r3 == cell_vm_begin_expand)
|
|
|
|
|
goto begin_expand;
|
|
|
|
|
else if (r3 == cell_vm_begin_expand_primitive_load)
|
|
|
|
|
goto begin_expand_primitive_load;
|
|
|
|
|
else if (r3 == cell_vm_if)
|
|
|
|
|
goto vm_if;
|
|
|
|
|
else if (r3 == cell_vm_call_with_values2)
|
|
|
|
|
goto call_with_values2;
|
|
|
|
|
else if (r3 == cell_unspecified)
|
|
|
|
|
return r1;
|
2018-08-12 15:53:21 +01:00
|
|
|
|
else
|
2019-02-16 11:27:42 +00:00
|
|
|
|
error (cell_symbol_system_error, MAKE_STRING0 ("eval/apply unknown continuation"));
|
2016-12-22 15:34:28 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
evlis:
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (r1 == cell_nil)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
if (TYPE (r1) != TPAIR)
|
|
|
|
|
goto eval;
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_evlis2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
evlis2:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CDR (r2), r1, r0, cell_vm_evlis3);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto evlis;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
evlis3:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = cons (r2, r1);
|
|
|
|
|
goto vm_return;
|
2016-12-22 15:34:28 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
apply:
|
|
|
|
|
g_stack_array[g_stack + FRAME_PROCEDURE] = CAR (r1);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
t = TYPE (CAR (r1));
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
if (t == TSTRUCT && builtin_p (CAR (r1)) == cell_t)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
check_formals (CAR (r1), builtin_arity (CAR (r1)), CDR (r1));
|
2019-02-16 11:27:42 +00:00
|
|
|
|
r1 = apply_builtin (CAR (r1), CDR (r1)); /// FIXME: move into eval_apply
|
2018-08-12 15:53:21 +01:00
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
else if (t == TCLOSURE)
|
|
|
|
|
{
|
|
|
|
|
cl = CLOSURE (CAR (r1));
|
|
|
|
|
body = CDDR (cl);
|
|
|
|
|
formals = CADR (cl);
|
|
|
|
|
args = CDR (r1);
|
|
|
|
|
aa = CDAR (cl);
|
|
|
|
|
aa = CDR (aa);
|
|
|
|
|
check_formals (CAR (r1), formals, CDR (r1));
|
|
|
|
|
p = pairlis (formals, args, aa);
|
|
|
|
|
call_lambda (body, p, aa, r0);
|
|
|
|
|
goto begin;
|
|
|
|
|
}
|
|
|
|
|
else if (t == TCONTINUATION)
|
|
|
|
|
{
|
2017-12-14 06:05:53 +00:00
|
|
|
|
v = CONTINUATION (CAR (r1));
|
|
|
|
|
if (LENGTH (v))
|
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
for (t = 0; t < LENGTH (v); t++)
|
|
|
|
|
g_stack_array[STACK_SIZE - LENGTH (v) + t] = vector_ref_ (v, t);
|
|
|
|
|
g_stack = STACK_SIZE - LENGTH (v);
|
2017-12-14 06:05:53 +00:00
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CADR (x);
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
|
|
|
|
else if (t == TSPECIAL)
|
|
|
|
|
{
|
|
|
|
|
c = CAR (r1);
|
|
|
|
|
if (c == cell_vm_apply)
|
|
|
|
|
{
|
|
|
|
|
push_cc (cons (CADR (r1), CADDR (r1)), r1, r0, cell_vm_return);
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_vm_eval)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, CADDR (r1), cell_vm_return);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_vm_begin_expand)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
push_cc (cons (CADR (r1), cell_nil), r1, CADDR (r1), cell_vm_return);
|
|
|
|
|
goto begin_expand;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_call_with_current_continuation)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
r1 = CDR (r1);
|
|
|
|
|
goto call_with_current_continuation;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
check_apply (cell_f, CAR (r1));
|
|
|
|
|
}
|
|
|
|
|
else if (t == TSYMBOL)
|
|
|
|
|
{
|
|
|
|
|
if (CAR (r1) == cell_symbol_call_with_values)
|
|
|
|
|
{
|
|
|
|
|
r1 = CDR (r1);
|
|
|
|
|
goto call_with_values;
|
|
|
|
|
}
|
|
|
|
|
if (CAR (r1) == cell_symbol_current_module)
|
|
|
|
|
{
|
|
|
|
|
r1 = r0;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2018-10-15 09:44:47 +01:00
|
|
|
|
if (CAR (r1) == cell_symbol_boot_module)
|
|
|
|
|
{
|
|
|
|
|
r1 = m0;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
}
|
|
|
|
|
else if (t == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (r1) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
formals = CADR (CAR (r1));
|
|
|
|
|
args = CDR (r1);
|
|
|
|
|
body = CDDR (CAR (r1));
|
|
|
|
|
p = pairlis (formals, CDR (r1), r0);
|
|
|
|
|
check_formals (r1, formals, args);
|
|
|
|
|
call_lambda (body, p, p, r0);
|
|
|
|
|
goto begin;
|
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
}
|
2018-11-15 23:15:50 +00:00
|
|
|
|
// write_error_ (CAR (r1));
|
|
|
|
|
// eputs ("\n");
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_apply2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
apply2:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
check_apply (r1, CAR (r2));
|
|
|
|
|
r1 = cons (r1, CDR (r2));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
2016-05-28 15:39:44 +01:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
eval:
|
2018-08-12 15:53:21 +01:00
|
|
|
|
t = TYPE (r1);
|
|
|
|
|
if (t == TPAIR)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2018-08-12 15:53:21 +01:00
|
|
|
|
c = CAR (r1);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (c == cell_symbol_pmatch_car)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_car);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_pmatch_car:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CAR (x);
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_pmatch_cdr)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_cdr);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_pmatch_cdr:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CDR (x);
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_quote)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CADR (x);
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_begin)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
goto begin;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_lambda)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
r1 = make_closure_ (CADR (r1), CDDR (r1), r0);
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_if)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
r1 = CDR (r1);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
goto vm_if;
|
|
|
|
|
}
|
2019-02-16 11:27:42 +00:00
|
|
|
|
else if (c == cell_symbol_set_x)
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
push_cc (CAR (CDDR (r1)), r1, r0, cell_vm_eval_set_x);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_set_x:
|
|
|
|
|
r1 = set_env_x (CADR (r2), r1, r0);
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
else if (c == cell_vm_macro_expand)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_macro_expand_eval);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_macro_expand_eval:
|
|
|
|
|
push_cc (r1, r2, r0, cell_vm_eval_macro_expand_expand);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
eval_macro_expand_expand:
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (TYPE (r1) == TPAIR && (CAR (r1) == cell_symbol_define || CAR (r1) == cell_symbol_define_macro))
|
2018-02-03 20:43:52 +00:00
|
|
|
|
{
|
2018-08-12 15:53:21 +01:00
|
|
|
|
global_p = CAAR (r0) != cell_closure;
|
|
|
|
|
macro_p = CAR (r1) == cell_symbol_define_macro;
|
|
|
|
|
if (global_p)
|
2018-02-03 20:43:52 +00:00
|
|
|
|
{
|
2018-08-12 15:53:21 +01:00
|
|
|
|
name = CADR (r1);
|
|
|
|
|
if (TYPE (CADR (r1)) == TPAIR)
|
2017-12-09 07:33:50 +00:00
|
|
|
|
name = CAR (name);
|
|
|
|
|
if (macro_p)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = assq (name, g_macros);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
if (entry == cell_f)
|
2018-10-18 17:50:09 +01:00
|
|
|
|
macro_set_x (name, cell_f);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-14 07:30:18 +01:00
|
|
|
|
entry = module_variable (r0, name);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
if (entry == cell_f)
|
2018-10-14 08:10:30 +01:00
|
|
|
|
module_define_x (m0, name, cell_f);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
r2 = r1;
|
|
|
|
|
if (TYPE (CADR (r1)) != TPAIR)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CAR (CDDR (r1)), r2, cons (cons (CADR (r1), CADR (r1)), r0), cell_vm_eval_define);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p = pairlis (CADR (r1), CADR (r1), r0);
|
|
|
|
|
formals = CDR (CADR (r1));
|
|
|
|
|
body = CDDR (r1);
|
|
|
|
|
|
|
|
|
|
if (macro_p || global_p)
|
|
|
|
|
expand_variable (body, formals);
|
|
|
|
|
r1 = cons (cell_symbol_lambda, cons (formals, body));
|
|
|
|
|
push_cc (r1, r2, p, cell_vm_eval_define);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
eval_define:;
|
|
|
|
|
name = CADR (r2);
|
|
|
|
|
if (TYPE (CADR (r2)) == TPAIR)
|
|
|
|
|
name = CAR (name);
|
|
|
|
|
if (macro_p)
|
|
|
|
|
{
|
2018-10-18 17:50:09 +01:00
|
|
|
|
entry = macro_get_handle (name);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
r1 = MAKE_MACRO (name, r1);
|
|
|
|
|
set_cdr_x (entry, r1);
|
|
|
|
|
}
|
|
|
|
|
else if (global_p)
|
|
|
|
|
{
|
2018-10-14 07:30:18 +01:00
|
|
|
|
entry = module_variable (r0, name);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
set_cdr_x (entry, r1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entry = cons (name, r1);
|
|
|
|
|
aa = cons (entry, cell_nil);
|
|
|
|
|
set_cdr_x (aa, cdr (r0));
|
|
|
|
|
set_cdr_x (r0, aa);
|
2018-10-14 07:30:18 +01:00
|
|
|
|
cl = module_variable (r0, cell_closure);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
set_cdr_x (cl, aa);
|
|
|
|
|
}
|
|
|
|
|
r1 = cell_unspecified;
|
|
|
|
|
goto vm_return;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_eval_check_func);
|
|
|
|
|
gc_check ();
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_check_func:
|
|
|
|
|
push_cc (CDR (r2), r2, r0, cell_vm_eval2);
|
|
|
|
|
goto evlis;
|
|
|
|
|
eval2:
|
|
|
|
|
r1 = cons (CAR (r2), r1);
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (t == TSYMBOL)
|
|
|
|
|
{
|
2018-10-15 09:44:47 +01:00
|
|
|
|
if (r1 == cell_symbol_boot_module)
|
|
|
|
|
goto vm_return;
|
2018-08-12 15:53:21 +01:00
|
|
|
|
if (r1 == cell_symbol_current_module)
|
2017-12-09 07:33:50 +00:00
|
|
|
|
goto vm_return;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (r1 == cell_symbol_begin) // FIXME
|
2018-08-12 15:53:21 +01:00
|
|
|
|
{
|
|
|
|
|
r1 = cell_begin;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2018-10-14 07:30:18 +01:00
|
|
|
|
r1 = assert_defined (r1, module_ref (r0, r1));
|
2018-08-12 15:53:21 +01:00
|
|
|
|
goto vm_return;
|
2016-05-28 15:39:44 +01:00
|
|
|
|
}
|
2018-08-12 15:53:21 +01:00
|
|
|
|
else if (t == TVARIABLE)
|
|
|
|
|
{
|
|
|
|
|
r1 = CDR (VARIABLE (r1));
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
else if (t == TBROKEN_HEART)
|
2019-02-16 11:27:42 +00:00
|
|
|
|
error (cell_symbol_system_error, r1);
|
2018-08-12 15:53:21 +01:00
|
|
|
|
else
|
|
|
|
|
goto vm_return;
|
2016-10-08 16:00:32 +01:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
macro_expand:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
macro;
|
|
|
|
|
expanders;
|
2016-10-30 15:16:20 +00:00
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (TYPE (r1) != TPAIR || CAR (r1) == cell_symbol_quote)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (CAR (r1) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_lambda);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_lambda:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (TYPE (r1) == TPAIR && (macro = get_macro (CAR (r1))) != cell_f)
|
2018-03-04 09:05:55 +00:00
|
|
|
|
{
|
|
|
|
|
r1 = cons (macro, CDR (r1));
|
|
|
|
|
push_cc (r1, cell_nil, r0, cell_vm_macro_expand);
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if (CAR (r1) == cell_symbol_define || CAR (r1) == cell_symbol_define_macro)
|
2016-12-07 19:26:41 +00:00
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_define);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_define:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
if (CAR (r1) == cell_symbol_define_macro)
|
2016-12-13 18:58:34 +00:00
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (r1, r1, r0, cell_vm_macro_expand_define_macro);
|
|
|
|
|
goto eval;
|
|
|
|
|
macro_expand_define_macro:
|
|
|
|
|
r1 = r2;
|
2016-12-13 18:58:34 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
goto vm_return;
|
2016-12-07 19:26:41 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
|
|
|
|
if (CAR (r1) == cell_symbol_set_x)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_set_x);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_set_x:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR
|
|
|
|
|
&& TYPE (CAR (r1)) == TSYMBOL
|
|
|
|
|
&& CAR (r1) != cell_symbol_begin
|
2018-10-18 17:50:09 +01:00
|
|
|
|
&& ((macro = macro_get_handle (cell_symbol_portable_macro_expand)) != cell_f)
|
2018-10-14 07:30:18 +01:00
|
|
|
|
&& ((expanders = module_ref (r0, cell_symbol_sc_expander_alist)) != cell_undefined)
|
2018-03-04 09:05:55 +00:00
|
|
|
|
&& ((macro = assq (CAR (r1), expanders)) != cell_f))
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2018-10-14 07:30:18 +01:00
|
|
|
|
sc_expand = module_ref (r0, cell_symbol_macro_expand);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r2 = r1;
|
|
|
|
|
if (sc_expand != cell_undefined && sc_expand != cell_f)
|
|
|
|
|
{
|
|
|
|
|
r1 = cons (sc_expand, cons (r1, cell_nil));
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2016-12-22 15:50:51 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_macro_expand_car);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
|
|
|
|
|
macro_expand_car:
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
if (CDR (r1) == cell_nil)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
push_cc (CDR (r1), r1, r0, cell_vm_macro_expand_cdr);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
|
|
|
|
|
macro_expand_cdr:
|
|
|
|
|
CDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
|
|
|
|
|
goto vm_return;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
begin:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
x = cell_unspecified;
|
|
|
|
|
while (r1 != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
gc_check ();
|
|
|
|
|
if (TYPE (r1) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (r1) == cell_symbol_primitive_load)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
program = cons (CAR (r1), cell_nil);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (program, r1, r0, cell_vm_begin_primitive_load);
|
|
|
|
|
goto begin_expand;
|
|
|
|
|
begin_primitive_load:
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR && TYPE (CAR (r1)) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (r1) == cell_symbol_begin)
|
|
|
|
|
r1 = append2 (CDAR (r1), CDR (r1));
|
|
|
|
|
}
|
|
|
|
|
if (CDR (r1) == cell_nil)
|
|
|
|
|
{
|
|
|
|
|
r1 = CAR (r1);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_eval);
|
|
|
|
|
goto eval;
|
|
|
|
|
begin_eval:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = CDR (r2);
|
|
|
|
|
}
|
|
|
|
|
r1 = x;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
begin_expand:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
x = cell_unspecified;
|
|
|
|
|
while (r1 != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
gc_check ();
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (CAR (r1)) == TPAIR && CAAR (r1) == cell_symbol_begin)
|
|
|
|
|
r1 = append2 (CDAR (r1), CDR (r1));
|
|
|
|
|
if (CAAR (r1) == cell_symbol_primitive_load)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (CAR (r1)), r1, r0, cell_vm_begin_expand_primitive_load);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
goto eval; // FIXME: expand too?!
|
2018-04-14 07:15:49 +01:00
|
|
|
|
begin_expand_primitive_load:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (TYPE (r1) == TNUMBER && VALUE (r1) == 0)
|
|
|
|
|
;
|
|
|
|
|
else if (TYPE (r1) == TSTRING)
|
|
|
|
|
input = set_current_input_port (open_input_file (r1));
|
2018-04-29 16:48:38 +01:00
|
|
|
|
else if (TYPE (r1) == TPORT)
|
|
|
|
|
input = set_current_input_port (r1);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
else
|
|
|
|
|
assert (0);
|
2018-05-28 17:53:25 +01:00
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (input, r2, r0, cell_vm_return);
|
|
|
|
|
x = read_input_file_env (r0);
|
2019-02-25 19:30:48 +00:00
|
|
|
|
if (g_debug > 5)
|
2018-10-14 08:10:30 +01:00
|
|
|
|
module_printer (m0);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
input = r1;
|
|
|
|
|
r1 = x;
|
|
|
|
|
set_current_input_port (input);
|
|
|
|
|
r1 = cons (cell_symbol_begin, r1);
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_expand_macro);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
begin_expand_macro:
|
|
|
|
|
if (r1 != CAR (r2))
|
|
|
|
|
{
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
r1 = r2;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
expand_variable (CAR (r1), cell_nil);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_expand_eval);
|
|
|
|
|
goto eval;
|
|
|
|
|
begin_expand_eval:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = CDR (r2);
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = x;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
vm_if:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_if_expr);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if_expr:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
x = r1;
|
|
|
|
|
r1 = r2;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
if (x != cell_f)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
r1 = CADR (r1);
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
}
|
2017-03-25 14:58:44 +00:00
|
|
|
|
if (CDDR (r1) != cell_nil)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
r1 = CAR (CDDR (r1));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = cell_unspecified;
|
|
|
|
|
goto vm_return;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
call_with_current_continuation:
|
2016-12-28 21:04:57 +00:00
|
|
|
|
gc_push_frame ();
|
|
|
|
|
x = MAKE_CONTINUATION (g_continuations++);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
v = make_vector__ (STACK_SIZE - g_stack);
|
|
|
|
|
for (t = g_stack; t < STACK_SIZE; t++)
|
|
|
|
|
vector_set_x_ (v, t - g_stack, g_stack_array[t]);
|
2017-12-14 06:05:53 +00:00
|
|
|
|
CONTINUATION (x) = v;
|
2016-12-28 21:04:57 +00:00
|
|
|
|
gc_pop_frame ();
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (cons (CAR (r1), cons (x, cell_nil)), x, r0, cell_vm_call_with_current_continuation2);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
goto apply;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
call_with_current_continuation2:
|
|
|
|
|
v = make_vector__ (STACK_SIZE - g_stack);
|
|
|
|
|
for (t = g_stack; t < STACK_SIZE; t++)
|
|
|
|
|
vector_set_x_ (v, t - g_stack, g_stack_array[t]);
|
2017-12-14 06:05:53 +00:00
|
|
|
|
CONTINUATION (r2) = v;
|
2016-12-28 21:04:57 +00:00
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
call_with_values:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (cons (CAR (r1), cell_nil), r1, r0, cell_vm_call_with_values2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto apply;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
call_with_values2:
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
if (TYPE (r1) == TVALUES)
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = CDR (r1);
|
2017-03-25 14:58:44 +00:00
|
|
|
|
r1 = cons (CADR (r2), r1);
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
|
2019-02-16 11:27:42 +00:00
|
|
|
|
vm_return:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = x;
|
|
|
|
|
goto eval_apply;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
apply (SCM f, SCM x, SCM a) ///((internal))
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified);
|
|
|
|
|
r3 = cell_vm_apply;
|
|
|
|
|
return eval_apply ();
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:01:22 +01:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
mes_g_stack (SCM a) ///((internal))
|
2017-04-02 16:01:22 +01:00
|
|
|
|
{
|
2017-12-14 06:05:53 +00:00
|
|
|
|
//g_stack = g_free + ARENA_SIZE;
|
|
|
|
|
g_stack = STACK_SIZE;
|
|
|
|
|
r0 = a;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
r1 = MAKE_CHAR (0);
|
|
|
|
|
r2 = MAKE_CHAR (0);
|
|
|
|
|
r3 = MAKE_CHAR (0);
|
2017-12-14 06:05:53 +00:00
|
|
|
|
return r0;
|
2017-04-02 16:01:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-21 07:07:48 +00:00
|
|
|
|
void
|
2019-02-16 11:27:42 +00:00
|
|
|
|
init_symbol (long x, long type, char const *name)
|
2018-12-21 07:07:48 +00:00
|
|
|
|
{
|
|
|
|
|
TYPE (x) = type;
|
|
|
|
|
int length = strlen (name);
|
|
|
|
|
SCM string = make_string (name, length);
|
|
|
|
|
CAR (x) = length;
|
|
|
|
|
CDR (x) = STRING (string);
|
|
|
|
|
hash_set_x (g_symbols, string, x);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-11 07:23:15 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
mes_symbols () ///((internal))
|
2016-12-11 07:23:15 +00:00
|
|
|
|
{
|
2018-12-21 07:07:48 +00:00
|
|
|
|
g_free = cell_symbol_test + 1;
|
|
|
|
|
g_symbol_max = g_free;
|
2018-10-18 17:50:09 +01:00
|
|
|
|
g_symbols = make_hash_table_ (500);
|
2018-12-21 07:07:48 +00:00
|
|
|
|
|
|
|
|
|
init_symbol (cell_nil, TSPECIAL, "()");
|
|
|
|
|
init_symbol (cell_f, TSPECIAL, "#f");
|
|
|
|
|
init_symbol (cell_t, TSPECIAL, "#t");
|
|
|
|
|
init_symbol (cell_dot, TSPECIAL, ".");
|
|
|
|
|
init_symbol (cell_arrow, TSPECIAL, "=>");
|
|
|
|
|
init_symbol (cell_undefined, TSPECIAL, "*undefined*");
|
|
|
|
|
init_symbol (cell_unspecified, TSPECIAL, "*unspecified*");
|
|
|
|
|
init_symbol (cell_closure, TSPECIAL, "*closure*");
|
|
|
|
|
init_symbol (cell_circular, TSPECIAL, "*circular*");
|
|
|
|
|
init_symbol (cell_begin, TSPECIAL, "*begin*");
|
|
|
|
|
init_symbol (cell_call_with_current_continuation, TSPECIAL, "*call/cc*");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_vm_apply, TSPECIAL, "core:apply");
|
|
|
|
|
init_symbol (cell_vm_apply2, TSPECIAL, "*vm-apply2*");
|
|
|
|
|
init_symbol (cell_vm_begin, TSPECIAL, "*vm-begin*");
|
|
|
|
|
init_symbol (cell_vm_begin_eval, TSPECIAL, "*vm:begin-eval*");
|
|
|
|
|
init_symbol (cell_vm_begin_expand, TSPECIAL, "core:eval");
|
|
|
|
|
init_symbol (cell_vm_begin_expand_eval, TSPECIAL, "*vm:begin-expand-eval*");
|
|
|
|
|
init_symbol (cell_vm_begin_expand_macro, TSPECIAL, "*vm:begin-expand-macro*");
|
|
|
|
|
init_symbol (cell_vm_begin_expand_primitive_load, TSPECIAL, "*vm:core:begin-expand-primitive-load*");
|
|
|
|
|
init_symbol (cell_vm_begin_primitive_load, TSPECIAL, "*vm:core:begin-primitive-load*");
|
|
|
|
|
init_symbol (cell_vm_begin_read_input_file, TSPECIAL, "*vm-begin-read-input-file*");
|
|
|
|
|
init_symbol (cell_vm_call_with_current_continuation2, TSPECIAL, "*vm-call-with-current-continuation2*");
|
|
|
|
|
init_symbol (cell_vm_call_with_values2, TSPECIAL, "*vm-call-with-values2*");
|
|
|
|
|
init_symbol (cell_vm_eval, TSPECIAL, "core:eval-expanded");
|
|
|
|
|
init_symbol (cell_vm_eval2, TSPECIAL, "*vm-eval2*");
|
|
|
|
|
init_symbol (cell_vm_eval_check_func, TSPECIAL, "*vm-eval-check-func*");
|
|
|
|
|
init_symbol (cell_vm_eval_define, TSPECIAL, "*vm-eval-define*");
|
|
|
|
|
init_symbol (cell_vm_eval_macro_expand_eval, TSPECIAL, "*vm:eval-macro-expand-eval*");
|
|
|
|
|
init_symbol (cell_vm_eval_macro_expand_expand, TSPECIAL, "*vm:eval-macro-expand-expand*");
|
|
|
|
|
init_symbol (cell_vm_eval_pmatch_car, TSPECIAL, "*vm-eval-pmatch-car*");
|
|
|
|
|
init_symbol (cell_vm_eval_pmatch_cdr, TSPECIAL, "*vm-eval-pmatch-cdr*");
|
|
|
|
|
init_symbol (cell_vm_eval_set_x, TSPECIAL, "*vm-eval-set!*");
|
|
|
|
|
init_symbol (cell_vm_evlis, TSPECIAL, "*vm-evlis*");
|
|
|
|
|
init_symbol (cell_vm_evlis2, TSPECIAL, "*vm-evlis2*");
|
|
|
|
|
init_symbol (cell_vm_evlis3, TSPECIAL, "*vm-evlis3*");
|
|
|
|
|
init_symbol (cell_vm_if, TSPECIAL, "*vm-if*");
|
|
|
|
|
init_symbol (cell_vm_if_expr, TSPECIAL, "*vm-if-expr*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand, TSPECIAL, "core:macro-expand");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_car, TSPECIAL, "*vm:core:macro-expand-car*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_cdr, TSPECIAL, "*vm:macro-expand-cdr*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_define, TSPECIAL, "*vm:core:macro-expand-define*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_define_macro, TSPECIAL, "*vm:core:macro-expand-define-macro*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_lambda, TSPECIAL, "*vm:core:macro-expand-lambda*");
|
|
|
|
|
init_symbol (cell_vm_macro_expand_set_x, TSPECIAL, "*vm:core:macro-expand-set!*");
|
|
|
|
|
init_symbol (cell_vm_return, TSPECIAL, "*vm-return*");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_dot, TSYMBOL, "*dot*");
|
|
|
|
|
init_symbol (cell_symbol_lambda, TSYMBOL, "lambda");
|
|
|
|
|
init_symbol (cell_symbol_begin, TSYMBOL, "begin");
|
|
|
|
|
init_symbol (cell_symbol_if, TSYMBOL, "if");
|
|
|
|
|
init_symbol (cell_symbol_quote, TSYMBOL, "quote");
|
|
|
|
|
init_symbol (cell_symbol_define, TSYMBOL, "define");
|
|
|
|
|
init_symbol (cell_symbol_define_macro, TSYMBOL, "define-macro");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_quasiquote, TSYMBOL, "quasiquote");
|
|
|
|
|
init_symbol (cell_symbol_unquote, TSYMBOL, "unquote");
|
|
|
|
|
init_symbol (cell_symbol_unquote_splicing, TSYMBOL, "unquote-splicing");
|
|
|
|
|
init_symbol (cell_symbol_syntax, TSYMBOL, "syntax");
|
|
|
|
|
init_symbol (cell_symbol_quasisyntax, TSYMBOL, "quasisyntax");
|
|
|
|
|
init_symbol (cell_symbol_unsyntax, TSYMBOL, "unsyntax");
|
|
|
|
|
init_symbol (cell_symbol_unsyntax_splicing, TSYMBOL, "unsyntax-splicing");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_set_x, TSYMBOL, "set!");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_sc_expand, TSYMBOL, "sc-expand");
|
|
|
|
|
init_symbol (cell_symbol_macro_expand, TSYMBOL, "macro-expand");
|
|
|
|
|
init_symbol (cell_symbol_portable_macro_expand, TSYMBOL, "portable-macro-expand");
|
|
|
|
|
init_symbol (cell_symbol_sc_expander_alist, TSYMBOL, "*sc-expander-alist*");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_call_with_values, TSYMBOL, "call-with-values");
|
|
|
|
|
init_symbol (cell_symbol_call_with_current_continuation, TSYMBOL, "call-with-current-continuation");
|
|
|
|
|
init_symbol (cell_symbol_boot_module, TSYMBOL, "boot-module");
|
|
|
|
|
init_symbol (cell_symbol_current_module, TSYMBOL, "current-module");
|
|
|
|
|
init_symbol (cell_symbol_primitive_load, TSYMBOL, "primitive-load");
|
|
|
|
|
init_symbol (cell_symbol_read_input_file, TSYMBOL, "read-input-file");
|
|
|
|
|
init_symbol (cell_symbol_write, TSYMBOL, "write");
|
|
|
|
|
init_symbol (cell_symbol_display, TSYMBOL, "display");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_car, TSYMBOL, "car");
|
|
|
|
|
init_symbol (cell_symbol_cdr, TSYMBOL, "cdr");
|
|
|
|
|
init_symbol (cell_symbol_not_a_number, TSYMBOL, "not-a-number");
|
|
|
|
|
init_symbol (cell_symbol_not_a_pair, TSYMBOL, "not-a-pair");
|
|
|
|
|
init_symbol (cell_symbol_system_error, TSYMBOL, "system-error");
|
|
|
|
|
init_symbol (cell_symbol_throw, TSYMBOL, "throw");
|
|
|
|
|
init_symbol (cell_symbol_unbound_variable, TSYMBOL, "unbound-variable");
|
|
|
|
|
init_symbol (cell_symbol_wrong_number_of_args, TSYMBOL, "wrong-number-of-args");
|
|
|
|
|
init_symbol (cell_symbol_wrong_type_arg, TSYMBOL, "wrong-type-arg");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_buckets, TSYMBOL, "buckets");
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
init_symbol (cell_symbol_builtin, TSYMBOL, "<builtin>");
|
2018-12-21 07:07:48 +00:00
|
|
|
|
init_symbol (cell_symbol_frame, TSYMBOL, "<frame>");
|
|
|
|
|
init_symbol (cell_symbol_hashq_table, TSYMBOL, "<hashq-table>");
|
|
|
|
|
init_symbol (cell_symbol_module, TSYMBOL, "<module>");
|
|
|
|
|
init_symbol (cell_symbol_procedure, TSYMBOL, "procedure");
|
|
|
|
|
init_symbol (cell_symbol_record_type, TSYMBOL, "<record-type>");
|
|
|
|
|
init_symbol (cell_symbol_size, TSYMBOL, "size");
|
|
|
|
|
init_symbol (cell_symbol_stack, TSYMBOL, "<stack>");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_argv, TSYMBOL, "%argv");
|
2019-03-02 13:36:22 +00:00
|
|
|
|
init_symbol (cell_symbol_mes_datadir, TSYMBOL, "%datadir");
|
2018-12-21 07:07:48 +00:00
|
|
|
|
init_symbol (cell_symbol_mes_version, TSYMBOL, "%version");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_internal_time_units_per_second, TSYMBOL, "internal-time-units-per-second");
|
|
|
|
|
init_symbol (cell_symbol_compiler, TSYMBOL, "%compiler");
|
|
|
|
|
init_symbol (cell_symbol_arch, TSYMBOL, "%arch");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_pmatch_car, TSYMBOL, "pmatch-car");
|
|
|
|
|
init_symbol (cell_symbol_pmatch_cdr, TSYMBOL, "pmatch-cdr");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_type_bytes, TSYMBOL, "<cell:bytes>");
|
|
|
|
|
init_symbol (cell_type_char, TSYMBOL, "<cell:char>");
|
|
|
|
|
init_symbol (cell_type_closure, TSYMBOL, "<cell:closure>");
|
|
|
|
|
init_symbol (cell_type_continuation, TSYMBOL, "<cell:continuation>");
|
|
|
|
|
init_symbol (cell_type_function, TSYMBOL, "<cell:function>");
|
|
|
|
|
init_symbol (cell_type_keyword, TSYMBOL, "<cell:keyword>");
|
|
|
|
|
init_symbol (cell_type_macro, TSYMBOL, "<cell:macro>");
|
|
|
|
|
init_symbol (cell_type_number, TSYMBOL, "<cell:number>");
|
|
|
|
|
init_symbol (cell_type_pair, TSYMBOL, "<cell:pair>");
|
|
|
|
|
init_symbol (cell_type_port, TSYMBOL, "<cell:port>");
|
|
|
|
|
init_symbol (cell_type_ref, TSYMBOL, "<cell:ref>");
|
|
|
|
|
init_symbol (cell_type_special, TSYMBOL, "<cell:special>");
|
|
|
|
|
init_symbol (cell_type_string, TSYMBOL, "<cell:string>");
|
|
|
|
|
init_symbol (cell_type_struct, TSYMBOL, "<cell:struct>");
|
|
|
|
|
init_symbol (cell_type_symbol, TSYMBOL, "<cell:symbol>");
|
|
|
|
|
init_symbol (cell_type_values, TSYMBOL, "<cell:values>");
|
|
|
|
|
init_symbol (cell_type_variable, TSYMBOL, "<cell:variable>");
|
|
|
|
|
init_symbol (cell_type_vector, TSYMBOL, "<cell:vector>");
|
|
|
|
|
init_symbol (cell_type_broken_heart, TSYMBOL, "<cell:broken-heart>");
|
|
|
|
|
|
|
|
|
|
init_symbol (cell_symbol_test, TSYMBOL, "%%test");
|
2018-10-18 17:50:09 +01:00
|
|
|
|
|
|
|
|
|
SCM a = cell_nil;
|
2017-03-27 19:14:48 +01:00
|
|
|
|
a = acons (cell_symbol_call_with_values, cell_symbol_call_with_values, a);
|
2018-10-15 09:44:47 +01:00
|
|
|
|
a = acons (cell_symbol_boot_module, cell_symbol_boot_module, a);
|
2017-03-27 19:14:48 +01:00
|
|
|
|
a = acons (cell_symbol_current_module, cell_symbol_current_module, a);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
a = acons (cell_symbol_call_with_current_continuation, cell_call_with_current_continuation, a);
|
2018-04-09 06:12:38 +01:00
|
|
|
|
|
2019-04-05 17:20:32 +01:00
|
|
|
|
a = acons (cell_symbol_mes_version, MAKE_STRING0 (MES_VERSION), a);
|
2019-03-02 13:36:22 +00:00
|
|
|
|
a = acons (cell_symbol_mes_datadir, MAKE_STRING0 (g_datadir), a);
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
|
2018-11-11 15:25:36 +00:00
|
|
|
|
a = acons (cell_type_bytes, MAKE_NUMBER (TBYTES), a);
|
core: Use single definition rule for cell-type.
* src/mes.c (scm_type_char, scm_type_closure, scm_type_continuation,
scm_type_function, scm_type_keyword, scm_type_macro,
scm_type_number, scm_type_pair, scm_type_ref, scm_type_special,
scm_type_string, scm_type_symbol, scm_type_values,
scm_type_variable, scm_type_vector): New symbol.
(mes_symbols): Add them.
* module/mes/type-0.mes (<cell:char>, <cell:char>, <cell:closure>,
<cell:continuation>, <cell:function>, <cell:keyword>, <cell:macro>,
<cell:number>, <cell:pair>, <cell:ref>, <cell:special>,
<cell:string>, <cell:symbol>, <cell:values>, <cell:variable>,
<cell:vector>, <cell:broken-heart): Remove.
* module/mes/boot-0.scm: Likewise.
* module/mes/boot-01.scm: Likewise.
* module/mes/boot-02.scm: Likewise.
* scaffold/boot/20-define-quote.scm: Likewise.
* scaffold/boot/37-closure-lambda.scm: Likewise.
* scaffold/boot/38-simple-format.scm: Likewise.
* scaffold/boot/4c-quasiquote.scm:
* scaffold/boot/4e-string-split.scm: Likewise.
* scaffold/boot/51-module.scm: Likewise.
* scaffold/boot/52-define-module.scm: Likewise.
* scaffold/boot/60-let-syntax.scm: Likewise.
* module/mes/guile.scm: Add some of them.
2018-04-29 12:22:02 +01:00
|
|
|
|
a = acons (cell_type_char, MAKE_NUMBER (TCHAR), a);
|
|
|
|
|
a = acons (cell_type_closure, MAKE_NUMBER (TCLOSURE), a);
|
|
|
|
|
a = acons (cell_type_continuation, MAKE_NUMBER (TCONTINUATION), a);
|
|
|
|
|
a = acons (cell_type_keyword, MAKE_NUMBER (TKEYWORD), a);
|
|
|
|
|
a = acons (cell_type_macro, MAKE_NUMBER (TMACRO), a);
|
|
|
|
|
a = acons (cell_type_number, MAKE_NUMBER (TNUMBER), a);
|
|
|
|
|
a = acons (cell_type_pair, MAKE_NUMBER (TPAIR), a);
|
2018-04-29 16:48:38 +01:00
|
|
|
|
a = acons (cell_type_port, MAKE_NUMBER (TPORT), a);
|
core: Use single definition rule for cell-type.
* src/mes.c (scm_type_char, scm_type_closure, scm_type_continuation,
scm_type_function, scm_type_keyword, scm_type_macro,
scm_type_number, scm_type_pair, scm_type_ref, scm_type_special,
scm_type_string, scm_type_symbol, scm_type_values,
scm_type_variable, scm_type_vector): New symbol.
(mes_symbols): Add them.
* module/mes/type-0.mes (<cell:char>, <cell:char>, <cell:closure>,
<cell:continuation>, <cell:function>, <cell:keyword>, <cell:macro>,
<cell:number>, <cell:pair>, <cell:ref>, <cell:special>,
<cell:string>, <cell:symbol>, <cell:values>, <cell:variable>,
<cell:vector>, <cell:broken-heart): Remove.
* module/mes/boot-0.scm: Likewise.
* module/mes/boot-01.scm: Likewise.
* module/mes/boot-02.scm: Likewise.
* scaffold/boot/20-define-quote.scm: Likewise.
* scaffold/boot/37-closure-lambda.scm: Likewise.
* scaffold/boot/38-simple-format.scm: Likewise.
* scaffold/boot/4c-quasiquote.scm:
* scaffold/boot/4e-string-split.scm: Likewise.
* scaffold/boot/51-module.scm: Likewise.
* scaffold/boot/52-define-module.scm: Likewise.
* scaffold/boot/60-let-syntax.scm: Likewise.
* module/mes/guile.scm: Add some of them.
2018-04-29 12:22:02 +01:00
|
|
|
|
a = acons (cell_type_ref, MAKE_NUMBER (TREF), a);
|
|
|
|
|
a = acons (cell_type_special, MAKE_NUMBER (TSPECIAL), a);
|
|
|
|
|
a = acons (cell_type_string, MAKE_NUMBER (TSTRING), a);
|
2018-10-13 16:34:27 +01:00
|
|
|
|
a = acons (cell_type_struct, MAKE_NUMBER (TSTRUCT), a);
|
core: Use single definition rule for cell-type.
* src/mes.c (scm_type_char, scm_type_closure, scm_type_continuation,
scm_type_function, scm_type_keyword, scm_type_macro,
scm_type_number, scm_type_pair, scm_type_ref, scm_type_special,
scm_type_string, scm_type_symbol, scm_type_values,
scm_type_variable, scm_type_vector): New symbol.
(mes_symbols): Add them.
* module/mes/type-0.mes (<cell:char>, <cell:char>, <cell:closure>,
<cell:continuation>, <cell:function>, <cell:keyword>, <cell:macro>,
<cell:number>, <cell:pair>, <cell:ref>, <cell:special>,
<cell:string>, <cell:symbol>, <cell:values>, <cell:variable>,
<cell:vector>, <cell:broken-heart): Remove.
* module/mes/boot-0.scm: Likewise.
* module/mes/boot-01.scm: Likewise.
* module/mes/boot-02.scm: Likewise.
* scaffold/boot/20-define-quote.scm: Likewise.
* scaffold/boot/37-closure-lambda.scm: Likewise.
* scaffold/boot/38-simple-format.scm: Likewise.
* scaffold/boot/4c-quasiquote.scm:
* scaffold/boot/4e-string-split.scm: Likewise.
* scaffold/boot/51-module.scm: Likewise.
* scaffold/boot/52-define-module.scm: Likewise.
* scaffold/boot/60-let-syntax.scm: Likewise.
* module/mes/guile.scm: Add some of them.
2018-04-29 12:22:02 +01:00
|
|
|
|
a = acons (cell_type_symbol, MAKE_NUMBER (TSYMBOL), a);
|
|
|
|
|
a = acons (cell_type_values, MAKE_NUMBER (TVALUES), a);
|
|
|
|
|
a = acons (cell_type_variable, MAKE_NUMBER (TVARIABLE), a);
|
|
|
|
|
a = acons (cell_type_vector, MAKE_NUMBER (TVECTOR), a);
|
|
|
|
|
a = acons (cell_type_broken_heart, MAKE_NUMBER (TBROKEN_HEART), a);
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
a = acons (cell_closure, a, a);
|
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
2018-10-14 08:10:30 +01:00
|
|
|
|
mes_environment (int argc, char *argv[])
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
SCM a = mes_symbols ();
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
|
|
|
|
char *compiler = "gnuc";
|
|
|
|
|
#if __MESC__
|
|
|
|
|
compiler = "mesc";
|
|
|
|
|
#elif __TINYC__
|
|
|
|
|
compiler = "tcc";
|
|
|
|
|
#endif
|
2018-11-11 15:25:36 +00:00
|
|
|
|
a = acons (cell_symbol_compiler, MAKE_STRING0 (compiler), a);
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
2019-02-13 15:55:20 +00:00
|
|
|
|
char *arch;
|
|
|
|
|
#if __i386__
|
|
|
|
|
arch = "x86";
|
|
|
|
|
#elif __arm__
|
|
|
|
|
arch = "arm";
|
|
|
|
|
#elif __x86_64__
|
2018-10-14 08:10:30 +01:00
|
|
|
|
arch = "x86_64";
|
2019-02-13 15:55:20 +00:00
|
|
|
|
#else
|
|
|
|
|
#error arch not supported
|
2018-10-14 08:10:30 +01:00
|
|
|
|
#endif
|
2018-11-11 15:25:36 +00:00
|
|
|
|
a = acons (cell_symbol_arch, MAKE_STRING0 (arch), a);
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
|
|
|
|
#if !MES_MINI
|
|
|
|
|
SCM lst = cell_nil;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
for (int i = argc - 1; i >= 0; i--)
|
2018-11-11 15:25:36 +00:00
|
|
|
|
lst = cons (MAKE_STRING0 (argv[i]), lst);
|
2018-10-14 08:10:30 +01:00
|
|
|
|
a = acons (cell_symbol_argv, lst, a);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return mes_g_stack (a);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
init_builtin (SCM builtin_type, char const *name, int arity, SCM (*function) (SCM), SCM a)
|
2016-11-19 22:25:24 +00:00
|
|
|
|
{
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM s = cstring_to_symbol (name);
|
2019-02-16 11:27:42 +00:00
|
|
|
|
return acons (s,
|
|
|
|
|
make_builtin (builtin_type, symbol_to_string (s), MAKE_NUMBER (arity),
|
|
|
|
|
MAKE_NUMBER (function)), a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
}
|
2018-04-10 20:43:19 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
make_builtin_type () ///(internal))
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
{
|
|
|
|
|
SCM record_type = cell_symbol_record_type;
|
|
|
|
|
SCM fields = cell_nil;
|
|
|
|
|
fields = cons (cstring_to_symbol ("address"), fields);
|
|
|
|
|
fields = cons (cstring_to_symbol ("arity"), fields);
|
|
|
|
|
fields = cons (cstring_to_symbol ("name"), fields);
|
|
|
|
|
fields = cons (fields, cell_nil);
|
|
|
|
|
fields = cons (cell_symbol_builtin, fields);
|
|
|
|
|
return make_struct (record_type, fields, cell_unspecified);
|
|
|
|
|
}
|
2018-04-10 20:43:19 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_builtin (SCM builtin_type, SCM name, SCM arity, SCM function)
|
|
|
|
|
{
|
|
|
|
|
SCM values = cell_nil;
|
|
|
|
|
values = cons (function, values);
|
|
|
|
|
values = cons (arity, values);
|
|
|
|
|
values = cons (name, values);
|
|
|
|
|
values = cons (cell_symbol_builtin, values);
|
|
|
|
|
return make_struct (builtin_type, values, cstring_to_symbol ("builtin-printer"));
|
|
|
|
|
}
|
2018-04-10 20:43:19 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
|
|
|
|
builtin_name (SCM builtin)
|
|
|
|
|
{
|
|
|
|
|
return struct_ref_ (builtin, 3);
|
|
|
|
|
}
|
2018-04-10 20:43:19 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
|
|
|
|
builtin_arity (SCM builtin)
|
|
|
|
|
{
|
|
|
|
|
return struct_ref_ (builtin, 4);
|
|
|
|
|
}
|
2018-04-10 20:43:19 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
#if __MESC__
|
|
|
|
|
long
|
|
|
|
|
builtin_function (SCM builtin)
|
2019-01-04 08:28:46 +00:00
|
|
|
|
{
|
|
|
|
|
return VALUE (struct_ref_ (builtin, 5));
|
|
|
|
|
}
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*builtin_function (SCM builtin)) (SCM)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
return (function1_t) VALUE (struct_ref_ (builtin, 5));
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
}
|
2019-01-04 08:28:46 +00:00
|
|
|
|
#endif
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
|
|
|
|
builtin_p (SCM x)
|
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
return (TYPE (x) == TSTRUCT && struct_ref_ (x, 2) == cell_symbol_builtin) ? cell_t : cell_f;
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
builtin_printer (SCM builtin)
|
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputs ("#<procedure ", __stdout);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
display_ (builtin_name (builtin));
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputc (' ', __stdout);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
int arity = VALUE (builtin_arity (builtin));
|
|
|
|
|
if (arity == -1)
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputc ('_', __stdout);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
else
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputc ('(', __stdout);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
for (int i = 0; i < arity; i++)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
{
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
if (i)
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputc (' ', __stdout);
|
|
|
|
|
fdputc ('_', __stdout);
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-05 11:35:18 +00:00
|
|
|
|
fdputc ('>', __stdout);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
apply_builtin (SCM fn, SCM x) ///((internal))
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
{
|
|
|
|
|
int arity = VALUE (builtin_arity (fn));
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if ((arity > 0 || arity == -1) && x != cell_nil && TYPE (CAR (x)) == TVALUES)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
x = cons (CADAR (x), CDR (x));
|
2019-02-16 11:27:42 +00:00
|
|
|
|
if ((arity > 1 || arity == -1) && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
|
|
|
|
|
|
|
|
|
|
#if __M2_PLANET__
|
2019-02-16 11:27:42 +00:00
|
|
|
|
FUNCTION fp = builtin_function (fn) if (arity == 0)
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp ();
|
|
|
|
|
else if (arity == 1)
|
|
|
|
|
return fp (CAR (x));
|
|
|
|
|
else if (arity == 2)
|
|
|
|
|
return fp (CAR (x), CADR (x));
|
|
|
|
|
else if (arity == 3)
|
|
|
|
|
return fp (CAR (x), CADR (x), CAR (CDDR (x)));
|
|
|
|
|
else if (arity == -1)
|
|
|
|
|
return fp (x);
|
2019-01-04 08:28:46 +00:00
|
|
|
|
#else // !__M2_PLANET__
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
if (arity == 0)
|
|
|
|
|
{
|
|
|
|
|
//function0_t fp = f->function;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*fp) (void) = (function0_t) builtin_function (fn);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp ();
|
|
|
|
|
}
|
|
|
|
|
else if (arity == 1)
|
|
|
|
|
{
|
|
|
|
|
//function1_t fp = f->function;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*fp) (SCM) = (function1_t) builtin_function (fn);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp (CAR (x));
|
|
|
|
|
}
|
|
|
|
|
else if (arity == 2)
|
|
|
|
|
{
|
|
|
|
|
//function2_t fp = f->function;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*fp) (SCM, SCM) = (function2_t) builtin_function (fn);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp (CAR (x), CADR (x));
|
|
|
|
|
}
|
|
|
|
|
else if (arity == 3)
|
|
|
|
|
{
|
|
|
|
|
//function3_t fp = f->function;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*fp) (SCM, SCM, SCM) = (function3_t) builtin_function (fn);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp (CAR (x), CADR (x), CAR (CDDR (x)));
|
|
|
|
|
}
|
|
|
|
|
else if (arity == -1)
|
|
|
|
|
{
|
|
|
|
|
//functionn_t fp = f->function;
|
2019-02-16 11:27:42 +00:00
|
|
|
|
SCM (*fp) (SCM) = (function1_t) builtin_function (fn);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return fp (x);
|
|
|
|
|
}
|
2019-01-04 08:28:46 +00:00
|
|
|
|
#endif //! __M2_PLANET__
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
return cell_unspecified;
|
2016-11-19 22:25:24 +00:00
|
|
|
|
}
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
|
mes_builtins (SCM a) ///((internal))
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
{
|
|
|
|
|
// TODO minimal: cons, car, cdr, list, null_p, eq_p minus, plus
|
|
|
|
|
// display_, display_error_, getenv
|
|
|
|
|
|
|
|
|
|
SCM builtin_type = make_builtin_type ();
|
|
|
|
|
|
|
|
|
|
// src/gc.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "gc-check", 0, (function1_t) & gc_check, a);
|
|
|
|
|
a = init_builtin (builtin_type, "gc", 0, (function1_t) & gc, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/hash.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "hashq", 2, (function1_t) & hashq, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hash", 2, (function1_t) & hash, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hashq-get-handle", 3, (function1_t) & hashq_get_handle, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hashq-ref", 3, (function1_t) & hashq_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hash-ref", 3, (function1_t) & hash_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hashq-set!", 3, (function1_t) & hashq_set_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hash-set!", 3, (function1_t) & hash_set_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "hash-table-printer", 1, (function1_t) & hash_table_printer, a);
|
|
|
|
|
a = init_builtin (builtin_type, "make-hash-table", 1, (function1_t) & make_hash_table, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/lib.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "core:display", 1, (function1_t) & display_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:display-error", 1, (function1_t) & display_error_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:display-port", 2, (function1_t) & display_port_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:write", 1, (function1_t) & write_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:write-error", 1, (function1_t) & write_error_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:write-port", 2, (function1_t) & write_port_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "exit", 1, (function1_t) & exit_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "frame-printer", 1, (function1_t) & frame_printer, a);
|
|
|
|
|
a = init_builtin (builtin_type, "make-stack", -1, (function1_t) & make_stack, a);
|
|
|
|
|
a = init_builtin (builtin_type, "stack-length", 1, (function1_t) & stack_length, a);
|
|
|
|
|
a = init_builtin (builtin_type, "stack-ref", 2, (function1_t) & stack_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "xassq", 2, (function1_t) & xassq, a);
|
|
|
|
|
a = init_builtin (builtin_type, "memq", 2, (function1_t) & memq, a);
|
|
|
|
|
a = init_builtin (builtin_type, "equal2?", 2, (function1_t) & equal2_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "last-pair", 1, (function1_t) & last_pair, a);
|
|
|
|
|
a = init_builtin (builtin_type, "pair?", 1, (function1_t) & pair_p, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/math.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, ">", -1, (function1_t) & greater_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "<", -1, (function1_t) & less_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "=", -1, (function1_t) & is_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "-", -1, (function1_t) & minus, a);
|
|
|
|
|
a = init_builtin (builtin_type, "+", -1, (function1_t) & plus, a);
|
|
|
|
|
a = init_builtin (builtin_type, "/", -1, (function1_t) & divide, a);
|
|
|
|
|
a = init_builtin (builtin_type, "modulo", 2, (function1_t) & modulo, a);
|
|
|
|
|
a = init_builtin (builtin_type, "*", -1, (function1_t) & multiply, a);
|
|
|
|
|
a = init_builtin (builtin_type, "logand", -1, (function1_t) & logand, a);
|
|
|
|
|
a = init_builtin (builtin_type, "logior", -1, (function1_t) & logior, a);
|
|
|
|
|
a = init_builtin (builtin_type, "lognot", 1, (function1_t) & lognot, a);
|
|
|
|
|
a = init_builtin (builtin_type, "logxor", -1, (function1_t) & logxor, a);
|
|
|
|
|
a = init_builtin (builtin_type, "ash", 2, (function1_t) & ash, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/mes.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "core:make-cell", 3, (function1_t) & make_cell_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:type", 1, (function1_t) & type_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:car", 1, (function1_t) & car_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:cdr", 1, (function1_t) & cdr_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "cons", 2, (function1_t) & cons, a);
|
|
|
|
|
a = init_builtin (builtin_type, "car", 1, (function1_t) & car, a);
|
|
|
|
|
a = init_builtin (builtin_type, "cdr", 1, (function1_t) & cdr, a);
|
|
|
|
|
a = init_builtin (builtin_type, "list", -1, (function1_t) & list, a);
|
|
|
|
|
a = init_builtin (builtin_type, "null?", 1, (function1_t) & null_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "eq?", 2, (function1_t) & eq_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "values", -1, (function1_t) & values, a);
|
|
|
|
|
a = init_builtin (builtin_type, "acons", 3, (function1_t) & acons, a);
|
|
|
|
|
a = init_builtin (builtin_type, "length", 1, (function1_t) & length, a);
|
|
|
|
|
a = init_builtin (builtin_type, "error", 2, (function1_t) & error, a);
|
|
|
|
|
a = init_builtin (builtin_type, "append2", 2, (function1_t) & append2, a);
|
|
|
|
|
a = init_builtin (builtin_type, "append-reverse", 2, (function1_t) & append_reverse, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:reverse!", 2, (function1_t) & reverse_x_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "pairlis", 3, (function1_t) & pairlis, a);
|
|
|
|
|
a = init_builtin (builtin_type, "assq", 2, (function1_t) & assq, a);
|
|
|
|
|
a = init_builtin (builtin_type, "assoc", 2, (function1_t) & assoc, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-car!", 2, (function1_t) & set_car_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-cdr!", 2, (function1_t) & set_cdr_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-env!", 3, (function1_t) & set_env_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "macro-get-handle", 1, (function1_t) & macro_get_handle, a);
|
|
|
|
|
a = init_builtin (builtin_type, "add-formals", 2, (function1_t) & add_formals, a);
|
|
|
|
|
a = init_builtin (builtin_type, "eval-apply", 0, (function1_t) & eval_apply, a);
|
|
|
|
|
a = init_builtin (builtin_type, "make-builtin-type", 0, (function1_t) & make_builtin_type, a);
|
|
|
|
|
a = init_builtin (builtin_type, "make-builtin", 4, (function1_t) & make_builtin, a);
|
|
|
|
|
a = init_builtin (builtin_type, "builtin-name", 1, (function1_t) & builtin_name, a);
|
|
|
|
|
a = init_builtin (builtin_type, "builtin-arity", 1, (function1_t) & builtin_arity, a);
|
|
|
|
|
a = init_builtin (builtin_type, "builtin?", 1, (function1_t) & builtin_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "builtin-printer", 1, (function1_t) & builtin_printer, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/module.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "make-module-type", 0, (function1_t) & make_module_type, a);
|
|
|
|
|
a = init_builtin (builtin_type, "module-printer", 1, (function1_t) & module_printer, a);
|
|
|
|
|
a = init_builtin (builtin_type, "module-variable", 2, (function1_t) & module_variable, a);
|
|
|
|
|
a = init_builtin (builtin_type, "module-ref", 2, (function1_t) & module_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "module-define!", 3, (function1_t) & module_define_x, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/posix.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "peek-byte", 0, (function1_t) & peek_byte, a);
|
|
|
|
|
a = init_builtin (builtin_type, "read-byte", 0, (function1_t) & read_byte, a);
|
|
|
|
|
a = init_builtin (builtin_type, "unread-byte", 1, (function1_t) & unread_byte, a);
|
|
|
|
|
a = init_builtin (builtin_type, "peek-char", 0, (function1_t) & peek_char, a);
|
|
|
|
|
a = init_builtin (builtin_type, "read-char", -1, (function1_t) & read_char, a);
|
|
|
|
|
a = init_builtin (builtin_type, "unread-char", 1, (function1_t) & unread_char, a);
|
|
|
|
|
a = init_builtin (builtin_type, "write-char", -1, (function1_t) & write_char, a);
|
|
|
|
|
a = init_builtin (builtin_type, "write-byte", -1, (function1_t) & write_byte, a);
|
|
|
|
|
a = init_builtin (builtin_type, "getenv", 1, (function1_t) & getenv_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "setenv", 2, (function1_t) & setenv_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "access?", 2, (function1_t) & access_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "current-input-port", 0, (function1_t) & current_input_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "open-input-file", 1, (function1_t) & open_input_file, a);
|
|
|
|
|
a = init_builtin (builtin_type, "open-input-string", 1, (function1_t) & open_input_string, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-current-input-port", 1, (function1_t) & set_current_input_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "current-output-port", 0, (function1_t) & current_output_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "current-error-port", 0, (function1_t) & current_error_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "open-output-file", -1, (function1_t) & open_output_file, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-current-output-port", 1, (function1_t) & set_current_output_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "set-current-error-port", 1, (function1_t) & set_current_error_port, a);
|
|
|
|
|
a = init_builtin (builtin_type, "chmod", 2, (function1_t) & chmod_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "isatty?", 1, (function1_t) & isatty_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "primitive-fork", 0, (function1_t) & primitive_fork, a);
|
|
|
|
|
a = init_builtin (builtin_type, "execl", 2, (function1_t) & execl_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "core:waitpid", 2, (function1_t) & waitpid_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "current-time", 0, (function1_t) & current_time, a);
|
|
|
|
|
a = init_builtin (builtin_type, "gettimeofday", 0, (function1_t) & gettimeofday_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "get-internal-run-time", 0, (function1_t) & get_internal_run_time, a);
|
|
|
|
|
a = init_builtin (builtin_type, "getcwd", 0, (function1_t) & getcwd_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "dup", 1, (function1_t) & dup_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "dup2", 2, (function1_t) & dup2_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "delete-file", 1, (function1_t) & delete_file, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/reader.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "core:read-input-file-env", 2, (function1_t) & read_input_file_env_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "read-input-file-env", 1, (function1_t) & read_input_file_env, a);
|
|
|
|
|
a = init_builtin (builtin_type, "read-env", 1, (function1_t) & read_env, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-sexp", 3, (function1_t) & reader_read_sexp, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-character", 0, (function1_t) & reader_read_character, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-binary", 0, (function1_t) & reader_read_binary, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-octal", 0, (function1_t) & reader_read_octal, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-hex", 0, (function1_t) & reader_read_hex, a);
|
|
|
|
|
a = init_builtin (builtin_type, "reader-read-string", 0, (function1_t) & reader_read_string, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/strings.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "string=?", 2, (function1_t) & string_equal_p, a);
|
|
|
|
|
a = init_builtin (builtin_type, "symbol->string", 1, (function1_t) & symbol_to_string, a);
|
|
|
|
|
a = init_builtin (builtin_type, "symbol->keyword", 1, (function1_t) & symbol_to_keyword, a);
|
|
|
|
|
a = init_builtin (builtin_type, "keyword->string", 1, (function1_t) & keyword_to_string, a);
|
|
|
|
|
a = init_builtin (builtin_type, "string->symbol", 1, (function1_t) & string_to_symbol, a);
|
|
|
|
|
a = init_builtin (builtin_type, "make-symbol", 1, (function1_t) & make_symbol, a);
|
|
|
|
|
a = init_builtin (builtin_type, "string->list", 1, (function1_t) & string_to_list, a);
|
|
|
|
|
a = init_builtin (builtin_type, "list->string", 1, (function1_t) & list_to_string, a);
|
|
|
|
|
a = init_builtin (builtin_type, "read-string", -1, (function1_t) & read_string, a);
|
|
|
|
|
a = init_builtin (builtin_type, "string-append", -1, (function1_t) & string_append, a);
|
|
|
|
|
a = init_builtin (builtin_type, "string-length", 1, (function1_t) & string_length, a);
|
|
|
|
|
a = init_builtin (builtin_type, "string-ref", 2, (function1_t) & string_ref, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/struct.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "make-struct", 3, (function1_t) & make_struct, a);
|
|
|
|
|
a = init_builtin (builtin_type, "struct-length", 1, (function1_t) & struct_length, a);
|
|
|
|
|
a = init_builtin (builtin_type, "struct-ref", 2, (function1_t) & struct_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "struct-set!", 3, (function1_t) & struct_set_x, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
// src/vector.mes
|
2019-02-16 11:27:42 +00:00
|
|
|
|
a = init_builtin (builtin_type, "core:make-vector", 1, (function1_t) & make_vector_, a);
|
|
|
|
|
a = init_builtin (builtin_type, "vector-length", 1, (function1_t) & vector_length, a);
|
|
|
|
|
a = init_builtin (builtin_type, "vector-ref", 2, (function1_t) & vector_ref, a);
|
|
|
|
|
a = init_builtin (builtin_type, "vector-entry", 1, (function1_t) & vector_entry, a);
|
|
|
|
|
a = init_builtin (builtin_type, "vector-set!", 3, (function1_t) & vector_set_x, a);
|
|
|
|
|
a = init_builtin (builtin_type, "list->vector", 1, (function1_t) & list_to_vector, a);
|
|
|
|
|
a = init_builtin (builtin_type, "vector->list", 1, (function1_t) & vector_to_list, a);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2018-12-21 08:55:16 +00:00
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
2017-05-23 06:16:08 +01:00
|
|
|
|
|
2018-05-28 17:53:25 +01:00
|
|
|
|
int
|
2019-03-02 13:36:22 +00:00
|
|
|
|
try_open_boot (char *file_name, char const *boot, char const *location)
|
2018-05-28 17:53:25 +01:00
|
|
|
|
{
|
2019-03-02 13:36:22 +00:00
|
|
|
|
strcpy (file_name + strlen (file_name), boot);
|
2018-05-28 17:53:25 +01:00
|
|
|
|
if (g_debug > 1)
|
|
|
|
|
{
|
|
|
|
|
eputs ("mes: reading boot-0 [");
|
|
|
|
|
eputs (location);
|
|
|
|
|
eputs ("]: ");
|
2019-03-02 13:36:22 +00:00
|
|
|
|
eputs (file_name);
|
2018-05-28 17:53:25 +01:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2019-03-02 13:36:22 +00:00
|
|
|
|
int fd = mes_open (file_name, O_RDONLY, 0);
|
2018-05-28 17:53:25 +01:00
|
|
|
|
if (g_debug && fd > 0)
|
|
|
|
|
{
|
|
|
|
|
eputs ("mes: read boot-0: ");
|
2019-03-02 13:36:22 +00:00
|
|
|
|
eputs (file_name);
|
2018-05-28 17:53:25 +01:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
|
void
|
|
|
|
|
open_boot ()
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
|
__stdin = -1;
|
2018-04-29 17:38:57 +01:00
|
|
|
|
char boot[1024];
|
2019-03-02 13:36:22 +00:00
|
|
|
|
char file_name[1024];
|
|
|
|
|
strcpy (g_datadir, ".");
|
|
|
|
|
if (g_debug > 1)
|
|
|
|
|
{
|
|
|
|
|
eputs (";;; pkgdatadir=");
|
2019-04-05 17:20:32 +01:00
|
|
|
|
eputs (MES_PKGDATADIR);
|
2019-03-02 13:36:22 +00:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
if (getenv ("MES_BOOT"))
|
|
|
|
|
strcpy (boot, getenv ("MES_BOOT"));
|
|
|
|
|
else
|
|
|
|
|
strcpy (boot, "boot-0.scm");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
if (getenv ("MES_PREFIX"))
|
|
|
|
|
{
|
2019-03-02 13:36:22 +00:00
|
|
|
|
strcpy (g_datadir, getenv ("MES_PREFIX"));
|
2019-04-06 08:19:53 +01:00
|
|
|
|
strcpy (g_datadir + strlen (g_datadir), "/mes");
|
2019-03-02 13:36:22 +00:00
|
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
|
|
|
|
__stdin = try_open_boot (file_name, boot, "MES_PREFIX");
|
|
|
|
|
if (__stdin < 0)
|
|
|
|
|
{
|
|
|
|
|
strcpy (g_datadir, getenv ("MES_PREFIX"));
|
|
|
|
|
strcpy (g_datadir + strlen (g_datadir), "/share/mes");
|
|
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
|
|
|
|
__stdin = try_open_boot (file_name, boot, "MES_PREFIX/share/mes");
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
}
|
2019-01-05 11:35:18 +00:00
|
|
|
|
if (__stdin < 0)
|
2018-02-03 20:43:52 +00:00
|
|
|
|
{
|
2019-04-05 17:20:32 +01:00
|
|
|
|
strcpy (g_datadir, MES_PKGDATADIR);
|
2019-03-02 13:36:22 +00:00
|
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
|
|
|
|
__stdin = try_open_boot (file_name, boot, "pkgdatadir");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
}
|
2019-01-05 11:35:18 +00:00
|
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
|
{
|
2019-04-06 08:19:53 +01:00
|
|
|
|
g_datadir[0] = 0;
|
|
|
|
|
if (getenv ("srcdest"))
|
|
|
|
|
strcpy (g_datadir, getenv ("srcdest"));
|
|
|
|
|
strcpy (g_datadir + strlen (g_datadir), "mes");
|
2019-03-02 13:36:22 +00:00
|
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
2019-04-06 08:19:53 +01:00
|
|
|
|
__stdin = try_open_boot (file_name, boot, "${srcdest}mes");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
}
|
2019-01-05 11:35:18 +00:00
|
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
|
{
|
2019-03-02 13:36:22 +00:00
|
|
|
|
file_name[0] = 0;
|
|
|
|
|
__stdin = try_open_boot (file_name, boot, "<boot>");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
}
|
2019-01-05 11:35:18 +00:00
|
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
eputs ("mes: boot failed: no such file: ");
|
|
|
|
|
eputs (boot);
|
|
|
|
|
eputs ("\n");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2019-03-02 13:36:22 +00:00
|
|
|
|
}
|
2017-12-09 21:38:51 +00:00
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
|
SCM
|
|
|
|
|
read_boot () ///((internal))
|
|
|
|
|
{
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
r2 = read_input_file_env (r0);
|
2019-01-05 11:35:18 +00:00
|
|
|
|
__stdin = STDIN;
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
return r2;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
|
void
|
|
|
|
|
init ()
|
2016-07-16 21:43:13 +01:00
|
|
|
|
{
|
2017-04-17 22:32:02 +01:00
|
|
|
|
char *p;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (p = getenv ("MES_DEBUG"))
|
|
|
|
|
g_debug = atoi (p);
|
2019-03-02 13:36:22 +00:00
|
|
|
|
open_boot ();
|
|
|
|
|
gc_init ();
|
|
|
|
|
g_ports = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
init ();
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
|
|
|
|
SCM a = mes_environment (argc, argv);
|
|
|
|
|
a = mes_builtins (a);
|
2018-10-20 13:18:04 +01:00
|
|
|
|
a = init_time (a);
|
2018-10-14 08:10:30 +01:00
|
|
|
|
m0 = make_initial_module (a);
|
2018-10-15 13:13:51 +01:00
|
|
|
|
g_macros = make_hash_table_ (0);
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
2019-02-25 19:30:48 +00:00
|
|
|
|
if (g_debug > 5)
|
2018-10-14 08:10:30 +01:00
|
|
|
|
module_printer (m0);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
|
2018-12-30 06:44:59 +00:00
|
|
|
|
SCM program = read_boot ();
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
push_cc (r2, cell_unspecified, r0, cell_unspecified);
|
2018-04-09 06:12:38 +01:00
|
|
|
|
|
|
|
|
|
if (g_debug > 2)
|
|
|
|
|
{
|
|
|
|
|
eputs ("\ngc stats: [");
|
|
|
|
|
eputs (itoa (g_free));
|
|
|
|
|
eputs ("]\n");
|
|
|
|
|
}
|
|
|
|
|
if (g_debug > 3)
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
eputs ("program: ");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (r1);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r3 = cell_vm_begin_expand;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = eval_apply ();
|
2017-04-10 18:13:20 +01:00
|
|
|
|
if (g_debug)
|
|
|
|
|
{
|
2018-04-09 06:12:38 +01:00
|
|
|
|
write_error_ (r1);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
if (g_debug)
|
|
|
|
|
{
|
2019-02-25 19:30:48 +00:00
|
|
|
|
if (g_debug > 5)
|
2018-11-11 15:25:36 +00:00
|
|
|
|
module_printer (m0);
|
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
eputs ("\ngc stats: [");
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs (itoa (g_free));
|
2018-04-14 07:15:49 +01:00
|
|
|
|
MAX_ARENA_SIZE = 0;
|
2018-11-11 15:25:36 +00:00
|
|
|
|
|
|
|
|
|
gc (g_stack);
|
|
|
|
|
eputs (" => ");
|
|
|
|
|
eputs (itoa (g_free));
|
|
|
|
|
eputs ("]\n");
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
|
2019-02-25 19:30:48 +00:00
|
|
|
|
if (g_debug > 5)
|
2018-11-11 15:25:36 +00:00
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
|
eputs ("ports:");
|
|
|
|
|
write_error_ (g_ports);
|
|
|
|
|
eputs ("\n");
|
2018-11-11 15:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
}
|
2016-07-16 21:43:13 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|