From bc8546bae0837dfd38ecb451249ac3b4b6da2a16 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Tue, 5 Jul 2011 16:56:56 -0400 Subject: [PATCH] lifting out more types --- js-assembler/get-runtime.rkt | 116 +++++++------------- js-assembler/runtime-src/baselib_boxes.js | 59 ++++++++++ js-assembler/runtime-src/baselib_paths.js | 19 ++++ js-assembler/runtime-src/baselib_regexps.js | 22 ++++ js-assembler/runtime-src/types.js | 81 ++------------ 5 files changed, 149 insertions(+), 148 deletions(-) create mode 100644 js-assembler/runtime-src/baselib_boxes.js create mode 100644 js-assembler/runtime-src/baselib_paths.js create mode 100644 js-assembler/runtime-src/baselib_regexps.js diff --git a/js-assembler/get-runtime.rkt b/js-assembler/get-runtime.rkt index 139df0d..2a17d73 100644 --- a/js-assembler/get-runtime.rkt +++ b/js-assembler/get-runtime.rkt @@ -22,85 +22,49 @@ (provide/contract [get-runtime (-> string?)]) -;; jquery is special: we need to make sure it's resilient against -;; multiple invokation and inclusion. -(define-runtime-path jquery-protect-header.js "runtime-src/jquery-protect-header.js") -(define-runtime-path jquery.js "runtime-src/jquery.js") -(define-runtime-path jquery-protect-footer.js "runtime-src/jquery-protect-footer.js") - -(define-runtime-path baselib.js "runtime-src/baselib.js") -(define-runtime-path baselib_unionfind.js "runtime-src/baselib_unionfind.js") -(define-runtime-path baselib_equality.js "runtime-src/baselib_equality.js") -(define-runtime-path baselib_lists.js "runtime-src/baselib_lists.js") -(define-runtime-path baselib_vectors.js "runtime-src/baselib_vectors.js") -(define-runtime-path baselib_hash.js "runtime-src/baselib_hash.js") -(define-runtime-path baselib_symbol.js "runtime-src/baselib_symbol.js") -(define-runtime-path baselib_structs.js "runtime-src/baselib_structs.js") -(define-runtime-path baselib_arity.js "runtime-src/baselib_arity.js") -(define-runtime-path baselib_inspectors.js "runtime-src/baselib_inspectors.js") -(define-runtime-path baselib_exceptions.js "runtime-src/baselib_exceptions.js") -(define-runtime-path baselib_format.js "runtime-src/baselib_format.js") -(define-runtime-path baselib_chars.js "runtime-src/baselib_chars.js") -(define-runtime-path baselib_strings.js "runtime-src/baselib_strings.js") -(define-runtime-path baselib_bytes.js "runtime-src/baselib_bytes.js") -(define-runtime-path baselib_readergraph.js "runtime-src/baselib_readergraph.js") - - - -(define-runtime-path jshashtable.js "runtime-src/jshashtable-2.1_src.js") -(define-runtime-path jsnums.js "runtime-src/js-numbers.js") -(define-runtime-path link.js "runtime-src/link.js") - -;; from js-vm -;; Deprecated: -;; (define-runtime-path helpers.js "runtime-src/helpers.js") - - -;; from js-vm -(define-runtime-path types.js "runtime-src/types.js") -;; These primitives were coded for the js-vm project, and we'll gradually -;; absorb them in. -;(define-runtime-path js-vm-primitives.js "runtime-src/js-vm-primitives.js") - -(define-runtime-path runtime.js "runtime-src/runtime.js") +(define-runtime-path base-path "runtime-src") ;; The order matters here. link needs to come near the top, because ;; the other modules below have some circular dependencies that are resolved ;; by link. -(define files (list jquery-protect-header.js - jquery.js - jquery-protect-footer.js - - jshashtable.js - jsnums.js - - baselib.js - - baselib_unionfind.js - baselib_equality.js - baselib_format.js - - baselib_lists.js - baselib_vectors.js - baselib_chars.js - baselib_symbol.js - baselib_strings.js - baselib_bytes.js - baselib_hash.js - - baselib_structs.js - baselib_arity.js - baselib_inspectors.js - baselib_exceptions.js - baselib_readergraph.js - - link.js -; helpers.js - types.js -; js-vm-primitives.js - runtime.js)) +(define files '( + ;; jquery is special: we need to make sure it's resilient against + ;; multiple invokation and inclusion. + jquery-protect-header.js + jquery.js + jquery-protect-footer.js + + jshashtable-2.1_src.js + js-numbers.js + + baselib.js + + baselib_unionfind.js + baselib_equality.js + baselib_format.js + + baselib_lists.js + baselib_vectors.js + baselib_chars.js + baselib_symbol.js + baselib_strings.js + baselib_bytes.js + baselib_hash.js + baselib_regexps.js + baselib_paths.js + baselib_boxes.js + + baselib_structs.js + baselib_arity.js + baselib_inspectors.js + baselib_exceptions.js + baselib_readergraph.js + + link.js + types.js + runtime.js)) @@ -111,8 +75,10 @@ (define text (apply string-append - (map path->string files))) - + (map (lambda (n) + (path->string + (build-path base-path (symbol->string n)))) + files))) (define (get-runtime) text) \ No newline at end of file diff --git a/js-assembler/runtime-src/baselib_boxes.js b/js-assembler/runtime-src/baselib_boxes.js new file mode 100644 index 0000000..b8d48c0 --- /dev/null +++ b/js-assembler/runtime-src/baselib_boxes.js @@ -0,0 +1,59 @@ +// Exceptions + +(function(baselib) { + var exceptions = {}; + baselib.boxes = exceptions; + + + ////////////////////////////////////////////////////////////////////// + // Boxes + + var Box = function(x, mutable) { + this.val = x; + this.mutable = mutable; + }; + + Box.prototype.ref = function() { + return this.val; + }; + + Box.prototype.set = function(newVal) { + if (this.mutable) { + this.val = newVal; + } + }; + + Box.prototype.toString = function(cache) { + cache.put(this, true); + return "#&" + toWrittenString(this.val, cache); + }; + + Box.prototype.toWrittenString = function(cache) { + cache.put(this, true); + return "#&" + toWrittenString(this.val, cache); + }; + + Box.prototype.toDisplayedString = function(cache) { + cache.put(this, true); + return "#&" + toDisplayedString(this.val, cache); + }; + + Box.prototype.toDomNode = function(cache) { + cache.put(this, true); + var parent = document.createElement("span"); + parent.appendChild(document.createTextNode('#&')); + parent.appendChild(toDomNode(this.val, cache)); + return parent; + }; + + Box.prototype.equals = function(other, aUnionFind) { + return ((other instanceof Box) && + equals(this.val, other.val, aUnionFind)); + }; + + + exports.Box = Box; + + + +})(this['plt'].baselib); \ No newline at end of file diff --git a/js-assembler/runtime-src/baselib_paths.js b/js-assembler/runtime-src/baselib_paths.js new file mode 100644 index 0000000..54dbc35 --- /dev/null +++ b/js-assembler/runtime-src/baselib_paths.js @@ -0,0 +1,19 @@ +(function(baselib) { + var exports = {}; + baselib.paths = exports; + + // Paths + + var Path = function(p) { + this.path = p; + }; + + Path.prototype.toString = function() { + return this.path; + }; + + ////////////////////////////////////////////////////////////////////// + + exports.Path = Path; + +})(this['plt'].baselib); \ No newline at end of file diff --git a/js-assembler/runtime-src/baselib_regexps.js b/js-assembler/runtime-src/baselib_regexps.js new file mode 100644 index 0000000..f7ef063 --- /dev/null +++ b/js-assembler/runtime-src/baselib_regexps.js @@ -0,0 +1,22 @@ +(function(baselib) { + var exports = {}; + baselib.regexps = exports; + + + // Regular expressions. + + var RegularExpression = function(pattern) { + this.pattern = pattern; + }; + + + var ByteRegularExpression = function(pattern) { + this.pattern = pattern; + }; + + ////////////////////////////////////////////////////////////////////// + + exports.RegularExpression = RegularExpression; + exports.ByteRegularExpression = ByteRegularExpression; + +})(this['plt'].baselib); \ No newline at end of file diff --git a/js-assembler/runtime-src/types.js b/js-assembler/runtime-src/types.js index b3c503c..f46fa86 100644 --- a/js-assembler/runtime-src/types.js +++ b/js-assembler/runtime-src/types.js @@ -69,31 +69,6 @@ if (! this['plt']) { this['plt'] = {}; } ////////////////////////////////////////////////////////////////////// - // Regular expressions. - - var RegularExpression = function(pattern) { - this.pattern = pattern; - }; - - - var ByteRegularExpression = function(pattern) { - this.pattern = pattern; - }; - - - - - ////////////////////////////////////////////////////////////////////// - - // Paths - - var Path = function(p) { - this.path = p; - }; - - Path.prototype.toString = function() { - return this.path; - }; @@ -101,51 +76,11 @@ if (! this['plt']) { this['plt'] = {}; } + ////////////////////////////////////////////////////////////////////// - // Boxes - - var Box = function(x, mutable) { - this.val = x; - this.mutable = mutable; - }; - Box.prototype.ref = function() { - return this.val; - }; - Box.prototype.set = function(newVal) { - if (this.mutable) { - this.val = newVal; - } - }; - Box.prototype.toString = function(cache) { - cache.put(this, true); - return "#&" + toWrittenString(this.val, cache); - }; - - Box.prototype.toWrittenString = function(cache) { - cache.put(this, true); - return "#&" + toWrittenString(this.val, cache); - }; - - Box.prototype.toDisplayedString = function(cache) { - cache.put(this, true); - return "#&" + toDisplayedString(this.val, cache); - }; - - Box.prototype.toDomNode = function(cache) { - cache.put(this, true); - var parent = document.createElement("span"); - parent.appendChild(document.createTextNode('#&')); - parent.appendChild(toDomNode(this.val, cache)); - return parent; - }; - - Box.prototype.equals = function(other, aUnionFind) { - return ((other instanceof Box) && - equals(this.val, other.val, aUnionFind)); - }; ////////////////////////////////////////////////////////////////////// @@ -765,14 +700,14 @@ if (! this['plt']) { this['plt'] = {}; } types.list = makeList; types.vector = makeVector; types.vectorImmutable = makeVectorImmutable; - types.regexp = function(p) { return new RegularExpression(p) ; } - types.byteRegexp = function(p) { return new ByteRegularExpression(p) ; } + types.regexp = function(p) { return new plt.baselib.regexps.RegularExpression(p) ; } + types.byteRegexp = function(p) { return new plt.baselib.regexps.ByteRegularExpression(p) ; } types.character = plt.baselib.chars.Char.makeInstance; types['string'] = makeString; - types.box = function(x) { return new Box(x, true); }; + types.box = function(x) { return new plt.baselib.boxes.Box(x, true); }; types.placeholder = function(x) { return new Placeholder(x); }; - types.boxImmutable = function(x) { return new Box(x, false); }; - types.path = function(x) { return new Path(x); }; + types.boxImmutable = function(x) { return new plt.baselib.boxes.Box(x, false); }; + types.path = function(x) { return new plt.baselib.paths.Path(x); }; types.bytes = function(x, mutable) { return new plt.baselib.bytes.Bytes(x, mutable); }; types.bytesImmutable = function(x) { return new plt.baselib.bytes.Bytes(x, false); }; types.keyword = function(k) { return new Keyword(k); }; @@ -812,7 +747,7 @@ if (! this['plt']) { this['plt'] = {}; } types.isList = isList; types.isEmpty = function(x) { return x === Empty.EMPTY; }; types.isVector = function(x) { return x instanceof Vector; }; - types.isBox = function(x) { return x instanceof Box; }; + types.isBox = function(x) { return x instanceof plt.baselib.boxes.Box; }; types.isPlaceholder = function(x) { return x instanceof Placeholder; }; types.isHash = function(x) { return (x instanceof plt.baselib.hash.EqHashTable || x instanceof plt.baselib.hash.EqualHashTable); }; @@ -851,7 +786,7 @@ if (! this['plt']) { this['plt'] = {}; } // types.isContinuationPromptTag = function(x) { return x instanceof ContinuationPromptTag; }; - types.Box = Box; + types.Box = plt.baselib.boxes.Box; types.Placeholder = Placeholder; types.ThreadCell = ThreadCell;