mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-03 16:20:39 +02:00
Syntax uses scm_allocate_tagged
* libguile/syntax.c: Define a "struct scm_syntax". Use it instead of scm_words and SCM_CELL_OBJECT.
This commit is contained in:
parent
a5f9d0da6a
commit
61af4d201a
1 changed files with 32 additions and 17 deletions
|
@ -40,14 +40,13 @@
|
|||
|
||||
|
||||
|
||||
enum
|
||||
struct scm_syntax
|
||||
{
|
||||
TAG_WORD,
|
||||
EXPR_WORD,
|
||||
WRAP_WORD,
|
||||
MODULE_WORD,
|
||||
SOURCE_WORD,
|
||||
WORD_COUNT
|
||||
scm_t_bits tag;
|
||||
SCM expr;
|
||||
SCM wrap;
|
||||
SCM module;
|
||||
SCM source;
|
||||
};
|
||||
|
||||
static int
|
||||
|
@ -56,6 +55,20 @@ scm_is_syntax (SCM x)
|
|||
return SCM_HAS_TYP7 (x, scm_tc7_syntax);
|
||||
}
|
||||
|
||||
static inline struct scm_syntax *
|
||||
scm_to_syntax (SCM x)
|
||||
{
|
||||
if (!scm_is_syntax (x))
|
||||
abort ();
|
||||
return (struct scm_syntax *) SCM_UNPACK_POINTER (x);
|
||||
}
|
||||
|
||||
static inline SCM
|
||||
scm_from_syntax (struct scm_syntax *stx)
|
||||
{
|
||||
return SCM_PACK_POINTER (stx);
|
||||
}
|
||||
|
||||
#define SCM_VALIDATE_SYNTAX(pos, scm) \
|
||||
SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_syntax, "syntax object")
|
||||
|
||||
|
@ -79,13 +92,15 @@ SCM_DEFINE (scm_make_syntax, "make-syntax", 3, 1, 0,
|
|||
else if (!scm_is_eq (source, SCM_BOOL_F))
|
||||
SCM_VALIDATE_VECTOR (1, source);
|
||||
|
||||
SCM ret = scm_words (scm_tc7_syntax, WORD_COUNT);
|
||||
SCM_SET_CELL_OBJECT (ret, EXPR_WORD, exp);
|
||||
SCM_SET_CELL_OBJECT (ret, WRAP_WORD, wrap);
|
||||
SCM_SET_CELL_OBJECT (ret, MODULE_WORD, module);
|
||||
SCM_SET_CELL_OBJECT (ret, SOURCE_WORD, source);
|
||||
struct scm_syntax *ret = scm_allocate_tagged (SCM_I_CURRENT_THREAD,
|
||||
sizeof (*ret));
|
||||
ret->tag = scm_tc7_syntax;
|
||||
ret->expr = exp;
|
||||
ret->wrap = wrap;
|
||||
ret->module = module;
|
||||
ret->source = source;
|
||||
|
||||
return ret;
|
||||
return scm_from_syntax (ret);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
@ -95,7 +110,7 @@ SCM_DEFINE (scm_syntax_expression, "syntax-expression", 1, 0, 0,
|
|||
#define FUNC_NAME s_scm_syntax_expression
|
||||
{
|
||||
SCM_VALIDATE_SYNTAX (1, obj);
|
||||
return SCM_CELL_OBJECT (obj, EXPR_WORD);
|
||||
return scm_to_syntax (obj)->expr;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
@ -105,7 +120,7 @@ SCM_DEFINE (scm_syntax_wrap, "syntax-wrap", 1, 0, 0,
|
|||
#define FUNC_NAME s_scm_syntax_wrap
|
||||
{
|
||||
SCM_VALIDATE_SYNTAX (1, obj);
|
||||
return SCM_CELL_OBJECT (obj, WRAP_WORD);
|
||||
return scm_to_syntax (obj)->wrap;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
@ -115,7 +130,7 @@ SCM_DEFINE (scm_syntax_module, "syntax-module", 1, 0, 0,
|
|||
#define FUNC_NAME s_scm_syntax_module
|
||||
{
|
||||
SCM_VALIDATE_SYNTAX (1, obj);
|
||||
return SCM_CELL_OBJECT (obj, MODULE_WORD);
|
||||
return scm_to_syntax (obj)->module;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
@ -128,7 +143,7 @@ SCM_DEFINE (scm_syntax_source, "syntax-source", 1, 0, 0,
|
|||
#define FUNC_NAME s_scm_syntax_source
|
||||
{
|
||||
SCM_VALIDATE_SYNTAX (1, obj);
|
||||
return SCM_CELL_OBJECT (obj, SOURCE_WORD);
|
||||
return scm_to_syntax (obj)->source;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue