From f547bc5f707e087af5b3c41519efbaf3e6bbbc87 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 11 Dec 2023 11:54:31 -0500 Subject: Update reflect.js. --- js-runtime/reflect.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'js-runtime') 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 "#"; } - 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}, )`; } } +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 + ''; } -- cgit v1.2.3