diff options
author | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1997-09-10 20:05:28 +0000 |
---|---|---|
committer | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1997-09-10 20:05:28 +0000 |
commit | 7332df664494f9a206b2460524f95e8dffe240a4 (patch) | |
tree | 86d87b07daa396ccd0425aacfe25cbc2031a49e5 /libguile/eval.c | |
parent | 87688f5f1282080e4fff755c4ba544f19ed418fb (diff) | |
download | guile-7332df664494f9a206b2460524f95e8dffe240a4.tar.gz |
* * eval.c (macro?, macro-type, macro-name, macro-transfomer): New
procedures;
(prinmacro): Removed. The code has been moved/merged into print.c
in order to decrease code redundancy. We want macros to print in
a way equivalent to procedures, and it would be silly to duplicate
the required code. (We don't want to maintain two places.)
(macrosmob): Print field is now a NULL pointer.
* eval.h (scm_macro_p, scm_macro_type, scm_macro_name,
scm_macro_transformer): New prototypes.
(scm_tc16_macro): Declared.
* * print.c (scm_iprin1): Added code for printing of macros. Macros
are now printed in a way equivalent to procedures.
Diffstat (limited to 'libguile/eval.c')
-rw-r--r-- | libguile/eval.c | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/libguile/eval.c b/libguile/eval.c index 2bb5487df..43dfa8644 100644 --- a/libguile/eval.c +++ b/libguile/eval.c @@ -2925,30 +2925,69 @@ scm_makmmacro (code) } +SCM_PROC (s_macro_p, "macro?", 1, 0, 0, scm_macro_p); -static int prinmacro SCM_P ((SCM exp, SCM port, scm_print_state *pstate)); +SCM +scm_macro_p (obj) + SCM obj; +{ + return (SCM_NIMP (obj) && SCM_TYP16 (obj) == scm_tc16_macro + ? SCM_BOOL_T + : SCM_BOOL_F); +} -static int -prinmacro (exp, port, pstate) - SCM exp; - SCM port; - scm_print_state *pstate; + +SCM_SYMBOL (scm_sym_syntax, "syntax"); +SCM_SYMBOL (scm_sym_macro, "macro"); +SCM_SYMBOL (scm_sym_mmacro, "macro!"); + +SCM_PROC (s_macro_type, "macro-type", 1, 0, 0, scm_macro_type); + +SCM +scm_macro_type (m) + SCM m; { - int writingp = SCM_WRITINGP (pstate); - if (SCM_CAR (exp) & (3L << 16)) - scm_gen_puts (scm_regular_string, "#<macro", port); - else - scm_gen_puts (scm_regular_string, "#<syntax", port); - if (SCM_CAR (exp) & (2L << 16)) - scm_gen_putc ('!', port); - scm_gen_putc (' ', port); - SCM_SET_WRITINGP (pstate, 1); - scm_iprin1 (SCM_CDR (exp), port, pstate); - SCM_SET_WRITINGP (pstate, writingp); - scm_gen_putc ('>', port); - return !0; + if (!(SCM_NIMP (m) && SCM_TYP16 (m) == scm_tc16_macro)) + return SCM_BOOL_F; + switch ((int) (SCM_CAR (m) >> 16)) + { + case 0: return scm_sym_syntax; + case 1: return scm_sym_macro; + case 2: return scm_sym_mmacro; + default: scm_wrong_type_arg (s_macro_type, 1, m); + } +} + + +SCM_PROC (s_macro_name, "macro-name", 1, 0, 0, scm_macro_name); + +SCM +scm_macro_name (m) + SCM m; +{ + SCM_ASSERT (SCM_NIMP (m) && SCM_TYP16 (m) == scm_tc16_macro, + m, + SCM_ARG1, + s_macro_name); + return scm_procedure_name (SCM_CDR (m)); } + +SCM_PROC (s_macro_transformer, "macro-transformer", 1, 0, 0, scm_macro_transformer); + +SCM +scm_macro_transformer (m) + SCM m; +{ + SCM_ASSERT (SCM_NIMP (m) && SCM_TYP16 (m) == scm_tc16_macro, + m, + SCM_ARG1, + s_macro_transformer); + return SCM_NFALSEP (scm_closure_p (SCM_CDR (m))) ? SCM_CDR (m) : SCM_BOOL_F; +} + + + SCM_PROC(s_force, "force", 1, 0, 0, scm_force); SCM @@ -3100,12 +3139,9 @@ scm_definedp (sym) SCM_BOOL_F : SCM_BOOL_T; } -static scm_smobfuns promsmob = -{scm_markcdr, scm_free0, prinprom}; - -static scm_smobfuns macrosmob = -{scm_markcdr, scm_free0, prinmacro}; +static scm_smobfuns promsmob = {scm_markcdr, scm_free0, prinprom}; +static scm_smobfuns macrosmob = {scm_markcdr, scm_free0}; SCM scm_make_synt (name, macroizer, fcn) |