diff --git a/js-assembler/assemble.rkt b/js-assembler/assemble.rkt index fc93569..47e75a9 100644 --- a/js-assembler/assemble.rkt +++ b/js-assembler/assemble.rkt @@ -559,8 +559,7 @@ EOF (assemble-label (make-Label (LinkedLabel-label label)))])))] [(PushControlFrame/Prompt? stmt) - ;; fixme: use a different frame structure - (format "M.c.push(new RT.PromptFrame(~a,~a));" + (format "M.c.push(new RT.PromptFrame(~a,~a,M.e.length,false));" (let: ([label : (U Symbol LinkedLabel) (PushControlFrame/Prompt-label stmt)]) (cond [(symbol? label) diff --git a/js-assembler/runtime-src/baselib-frames.js b/js-assembler/runtime-src/baselib-frames.js index a7c6379..ebd47b3 100644 --- a/js-assembler/runtime-src/baselib-frames.js +++ b/js-assembler/runtime-src/baselib-frames.js @@ -40,11 +40,15 @@ - // A prompt frame includes a return address, as well as a prompt tag - // for supporting delimited continuations. - var PromptFrame = function(label, tag) { + // A prompt frame includes a return address, as well as a prompt + // tag for supporting delimited continuations. To support abort, + // we also keep the size of the environment, and the handler + // to call if an abort happens. + var PromptFrame = function(label, tag, envLength, handler) { this.label = label; this.tag = tag; // ContinuationPromptTag + this.envLength = envLength; + this.handler = handler; }; PromptFrame.prototype = baselib.heir(Frame.prototype); diff --git a/js-assembler/runtime-src/baselib-primitives.js b/js-assembler/runtime-src/baselib-primitives.js index b0cc6fc..9987651 100644 --- a/js-assembler/runtime-src/baselib-primitives.js +++ b/js-assembler/runtime-src/baselib-primitives.js @@ -114,9 +114,19 @@ var checkHash = baselib.check.checkHash; var checkMutableHash = baselib.check.checkMutableHash; var checkImmutableHash = baselib.check.checkImmutableHash; - var checkAny = baselib.check.makeCheckArgumentType( - function(x) { return true; }, - 'any'); + + // Just for consistency with the other names, we provide checkAny, which + // doesn't really do any checking. + var checkAny = function(M, name, offset) { + return M.e[M.e.length-1-offset]; + }; + + var checkPromptTag = baselib.check.makeCheckArgumentType( + baselib.contmarks.isContinuationPromptTag, + 'prompt tag'); + + var PromptFrame = baselib.frames.PromptFrame; + ////////////////////////////////////////////////////////////////////// @@ -3135,6 +3145,45 @@ }); + installPrimitiveClosure( + 'abort-current-continuation', + 2, //baselib.arity.makeArityAtLeast(1), + function(M) { + var promptTag = checkPromptTag(M, 'abort-current-continuation', 0); + var vals = []; + var frame; + for(i = 1; i < M.a; i++) { + vals.push(M.e[M.e.length-1-i]); + } + + // First, find the continuation prompt. + while(true) { + frame = M.c.pop(); + if (frame instanceof PromptFrame) { + break; + } + } + // Shrink the environment to what was observed when the PromptFrame was installed. + M.e.length = frame.envLength; + + // Default behavior: + // Re-establish the prompt frame and call the thunk. + // FIXME: generalize to different handlers! + M.e.push(c); + if (isProcedure(vals[0])) { + M.p = vals[0]; + M.a = 0; + baselib.functions.rawApply(M); + } else { + raiseArgumentTypeError(M, + 'abort-current-continuation', + 'thunk', + 1, + vals[0]); + } + }); + + exports['Primitives'] = Primitives; diff --git a/lang/kernel.rkt b/lang/kernel.rkt index 8c31595..7a16d30 100644 --- a/lang/kernel.rkt +++ b/lang/kernel.rkt @@ -228,6 +228,8 @@ current-inexact-milliseconds current-seconds + + abort-current-continuation ;; needed for cs019-local #%stratified-body diff --git a/web-world/google-maps/google-maps.rkt b/web-world/google-maps/google-maps.rkt new file mode 100644 index 0000000..daf37b4 --- /dev/null +++ b/web-world/google-maps/google-maps.rkt @@ -0,0 +1,13 @@ +#lang s-exp "../../lang/base.rkt" + +(require "../../js.rkt") + +(provide load-gmaps-library) + + +(define (load-gmaps-library api-key with-sensor) + (load-script (string-append + "http://maps.googleapis.com/maps/api/js?key=" + api-key + "&sensor=" + (if with-sensor "true" "false")))) \ No newline at end of file