Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/arr/compiler/repl.arr
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ fun make-repl<a>(
make-interaction-locator: make-interaction-locator,
make-definitions-locator: make-definitions-locator,
run-interaction: run-interaction,
runtime: runtime
runtime: runtime,
current-modules: current-modules
}
end
3 changes: 3 additions & 0 deletions src/arr/compiler/type-defaults.arr
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ module-const-valueskeleton = t-module("builtin://valueskeleton",
"is-vs-collection", t-arrow([list: t-top], t-boolean),
"vs-constr", t-arrow([list: t-string, t-list-app(t-top)], t-value-skeleton),
"is-vs-constr", t-arrow([list: t-top], t-boolean),
"vs-constr-render", t-arrow([list: t-string, t-list-app(t-top), t-top], t-value-skeleton),
"is-vs-constr-render", t-arrow([list: t-top], t-boolean),

"vs-table", t-arrow([list: t-array(t-string), t-array(t-array(t-top))], t-value-skeleton),
"is-table", t-arrow([list: t-top], t-boolean),
"vs-row", t-arrow([list: t-array(t-string), t-array(t-top)], t-value-skeleton),
Expand Down
1 change: 1 addition & 0 deletions src/arr/trove/valueskeleton.arr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data ValueSkeleton:
| vs-value(v :: Any)
| vs-collection(name :: String, items)
| vs-constr(name :: String, args)
| vs-constr-render(name :: String, args, renderers)
| vs-table(headers :: RawArray, rows #| :: RawArray<RawArray>|#)
| vs-table-truncated(headers :: RawArray, rows #| :: RawArray<RawArray>|#, total-rows :: Number)
| vs-row(headers :: RawArray, values :: RawArray)
Expand Down
15 changes: 15 additions & 0 deletions src/js/base/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,24 @@ function (Namespace, jsnums, codePoint, util, exnStackParser, loader, seedrandom
*/
function isBase(obj) { return obj instanceof PBase; }

const thisContext = "cli";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very brittle to me. I also don't see where this gets changed for other contexts -- you have it marked as a const, so line 221 will never look for anything other than cli context, right? (In the PR you linked to, it's a const of cpo, which again is rigid.

Also -- how does this interact with to-repr and to-string?

function isInRendererContext(val) {
var renderers = thisRuntime.getField(val, "renderers");
return thisRuntime.hasField(renderers, thisContext);
}

function renderValueSkeleton(val, values) {
if (thisRuntime.ffi.isVSValue(val)) { return values.pop(); } // double-check order!
else if (thisRuntime.ffi.isVSStr(val)) { return thisRuntime.unwrap(thisRuntime.getField(val, "s")); }
else if (thisRuntime.ffi.isVSConstrRender(val) && isInRendererContext(val)) {
var items = thisRuntime.ffi.toArray(thisRuntime.getField(val, "args"));
var strs = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't actually guaranteed to be strings, though, right? (It could be arbitrary HTML or something?)

for (var i = 0; i < items.length; i++) {
strs.push(renderValueSkeleton(items[i], values));
}
const renderers = thisRuntime.getField(val, "renderers");
return thisRuntime.getField(renderers, thisContext).app(strs);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this app returns a value that's not of the expected type? E.g. returns a DOM node when it's supposed to be a raw string? Or if it crashes/throws an error?

In general, I'm concerned about allowing arbitrary Pyret code to run during rendering, such that if the Pyret code is buggy/unexpected, the overall rendering algorithm will choke and produce no output at all, or the dreaded "error while rendering; details logged to console" message... Do you have a fallback here for what to do if that .app fails for whatever reason?

}
else if (thisRuntime.ffi.isVSCollection(val)) {
var name = thisRuntime.unwrap(thisRuntime.getField(val, "name"));
var items = thisRuntime.ffi.toArray(thisRuntime.getField(val, "items"));
Expand Down
4 changes: 4 additions & 0 deletions src/js/trove/ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@
isVSRow: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-row").app(v)); },
isVSCollection: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-collection").app(v)); },
isVSConstr: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-constr").app(v)); },
isVSConstrRender: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-constr-render").app(v)); },
isVSStr: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-str").app(v)); },
isVSSeq: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-seq").app(v)); },
isVSMatrix: function(v) { return runtime.unwrap(runtime.getField(VS, "is-vs-matrix").app(v)); },
Expand Down Expand Up @@ -777,6 +778,7 @@
var isStr = runtime.getField(VS, "is-vs-str");
var isSeq = runtime.getField(VS, "is-vs-seq");
var isMatrix = runtime.getField(VS, "is-vs-matrix");
var isConstRenderer = runtime.getField(VS, "is-vs-constr-render");
if(!(runtime.unwrap(isValueSkeleton.app(skel)) === true)) {
throwTypeMismatch(skel, "ValueSkeleton");
}
Expand All @@ -798,6 +800,8 @@
Array.prototype.push.apply(worklist, row); });
} else if (runtime.unwrap(isConstr.app(cur)) === true) {
Array.prototype.push.apply(worklist, toArray(runtime.getField(cur, "args")));
} else if (runtime.unwrap(isConstRenderer.app(cur)) === true) {
Array.prototype.push.apply(worklist, toArray(runtime.getField(cur, "args")));
} else if (runtime.unwrap(isStr.app(cur)) === true) {
// nothing
} else if (runtime.unwrap(isSeq.app(cur)) === true) {
Expand Down