qse/ase/lsp/lisp.c

73 lines
1.4 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2005-05-30 07:19:09 +00:00
* $Id: lisp.c,v 1.10 2005-05-30 07:15:35 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2005-05-28 13:34:26 +00:00
#include <xp/lsp/lisp.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
xp_lisp_t* xp_lisp_new (xp_size_t mem_ubound, xp_size_t mem_ubound_inc)
{
xp_lisp_t* lsp;
2005-02-04 16:00:37 +00:00
lsp = (xp_lisp_t*)xp_malloc(sizeof(xp_lisp_t));
2005-02-04 15:39:11 +00:00
if (lsp == XP_NULL) return lsp;
lsp->token = xp_lisp_token_new (256);
if (lsp->token == XP_NULL) {
2005-02-04 16:00:37 +00:00
xp_free (lsp);
2005-02-04 15:39:11 +00:00
return XP_NULL;
}
2005-02-04 16:00:37 +00:00
lsp->error = XP_LISP_ERR_NONE;
2005-02-04 15:39:11 +00:00
//lsp->opt_undef_symbol = 1;
lsp->opt_undef_symbol = 0;
2005-05-30 07:19:09 +00:00
lsp->curc = XP_CHAR_EOF;
2005-02-04 15:39:11 +00:00
lsp->creader = XP_NULL;
lsp->creader_extra = XP_NULL;
lsp->creader_just_set = 0;
2005-02-04 16:00:37 +00:00
lsp->outstream = xp_stdout;
2005-02-04 15:39:11 +00:00
lsp->mem = xp_lisp_mem_new (mem_ubound, mem_ubound_inc);
if (lsp->mem == XP_NULL) {
xp_lisp_token_free (lsp->token);
free (lsp);
return XP_NULL;
}
if (xp_lisp_add_prims (lsp->mem) == -1) {
xp_lisp_mem_free (lsp->mem);
xp_lisp_token_free (lsp->token);
free (lsp);
return XP_NULL;
}
return lsp;
}
void xp_lisp_free (xp_lisp_t* lsp)
{
2005-02-05 05:18:20 +00:00
xp_assert (lsp != XP_NULL);
2005-02-04 15:39:11 +00:00
xp_lisp_mem_free (lsp->mem);
xp_lisp_token_free (lsp->token);
free (lsp);
}
2005-02-07 15:10:41 +00:00
int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size)
2005-02-04 15:39:11 +00:00
{
if (buf != XP_NULL || size == 0) return lsp->error;
// TODO:...
/*
switch (lsp->error) {
default:
xp_lisp_copy_string (buf, size, "unknown error");
}
*/
return lsp->error;
}