Login
7 branches 0 tags
Ben (Win10) Removed some old/unused functions a6201a1 3 years ago 598 Commits
nujel / lib / type / native-function.c
/* Nujel - Copyright (C) 2020-2022 - Benjamin Vincent Schulenburg
 * This project uses the MIT license, a copy should be included under /LICENSE */
#include "native-function.h"
#include "val.h"
#include "../display.h"
#include "../allocation/native-function.h"
#include "../allocation/val.h"
#include "../collection/list.h"
#include "../s-expression/reader.h"
#include "../type/closure.h"

/* Create a new NFunc,should only be used during root closure creation  */
static lVal *lValNativeFunc(lVal *(*func)(lClosure *,lVal *), lVal *args, lVal *docString){
	lVal *v = lRootsValPush(lValAlloc(ltNativeFunc));
	v->vNFunc = lNFuncAlloc();

	v->vNFunc->fp   = func;
	v->vNFunc->doc  = docString;
	v->vNFunc->args = args;
	return v;
}

/* Add a NFunc to closure C, should only be used during root closure creation */
lVal *lAddNativeFunc(lClosure *c, const char *sym, const char *args, const char *doc, lVal *(*func)(lClosure *,lVal *)){
	lVal *lNF = lValNativeFunc(func,RVP(lCar(lRead(args))),RVP(lValString(doc)));
	return lDefineAliased(c,lNF,sym);
}

/* Add a Special Form to closure C, should only be used during root closure creation */
lVal *lAddSpecialForm(lClosure *c, const char *sym, const char *args, const char *doc, lVal *(*func)(lClosure *,lVal *)){
	lVal *lNF = lValNativeFunc(func,RVP(lCar(lRead(args))),RVP(lValString(doc)));
	lNF->type = ltSpecialForm;
	return lDefineAliased(c,lNF,sym);
}