2016-10-22 18:51:32 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* Mes --- Maxwell Equations of Software
|
2017-03-25 14:58:44 +00:00
|
|
|
* Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
2016-10-22 18:51:32 +00:00
|
|
|
*
|
|
|
|
* This file is part of Mes.
|
|
|
|
*
|
|
|
|
* Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Mes is distributed in the hope that it will be useful, but
|
|
|
|
* 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
|
|
|
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
//MINI_MES
|
|
|
|
// SCM
|
|
|
|
// length (SCM x)
|
|
|
|
// {
|
|
|
|
// int n = 0;
|
|
|
|
// while (x != cell_nil)
|
|
|
|
// {
|
|
|
|
// n++;
|
|
|
|
// if (TYPE (x) != TPAIR) return MAKE_NUMBER (-1);
|
|
|
|
// x = cdr (x);
|
|
|
|
// }
|
|
|
|
// return MAKE_NUMBER (n);
|
|
|
|
// }
|
2016-10-22 18:51:32 +00:00
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
SCM fdisplay_ (SCM,FILE*);
|
|
|
|
|
|
|
|
int g_depth;
|
|
|
|
|
|
|
|
SCM
|
|
|
|
display_helper (SCM x, int cont, char* sep, FILE *fd)
|
|
|
|
{
|
|
|
|
fputs (sep, fd);
|
|
|
|
if (g_depth == 0) return cell_unspecified;
|
|
|
|
g_depth = g_depth - 1;
|
|
|
|
|
|
|
|
switch (TYPE (x))
|
|
|
|
{
|
|
|
|
case TCHAR:
|
|
|
|
{
|
|
|
|
fputs ("#\\", fd);
|
|
|
|
putc (VALUE (x), fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TFUNCTION:
|
|
|
|
{
|
|
|
|
fputs ("#<procedure ", fd);
|
|
|
|
char *p = "?";
|
|
|
|
if (FUNCTION (x).name != 0)
|
|
|
|
p = FUNCTION (x).name;
|
|
|
|
fputs (p, fd);
|
|
|
|
fputs ("[", fd);
|
|
|
|
fputs (itoa (CDR (x)), fd);
|
|
|
|
fputs (",", fd);
|
|
|
|
fputs (itoa (x), fd);
|
|
|
|
fputs ("]>", fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TMACRO:
|
|
|
|
{
|
|
|
|
fputs ("#<macro ", fd);
|
|
|
|
display_helper (cdr (x), cont, "", fd);
|
|
|
|
fputs (">", fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TNUMBER:
|
|
|
|
{
|
|
|
|
fputs (itoa (VALUE (x)), fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TPAIR:
|
|
|
|
{
|
|
|
|
if (!cont) fputs ("(", fd);
|
|
|
|
if (x && x != cell_nil) fdisplay_ (CAR (x), fd);
|
|
|
|
if (CDR (x) && TYPE (CDR (x)) == TPAIR)
|
|
|
|
display_helper (CDR (x), 1, " ", fd);
|
|
|
|
else if (CDR (x) && CDR (x) != cell_nil)
|
|
|
|
{
|
|
|
|
if (TYPE (CDR (x)) != TPAIR)
|
|
|
|
fputs (" . ", fd);
|
|
|
|
fdisplay_ (CDR (x), fd);
|
|
|
|
}
|
|
|
|
if (!cont) fputs (")", fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TSPECIAL:
|
|
|
|
#if __NYACC__
|
|
|
|
// FIXME
|
|
|
|
//{}
|
|
|
|
{
|
|
|
|
SCM t = CAR (x);
|
|
|
|
while (t && t != cell_nil)
|
|
|
|
{
|
|
|
|
putc (VALUE (CAR (t)), fd);
|
|
|
|
t = CDR (t);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case TSTRING:
|
|
|
|
#if __NYACC__
|
|
|
|
// FIXME
|
|
|
|
{
|
|
|
|
SCM t = CAR (x);
|
|
|
|
while (t && t != cell_nil)
|
|
|
|
{
|
|
|
|
putc (VALUE (CAR (t)), fd);
|
|
|
|
t = CDR (t);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case TSYMBOL:
|
|
|
|
{
|
|
|
|
SCM t = CAR (x);
|
|
|
|
while (t && t != cell_nil)
|
|
|
|
{
|
|
|
|
putc (VALUE (CAR (t)), fd);
|
|
|
|
t = CDR (t);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fputs ("<", fd);
|
|
|
|
fputs (itoa (TYPE (x)), fd);
|
|
|
|
fputs (":", fd);
|
|
|
|
fputs (itoa (x), fd);
|
|
|
|
fputs (">", fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
display_ (SCM x)
|
|
|
|
{
|
|
|
|
g_depth = 5;
|
|
|
|
return display_helper (x, 0, "", stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
display_error_ (SCM x)
|
|
|
|
{
|
|
|
|
g_depth = 5;
|
|
|
|
return display_helper (x, 0, "", stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
fdisplay_ (SCM x, FILE *fd) ///((internal))
|
|
|
|
{
|
|
|
|
g_depth = 5;
|
|
|
|
return display_helper (x, 0, "", fd);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-12-23 19:31:45 +00:00
|
|
|
exit_ (SCM x) ///((name . "exit"))
|
2016-10-22 18:51:32 +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 (x) == TNUMBER);
|
2016-11-21 08:30:59 +00:00
|
|
|
exit (VALUE (x));
|
2016-10-22 18:51:32 +00:00
|
|
|
}
|
2016-12-24 00:23: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
|
|
|
|
append (SCM x) ///((arity . n))
|
2016-12-24 00:23: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
|
|
|
if (x == cell_nil) return cell_nil;
|
|
|
|
if (cdr (x) == cell_nil) return car (x);
|
|
|
|
return append2 (car (x), append (cdr (x)));
|
2016-12-24 00:23: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
|
|
|
//MINI_MES
|
|
|
|
// char const*
|
|
|
|
// string_to_cstring (SCM s)
|
|
|
|
// {
|
|
|
|
// static char buf[1024];
|
|
|
|
// char *p = buf;
|
|
|
|
// s = STRING (s);
|
|
|
|
// while (s != cell_nil)
|
|
|
|
// {
|
|
|
|
// *p++ = VALUE (car (s));
|
|
|
|
// s = cdr (s);
|
|
|
|
// }
|
|
|
|
// *p = 0;
|
|
|
|
// return buf;
|
|
|
|
// }
|
|
|
|
|
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)
|
|
|
|
// {
|
|
|
|
// SCM throw;
|
|
|
|
// if ((throw = assq_ref_env (cell_symbol_throw, r0)) != cell_undefined)
|
|
|
|
// return apply (throw, cons (key, cons (x, cell_nil)), r0);
|
|
|
|
// assert (!"error");
|
|
|
|
// }
|
2016-12-24 11:10:05 +00:00
|
|
|
|
2016-12-24 00:23:50 +00:00
|
|
|
SCM
|
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 19:13:01 +00:00
|
|
|
assert_defined (SCM x, SCM e) ///((internal))
|
2016-12-24 00:23:50 +00:00
|
|
|
{
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
if (e == cell_undefined) return error (cell_symbol_unbound_variable, x);
|
2016-12-24 11:10:05 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
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
|
|
|
check_formals (SCM f, SCM formals, SCM args) ///((internal))
|
2016-12-24 11:10:05 +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
|
|
|
int flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : VALUE (length (formals));
|
2016-12-24 11:10:05 +00:00
|
|
|
int alen = VALUE (length (args));
|
|
|
|
if (alen != flen && alen != -1 && flen != -1)
|
2016-12-24 00:23:50 +00:00
|
|
|
{
|
2016-12-24 11:10:05 +00:00
|
|
|
char buf[1024];
|
|
|
|
sprintf (buf, "apply: wrong number of arguments; expected: %d, got: %d: ", flen, alen);
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
SCM e = MAKE_STRING (cstring_to_list (buf));
|
|
|
|
return error (cell_symbol_wrong_number_of_args, cons (e, f));
|
2016-12-24 00:23:50 +00:00
|
|
|
}
|
2016-12-24 11:10:05 +00:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
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 19:13:01 +00:00
|
|
|
check_apply (SCM f, SCM e) ///((internal))
|
2016-12-24 11:10:05 +00:00
|
|
|
{
|
|
|
|
char const* type = 0;
|
|
|
|
if (f == cell_f || f == cell_t) type = "bool";
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
if (f == cell_nil) type = "nil";
|
|
|
|
if (f == cell_unspecified) type = "*unspecified*";
|
|
|
|
if (f == cell_undefined) type = "*undefined*";
|
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 (f) == TCHAR) type = "char";
|
|
|
|
if (TYPE (f) == TNUMBER) type = "number";
|
|
|
|
if (TYPE (f) == TSTRING) type = "string";
|
2016-12-24 11:10:05 +00:00
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
sprintf (buf, "cannot apply: %s:", type);
|
|
|
|
fprintf (stderr, " [");
|
2017-03-25 14:58:44 +00:00
|
|
|
display_error_ (e);
|
2016-12-24 11:10:05 +00:00
|
|
|
fprintf (stderr, "]\n");
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
SCM e = MAKE_STRING (cstring_to_list (buf));
|
|
|
|
return error (cell_symbol_wrong_type_arg, cons (e, f));
|
2016-12-24 11:10:05 +00:00
|
|
|
}
|
|
|
|
return cell_unspecified;
|
2016-12-24 00:23:50 +00:00
|
|
|
}
|
2016-12-24 13:05:33 +00:00
|
|
|
|
2017-03-06 06:14:15 +00:00
|
|
|
char const*
|
|
|
|
itoa (int x)
|
|
|
|
{
|
|
|
|
static char buf[10];
|
|
|
|
char *p = buf+9;
|
|
|
|
*p-- = 0;
|
|
|
|
|
|
|
|
int sign = x < 0;
|
|
|
|
if (sign)
|
|
|
|
x = -x;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*p-- = '0' + (x % 10);
|
|
|
|
x = x / 10;
|
|
|
|
} while (x);
|
|
|
|
|
|
|
|
if (sign)
|
|
|
|
*p-- = '-';
|
|
|
|
|
|
|
|
return p+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
|
|
|
//FILE *g_stdin;
|
2016-12-24 13:05:33 +00:00
|
|
|
int
|
|
|
|
dump ()
|
|
|
|
{
|
2017-03-07 21:33:59 +00:00
|
|
|
fputs ("program r2=", stderr);
|
2017-03-25 14:58:44 +00:00
|
|
|
display_error_ (r2);
|
2017-03-07 21:33:59 +00:00
|
|
|
fputs ("\n", stderr);
|
|
|
|
|
2016-12-24 13:05:33 +00:00
|
|
|
r1 = g_symbols;
|
2017-03-06 06:14:15 +00:00
|
|
|
gc_push_frame ();
|
|
|
|
gc ();
|
|
|
|
gc_peek_frame ();
|
2016-12-24 13:05:33 +00:00
|
|
|
char *p = (char*)g_cells;
|
|
|
|
fputc ('M', stdout);
|
|
|
|
fputc ('E', stdout);
|
|
|
|
fputc ('S', stdout);
|
2016-12-26 08:00:43 +00:00
|
|
|
fputc (g_stack >> 8, stdout);
|
|
|
|
fputc (g_stack % 256, stdout);
|
2017-03-19 12:41:56 +00:00
|
|
|
// See HACKING, simple crafted dump for tiny-mes.c
|
|
|
|
if (getenv ("MES_TINY"))
|
2017-01-10 19:05:47 +00:00
|
|
|
{
|
|
|
|
TYPE (9) = 0x2d2d2d2d;
|
|
|
|
CAR (9) = 0x2d2d2d2d;
|
|
|
|
CDR (9) = 0x3e3e3e3e;
|
|
|
|
|
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 (10) = TPAIR;
|
2017-01-10 19:05:47 +00:00
|
|
|
CAR (10) = 11;
|
|
|
|
CDR (10) = 12;
|
|
|
|
|
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 (11) = TCHAR;
|
2017-01-10 19:05:47 +00:00
|
|
|
CAR (11) = 0x58585858;
|
|
|
|
CDR (11) = 65;
|
|
|
|
|
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 (12) = TPAIR;
|
2017-01-10 19:05:47 +00:00
|
|
|
CAR (12) = 13;
|
|
|
|
CDR (12) = 1;
|
|
|
|
|
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 (13) = TCHAR;
|
2017-01-10 19:05:47 +00:00
|
|
|
CAR (11) = 0x58585858;
|
|
|
|
CDR (13) = 66;
|
|
|
|
|
|
|
|
TYPE (14) = 0x3c3c3c3c;
|
|
|
|
CAR (14) = 0x2d2d2d2d;
|
|
|
|
CDR (14) = 0x2d2d2d2d;
|
|
|
|
|
|
|
|
g_free = 15;
|
|
|
|
}
|
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
|
|
|
for (int i=0; i<g_free * sizeof(struct scm); i++)
|
2016-12-24 13:05:33 +00:00
|
|
|
fputc (*p++, stdout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
load_env (SCM a) ///((internal))
|
|
|
|
{
|
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
|
|
|
r0 = a;
|
2017-03-22 05:59:50 +00:00
|
|
|
g_stdin = fopen ("module/mes/read-0.mes", "r");
|
|
|
|
g_stdin = g_stdin ? g_stdin : fopen (PREFIX "module/mes/read-0.mes", "r");
|
2016-12-24 13:05:33 +00:00
|
|
|
if (!g_function) r0 = mes_builtins (r0);
|
2016-12-26 08:04:40 +00:00
|
|
|
r2 = read_input_file_env (r0);
|
2016-12-24 13:05:33 +00:00
|
|
|
g_stdin = stdin;
|
2016-12-26 08:04:40 +00:00
|
|
|
return r2;
|
2016-12-24 13:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
bload_env (SCM a) ///((internal))
|
|
|
|
{
|
2017-03-07 21:33:59 +00:00
|
|
|
#if MES_MINI
|
2017-03-19 12:41:56 +00:00
|
|
|
g_stdin = fopen ("module/mes/read-0-32.mo", "r");
|
2017-03-07 21:33:59 +00:00
|
|
|
#else
|
2016-12-24 13:05:33 +00:00
|
|
|
g_stdin = fopen ("module/mes/read-0.mo", "r");
|
|
|
|
g_stdin = g_stdin ? g_stdin : fopen (PREFIX "module/mes/read-0.mo", "r");
|
2017-03-07 21:33:59 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-24 13:05:33 +00:00
|
|
|
char *p = (char*)g_cells;
|
|
|
|
assert (getchar () == 'M');
|
|
|
|
assert (getchar () == 'E');
|
|
|
|
assert (getchar () == 'S');
|
2016-12-26 08:00:43 +00:00
|
|
|
g_stack = getchar () << 8;
|
|
|
|
g_stack += getchar ();
|
2016-12-24 13:05:33 +00:00
|
|
|
int c = getchar ();
|
|
|
|
while (c != EOF)
|
|
|
|
{
|
|
|
|
*p++ = c;
|
|
|
|
c = getchar ();
|
|
|
|
}
|
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
|
|
|
g_free = (p-(char*)g_cells) / sizeof (struct scm);
|
2016-12-26 08:00:43 +00:00
|
|
|
gc_peek_frame ();
|
2016-12-24 13:05:33 +00:00
|
|
|
g_symbols = r1;
|
|
|
|
g_stdin = stdin;
|
|
|
|
r0 = mes_builtins (r0);
|
2016-12-26 08:04:40 +00:00
|
|
|
return r2;
|
2016-12-24 13:05:33 +00:00
|
|
|
}
|
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 19:13:01 +00:00
|
|
|
|
|
|
|
SCM
|
|
|
|
xassq (SCM x, SCM a) ///for speed in core only
|
|
|
|
{
|
|
|
|
while (a != cell_nil && x != CDAR (a)) a = CDR (a);
|
|
|
|
return a != cell_nil ? CAR (a) : cell_f;
|
|
|
|
}
|