diff --git a/js-assembler/find-primitive-implemented.rkt b/js-assembler/find-primitive-implemented.rkt new file mode 100644 index 0000000..9467927 --- /dev/null +++ b/js-assembler/find-primitive-implemented.rkt @@ -0,0 +1,27 @@ +#lang racket/base + +(require racket/runtime-path + racket/list + (for-syntax racket/base)) + +;; Provides a list of symbols of the function implemented primitively. Knowing +;; this allows us to do certain procedure applications more efficiently without +;; touching the stack so much. +(provide primitive-ids) + +(define a-regexp + #px"installPrimitiveProcedure\\s*\\(\\s*['\"]([^'\"]+)['\"]") + +(define-runtime-path baselib-primitives.js + (build-path "runtime-src" "baselib-primitives.js")) + +(define ip (open-input-file baselib-primitives.js)) + +(define primitive-ids + (let loop () + (let ([a-match (regexp-match a-regexp ip)]) + (cond + [a-match => (lambda (a-match) + (cons (string->symbol (bytes->string/utf-8 (second a-match))) + (loop)))] + [else empty])))) \ No newline at end of file diff --git a/js-assembler/runtime-src/baselib-functions.js b/js-assembler/runtime-src/baselib-functions.js index f77d278..0dfffe0 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -317,18 +317,18 @@ var makePrimitiveProcedure = function (name, arity, f) { - // f.racketArity = arity; - // f.displayName = name; - // return f; - return makeClosure(name, - arity, - function(M) { - --M.cbt; - M.v = f(M); - M.e.length -= M.a; - return M.c.pop().label(M); - }, - []); + var proc = makeClosure(name, + arity, + function(M) { + --M.cbt; + M.v = f(M); + M.e.length -= M.a; + return M.c.pop().label(M); + }, + []); + // Also, record the raw implementation of the function. + proc.rawImpl = f; + return proc; }; diff --git a/js-assembler/runtime-src/baselib-primitives.js b/js-assembler/runtime-src/baselib-primitives.js index 110a6ed..62ff9f1 100644 --- a/js-assembler/runtime-src/baselib-primitives.js +++ b/js-assembler/runtime-src/baselib-primitives.js @@ -2476,6 +2476,21 @@ return baselib.contmarks.DEFAULT_CONTINUATION_PROMPT_TAG; }); + installPrimitiveProcedure( + 'current-inexact-milliseconds', + 0, + function(M) { + return makeFloat((new Date()).valueOf()); + }); + + + installPrimitiveProcedure( + 'current-seconds', + 0, + function() { + return Math.floor( (new Date()).getTime() / 1000 ); + }); + exports['Primitives'] = Primitives; exports['installPrimitiveProcedure'] = installPrimitiveProcedure; exports['installPrimitiveClosure'] = installPrimitiveClosure; diff --git a/lang/kernel.rkt b/lang/kernel.rkt index e96ea65..a561a12 100644 --- a/lang/kernel.rkt +++ b/lang/kernel.rkt @@ -204,6 +204,10 @@ prop:exn:srclocs + current-inexact-milliseconds + current-seconds + + ;; needed for cs019-local #%stratified-body ) diff --git a/version.rkt b/version.rkt index ad5e069..7f00bbb 100644 --- a/version.rkt +++ b/version.rkt @@ -6,4 +6,4 @@ (provide version) (: version String) -(define version "1.47") +(define version "1.48")