shithub: femtolisp

Download patch

ref: eec95c17b8912b9ce79617bc23263d26ed1d71f6
parent: 45c11c944bd4d757603f2dad3ea739410db7261a
author: JeffBezanson <jeff.bezanson@gmail.com>
date: Thu Apr 29 14:01:26 EDT 2010

adding fl_ prefix to some functions


--- a/femtolisp/builtins.c
+++ b/femtolisp/builtins.c
@@ -144,7 +144,7 @@
     argcount("top-level-value", nargs, 1);
     symbol_t *sym = tosymbol(args[0], "top-level-value");
     if (sym->binding == UNBOUND)
-        fl_raise(list2(UnboundError, args[0]));
+        fl_raise(fl_list2(UnboundError, args[0]));
     return sym->binding;
 }
 
--- a/femtolisp/cvalues.c
+++ b/femtolisp/cvalues.c
@@ -369,7 +369,7 @@
 value_t cvalue_enum(value_t *args, u_int32_t nargs)
 {
     argcount("enum", nargs, 2);
-    value_t type = list2(enumsym, args[0]);
+    value_t type = fl_list2(enumsym, args[0]);
     fltype_t *ft = get_type(type);
     value_t cv = cvalue(ft, sizeof(int32_t));
     cvalue_enum_init(ft, args[1], cp_data((cprim_t*)ptr(cv)));
@@ -973,10 +973,10 @@
     assign_global_builtins(cvalues_builtin_info);
 
     stringtypesym = symbol("*string-type*");
-    setc(stringtypesym, list2(arraysym, bytesym));
+    setc(stringtypesym, fl_list2(arraysym, bytesym));
 
     wcstringtypesym = symbol("*wcstring-type*");
-    setc(wcstringtypesym, list2(arraysym, wcharsym));
+    setc(wcstringtypesym, fl_list2(arraysym, wcharsym));
 
     mk_primtype(int8);
     mk_primtype(uint8);
--- a/femtolisp/equal.c
+++ b/femtolisp/equal.c
@@ -255,12 +255,12 @@
     return guess;
 }
 
-value_t compare(value_t a, value_t b)
+value_t fl_compare(value_t a, value_t b)
 {
     return compare_(a, b, 0);
 }
 
-value_t equal(value_t a, value_t b)
+value_t fl_equal(value_t a, value_t b)
 {
     if (eq_comparable(a, b))
         return (a == b) ? FL_T : FL_F;
--- a/femtolisp/flisp.c
+++ b/femtolisp/flisp.c
@@ -191,7 +191,7 @@
     va_end(args);
 
     e = POP();
-    fl_raise(list2(e, msg));
+    fl_raise(fl_list2(e, msg));
 }
 
 void lerror(value_t e, const char *msg)
@@ -199,17 +199,17 @@
     PUSH(e);
     value_t m = cvalue_static_cstring(msg);
     e = POP();
-    fl_raise(list2(e, m));
+    fl_raise(fl_list2(e, m));
 }
 
 void type_error(char *fname, char *expected, value_t got)
 {
-    fl_raise(listn(4, TypeError, symbol(fname), symbol(expected), got));
+    fl_raise(fl_listn(4, TypeError, symbol(fname), symbol(expected), got));
 }
 
 void bounds_error(char *fname, value_t arr, value_t ind)
 {
-    fl_raise(listn(4, BoundsError, symbol(fname), arr, ind));
+    fl_raise(fl_listn(4, BoundsError, symbol(fname), arr, ind));
 }
 
 // safe cast operators --------------------------------------------------------
@@ -626,7 +626,7 @@
     return v;
 }
 
-value_t apply(value_t f, value_t l)
+value_t fl_apply(value_t f, value_t l)
 {
     value_t v = l;
     uint32_t n = SP;
@@ -644,7 +644,7 @@
     return v;
 }
 
-value_t applyn(uint32_t n, value_t f, ...)
+value_t fl_applyn(uint32_t n, value_t f, ...)
 {
     va_list ap;
     va_start(ap, f);
@@ -663,7 +663,7 @@
     return v;
 }
 
-value_t listn(size_t n, ...)
+value_t fl_listn(size_t n, ...)
 {
     va_list ap;
     va_start(ap, n);
@@ -690,7 +690,7 @@
     return tagptr(l, TAG_CONS);
 }
 
