qse/ase/lsp/env.c

101 lines
2.1 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2006-10-22 13:10:46 +00:00
* $Id: env.c,v 1.9 2006-10-22 13:10:45 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2006-10-22 13:10:46 +00:00
#include <sse/lsp/env.h>
#include <sse/bas/memory.h>
#include <sse/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....
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* sse_lsp_assoc_new (
sse_lsp_obj_t* name, sse_lsp_obj_t* value, sse_lsp_obj_t* func)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
assoc = (sse_lsp_assoc_t*) sse_malloc (sizeof(sse_lsp_assoc_t));
if (assoc == SSE_NULL) return SSE_NULL;
2005-02-04 15:39:11 +00:00
assoc->name = name;
assoc->value = value;
2005-09-20 09:17:06 +00:00
assoc->func = func;
2006-10-22 13:10:46 +00:00
assoc->link = SSE_NULL;
2005-02-04 15:39:11 +00:00
return assoc;
}
2006-10-22 13:10:46 +00:00
void sse_lsp_assoc_free (sse_lsp_assoc_t* assoc)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_free (assoc);
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
sse_lsp_frame_t* sse_lsp_frame_new (void)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_frame_t* frame;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
frame = (sse_lsp_frame_t*) sse_malloc (sizeof(sse_lsp_frame_t));
if (frame == SSE_NULL) return SSE_NULL;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
frame->assoc = SSE_NULL;
frame->link = SSE_NULL;
2005-02-04 15:39:11 +00:00
return frame;
}
2006-10-22 13:10:46 +00:00
void sse_lsp_frame_free (sse_lsp_frame_t* frame)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* assoc, * link;
2005-02-04 15:39:11 +00:00
// destroy the associations
assoc = frame->assoc;
2006-10-22 13:10:46 +00:00
while (assoc != SSE_NULL) {
2005-02-04 15:39:11 +00:00
link = assoc->link;
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_free (assoc);
2005-02-04 15:39:11 +00:00
assoc = link;
}
2006-10-22 13:10:46 +00:00
sse_free (frame);
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* sse_lsp_frame_lookup (sse_lsp_frame_t* frame, sse_lsp_obj_t* name)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
sse_assert (SSE_LSP_TYPE(name) == SSE_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
assoc = frame->assoc;
2006-10-22 13:10:46 +00:00
while (assoc != SSE_NULL) {
2005-02-04 15:39:11 +00:00
if (name == assoc->name) return assoc;
assoc = assoc->link;
}
2006-10-22 13:10:46 +00:00
return SSE_NULL;
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* sse_lsp_frame_insert_value (
sse_lsp_frame_t* frame, sse_lsp_obj_t* name, sse_lsp_obj_t* value)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
sse_assert (SSE_LSP_TYPE(name) == SSE_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
assoc = sse_lsp_assoc_new (name, value, SSE_NULL);
if (assoc == SSE_NULL) return SSE_NULL;
2005-02-04 15:39:11 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* sse_lsp_frame_insert_func (
sse_lsp_frame_t* frame, sse_lsp_obj_t* name, sse_lsp_obj_t* func)
2005-09-20 09:17:06 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_assoc_t* assoc;
2005-09-20 09:17:06 +00:00
2006-10-22 13:10:46 +00:00
sse_assert (SSE_LSP_TYPE(name) == SSE_LSP_OBJ_SYMBOL);
2005-09-20 09:17:06 +00:00
2006-10-22 13:10:46 +00:00
assoc = sse_lsp_assoc_new (name, SSE_NULL, func);
if (assoc == SSE_NULL) return SSE_NULL;
2005-09-20 09:17:06 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}