qse/ase/lsp/env.c

104 lines
2.1 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2007-02-03 10:52:36 +00:00
* $Id: env.c,v 1.14 2007-02-03 10:51:52 bacon Exp $
*
* {License}
2005-02-04 15:39:11 +00:00
*/
2006-10-25 13:42:31 +00:00
#include <ase/lsp/lsp_i.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-26 08:17:38 +00:00
static ase_lsp_assoc_t* __new_assoc (
ase_lsp_t* lsp, 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-26 08:17:38 +00:00
assoc = (ase_lsp_assoc_t*)
ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_assoc_t));
2006-10-24 04:22:40 +00:00
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-26 08:17:38 +00:00
ase_lsp_frame_t* ase_lsp_newframe (ase_lsp_t* lsp)
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-26 08:17:38 +00:00
frame = (ase_lsp_frame_t*)
ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_frame_t));
2006-10-24 04:22:40 +00:00
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-26 08:17:38 +00:00
void ase_lsp_freeframe (ase_lsp_t* lsp, 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-25 13:42:31 +00:00
while (assoc != ASE_NULL)
{
2005-02-04 15:39:11 +00:00
link = assoc->link;
2006-10-26 08:17:38 +00:00
ASE_LSP_FREE (lsp, assoc);
2005-02-04 15:39:11 +00:00
assoc = link;
}
2006-10-26 08:17:38 +00:00
ASE_LSP_FREE (lsp, frame);
2005-02-04 15:39:11 +00:00
}
2006-10-26 08:17:38 +00:00
ase_lsp_assoc_t* ase_lsp_lookupinframe (
ase_lsp_t* lsp, 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-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM);
2005-02-04 15:39:11 +00:00
assoc = frame->assoc;
2006-10-25 13:42:31 +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-26 08:17:38 +00:00
ase_lsp_assoc_t* ase_lsp_insertvalueintoframe (
ase_lsp_t* lsp, 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-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM);
2005-02-04 15:39:11 +00:00
2006-10-26 08:17:38 +00:00
assoc = __new_assoc (lsp, name, value, ASE_NULL);
2006-10-24 04:22:40 +00:00
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-26 08:17:38 +00:00
ase_lsp_assoc_t* ase_lsp_insertfuncintoframe (
ase_lsp_t* lsp, 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-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM);
2005-09-20 09:17:06 +00:00
2006-10-26 08:17:38 +00:00
assoc = __new_assoc (lsp, name, ASE_NULL, func);
2006-10-24 04:22:40 +00:00
if (assoc == ASE_NULL) return ASE_NULL;
2005-09-20 09:17:06 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}