-value_t list2(value_t a, value_t b)
+value_t fl_list2(value_t a, value_t b)
 {
     PUSH(a);
     PUSH(b);
@@ -1469,7 +1469,7 @@
                 v = (numval(Stack[SP-2]) < numval(Stack[SP-1])) ? FL_T : FL_F;
             }
             else {
-                v = (numval(compare(Stack[SP-2], Stack[SP-1])) < 0) ?
+                v = (numval(fl_compare(Stack[SP-2], Stack[SP-1])) < 0) ?
                     FL_T : FL_F;
             }
             POPN(1);
@@ -1575,7 +1575,7 @@
             assert(issymbol(v));
             sym = (symbol_t*)ptr(v);
             if (sym->binding == UNBOUND)
-                fl_raise(list2(UnboundError, v));
+                fl_raise(fl_list2(UnboundError, v));
             PUSH(sym->binding);
             NEXT_OP;
 
@@ -2229,8 +2229,8 @@
         setc(symbol("*install-dir*"), cvalue_static_cstring(EXEDIR));
     }
 
-    memory_exception_value = list2(MemoryError,
-                                   cvalue_static_cstring("out of memory"));
+    memory_exception_value = fl_list2(MemoryError,
+                                      cvalue_static_cstring("out of memory"));
 
     assign_global_builtins(core_builtin_info);
 
@@ -2239,9 +2239,9 @@
 
 // repl -----------------------------------------------------------------------
 
-value_t toplevel_eval(value_t expr)
+value_t fl_toplevel_eval(value_t expr)
 {
-    return applyn(1, symbol_value(evalsym), expr);
+    return fl_applyn(1, symbol_value(evalsym), expr);
 }
 
 static value_t argv_list(int argc, char *argv[])
@@ -2281,7 +2281,7 @@
         POPN(2);
         PUSH(f); saveSP = SP;
         while (1) {
-            e = read_sexpr(Stack[SP-1]);
+            e = fl_read_sexpr(Stack[SP-1]);
             if (ios_eof(value2c(ios_t*,Stack[SP-1]))) break;
             if (isfunction(e)) {
                 // stage 0 format: series of thunks
@@ -2310,7 +2310,7 @@
     }
     FL_CATCH {
         ios_puts("fatal error during bootstrap:\n", ios_stderr);
-        print(ios_stderr, lasterror);
+        fl_print(ios_stderr, lasterror);
         ios_putc('\n', ios_stderr);
         return 1;
     }
--- a/femtolisp/flisp.h
+++ b/femtolisp/flisp.h
@@ -118,26 +118,25 @@
 #define FL_UNSPECIFIED FL_T
 
 /* read, eval, print main entry points */
-value_t read_sexpr(value_t f);
-void print(ios_t *f, value_t v);
-value_t toplevel_eval(value_t expr);
-value_t apply(value_t f, value_t l);
-value_t applyn(uint32_t n, value_t f, ...);
-value_t load_file(char *fname);
+value_t fl_read_sexpr(value_t f);
+void fl_print(ios_t *f, value_t v);
+value_t fl_toplevel_eval(value_t expr);
+value_t fl_apply(value_t f, value_t l);
+value_t fl_applyn(uint32_t n, value_t f, ...);
 
 extern value_t printprettysym, printreadablysym, printwidthsym;
 
 /* object model manipulation */
 value_t fl_cons(value_t a, value_t b);
-value_t list2(value_t a, value_t b);
-value_t listn(size_t n, ...);
+value_t fl_list2(value_t a, value_t b);
+value_t fl_listn(size_t n, ...);
 value_t symbol(char *str);
 char *symbol_name(value_t v);
 int fl_is_keyword_name(char *str, size_t len);
 value_t alloc_vector(size_t n, int init);
 size_t llength(value_t v);
-value_t compare(value_t a, value_t b);  // -1, 0, or 1
-value_t equal(value_t a, value_t b);    // T or nil
+value_t fl_compare(value_t a, value_t b);  // -1, 0, or 1
+value_t fl_equal(value_t a, value_t b);    // T or nil
 int equal_lispvalue(value_t a, value_t b);
 uptrint_t hash_lispvalue(value_t a);
 int isnumtok_base(char *tok, value_t *pval, int base);
--- a/femtolisp/iostream.c
+++ b/femtolisp/iostream.c
@@ -116,7 +116,7 @@
     }
     (void)toiostream(arg, "read");
     fl_gc_handle(&arg);
