2016-10-22 17:26:12 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if QUASIQUOTE
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM add_environment (SCM a, char const *name, SCM x);
|
2016-10-30 15:01:34 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
unquote (SCM x) ///((no-environment))
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_unquote, x);
|
2016-10-22 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
unquote_splicing (SCM x) ///((no-environment))
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_unquote_splicing, x);
|
2016-10-22 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
eval_quasiquote (SCM e, SCM a)
|
2016-10-30 15:01:34 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return vm_call (vm_eval_quasiquote, e, cell_undefined, a);
|
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 16:42:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
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 16:42:03 +00:00
|
|
|
vm_eval_quasiquote ()
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (r1 == cell_nil) return r1;
|
|
|
|
else if (atom_p (r1) == cell_t) return r1;
|
|
|
|
else if (eq_p (car (r1), cell_symbol_unquote) == cell_t)
|
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 16:42:03 +00:00
|
|
|
return eval_env (cadr (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (type (r1) == PAIR && g_cells[car (r1)].type == PAIR
|
|
|
|
&& eq_p (caar (r1), cell_symbol_unquote_splicing) == cell_t)
|
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 16:42:03 +00:00
|
|
|
{
|
|
|
|
r2 = eval_env (cadar (r1), r0);
|
|
|
|
return append2 (r2, eval_quasiquote (cdr (r1), r0));
|
|
|
|
}
|
|
|
|
r2 = eval_quasiquote (car (r1), r0);
|
|
|
|
return cons (r2, eval_quasiquote (cdr (r1), r0));
|
2016-10-30 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
the_unquoters = 0;
|
2016-10-30 15:01:34 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
add_unquoters (SCM a)
|
2016-10-30 15:01:34 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (the_unquoters == 0)
|
|
|
|
the_unquoters = cons (cons (cell_symbol_unquote, cell_unquote),
|
|
|
|
cons (cons (cell_symbol_unquote_splicing, cell_unquote_splicing),
|
|
|
|
cell_nil));
|
2016-10-30 15:01:34 +00:00
|
|
|
return append2 (the_unquoters, a);
|
|
|
|
}
|
|
|
|
#else // !QUASIQUOTE
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM add_unquoters (SCM a){}
|
|
|
|
SCM eval_quasiquote (SCM e, SCM a){}
|
2016-10-30 15:01:34 +00:00
|
|
|
|
|
|
|
#endif // QUASIQUOTE
|
|
|
|
|
|
|
|
#if QUASISYNTAX
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
syntax (SCM x)
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_syntax, x);
|
2016-10-22 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
unsyntax (SCM x) ///((no-environment))
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_unsyntax, x);
|
2016-10-22 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
unsyntax_splicing (SCM x) ///((no-environment))
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_unsyntax_splicing, x);
|
2016-10-22 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
eval_quasisyntax (SCM e, SCM a)
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (e == cell_nil) return e;
|
|
|
|
else if (atom_p (e) == cell_t) return e;
|
|
|
|
else if (eq_p (car (e), cell_symbol_unsyntax) == cell_t)
|
2016-11-03 20:43:01 +00:00
|
|
|
return eval_env (cadr (e), a);
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (g_cells[e].type == PAIR && g_cells[car (e)].type == PAIR
|
|
|
|
&& eq_p (caar (e), cell_symbol_unsyntax_splicing) == cell_t)
|
2016-11-03 20:43:01 +00:00
|
|
|
return append2 (eval_env (cadar (e), a), eval_quasisyntax (cdr (e), a));
|
2016-10-22 17:26:12 +00:00
|
|
|
return cons (eval_quasisyntax (car (e), a), eval_quasisyntax (cdr (e), a));
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
add_unsyntaxers (SCM a)
|
2016-10-22 17:26:12 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
a = cons (cons (cell_symbol_unsyntax, cell_unsyntax), a);
|
|
|
|
a = cons (cons (cell_symbol_unsyntax_splicing, cell_unsyntax_splicing), a);
|
2016-10-22 17:26:12 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2016-10-30 15:01:34 +00:00
|
|
|
#else // !QUASISYNTAX
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM syntax (SCM x){}
|
|
|
|
SCM unsyntax (SCM x){}
|
|
|
|
SCM unsyntax_splicing (SCM x){}
|
|
|
|
SCM add_unsyntaxers (SCM a){}
|
|
|
|
SCM eval_unsyntax (SCM e, SCM a){}
|
|
|
|
SCM eval_quasisyntax (SCM e, SCM a){}
|
2016-10-22 17:26:12 +00:00
|
|
|
|
2016-10-30 15:01:34 +00:00
|
|
|
#endif // !QUASISYNTAX
|