2008-06-30 21:54:22 -04:00
|
|
|
/*
|
|
|
|
Extra femtoLisp builtin functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "llt.h"
|
|
|
|
#include "flisp.h"
|
2009-03-02 22:16:30 -05:00
|
|
|
#include "random.h"
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
size_t llength(value_t v)
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
while (iscons(v)) {
|
|
|
|
n++;
|
|
|
|
v = cdr_(v);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_exit(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
if (nargs > 0)
|
|
|
|
exit(tofixnum(args[0], "exit"));
|
|
|
|
exit(0);
|
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
value_t fl_intern(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("intern", nargs, 1);
|
|
|
|
if (!isstring(args[0]))
|
|
|
|
type_error("intern", "string", args[0]);
|
|
|
|
return symbol(cvalue_data(args[0]));
|
|
|
|
}
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
value_t fl_setconstant(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("set-constant!", nargs, 2);
|
|
|
|
symbol_t *sym = tosymbol(args[0], "set-constant!");
|
|
|
|
if (isconstant(args[0]) || sym->binding != UNBOUND)
|
|
|
|
lerror(ArgError, "set-constant!: cannot redefine %s",
|
|
|
|
symbol_name(args[0]));
|
|
|
|
setc(args[0], args[1]);
|
|
|
|
return args[1];
|
|
|
|
}
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
extern value_t LAMBDA;
|
|
|
|
|
|
|
|
value_t fl_setsyntax(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
argcount("set-syntax!", nargs, 2);
|
|
|
|
symbol_t *sym = tosymbol(args[0], "set-syntax!");
|
2008-06-30 21:54:22 -04:00
|
|
|
if (sym->syntax && (sym->syntax == TAG_CONST || isspecial(sym->syntax)))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
lerror(ArgError, "set-syntax!: cannot define syntax for %s",
|
2008-06-30 21:54:22 -04:00
|
|
|
symbol_name(args[0]));
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
if (args[1] == FL_F) {
|
2008-06-30 21:54:22 -04:00
|
|
|
sym->syntax = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!iscons(args[1]) || car_(args[1])!=LAMBDA)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
type_error("set-syntax!", "function", args[1]);
|
2008-06-30 21:54:22 -04:00
|
|
|
sym->syntax = args[1];
|
|
|
|
}
|
|
|
|
return args[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_symbolsyntax(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("symbol-syntax", nargs, 1);
|
|
|
|
symbol_t *sym = tosymbol(args[0], "symbol-syntax");
|
|
|
|
// must avoid returning built-in syntax expanders, because they
|
|
|
|
// don't behave like functions (they take their arguments directly
|
|
|
|
// from the form rather than from the stack of evaluated arguments)
|
|
|
|
if (sym->syntax == TAG_CONST || isspecial(sym->syntax))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return FL_F;
|
2008-06-30 21:54:22 -04:00
|
|
|
return sym->syntax;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syntax_env_assoc_list(symbol_t *root, value_t *pv)
|
|
|
|
{
|
|
|
|
while (root != NULL) {
|
|
|
|
if (root->syntax && root->syntax != TAG_CONST &&
|
|
|
|
!isspecial(root->syntax)) {
|
|
|
|
PUSH(fl_cons(tagptr(root,TAG_SYM), root->syntax));
|
|
|
|
*pv = fl_cons(POP(), *pv);
|
|
|
|
}
|
|
|
|
syntax_env_assoc_list(root->left, pv);
|
|
|
|
root = root->right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void global_env_assoc_list(symbol_t *root, value_t *pv)
|
|
|
|
{
|
|
|
|
while (root != NULL) {
|
|
|
|
if (root->binding != UNBOUND) {
|
|
|
|
PUSH(fl_cons(tagptr(root,TAG_SYM), root->binding));
|
|
|
|
*pv = fl_cons(POP(), *pv);
|
|
|
|
}
|
|
|
|
global_env_assoc_list(root->left, pv);
|
|
|
|
root = root->right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern symbol_t *symtab;
|
|
|
|
|
|
|
|
value_t fl_syntax_env(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
(void)args;
|
|
|
|
argcount("syntax-environment", nargs, 0);
|
|
|
|
PUSH(NIL);
|
|
|
|
syntax_env_assoc_list(symtab, &Stack[SP-1]);
|
|
|
|
return POP();
|
|
|
|
}
|
|
|
|
value_t fl_global_env(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
(void)args;
|
|
|
|
argcount("environment", nargs, 0);
|
|
|
|
PUSH(NIL);
|
|
|
|
global_env_assoc_list(symtab, &Stack[SP-1]);
|
|
|
|
return POP();
|
|
|
|
}
|
|
|
|
|
2008-07-18 00:16:07 -04:00
|
|
|
extern value_t QUOTE;
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t fl_constantp(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
argcount("constant?", nargs, 1);
|
2008-06-30 21:54:22 -04:00
|
|
|
if (issymbol(args[0]))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return (isconstant(args[0]) ? FL_T : FL_F);
|
2008-07-18 00:16:07 -04:00
|
|
|
if (iscons(args[0])) {
|
|
|
|
if (car_(args[0]) == QUOTE)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return FL_T;
|
|
|
|
return FL_F;
|
2008-07-18 00:16:07 -04:00
|
|
|
}
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return FL_T;
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
|
2009-02-01 00:41:43 -05:00
|
|
|
value_t fl_integerp(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("integer?", nargs, 1);
|
|
|
|
value_t v = args[0];
|
|
|
|
if (isfixnum(v)) {
|
|
|
|
return FL_T;
|
|
|
|
}
|
|
|
|
else if (iscprim(v)) {
|
|
|
|
numerictype_t nt = cp_numtype((cprim_t*)ptr(v));
|
|
|
|
if (nt < T_FLOAT)
|
|
|
|
return FL_T;
|
|
|
|
void *data = cp_data((cprim_t*)ptr(v));
|
|
|
|
if (nt == T_FLOAT) {
|
|
|
|
float f = *(float*)data;
|
|
|
|
if (f < 0) f = -f;
|
|
|
|
if (f <= FLT_MAXINT && (float)(int32_t)f == f)
|
|
|
|
return FL_T;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(nt == T_DOUBLE);
|
|
|
|
double d = *(double*)data;
|
|
|
|
if (d < 0) d = -d;
|
|
|
|
if (d <= DBL_MAXINT && (double)(int64_t)d == d)
|
|
|
|
return FL_T;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FL_F;
|
|
|
|
}
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t fl_fixnum(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("fixnum", nargs, 1);
|
2009-01-02 18:00:21 -05:00
|
|
|
if (isfixnum(args[0])) {
|
2008-06-30 21:54:22 -04:00
|
|
|
return args[0];
|
2009-01-02 18:00:21 -05:00
|
|
|
}
|
|
|
|
else if (iscprim(args[0])) {
|
|
|
|
cprim_t *cp = (cprim_t*)ptr(args[0]);
|
|
|
|
return fixnum(conv_to_long(cp_data(cp), cp_numtype(cp)));
|
|
|
|
}
|
|
|
|
else if (isstring(args[0])) {
|
2008-06-30 21:54:22 -04:00
|
|
|
cvalue_t *cv = (cvalue_t*)ptr(args[0]);
|
2009-01-02 18:00:21 -05:00
|
|
|
char *pend;
|
|
|
|
errno = 0;
|
|
|
|
long i = strtol(cv_data(cv), &pend, 0);
|
|
|
|
if (*pend != '\0' || errno!=0)
|
|
|
|
lerror(ArgError, "fixnum: invalid string");
|
|
|
|
return fixnum(i);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
lerror(ArgError, "fixnum: cannot convert argument");
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_truncate(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("truncate", nargs, 1);
|
|
|
|
if (isfixnum(args[0]))
|
|
|
|
return args[0];
|
2009-01-02 18:00:21 -05:00
|
|
|
if (iscprim(args[0])) {
|
|
|
|
cprim_t *cp = (cprim_t*)ptr(args[0]);
|
|
|
|
void *data = cp_data(cp);
|
|
|
|
numerictype_t nt = cp_numtype(cp);
|
|
|
|
double d;
|
|
|
|
if (nt == T_FLOAT)
|
|
|
|
d = (double)*(float*)data;
|
|
|
|
else if (nt == T_DOUBLE)
|
|
|
|
d = *(double*)data;
|
|
|
|
else
|
|
|
|
return args[0];
|
|
|
|
if (d > 0)
|
|
|
|
return return_from_uint64((uint64_t)d);
|
|
|
|
return return_from_int64((int64_t)d);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
type_error("truncate", "number", args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_vector_alloc(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
fixnum_t i;
|
|
|
|
value_t f, v;
|
|
|
|
if (nargs == 0)
|
|
|
|
lerror(ArgError, "vector.alloc: too few arguments");
|
|
|
|
i = tofixnum(args[0], "vector.alloc");
|
|
|
|
if (i < 0)
|
|
|
|
lerror(ArgError, "vector.alloc: invalid size");
|
|
|
|
if (nargs == 2)
|
|
|
|
f = args[1];
|
|
|
|
else
|
|
|
|
f = NIL;
|
|
|
|
v = alloc_vector((unsigned)i, f==NIL);
|
|
|
|
if (f != NIL) {
|
|
|
|
int k;
|
|
|
|
for(k=0; k < i; k++)
|
|
|
|
vector_elt(v,k) = f;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_time_now(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("time.now", nargs, 0);
|
|
|
|
(void)args;
|
|
|
|
return mk_double(clock_now());
|
|
|
|
}
|
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
static double todouble(value_t a, char *fname)
|
2008-06-30 21:54:22 -04:00
|
|
|
{
|
|
|
|
if (isfixnum(a))
|
|
|
|
return (double)numval(a);
|
2009-01-02 18:00:21 -05:00
|
|
|
if (iscprim(a)) {
|
|
|
|
cprim_t *cp = (cprim_t*)ptr(a);
|
|
|
|
numerictype_t nt = cp_numtype(cp);
|
|
|
|
return conv_to_double(cp_data(cp), nt);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
type_error(fname, "number", a);
|
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_time_string(value_t *args, uint32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("time.string", nargs, 1);
|
2008-12-28 03:01:18 -05:00
|
|
|
double t = todouble(args[0], "time.string");
|
2008-06-30 21:54:22 -04:00
|
|
|
char buf[64];
|
|
|
|
timestring(t, buf, sizeof(buf));
|
2008-09-10 22:37:38 -04:00
|
|
|
return string_from_cstr(buf);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_path_cwd(value_t *args, uint32_t nargs)
|
|
|
|
{
|
|
|
|
if (nargs > 1)
|
|
|
|
argcount("path.cwd", nargs, 1);
|
|
|
|
if (nargs == 0) {
|
|
|
|
char buf[1024];
|
|
|
|
get_cwd(buf, sizeof(buf));
|
2008-09-10 22:37:38 -04:00
|
|
|
return string_from_cstr(buf);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
char *ptr = tostring(args[0], "path.cwd");
|
|
|
|
if (set_cwd(ptr))
|
2009-02-09 00:38:40 -05:00
|
|
|
lerror(IOError, "path.cwd: could not cd to %s", ptr);
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return FL_T;
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_os_getenv(value_t *args, uint32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("os.getenv", nargs, 1);
|
|
|
|
char *name = tostring(args[0], "os.getenv");
|
|
|
|
char *val = getenv(name);
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
if (val == NULL) return FL_F;
|
2008-06-30 21:54:22 -04:00
|
|
|
if (*val == 0)
|
|
|
|
return symbol_value(emptystringsym);
|
2008-09-10 22:37:38 -04:00
|
|
|
return cvalue_static_cstring(val);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_os_setenv(value_t *args, uint32_t nargs)
|
|
|
|
{
|
|
|
|
argcount("os.setenv", nargs, 2);
|
|
|
|
char *name = tostring(args[0], "os.setenv");
|
|
|
|
int result;
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
if (args[1] == FL_F) {
|
2008-06-30 21:54:22 -04:00
|
|
|
result = unsetenv(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *val = tostring(args[1], "os.setenv");
|
|
|
|
result = setenv(name, val, 1);
|
|
|
|
}
|
|
|
|
if (result != 0)
|
|
|
|
lerror(ArgError, "os.setenv: invalid environment variable");
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
return FL_T;
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
value_t fl_rand(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
2008-08-16 17:15:36 -04:00
|
|
|
(void)args; (void)nargs;
|
|
|
|
fixnum_t r;
|
|
|
|
#ifdef BITS64
|
|
|
|
r = ((((uint64_t)random())<<32) | random()) & 0x1fffffffffffffffLL;
|
|
|
|
#else
|
|
|
|
r = random() & 0x1fffffff;
|
|
|
|
#endif
|
|
|
|
return fixnum(r);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
value_t fl_rand32(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
2008-08-16 17:15:36 -04:00
|
|
|
(void)args; (void)nargs;
|
|
|
|
ulong r = random();
|
|
|
|
#ifdef BITS64
|
|
|
|
return fixnum(r);
|
|
|
|
#else
|
|
|
|
return mk_uint32(r);
|
|
|
|
#endif
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
value_t fl_rand64(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
2008-08-16 17:15:36 -04:00
|
|
|
(void)args; (void)nargs;
|
|
|
|
ulong r = (((uint64_t)random())<<32) | random();
|
|
|
|
return mk_uint64(r);
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|
|
|
|
value_t fl_randd(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
2008-08-16 17:15:36 -04:00
|
|
|
(void)args; (void)nargs;
|
2008-06-30 21:54:22 -04:00
|
|
|
return mk_double(rand_double());
|
|
|
|
}
|
2008-08-16 17:15:36 -04:00
|
|
|
value_t fl_randf(value_t *args, u_int32_t nargs)
|
|
|
|
{
|
|
|
|
(void)args; (void)nargs;
|
|
|
|
return mk_float(rand_float());
|
|
|
|
}
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2008-08-05 00:34:14 -04:00
|
|
|
extern void stringfuncs_init();
|
2008-12-20 01:16:00 -05:00
|
|
|
extern void table_init();
|
2009-02-08 22:22:31 -05:00
|
|
|
extern void iostream_init();
|
2008-08-05 00:34:14 -04:00
|
|
|
|
2008-11-23 02:12:37 -05:00
|
|
|
static builtinspec_t builtin_info[] = {
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
{ "set-constant!", fl_setconstant },
|
|
|
|
{ "set-syntax!", fl_setsyntax },
|
2008-11-23 02:12:37 -05:00
|
|
|
{ "symbol-syntax", fl_symbolsyntax },
|
|
|
|
{ "syntax-environment", fl_syntax_env },
|
|
|
|
{ "environment", fl_global_env },
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
{ "constant?", fl_constantp },
|
2008-11-23 02:12:37 -05:00
|
|
|
|
|
|
|
{ "exit", fl_exit },
|
2008-12-28 03:01:18 -05:00
|
|
|
{ "intern", fl_intern },
|
2008-11-23 02:12:37 -05:00
|
|
|
{ "fixnum", fl_fixnum },
|
|
|
|
{ "truncate", fl_truncate },
|
2009-02-01 00:41:43 -05:00
|
|
|
{ "integer?", fl_integerp },
|
2008-11-23 02:12:37 -05:00
|
|
|
|
|
|
|
{ "vector.alloc", fl_vector_alloc },
|
|
|
|
|
|
|
|
{ "time.now", fl_time_now },
|
|
|
|
{ "time.string", fl_time_string },
|
|
|
|
|
|
|
|
{ "rand", fl_rand },
|
|
|
|
{ "rand.uint32", fl_rand32 },
|
|
|
|
{ "rand.uint64", fl_rand64 },
|
|
|
|
{ "rand.double", fl_randd },
|
|
|
|
{ "rand.float", fl_randf },
|
|
|
|
|
|
|
|
{ "path.cwd", fl_path_cwd },
|
|
|
|
|
|
|
|
{ "os.getenv", fl_os_getenv },
|
|
|
|
{ "os.setenv", fl_os_setenv },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
void builtins_init()
|
|
|
|
{
|
2008-11-23 02:12:37 -05:00
|
|
|
assign_global_builtins(builtin_info);
|
2008-08-05 00:34:14 -04:00
|
|
|
stringfuncs_init();
|
2008-12-20 01:16:00 -05:00
|
|
|
table_init();
|
2009-02-08 22:22:31 -05:00
|
|
|
iostream_init();
|
2008-06-30 21:54:22 -04:00
|
|
|
}
|