-    value_t v = read_sexpr(arg);
+    value_t v = fl_read_sexpr(arg);
     fl_free_gc_handles(1);
     if (ios_eof(value2c(ios_t*,arg)))
         return FL_EOF;
@@ -216,7 +216,7 @@
         s = toiostream(args[1], "write");
     else
         s = toiostream(symbol_value(outstrsym), "write");
-    print(s, args[0]);
+    fl_print(s, args[0]);
     return args[0];
 }
 
--- a/femtolisp/print.c
+++ b/femtolisp/print.c
@@ -732,7 +732,7 @@
     SCR_WIDTH = numval(pw);
 }
 
-void print(ios_t *f, value_t v)
+void fl_print(ios_t *f, value_t v)
 {
     print_pretty = (symbol_value(printprettysym) != FL_F);
     if (print_pretty)
--- a/femtolisp/read.c
+++ b/femtolisp/read.c
@@ -611,8 +611,8 @@
         }
         v = symbol_value(sym);
         if (v == UNBOUND)
-            fl_raise(list2(UnboundError, sym));
-        return apply(v, POP());
+            fl_raise(fl_list2(UnboundError, sym));
+        return fl_apply(v, POP());
     case TOK_OPENB:
         return read_vector(label, TOK_CLOSEB);
     case TOK_SHARPOPEN:
@@ -627,10 +627,10 @@
         if (issymbol(sym)) {
             v = symbol_value(sym);
             if (v == UNBOUND)
-                fl_raise(list2(UnboundError, sym));
+                fl_raise(fl_list2(UnboundError, sym));
             return v;
         }
-        return toplevel_eval(sym);
+        return fl_toplevel_eval(sym);
     case TOK_LABEL:
         // create backreference label
         if (ptrhash_has(&readstate->backrefs, (void*)tokval))
@@ -656,7 +656,7 @@
     return FL_UNSPECIFIED;
 }
 
-value_t read_sexpr(value_t f)
+value_t fl_read_sexpr(value_t f)
 {
     value_t v;
     readstate_t state;
--- a/femtolisp/string.c
+++ b/femtolisp/string.c
@@ -133,7 +133,7 @@
     set(printreadablysym, FL_F);
     set(printprettysym, FL_F);
     FOR_ARGS(i,0,arg,args) {
-        print(s, args[i]);
+        fl_print(s, args[i]);
     }
     set(printreadablysym, oldpr);
     set(printprettysym, oldpp);
@@ -358,7 +358,7 @@
     else if (!iscprim(n)) type_error("number->string", "integer", n);
     else num = conv_to_uint64(cp_data((cprim_t*)ptr(n)),
                               cp_numtype((cprim_t*)ptr(n)));
-    if (numval(compare(args[0],fixnum(0))) < 0) {
+    if (numval(fl_compare(args[0],fixnum(0))) < 0) {
         num = -num;
         neg = 1;
     }
--- a/femtolisp/table.c
+++ b/femtolisp/table.c
@@ -127,7 +127,7 @@
 
 static void key_error(char *fname, value_t key)
 {
-    lerrorf(list2(KeyError, key), "%s: key not found", fname);
+    lerrorf(fl_list2(KeyError, key), "%s: key not found", fname);
 }
 
 // (get table key [default])
@@ -175,10 +175,10 @@
     fl_gc_handle(&t);
     for(i=0; i < n; i+=2) {
         if (table[i+1] != HT_NOTFOUND) {
-            zero = applyn(3, f,
-                          (value_t)table[i],
-                          (value_t)table[i+1],
-                          zero);
+            zero = fl_applyn(3, f,
+                             (value_t)table[i],
+                             (value_t)table[i+1],
+                             zero);
             // reload pointer
             h = (htable_t*)cv_data((cvalue_t*)ptr(t));
             if (h->size != n)
--- a/femtolisp/types.c
+++ b/femtolisp/types.c
@@ -64,7 +64,7 @@
     fltype_t *et = get_type(eltype);
     if (et->artype != NULL)
         return et->artype;
-    return get_type(list2(arraysym, eltype));
+    return get_type(fl_list2(arraysym, eltype));
 }
 
 fltype_t *define_opaque_type(value_t sym, size_t sz, cvtable_t *vtab,