qse/ase/lsp/env.c

101 lines
2.0 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2005-09-20 09:17:06 +00:00
* $Id: env.c,v 1.8 2005-09-20 09:17:06 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2005-05-28 13:34:26 +00:00
#include <xp/lsp/env.h>
2005-04-24 07:48:16 +00:00
#include <xp/bas/memory.h>
#include <xp/bas/assert.h>
2005-02-04 15:39:11 +00:00
2005-09-20 09:17:06 +00:00
// TODO: make the frame hash accessible....
xp_lsp_assoc_t* xp_lsp_assoc_new (
xp_lsp_obj_t* name, xp_lsp_obj_t* value, xp_lsp_obj_t* func)
2005-02-04 15:39:11 +00:00
{
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2005-09-18 11:34:35 +00:00
assoc = (xp_lsp_assoc_t*) xp_malloc (sizeof(xp_lsp_assoc_t));
2005-02-04 15:39:11 +00:00
if (assoc == XP_NULL) return XP_NULL;
assoc->name = name;
assoc->value = value;
2005-09-20 09:17:06 +00:00
assoc->func = func;
2005-02-04 15:39:11 +00:00
assoc->link = XP_NULL;
return assoc;
}
2005-09-18 11:34:35 +00:00
void xp_lsp_assoc_free (xp_lsp_assoc_t* assoc)
2005-02-04 15:39:11 +00:00
{
xp_free (assoc);
}
2005-09-18 11:34:35 +00:00
xp_lsp_frame_t* xp_lsp_frame_new (void)
2005-02-04 15:39:11 +00:00
{
2005-09-18 11:34:35 +00:00
xp_lsp_frame_t* frame;
2005-02-04 15:39:11 +00:00
2005-09-18 11:34:35 +00:00
frame = (xp_lsp_frame_t*) xp_malloc (sizeof(xp_lsp_frame_t));
2005-02-04 15:39:11 +00:00
if (frame == XP_NULL) return XP_NULL;
frame->assoc = XP_NULL;
frame->link = XP_NULL;
return frame;
}
2005-09-18 11:34:35 +00:00
void xp_lsp_frame_free (xp_lsp_frame_t* frame)
2005-02-04 15:39:11 +00:00
{
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_t* assoc, * link;
2005-02-04 15:39:11 +00:00
// destroy the associations
assoc = frame->assoc;
while (assoc != XP_NULL) {
link = assoc->link;
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_free (assoc);
2005-02-04 15:39:11 +00:00
assoc = link;
}
xp_free (frame);
}
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_t* xp_lsp_frame_lookup (xp_lsp_frame_t* frame, xp_lsp_obj_t* name)
2005-02-04 15:39:11 +00:00
{
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2005-09-18 11:34:35 +00:00
xp_assert (XP_LSP_TYPE(name) == XP_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
assoc = frame->assoc;
while (assoc != XP_NULL) {
if (name == assoc->name) return assoc;
assoc = assoc->link;
}
return XP_NULL;
}
2005-09-20 09:17:06 +00:00
xp_lsp_assoc_t* xp_lsp_frame_insert_value (
2005-09-18 11:34:35 +00:00
xp_lsp_frame_t* frame, xp_lsp_obj_t* name, xp_lsp_obj_t* value)
2005-02-04 15:39:11 +00:00
{
2005-09-18 11:34:35 +00:00
xp_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2005-09-18 11:34:35 +00:00
xp_assert (XP_LSP_TYPE(name) == XP_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
2005-09-20 09:17:06 +00:00
assoc = xp_lsp_assoc_new (name, value, XP_NULL);
2005-02-04 15:39:11 +00:00
if (assoc == XP_NULL) return XP_NULL;
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}
2005-09-20 09:17:06 +00:00
xp_lsp_assoc_t* xp_lsp_frame_insert_func (
xp_lsp_frame_t* frame, xp_lsp_obj_t* name, xp_lsp_obj_t* func)
{
xp_lsp_assoc_t* assoc;
xp_assert (XP_LSP_TYPE(name) == XP_LSP_OBJ_SYMBOL);
assoc = xp_lsp_assoc_new (name, XP_NULL, func);
if (assoc == XP_NULL) return XP_NULL;
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}