From 3553c81d0ac93cde12f6b8ceacf8af10ba5da2f1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 20 Jun 2019 02:32:02 -0400 Subject: Re-factored constant attributes. --- stdlib/source/lux/target/jvm/attribute.lux | 34 +++++++--------------- .../source/lux/target/jvm/attribute/constant.lux | 25 ++++++++++++++++ 2 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 stdlib/source/lux/target/jvm/attribute/constant.lux diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux index c867f1e57..6c7f92812 100644 --- a/stdlib/source/lux/target/jvm/attribute.lux +++ b/stdlib/source/lux/target/jvm/attribute.lux @@ -20,7 +20,9 @@ ["#." encoding (#+ U2 U4)] ["#." index (#+ Index)] ["#." constant (#+ UTF8 Class Value) - ["#/." pool (#+ Pool)]]]) + ["#/." pool (#+ Pool)]]] + ["." / #_ + ["#." constant (#+ Constant)]]) (type: #export (Info about) {#name (Index UTF8) @@ -47,17 +49,6 @@ [($_ n/+ nameS lengthS infoS) (|>> nameT lengthT infoT)]))) -(type: #export Constant - (Index (Value Any))) - -(def: #export constant-equivalence - (Equivalence Constant) - //index.equivalence) - -(def: constant-format - (Format Constant) - //index.format) - (type: #export Label U2) (def: #export label-equivalence @@ -151,7 +142,7 @@ (equivalence.rec (function (_ equivalence) ($_ equivalence.sum - (info-equivalence ..constant-equivalence) + (info-equivalence /constant.equivalence) (info-equivalence (..code'-equivalence equivalence)))))) (def: #export code-equivalence @@ -179,9 +170,6 @@ //encoding.u4-bytes )) -(def: constant-length - //encoding.u2-bytes) - (def: (length attribute) (-> Attribute Nat) (case attribute @@ -195,7 +183,7 @@ (def: (constant' @name index) (-> (Index UTF8) Constant Attribute) (#Constant {#name @name - #length (//encoding.to-u4 ..constant-length) + #length (//encoding.to-u4 /constant.length) #info index})) (def: #export (constant index) @@ -261,7 +249,7 @@ [@name (get@ #binaryF.reader //index.format) length (get@ #binaryF.reader //encoding.u4-format)] (cond (_@= ?@constant (#error.Success @name)) - (:: @ map (..constant' @name) (get@ #binaryF.reader ..constant-format)) + (:: @ map (..constant' @name) (get@ #binaryF.reader /constant.format)) (_@= ?@code (#error.Success @name)) (:: @ map (..code' @name) (code-reader reader)) @@ -269,10 +257,6 @@ ## else (<>.fail (exception.construct ..invalid-attribute [])))))))) -(def: constant-writer - (Writer Constant) - (get@ #binaryF.writer //index.format)) - (def: (code-writer' writer code) (-> (Writer Attribute) (Writer Code)) (let [format (: (Format Attribute) @@ -296,7 +280,9 @@ (Writer Attribute) (case value (#Constant attribute) - ((info-writer constant-writer) attribute) + ((info-writer (get@ #binaryF.writer /constant.format)) + attribute) (#Code attribute) - ((info-writer (code-writer' writer)) attribute))) + ((info-writer (code-writer' writer)) + attribute))) diff --git a/stdlib/source/lux/target/jvm/attribute/constant.lux b/stdlib/source/lux/target/jvm/attribute/constant.lux new file mode 100644 index 000000000..1cbe1f955 --- /dev/null +++ b/stdlib/source/lux/target/jvm/attribute/constant.lux @@ -0,0 +1,25 @@ +(.module: + [lux #* + [abstract + [equivalence (#+ Equivalence)]] + [data + [format + [binary (#+ Format)]]]] + ["." /// #_ + [constant (#+ Value)] + ["#." encoding (#+ U2 U4)] + ["#." index (#+ Index)]]) + +(type: #export Constant + (Index (Value Any))) + +(def: #export equivalence + (Equivalence Constant) + ///index.equivalence) + +(def: #export length + ///encoding.u2-bytes) + +(def: #export format + (Format Constant) + ///index.format) -- cgit v1.2.3