qse/ase/lsp/prim_compar.c

506 lines
11 KiB
C
Raw Normal View History

2005-09-20 12:06:51 +00:00
/*
2006-10-26 09:31:28 +00:00
* $Id: prim_compar.c,v 1.7 2006-10-26 09:31:28 bacon Exp $
2005-09-20 12:06:51 +00:00
*/
2006-10-26 08:17:38 +00:00
#include <ase/lsp/lsp_i.h>
2005-09-20 12:06:51 +00:00
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_eq (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-20 12:06:51 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-20 12:06:51 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-20 12:06:51 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) == ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) == ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) == ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) == ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) == 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) == 0;
2005-09-20 12:06:51 +00:00
}
else {
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_ne (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-21 11:52:36 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-21 11:52:36 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-21 11:52:36 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) != ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) != ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) != ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) != ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) != 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) != 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_gt (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-20 12:06:51 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-20 12:06:51 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-20 12:06:51 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) > ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) > ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) > ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) > ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) > 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) > 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_lt (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-20 12:06:51 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-20 12:06:51 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-20 12:06:51 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-20 12:06:51 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) < ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) < ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) < ASE_LSP_IVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) < ASE_LSP_RVALUE(p2);
2005-09-20 12:06:51 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) < 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) < 0;
2005-09-20 12:06:51 +00:00
}
else {
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-20 12:06:51 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}
2005-09-21 11:52:36 +00:00
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_ge (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-21 11:52:36 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-21 11:52:36 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-21 11:52:36 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) >= ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) >= ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) >= ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) >= ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) >= 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) >= 0;
2005-09-21 11:52:36 +00:00
}
else {
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* ase_lsp_prim_le (ase_lsp_t* lsp, ase_lsp_obj_t* args)
2005-09-21 11:52:36 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_obj_t* p1, * p2;
2005-09-21 11:52:36 +00:00
int res;
2006-10-24 04:22:40 +00:00
ASE_LSP_PRIM_CHECK_ARG_COUNT (lsp, args, 2, 2);
2006-10-26 09:31:28 +00:00
ASE_LSP_ASSERT (lsp, ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS);
2005-09-21 11:52:36 +00:00
2006-10-24 04:22:40 +00:00
p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args));
if (p1 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
// TODO: lock p1....
2006-10-24 04:22:40 +00:00
p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args)));
if (p2 == ASE_NULL) return ASE_NULL;
2005-09-21 11:52:36 +00:00
2006-10-25 13:42:31 +00:00
if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) <= ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_IVALUE(p1) <= ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) <= ASE_LSP_IVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL)
{
2006-10-24 04:22:40 +00:00
res = ASE_LSP_RVALUE(p1) <= ASE_LSP_RVALUE(p2);
2005-09-21 11:52:36 +00:00
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1),
ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) <= 0;
2006-10-25 13:42:31 +00:00
}
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR)
{
if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR)
{
res = ase_lsp_strxncmp (
2006-10-26 08:17:38 +00:00
ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1),
ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) <= 0;
2005-09-21 11:52:36 +00:00
}
else {
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
}
2006-10-25 13:42:31 +00:00
else
{
2006-10-24 04:22:40 +00:00
lsp->errnum = ASE_LSP_ERR_BAD_VALUE;
return ASE_NULL;
2005-09-21 11:52:36 +00:00
}
return (res)? lsp->mem->t: lsp->mem->nil;
}