From 0a8bfe10834784d69205fb8d1e36cc44dc2d66b8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 27 Dec 2018 00:04:09 -0400 Subject: Improved machinery for working with constant pools. --- stdlib/source/lux/host/jvm/constant/pool.lux | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 stdlib/source/lux/host/jvm/constant/pool.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/host/jvm/constant/pool.lux b/stdlib/source/lux/host/jvm/constant/pool.lux new file mode 100644 index 000000000..8d221712b --- /dev/null +++ b/stdlib/source/lux/host/jvm/constant/pool.lux @@ -0,0 +1,68 @@ +(.module: + [lux #* + [data + [text ("text/." Equivalence)] + [format + ["." binary (#+ Format)]] + [collection + [list ("list/." Fold)] + ["." row (#+ Row)]]]] + ["." // (#+ Constant) + [// + ["." encoding ("u2/." Equivalence)] + ["." index (#+ Index)]]]) + +(def: offset 1) + +(type: #export Pool (Row Constant)) + +(def: #export (utf8 value pool) + (-> Text Pool [Pool Index]) + (with-expansions [ (as-is (index.index (n/+ offset idx))) + (as-is (recur (.inc idx)))] + (loop [idx 0] + (case (row.nth idx pool) + (#.Some entry) + (case entry + (#//.UTF8 reference) + (if (text/= reference value) + [pool + ] + ) + + _ + ) + + #.None + [(row.add (#//.UTF8 value) pool) + ])))) + +(def: (class' value pool) + (-> Index Pool [Pool Index]) + (with-expansions [ (as-is (index.index (n/+ offset idx))) + (as-is (recur (.inc idx)))] + (loop [idx 0] + (case (row.nth idx pool) + (#.Some entry) + (case entry + (#//.Class reference) + (if (u2/= reference value) + [pool + ] + ) + + _ + ) + + #.None + [(row.add (#//.Class value) pool) + ])))) + +(def: #export (class name pool) + (-> Text Pool [Pool Index]) + (let [[pool @name] (utf8 name pool)] + (class' @name pool))) + +(def: #export format + (Format Pool) + (binary.row/16' ..offset //.format)) -- cgit v1.2.3