Login
7 branches 0 tags
Ben (X13/Arch) Added [let*] and made [eval] use [compile] 6ffa476 4 years ago 88 Commits
nujel / lib / nujel.h
#pragma once
#include "common.h"

typedef enum lType {
	ltNoAlloc = 0,

	ltSymbol,
	ltBool,
	ltInt,
	ltFloat,
	ltVec,
	ltInf,

	ltPair,
	ltString,
	ltArray,

	ltLambda,
	ltDynamic,
	ltObject,
	ltNativeFunc,
	ltSpecialForm,

	ltGUIWidget
} lType;

typedef struct lArray   lArray;;
typedef struct lClosure lClosure;
typedef struct lNFunc   lNFunc;;
typedef struct lSymbol  lSymbol;
typedef struct lString  lString;;
typedef struct lVec     lVec;
typedef struct lVal     lVal;

typedef struct {
	lVal *car,*cdr;
} lPair;

extern bool lVerbose;

void      lInit             ();
int       lMemUsage         ();
void      lPrintError       (const char *format, ...);

lClosure *lClosureNewRoot   ();
lClosure *lClosureNewRootNoStdLib();

void      lDisplayVal       (lVal *v);
void      lDisplayErrorVal  (lVal *v);
void      lWriteVal         (lVal *v);

lVal     *lMap              (lClosure *c, lVal *v, lVal *(*func)(lClosure *,lVal *));
lVal     *lEval             (lClosure *c, lVal *v);
lVal     *lnfBegin          (lClosure *c, lVal *v);
lVal     *lWrap             (lVal *v);

#define lCastIApply(FUNC, c , v) do { \
	if((c == NULL) || (v == NULL)){return lValInt(0);} \
	lVal *t = lCastSpecific(c,v,ltInt); \
	if((t == NULL) || (t->type != ltPair)){return lValInt(0);} \
	lVal *d = lValDup(t->vList.car); \
	if(d == NULL){return lValInt(0);} \
	return FUNC(d,t); \
	} while (0)

#define lCastApply(FUNC, c , v) do { \
	lVal *t = lCastAuto(c,v); \
	if((t == NULL) || (t->type != ltPair)){return lValInt(0);} \
	lVal *d = lValDup(t->vList.car); \
	if(d == NULL){return lValInt(0);} \
	switch(d->type){ \
	default:      return lValInt(0); \
	case ltInf:   return lValInf(); \
	case ltInt:   return FUNC##I(d,t); \
	case ltFloat: return FUNC##F(d,t); \
	case ltVec:   return FUNC##V(d,t); \
	}} while (0)