qse/ase/lsp/env.c

147 lines
2.9 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2007-02-11 07:36:55 +00:00
* $Id: env.c,v 1.16 2007-02-11 07:36:54 bacon Exp $
2007-02-03 10:52:36 +00:00
*
* {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
2007-02-11 07:36:55 +00:00
/* TODO: make the frame hash accessible */
2005-09-20 09:17:06 +00:00
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));
2007-02-10 13:52:41 +00:00
if (assoc == ASE_NULL)
{
2007-02-11 07:36:55 +00:00
ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0);
2007-02-10 13:52:41 +00:00
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));
2007-02-10 13:52:41 +00:00
if (frame == ASE_NULL)
{
2007-02-11 07:36:55 +00:00
ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0);
2007-02-10 13:52:41 +00:00
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
2007-02-11 07:36:55 +00:00
/* destroy the associations */
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
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
}
2007-02-10 13:52:41 +00:00
ase_lsp_assoc_t* ase_lsp_insvalueintoframe (
2006-10-26 08:17:38 +00:00
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;
2007-02-10 13:52:41 +00:00
2005-02-04 15:39:11 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}
2007-02-10 13:52:41 +00:00
ase_lsp_assoc_t* ase_lsp_insfuncintoframe (
2006-10-26 08:17:38 +00:00
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;
2007-02-10 13:52:41 +00:00
2005-09-20 09:17:06 +00:00
assoc->link = frame->assoc;
frame->assoc = assoc;
return assoc;
}
2007-02-10 13:52:41 +00:00
ase_lsp_tlink_t* ase_lsp_pushtmp (ase_lsp_t* lsp, ase_lsp_obj_t* obj)
{
ase_lsp_tlink_t* tlink;
tlink = (ase_lsp_tlink_t*)
ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_tlink_t));
if (tlink == ASE_NULL)
{
2007-02-11 07:36:55 +00:00
ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0);
2007-02-10 13:52:41 +00:00
return ASE_NULL;
}
tlink->obj = obj;
tlink->link = lsp->mem->tlink;
lsp->mem->tlink = tlink;
lsp->mem->tlink_count++;
return tlink;
}
void ase_lsp_poptmp (ase_lsp_t* lsp)
{
ase_lsp_tlink_t* top;
ASE_LSP_ASSERT (lsp, lsp->mem->tlink != ASE_NULL);
top = lsp->mem->tlink;
lsp->mem->tlink = top->link;
lsp->mem->tlink_count--;
ASE_LSP_FREE (lsp, top);
}