From 6f426736cb6da3116d159bdef815026d4901f1d7 Mon Sep 17 00:00:00 2001 From: Siddhartha Prasad Date: Thu, 6 Feb 2025 21:28:07 +0000 Subject: [PATCH 1/4] init --- src/arr/compiler/type-defaults.arr | 3 +++ src/arr/trove/valueskeleton.arr | 1 + src/js/base/runtime.js | 15 +++++++++++++++ src/js/trove/ffi.js | 4 ++++ vs-constr-render.arr | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 vs-constr-render.arr diff --git a/src/arr/compiler/type-defaults.arr b/src/arr/compiler/type-defaults.arr index 81f880635..f3b070d58 100644 --- a/src/arr/compiler/type-defaults.arr +++ b/src/arr/compiler/type-defaults.arr @@ -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), diff --git a/src/arr/trove/valueskeleton.arr b/src/arr/trove/valueskeleton.arr index f6823204f..ff10d5754 100644 --- a/src/arr/trove/valueskeleton.arr +++ b/src/arr/trove/valueskeleton.arr @@ -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|#) | vs-row(headers :: RawArray, values :: RawArray) | vs-seq(items) diff --git a/src/js/base/runtime.js b/src/js/base/runtime.js index 64a76b713..d4c7e3984 100644 --- a/src/js/base/runtime.js +++ b/src/js/base/runtime.js @@ -202,9 +202,24 @@ function (Namespace, jsnums, codePoint, util, exnStackParser, loader, seedrandom */ function isBase(obj) { return obj instanceof PBase; } + const thisContext = "cli"; + 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 = []; + 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); + } else if (thisRuntime.ffi.isVSCollection(val)) { var name = thisRuntime.unwrap(thisRuntime.getField(val, "name")); var items = thisRuntime.ffi.toArray(thisRuntime.getField(val, "items")); diff --git a/src/js/trove/ffi.js b/src/js/trove/ffi.js index d6d5c8ca4..08ea93146 100644 --- a/src/js/trove/ffi.js +++ b/src/js/trove/ffi.js @@ -744,6 +744,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)); }, @@ -770,6 +771,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"); } @@ -791,6 +793,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) { diff --git a/vs-constr-render.arr b/vs-constr-render.arr new file mode 100644 index 000000000..9e0f33f7f --- /dev/null +++ b/vs-constr-render.arr @@ -0,0 +1,18 @@ +import valueskeleton as VS + +fun render(args): + for raw-array-fold(str from "", elt from args, i from 0): + str + elt + end +end + +data Point: + | point(x, y) +sharing: + method _output(self): + VS.vs-constr-render("point", [list: VS.vs-value(self.x), VS.vs-value(self.y)], { cli: render }) + end +end + +print(point(4, 5)) + From 124ea096f05900c3f678781702362494ab18582c Mon Sep 17 00:00:00 2001 From: Siddhartha Prasad Date: Wed, 30 Jul 2025 12:19:08 -0400 Subject: [PATCH 2/4] Exposing something --- src/arr/compiler/repl.arr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arr/compiler/repl.arr b/src/arr/compiler/repl.arr index 5e6b73651..8cdaefdc4 100644 --- a/src/arr/compiler/repl.arr +++ b/src/arr/compiler/repl.arr @@ -187,6 +187,7 @@ fun make-repl( 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 From ec86502fa6bd237c471cb7097775795454c7077e Mon Sep 17 00:00:00 2001 From: Siddhartha Prasad Date: Sat, 16 Aug 2025 08:39:29 -0400 Subject: [PATCH 3/4] removing test file --- vs-constr-render.arr | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 vs-constr-render.arr diff --git a/vs-constr-render.arr b/vs-constr-render.arr deleted file mode 100644 index 9e0f33f7f..000000000 --- a/vs-constr-render.arr +++ /dev/null @@ -1,18 +0,0 @@ -import valueskeleton as VS - -fun render(args): - for raw-array-fold(str from "", elt from args, i from 0): - str + elt - end -end - -data Point: - | point(x, y) -sharing: - method _output(self): - VS.vs-constr-render("point", [list: VS.vs-value(self.x), VS.vs-value(self.y)], { cli: render }) - end -end - -print(point(4, 5)) - From 6a6c8728f7540d36a143538f6068eb033849ed27 Mon Sep 17 00:00:00 2001 From: Dorai Sitaram Date: Fri, 5 Sep 2025 08:47:17 -0400 Subject: [PATCH 4/4] Add essentials2021.arr --- src/arr/compiler/libs.arr | 1 + src/arr/trove/essentials2021.arr | 488 +++++++++++++++++++++++++++++++ 2 files changed, 489 insertions(+) create mode 100644 src/arr/trove/essentials2021.arr diff --git a/src/arr/compiler/libs.arr b/src/arr/compiler/libs.arr index 6d7b71678..bc6784a55 100644 --- a/src/arr/compiler/libs.arr +++ b/src/arr/compiler/libs.arr @@ -1,5 +1,6 @@ import base as _ import essentials2020 as _ +import essentials2021 as _ import arrays as _ import ast as _ diff --git a/src/arr/trove/essentials2021.arr b/src/arr/trove/essentials2021.arr new file mode 100644 index 000000000..f1d020976 --- /dev/null +++ b/src/arr/trove/essentials2021.arr @@ -0,0 +1,488 @@ +use context empty-context + +import lists as L +import image as I +import arrays as A +import option as O +import constants as C +import global as G + +provide from L: + all, + all2, + any, + append, + distinct, + drop, + each, + each2, + each3, + each3_n, + each4, + each4_n, + each_n, + empty, + filter, + filter-map, + filter-values, + find, + fold, + fold-while, + fold2, + fold3, + fold4, + fold_n, + foldl, + foldr, + get, + is-List, + is-empty, + is-link, + join-str, + join-str-last, + last, + length, + link, + list, + longer-than, + map, + map2, + map2_n, + map3, + map3_n, + map4, + map4_n, + map_n, + member, + member-always, + member-always3, + member-identical, + member-identical3, + member-now, + member-now3, + member-with, + member3, + partition, + push, + range, + range-by, + remove, + repeat, + reverse, + same-length, + set, + shorter-than, + shuffle, + sort, + sort-by, + split-at, + take, + take-while, + + type List, + data List +end + +provide from I: + above, + above-align, + above-align-list, + above-list, + add-line, + below, + below-align, + below-align-list, + below-list, + beside, + beside-align, + beside-align-list, + beside-list, + center-pinhole, + circle, + color-at-position, + color-list-to-bitmap, + color-list-to-image, + color-named, + crop, + draw-pinhole, + ellipse, + empty-color-scene, + empty-image, + empty-scene, + ff-decorative, + ff-default, + ff-modern, + ff-roman, + ff-script, + ff-swiss, + ff-symbol, + ff-system, + flip-horizontal, + flip-vertical, + frame, + fs-italic, + fs-normal, + fs-slant, + fw-bold, + fw-light, + fw-normal, + image-baseline, + image-height, + image-pinhole-x, + image-pinhole-y, + image-to-color-list, + image-url, + image-width, + images-difference, + images-equal, + is-FillMode, + is-FontFamily, + is-FontStyle, + is-FontWeight, + is-Point, + is-XPlace, + is-YPlace, + is-angle, + is-ff-decorative, + is-ff-default, + is-ff-modern, + is-ff-roman, + is-ff-script, + is-ff-swiss, + is-ff-symbol, + is-ff-system, + is-fs-italic, + is-fs-normal, + is-fs-slant, + is-fw-bold, + is-fw-light, + is-image, + is-image-color, + is-mode, + is-mode-fade, + is-mode-outline, + is-mode-solid, + is-point-polar, + is-point-xy, + is-side-count, + is-step-count, + is-transparency, + is-x-left, + is-x-middle, + is-x-pinhole, + is-x-place, + is-x-right, + is-y-baseline, + is-y-bottom, + is-y-center, + is-y-pinhole, + is-y-place, + is-y-top, + isosceles-triangle, + line, + mode-fade, + mode-outline, + mode-solid, + move-pinhole, + name-to-color, + overlay, + overlay-align, + overlay-align-list, + overlay-list, + overlay-onto-offset, + overlay-xy, + place-image, + place-image-align, + place-pinhole, + point, + point-polar, + point-polygon, + point-xy, + put-image, + radial-star, + rectangle, + reflect-x, + reflect-y, + regular-polygon, + rhombus, + right-triangle, + rotate, + scale, + scale-xy, + scene-line, + square, + star, + star-polygon, + star-sized, + text, + text-font, + translate, + triangle, + triangle-aas, + triangle-asa, + triangle-ass, + triangle-saa, + triangle-sas, + triangle-ssa, + triangle-sss, + underlay, + underlay-align, + underlay-align-list, + underlay-list, + underlay-xy, + wedge, + x-center, + x-left, + x-middle, + x-pinhole, + x-right, + y-baseline, + y-bottom, + y-center, + y-middle, + y-pinhole, + y-top, + + type FillMode, + type FontFamily, + type FontStyle, + type FontWeight, + type Image, + type Point, + type XPlace, + type YPlace, + + data FillMode, + data FontFamily, + data FontStyle, + data FontWeight, + data Point, + data XPlace, + data YPlace, +end + +provide from A: + array, + array-from-list, + array-get-now, + array-length, + array-of, + array-set-now, + array-to-list-now, + build-array, + is-array, + + type Array +end + +provide from O: + is-Option, + is-none, + is-some, + none, + some, + + type Option, + data Option +end + +provide from C: + PI +end + +provide from G: + _divide, + _greaterequal, + _greaterthan, + _lessequal, + _lessthan, + _minus, + _plus, + _times, + brander, + builtins, + display, + display-error, + equal-always, + equal-always3, + equal-now, + equal-now3, + gensym, + identical, + identical3, + is-boolean, + is-function, + is-nothing, + is-number, + is-object, + is-raw-array, + is-row, + is-string, + is-table, + is-tuple, + not, + nothing, + num-abs, + num-acos, + num-asin, + num-atan, + num-atan2, + num-ceiling, + num-ceiling-digits, + num-ceiling-place, + num-cos, + num-equal, + num-exact, + num-exp, + num-expt, + num-floor, + num-floor-digits, + num-floor-place, + num-is-fixnum, + num-is-integer, + num-is-negative, + num-is-non-negative, + num-is-non-positive, + num-is-positive, + num-is-rational, + num-is-roughnum, + num-log, + num-max, + num-min, + num-modulo, + num-random, + num-random-seed, + num-remainder, + num-round, + num-round-digits, + num-round-even, + num-round-even-digits, + num-round-even-place, + num-round-place, + num-sin, + num-sqr, + num-sqrt, + num-tan, + num-to-fixnum, + num-to-rational, + num-to-roughnum, + num-to-string, + num-to-string-digits, + num-tostring, + num-truncate, + num-truncate-digits, + num-truncate-place, + num-within, + num-within-abs, + num-within-rel, + print, + print-error, + raise, + random, + raw-array, + raw-array-and-mapi, + raw-array-build, + raw-array-build-opt, + raw-array-filter, + raw-array-fold, + raw-array-from-list, + raw-array-get, + raw-array-length, + raw-array-map, + raw-array-map-1, + raw-array-of, + raw-array-or-mapi, + raw-array-set, + raw-array-sort-nums, + raw-array-to-list, + ref-freeze, + ref-get, + ref-set, + roughly-equal, + roughly-equal-always, + roughly-equal-always3, + roughly-equal-now, + roughly-equal-now3, + run-task, + string-append, + string-char-at, + string-contains, + string-ends-with, + string-equal, + string-explode, + string-from-code-point, + string-from-code-points, + string-index-of, + string-is-number, + string-isnumber, + string-length, + string-repeat, + string-replace, + string-split, + string-split-all, + string-starts-with, + string-substring, + string-to-code-point, + string-to-code-points, + string-to-lower, + string-to-number, + string-to-upper, + string-tolower, + string-tonumber, + string-toupper, + test-print, + time-now, + to-repr, + to-string, + torepr, + tostring, + within, + within-abs, + within-abs-now, + within-abs-now3, + within-abs3, + within-now, + within-now3, + within-rel, + within-rel-now, + within-rel-now3, + within-rel3, + within3, + + type Any, + type Method, + type Object, + type Function, + type NumNonNegative, + type NumNonPositive, + type NumNegative, + type NumPositive, + type NumRational, + type NumInteger, + type Roughnum, + type Exactnum, + type Boolean, + type Number, + type String, + type Nothing, + type RawArray, + type Row, + + data Boolean, + data Exactnum, + data Function, + data Method, + data Nothing, + data NumInteger, + data NumNegative, + data NumNonNegative, + data NumNonPositive, + data NumPositive, + data NumRational, + data Number, + data Object, + data Roughnum, + data Row, + data String, + data Table +end