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-06-08 14:36:22 +01: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-06-08 14:36:22 +01:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2020-04-19 12:18:09 +01:00
|
|
|
#include <limits.h>
|
2017-05-02 22:30:46 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-06-08 14:36:22 +01:00
|
|
|
#include <string.h>
|
2017-04-10 18:13:20 +01:00
|
|
|
|
2020-04-20 18:47:04 +01:00
|
|
|
// char const *MES_PKGDATADIR = "mes";
|
|
|
|
|
2018-10-19 21:38:19 +01:00
|
|
|
SCM
|
2020-04-19 12:18:09 +01:00
|
|
|
assoc_string (SCM x, SCM a) /*:((internal)) */
|
2018-10-19 21:38:19 +01:00
|
|
|
{
|
2019-05-18 12:27:42 +01: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);
|
2020-04-19 12:18:09 +01:00
|
|
|
if (a != cell_nil)
|
|
|
|
return CAR (a);
|
|
|
|
return cell_f;
|
2018-10-19 21:38:19 +01:00
|
|
|
}
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
SCM
|
|
|
|
type_ (SCM x)
|
|
|
|
{
|
|
|
|
return MAKE_NUMBER (TYPE (x));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
car_ (SCM x)
|
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
if (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))
|
|
|
|
return CAR (x);
|
|
|
|
return MAKE_NUMBER (CAR (x));
|
2017-03-25 14:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
cdr_ (SCM x)
|
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
if (TYPE (x) != TCHAR
|
|
|
|
&& TYPE (x) != TNUMBER
|
|
|
|
&& TYPE (x) != TPORT
|
|
|
|
&& (TYPE (CDR (x)) == TPAIR
|
|
|
|
|| TYPE (CDR (x)) == TREF
|
|
|
|
|| TYPE (CDR (x)) == TSPECIAL || TYPE (CDR (x)) == TSYMBOL || TYPE (CDR (x)) == TSTRING))
|
|
|
|
return CDR (x);
|
|
|
|
return MAKE_NUMBER (CDR (x));
|
2017-03-25 14:58:44 +00: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
|
2020-04-19 12:18:09 +01: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)
|
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
if (x == cell_nil)
|
|
|
|
return cell_t;
|
|
|
|
return 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
|
|
|
}
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
SCM
|
|
|
|
eq_p (SCM x, SCM y)
|
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
if (x == y
|
|
|
|
|| ((TYPE (x) == TKEYWORD && TYPE (y) == TKEYWORD
|
|
|
|
&& string_equal_p (x, y) == cell_t))
|
|
|
|
|| (TYPE (x) == TCHAR && TYPE (y) == TCHAR
|
|
|
|
&& VALUE (x) == VALUE (y))
|
|
|
|
|| (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER && VALUE (x) == VALUE (y)))
|
|
|
|
return cell_t;
|
|
|
|
return 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
|
2020-04-19 12:18:09 +01: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
|
2020-04-19 12:18:09 +01: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)
|
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
n = n + 1;
|
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;
|
2020-05-17 21:32:53 +01:00
|
|
|
if ((throw = module_ref (R0, cell_symbol_throw)) != cell_undefined)
|
|
|
|
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");
|
2020-05-17 15:07:04 +01:00
|
|
|
assert_msg (0, "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
|
|
|
}
|
|
|
|
|
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.
2019-01-04 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.
2019-01-04 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.
2019-01-04 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
|
|
|
|
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-05-18 12:27:42 +01: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-05-18 12:27:42 +01: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);
|
2020-04-19 12:18:09 +01:00
|
|
|
if (a != cell_nil)
|
|
|
|
return CAR (a);
|
|
|
|
return 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);
|
2020-04-19 12:18:09 +01:00
|
|
|
if (a != cell_nil)
|
|
|
|
return CAR (a);
|
|
|
|
return cell_f;
|
2018-10-19 21:38:19 +01:00
|
|
|
}
|
|
|
|
|
2017-04-02 16:01:22 +01:00
|
|
|
SCM
|
2020-04-19 12:18:09 +01: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 = STACK_SIZE;
|
2020-05-17 21:32:53 +01:00
|
|
|
R0 = a;
|
|
|
|
R1 = MAKE_CHAR (0);
|
|
|
|
R2 = MAKE_CHAR (0);
|
|
|
|
R3 = MAKE_CHAR (0);
|
|
|
|
return R0;
|
2017-04-02 16:01:22 +01:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
SCM
|
2020-04-19 12:18:09 +01:00
|
|
|
mes_environment (int argc, char **argv)
|
2017-04-10 18:13:20 +01:00
|
|
|
{
|
2020-05-17 19:50:12 +01:00
|
|
|
SCM a = init_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-05-22 16:55:20 +01: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-05-22 16:55:20 +01: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;
|
2020-04-19 12:18:09 +01:00
|
|
|
int i;
|
|
|
|
for (i = argc - 1; i >= 0; i = i - 1)
|
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);
|
|
|
|
}
|
|
|
|
|
2018-05-28 17:53:25 +01:00
|
|
|
int
|
2019-06-08 14:36:22 +01:00
|
|
|
try_open_boot (char *file_name, char const *boot, char const *location)
|
2018-05-28 17:53:25 +01:00
|
|
|
{
|
2019-06-08 14:36:22 +01: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-06-08 14:36:22 +01:00
|
|
|
eputs (file_name);
|
2018-05-28 17:53:25 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2019-06-08 14:36:22 +01:00
|
|
|
int fd = mes_open (file_name, O_RDONLY, 0);
|
2020-04-19 12:18:09 +01:00
|
|
|
if (g_debug != 0 && fd > 0)
|
2018-05-28 17:53:25 +01:00
|
|
|
{
|
|
|
|
eputs ("mes: read boot-0: ");
|
2019-06-08 14:36:22 +01:00
|
|
|
eputs (file_name);
|
2018-05-28 17:53:25 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2019-06-08 14:36:22 +01: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-03-02 11:35:18 +00:00
|
|
|
__stdin = -1;
|
2020-04-19 12:18:09 +01:00
|
|
|
char *boot = __open_boot_buf;
|
|
|
|
char *file_name = __open_boot_file_name;
|
2019-06-08 14:36:22 +01:00
|
|
|
strcpy (g_datadir, ".");
|
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-06-08 14:36:22 +01:00
|
|
|
strcpy (g_datadir, getenv ("MES_PREFIX"));
|
2019-07-27 08:19:53 +01:00
|
|
|
strcpy (g_datadir + strlen (g_datadir), "/mes");
|
2019-06-08 14:36:22 +01: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-03-02 11:35:18 +00:00
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2019-07-27 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-06-08 14:36:22 +01:00
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
2019-07-27 08:19:53 +01:00
|
|
|
__stdin = try_open_boot (file_name, boot, "${srcdest}mes");
|
2017-12-09 21:38:51 +00:00
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2019-06-08 14:36:22 +01:00
|
|
|
file_name[0] = 0;
|
|
|
|
__stdin = try_open_boot (file_name, boot, "<boot>");
|
2017-12-09 21:38:51 +00:00
|
|
|
}
|
2019-03-02 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-06-08 14:36:22 +01:00
|
|
|
}
|
2017-12-09 21:38:51 +00:00
|
|
|
|
2019-06-08 14:36:22 +01:00
|
|
|
SCM
|
2020-04-19 12:18:09 +01:00
|
|
|
read_boot () /*:((internal)) */
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2020-05-17 21:32:53 +01:00
|
|
|
R2 = read_input_file_env (R0);
|
2019-03-02 11:35:18 +00:00
|
|
|
__stdin = STDIN;
|
2020-05-17 21:32:53 +01:00
|
|
|
return R2;
|
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-06-08 14:36:22 +01:00
|
|
|
void
|
2020-04-19 12:18:09 +01:00
|
|
|
init (char **envp)
|
2016-07-16 21:43:13 +01:00
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
environ = envp;
|
|
|
|
__execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */
|
|
|
|
__getcwd_buf = malloc (PATH_MAX);
|
|
|
|
__open_boot_buf = malloc (PATH_MAX);
|
|
|
|
__open_boot_file_name = malloc (PATH_MAX);
|
|
|
|
__reader_read_char_buf = malloc (10);
|
|
|
|
__setenv_buf = malloc (1024);
|
|
|
|
g_datadir = malloc (1024);
|
|
|
|
|
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-06-08 14:36:22 +01:00
|
|
|
open_boot ();
|
|
|
|
gc_init ();
|
|
|
|
g_ports = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-19 12:18:09 +01:00
|
|
|
main (int argc, char **argv, char **envp)
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2020-04-19 12:18:09 +01:00
|
|
|
init (envp);
|
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);
|
2020-05-17 21:32:53 +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-05-27 20:30:48 +01:00
|
|
|
if (g_debug > 5)
|
2020-05-17 21:32:53 +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
|
|
|
|
2019-02-24 06:44:59 +00:00
|
|
|
SCM program = read_boot ();
|
2020-05-17 21:32:53 +01: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: ");
|
2020-05-17 21:32:53 +01:00
|
|
|
write_error_ (R1);
|
2017-04-10 18:13:20 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2020-05-17 21:32:53 +01:00
|
|
|
R3 = cell_vm_begin_expand;
|
|
|
|
R1 = eval_apply ();
|
2020-04-19 12:18:09 +01:00
|
|
|
if (g_debug != 0)
|
2017-04-10 18:13:20 +01:00
|
|
|
{
|
2020-05-17 21:32:53 +01:00
|
|
|
write_error_ (R1);
|
2018-04-09 06:12:38 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2020-04-19 12:18:09 +01:00
|
|
|
if (g_debug != 0)
|
2018-04-09 06:12:38 +01:00
|
|
|
{
|
2019-05-27 20:30:48 +01:00
|
|
|
if (g_debug > 5)
|
2020-05-17 21:32:53 +01:00
|
|
|
module_printer (M0);
|
2018-11-11 15:25:36 +00:00
|
|
|
|
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-05-27 20:30:48 +01:00
|
|
|
if (g_debug > 5)
|
2018-11-11 15:25:36 +00:00
|
|
|
{
|
2019-05-18 12:27:42 +01: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;
|
|
|
|
}
|