summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-12-11 11:54:31 -0500
committerDavid Thompson <dthompson2@worcester.edu>2023-12-11 11:54:31 -0500
commitf547bc5f707e087af5b3c41519efbaf3e6bbbc87 (patch)
tree73ae03fe41009088baa1acae9061518507093408
parent19a753893bab381f134e50d613e1d675e7019d71 (diff)
Update reflect.js.
-rw-r--r--js-runtime/reflect.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/js-runtime/reflect.js b/js-runtime/reflect.js
index a930547..b7d88f3 100644
--- a/js-runtime/reflect.js
+++ b/js-runtime/reflect.js
@@ -106,7 +106,7 @@ class MutableBitvector extends Bitvector {
class MutableString extends HeapObject {
toString() { return "#<mutable-string>"; }
- repr() { return this.reflector.string_value(this); }
+ repr() { return string_repr(this.reflector.string_value(this)); }
}
class Procedure extends HeapObject {
@@ -325,6 +325,11 @@ class SchemeTrapError extends Error {
toString() { return `SchemeTrap(${this.tag}, <data>)`; }
}
+function string_repr(str) {
+ // FIXME: Improve to match Scheme.
+ return '"' + str.replace(/(["\\])/g, '\\$1').replace(/\n/g, '\\n') + '"';
+}
+
function flonum_to_string(f64) {
if (Object.is(f64, -0)) {
return '-0.0';
@@ -435,7 +440,10 @@ class SchemeModule {
string_downcase: Function.call.bind(String.prototype.toLowerCase),
make_weak_map() { return new WeakMap; },
- weak_map_get(map, k) { return map.get(k); },
+ weak_map_get(map, k) {
+ const val = map.get(k);
+ return val === undefined ? null: val;
+ },
weak_map_set(map, k, v) { return map.set(k, v); },
weak_map_delete(map, k) { return map.delete(k); },
@@ -450,8 +458,8 @@ class SchemeModule {
flog: Math.log,
fexp: Math.exp,
- jiffies_per_second() { return 1000; },
- current_jiffy() { return BigInt(Math.floor(performance.now())); },
+ jiffies_per_second() { return 1000000; },
+ current_jiffy() { return performance.now() * 1000; },
current_second() { return Date.now() / 1000; },
// Wrap in functions to allow for lazy loading of the wtf8
@@ -554,7 +562,6 @@ function repr(obj) {
if (typeof obj === 'number')
return flonum_to_string(obj);
if (typeof obj === 'string')
- // FIXME: Improve to match Scheme.
- return '"' + obj.replace(/(["\\])/g, '\\$1').replace(/\n/g, '\\n') + '"';
+ return string_repr(obj);
return obj + '';
}