diff --git a/js-assembler/runtime-src/baselib-functions.js b/js-assembler/runtime-src/baselib-functions.js index 0556987..ff98f23 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -67,6 +67,12 @@ args.push(arguments[i]); } + // Check arity usage. + if (! plt.baselib.arity.isArityMatching(v.arity, args.length)) { + throw new Error("arity mismatch"); + } + + var oldVal = MACHINE.val; var oldArgcount = MACHINE.argcount; var oldProc = MACHINE.proc; @@ -117,6 +123,34 @@ + // internallCall: call a Racket procedure and get its results. + // The use MUST be in the context of a closure call. This assumes that + // it is still in the context of the trampoline + var internalCall = function(MACHINE, proc, success, fail) { + if (isPrimitiveProcedure(proc)) { + var args = []; + for (var i = 4; i < arguments.length; i++) { + args.push(arguments[i]); + } + var result = v.apply(null, args); + succ(result); + } else if (isClosure(v)) { + // FIXME + } else { + plt.baselib.exceptions.raise(MACHINE, + plt.baselib.exceptions.makeExnFail( + plt.baselib.format.format( + "Not a procedure: ~e", + v))); + } + }; + + + + + + + // A Closure is a function that takes on more responsibilities: it is // responsible for popping off stack space before it finishes, and it // is also explicitly responsible for continuing the computation by @@ -180,6 +214,8 @@ + + var makePrimitiveProcedure = function(name, arity, f) { f.arity = arity; f.displayName = name; @@ -236,6 +272,7 @@ ////////////////////////////////////////////////////////////////////// exports.Closure = Closure; + exports.internalCall = internalCall; exports.finalizeClosureCall = finalizeClosureCall; exports.makePrimitiveProcedure = makePrimitiveProcedure; diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index d24476d..84d1268 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -422,6 +422,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; } e.onHalt(MACHINE); return; } else { + // General error condition: just exit out + // of the trampoline and call the current error handler. MACHINE.running = false; MACHINE.params.currentErrorHandler(MACHINE, e); return;