X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=prelude.js;h=38a13d7fdb52ce9d7d011b820d885498eed2ad8e;hb=3731b8083a84b9a804935f2de32fcf2b8f78cfd1;hp=3b566b1a021085b52505324ea976495028359bf9;hpb=516b8d727076a2134320e34c6fac27e071ee9ad7;p=jscl.git diff --git a/prelude.js b/prelude.js index 3b566b1..38a13d7 100644 --- a/prelude.js +++ b/prelude.js @@ -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; + } +}