-//
+// 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);
+}
+
+// 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';
}
-console.log('Running test.js...');
+function checkArgs(args, n){
+ checkArgsAtLeast(args, n);
+ checkArgsAtMost(args, n);
+}
+
+// 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;
+ }
+}