2016-11-21 08:36: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-11-21 08:36: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/>.
|
|
|
|
*/
|
|
|
|
|
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 13:01:24 +00:00
|
|
|
#if _POSIX_SOURCE
|
|
|
|
#undef fputs
|
|
|
|
#undef fdputs
|
|
|
|
#undef fdputc
|
|
|
|
#endif
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
SCM
|
|
|
|
___end_of_mes___ ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
core: Move reader and posix functions from mes.c
* mes.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte, read_input_file_env_, read_input_file_env):
Remove.
* posix.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte): Move from mes.c.
* reader (read_input_file_env_, read_input_file_env): Move from mes.c.
2016-12-24 10:28:25 +00:00
|
|
|
|
|
|
|
SCM
|
|
|
|
read_input_file_env_ (SCM e, SCM a)
|
|
|
|
{
|
|
|
|
if (e == cell_nil) return e;
|
|
|
|
return cons (e, read_input_file_env_ (read_env (a), a));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
read_input_file_env (SCM a)
|
|
|
|
{
|
|
|
|
r0 = 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 (assq_ref_env (cell_symbol_read_input_file, r0) != cell_undefined)
|
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
|
|
|
return apply (cell_symbol_read_input_file, cell_nil, r0);
|
core: Move reader and posix functions from mes.c
* mes.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte, read_input_file_env_, read_input_file_env):
Remove.
* posix.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte): Move from mes.c.
* reader (read_input_file_env_, read_input_file_env): Move from mes.c.
2016-12-24 10:28:25 +00:00
|
|
|
return read_input_file_env_ (read_env (r0), r0);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
int
|
|
|
|
read_line_comment (int c)
|
|
|
|
{
|
|
|
|
if (c == '\n') return c;
|
|
|
|
return read_line_comment (getchar ());
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
read_word (int c, SCM w, SCM a)
|
|
|
|
{
|
|
|
|
if (c == EOF && w == cell_nil) return cell_nil;
|
2016-12-16 17:30:54 +00:00
|
|
|
if (c == '\t') return read_word ('\n', w, a);
|
|
|
|
if (c == '\f') return read_word ('\n', w, a);
|
2016-11-21 08:36:32 +00:00
|
|
|
if (c == '\n' && w == cell_nil) return read_word (getchar (), w, a);
|
|
|
|
if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
|
2016-12-23 10:31:34 +00:00
|
|
|
if (c == EOF || c == '\n') return lookup_ (w, a);
|
2016-11-21 08:36:32 +00:00
|
|
|
if (c == ' ') return read_word ('\n', w, a);
|
|
|
|
if (c == '(' && w == cell_nil) return read_list (a);
|
2016-12-23 10:31:34 +00:00
|
|
|
if (c == '(') {ungetchar (c); return lookup_ (w, a);}
|
2016-11-21 08:36:32 +00:00
|
|
|
if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
|
2016-12-23 10:31:34 +00:00
|
|
|
if (c == ')') {ungetchar (c); return lookup_ (w, a);}
|
2016-12-13 18:58:34 +00:00
|
|
|
if (c == ';') {read_line_comment (c); return read_word ('\n', w, a);}
|
2016-12-23 15:26:00 +00:00
|
|
|
return read_word (getchar (), append2 (w, cons (MAKE_CHAR (c), cell_nil)), a);
|
2016-11-21 08:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
eat_whitespace (int c)
|
|
|
|
{
|
2016-12-16 17:30:54 +00:00
|
|
|
while (c == ' ' || c == '\t' || c == '\n' || c == '\f') c = getchar ();
|
2016-11-21 08:36:32 +00:00
|
|
|
if (c == ';') return eat_whitespace (read_line_comment (c));
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
read_list (SCM a)
|
|
|
|
{
|
|
|
|
int c = getchar ();
|
|
|
|
c = eat_whitespace (c);
|
|
|
|
if (c == ')') return cell_nil;
|
|
|
|
SCM w = read_word (c, cell_nil, a);
|
|
|
|
if (w == cell_dot)
|
|
|
|
return car (read_list (a));
|
|
|
|
return cons (w, read_list (a));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
read_env (SCM a)
|
|
|
|
{
|
|
|
|
return read_word (getchar (), cell_nil, a);
|
|
|
|
}
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
SCM
|
|
|
|
lookup_ (SCM s, SCM a)
|
|
|
|
{
|
|
|
|
if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
|
|
|
|
SCM p = s;
|
|
|
|
int sign = 1;
|
|
|
|
if (VALUE (car (s)) == '-') {
|
|
|
|
sign = -1;
|
|
|
|
p = cdr (s);
|
|
|
|
}
|
|
|
|
int n = 0;
|
|
|
|
while (p != cell_nil && isdigit (VALUE (car (p)))) {
|
|
|
|
n *= 10;
|
|
|
|
n += VALUE (car (p)) - '0';
|
|
|
|
p = cdr (p);
|
|
|
|
}
|
|
|
|
if (p == cell_nil) return MAKE_NUMBER (n * sign);
|
|
|
|
}
|
2016-11-21 08:36:32 +00:00
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
return lookup_symbol_ (s);
|
|
|
|
}
|
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 13:01:24 +00:00
|
|
|
|
|
|
|
//FILE *g_stdin;
|
|
|
|
int
|
|
|
|
dump ()
|
|
|
|
{
|
|
|
|
fputs ("program r2=", stderr);
|
|
|
|
display_error_ (r2);
|
|
|
|
fputs ("\n", stderr);
|
|
|
|
|
|
|
|
r1 = g_symbols;
|
|
|
|
gc_push_frame ();
|
|
|
|
gc ();
|
|
|
|
gc_peek_frame ();
|
|
|
|
char *p = (char*)g_cells;
|
|
|
|
fputc ('M', stdout);
|
|
|
|
fputc ('E', stdout);
|
|
|
|
fputc ('S', stdout);
|
|
|
|
fputc (g_stack >> 8, stdout);
|
|
|
|
fputc (g_stack % 256, stdout);
|
|
|
|
// See HACKING, simple crafted dump for tiny-mes.c
|
|
|
|
if (getenv ("MES_TINY"))
|
|
|
|
{
|
|
|
|
TYPE (9) = 0x2d2d2d2d;
|
|
|
|
CAR (9) = 0x2d2d2d2d;
|
|
|
|
CDR (9) = 0x3e3e3e3e;
|
|
|
|
|
|
|
|
TYPE (10) = TPAIR;
|
|
|
|
CAR (10) = 11;
|
|
|
|
CDR (10) = 12;
|
|
|
|
|
|
|
|
TYPE (11) = TCHAR;
|
|
|
|
CAR (11) = 0x58585858;
|
|
|
|
CDR (11) = 65;
|
|
|
|
|
|
|
|
TYPE (12) = TPAIR;
|
|
|
|
CAR (12) = 13;
|
|
|
|
CDR (12) = 1;
|
|
|
|
|
|
|
|
TYPE (13) = TCHAR;
|
|
|
|
CAR (11) = 0x58585858;
|
|
|
|
CDR (13) = 66;
|
|
|
|
|
|
|
|
TYPE (14) = 0x3c3c3c3c;
|
|
|
|
CAR (14) = 0x2d2d2d2d;
|
|
|
|
CDR (14) = 0x2d2d2d2d;
|
|
|
|
|
|
|
|
g_free = 15;
|
|
|
|
}
|
|
|
|
for (int i=0; i<g_free * sizeof(struct scm); i++)
|
|
|
|
fputc (*p++, stdout);
|
|
|
|
return 0;
|
|
|
|
}
|