Move optional type predicates to type.c.
* mes.c (char_p, macro_p, number_p, pair_p, string_p, symbol_p,
vector_p, builtin_p, boolean_p): Move to type.c
* type.c: New file.
* GNUmakefile (mes.o): Depend on type snarf output.
* module/mes/loop-0.mes (cond, map, let, or, and not, evlis-env,
apply-env, eval-expand, uquote, add-unquoters, eval,
expand-macro-env, eval-begin-env, eval-if-env, sexp:define,
env:define, env:macro): Move to mes-0.mes.
* module/mes/mes-0.mes: New file.
* module/mes/type-0.mes: New file.
* scripts/include.mes: If BOOT, also include mes-0.mes. If TYPE0,
also include type-0.mes.
2016-10-22 10:16:19 +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 !TYPE0
|
|
|
|
|
|
|
|
scm *
|
|
|
|
char_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == CHAR ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
macro_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == MACRO ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
number_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == NUMBER ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
pair_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == PAIR ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
Introduce reference type, use vectors of SCM.
* mes.c (type): Add REF.
(scm_t): Add ref, change vector to *scm_t. Update users.
(alloc): New function.
(cons, make_char, make_macro, make_number, make_string,
internal_make_symbol, make_vector): Use it.
(make_ref): New function.
(vector_entry): New function.
(make_vector, list_to_vector, vector_set_x): Use it.
(vector_ref): Dereference REF entry.
(display_helper): Handle REF.
* lib.c (vector_to_list): Handle REF.
* type.c (ref_p): New function.
* tests/vector.test (vector list): New test.
Bugfix vector-ref.
* mes.c (vector-ref): Make copies of simple values. Fixes lalr.
* tests/vector.test (vector-set! 3): New test.
2016-10-24 22:21:28 +00:00
|
|
|
scm *
|
|
|
|
ref_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == REF ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
Move optional type predicates to type.c.
* mes.c (char_p, macro_p, number_p, pair_p, string_p, symbol_p,
vector_p, builtin_p, boolean_p): Move to type.c
* type.c: New file.
* GNUmakefile (mes.o): Depend on type snarf output.
* module/mes/loop-0.mes (cond, map, let, or, and not, evlis-env,
apply-env, eval-expand, uquote, add-unquoters, eval,
expand-macro-env, eval-begin-env, eval-if-env, sexp:define,
env:define, env:macro): Move to mes-0.mes.
* module/mes/mes-0.mes: New file.
* module/mes/type-0.mes: New file.
* scripts/include.mes: If BOOT, also include mes-0.mes. If TYPE0,
also include type-0.mes.
2016-10-22 10:16:19 +00:00
|
|
|
scm *
|
|
|
|
string_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == STRING ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
symbol_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == SYMBOL ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
vector_p (scm *x)
|
|
|
|
{
|
|
|
|
return x->type == VECTOR ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
builtin_p (scm *x)
|
|
|
|
{
|
|
|
|
return (x->type == FUNCTION0
|
|
|
|
|| x->type == FUNCTION1
|
|
|
|
|| x->type == FUNCTION2
|
|
|
|
|| x->type == FUNCTION3
|
|
|
|
|| x->type == FUNCTIONn)
|
|
|
|
? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-types
|
|
|
|
scm *
|
|
|
|
null_p (scm *x)
|
|
|
|
{
|
|
|
|
return x == &scm_nil ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
atom_p (scm *x)
|
|
|
|
{
|
|
|
|
return (x->type == PAIR ? &scm_f : &scm_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
boolean_p (scm *x)
|
|
|
|
{
|
|
|
|
return (x == &scm_t || x == &scm_f) ? &scm_t : &scm_f;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
scm*make_number (int);
|
|
|
|
scm *
|
|
|
|
mes_type_of (scm *x)
|
|
|
|
{
|
|
|
|
return make_number (x->type);
|
|
|
|
}
|
|
|
|
|