Print compile progress while bootstrapping
[jscl.git] / prelude.js
index 3b566b1..38a13d7 100644 (file)
@@ -1,14 +1,54 @@
-//
+// This file is prepended to the result of compile ecmalisp.lisp, and
+// contain runtime code that ecmalisp assumes to exist.
 
-function Symbol(name){
-    this.name = name;
+var window = this;
+var nil;
+
+function globalEval (x) {
+    return eval.call (window, x);
+}
+
+function pv (x) { return x==undefined? nil: x; }
+
+function mv(){
+    var r = [].slice.call(arguments);
+    r['multiple-value'] = true;
+    return r;
+}
+
+function forcemv (x) {
+    return typeof x == 'object' && 'multiple-value' in x? x: mv(x);
 }
 
-function Cons(car, cdr){
-    this.car = car;
-    this.cdr = cdr;
+// NOTE: Define VALUES to be MV for toplevel forms. It is because
+// `eval' compiles the forms and execute the Javascript code at
+// toplevel with `js-eval', so it is necessary to return multiple
+// values from the eval function.
+var values = mv;
+
+function checkArgsAtLeast(args, n){
+    if (args.length < n) throw 'too few arguments';
 }
 
+function checkArgsAtMost(args, n){
+    if (args.length > n) throw 'too many arguments';
+}
 
+function checkArgs(args, n){
+    checkArgsAtLeast(args, n);
+    checkArgsAtMost(args, n);
+}
 
-console.log('Running test.js...');
+// Improper list constructor (like LIST*)
+function QIList(){
+    if (arguments.length == 1)
+        return arguments[0];
+    else {
+        var i = arguments.length-1;
+        var r = arguments[i--];
+        for (; i>=0; i--){
+            r = {car: arguments[i], cdr: r};
+        }
+        return r;
+    }
+}