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-24 04:22:40 +00:00
* $Id: env.c,v 1.10 2006-10-24 04:22:39 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2006-10-24 04:22:40 +00:00
#include <ase/lsp/env.h>
#include <ase/bas/memory.h>
#include <ase/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-24 04:22:40 +00:00
ase_lsp_assoc_t* ase_lsp_assoc_new (
ase_lsp_obj_t* name, ase_lsp_obj_t* value, ase_lsp_obj_t* func)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
assoc = (ase_lsp_assoc_t*) ase_malloc (sizeof(ase_lsp_assoc_t));
if (assoc == ASE_NULL) return ASE_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-24 04:22:40 +00:00
assoc->link = ASE_NULL;
2005-02-04 15:39:11 +00:00
return assoc;
}
2006-10-24 04:22:40 +00:00
void ase_lsp_assoc_free (ase_lsp_assoc_t* assoc)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_free (assoc);
2005-02-04 15:39:11 +00:00
}
2006-10-24 04:22:40 +00:00
ase_lsp_frame_t* ase_lsp_frame_new (void)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_frame_t* frame;
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
frame = (ase_lsp_frame_t*) ase_malloc (sizeof(ase_lsp_frame_t));
if (frame == ASE_NULL) return ASE_NULL;
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
frame->assoc = ASE_NULL;
frame->link = ASE_NULL;
2005-02-04 15:39:11 +00:00
return frame;
}
2006-10-24 04:22:40 +00:00
void ase_lsp_frame_free (ase_lsp_frame_t* frame)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* assoc, * link;
2005-02-04 15:39:11 +00:00
// destroy the associations
assoc = frame->assoc;
2006-10-24 04:22:40 +00:00
while (assoc != ASE_NULL) {
2005-02-04 15:39:11 +00:00
link = assoc->link;
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_free (assoc);
2005-02-04 15:39:11 +00:00
assoc = link;
}
2006-10-24 04:22:40 +00:00
ase_free (frame);
2005-02-04 15:39:11 +00:00
}
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* ase_lsp_frame_lookup (ase_lsp_frame_t* frame, ase_lsp_obj_t* name)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
ase_assert (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
assoc = frame->assoc;
2006-10-24 04:22:40 +00:00
while (assoc != ASE_NULL) {
2005-02-04 15:39:11 +00:00
if (name == assoc->name) return assoc;
assoc = assoc->link;
}
2006-10-24 04:22:40 +00:00
return ASE_NULL;
2005-02-04 15:39:11 +00:00
}
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* ase_lsp_frame_insert_value (
ase_lsp_frame_t* frame, ase_lsp_obj_t* name, ase_lsp_obj_t* value)
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* assoc;
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
ase_assert (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYMBOL);
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
assoc = ase_lsp_assoc_new (name, value, ASE_NULL);
if (assoc == ASE_NULL) return ASE_NULL;
2005-02-04 15:39:11 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* ase_lsp_frame_insert_func (
ase_lsp_frame_t* frame, ase_lsp_obj_t* name, ase_lsp_obj_t* func)
2005-09-20 09:17:06 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_assoc_t* assoc;
2005-09-20 09:17:06 +00:00
2006-10-24 04:22:40 +00:00
ase_assert (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYMBOL);
2005-09-20 09:17:06 +00:00
2006-10-24 04:22:40 +00:00
assoc = ase_lsp_assoc_new (name, ASE_NULL, func);
if (assoc == ASE_NULL) return ASE_NULL;
2005-09-20 09:17:06 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}