From c7aff8faef0722c0982ef0c92e6766223d940333 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 29 Dec 2018 01:01:26 -0400 Subject: Expanded the number of constants that can be created (; but still missing some). --- stdlib/source/lux/host/jvm/constant.lux | 114 +++++++++++++++++++++++++----- stdlib/source/lux/host/jvm/descriptor.lux | 3 +- 2 files changed, 99 insertions(+), 18 deletions(-) diff --git a/stdlib/source/lux/host/jvm/constant.lux b/stdlib/source/lux/host/jvm/constant.lux index 184c3a5a8..7f87136a5 100644 --- a/stdlib/source/lux/host/jvm/constant.lux +++ b/stdlib/source/lux/host/jvm/constant.lux @@ -5,16 +5,18 @@ ["." parser] ["." equivalence (#+ Equivalence)]] [data + ["." number] ["." text] [format ["." binary (#+ Format) ("mutation/." Monoid)]] [collection ["." row (#+ Row)]]] [type - abstract] - ["." host (#+ import:)]] + abstract]] [// - ["//." index (#+ Index)]] + [encoding (#+ U4)] + ["//." index (#+ Index)] + [descriptor (#+ Descriptor)]] [/ ["/." tag ("tag/." Equivalence)]]) @@ -56,37 +58,117 @@ (All [kind] (-> (Value kind) kind)) (|>> :representation)) - (do-template [ ] - [(import: #long ) + (def: #export (Equivalence Equivalence) + (All [kind] + (-> (Equivalence kind) + (Equivalence (Value kind)))) + (:: equivalence.Contravariant map-1 + (|>> :representation) + Equivalence)) - (type: #export (Value )) + (do-template [ ] + [(type: #export (Value )) (def: #export - (-> ) + (-> ) (|>> :abstraction))] - [Integer java/lang/Integer integer] - [Long java/lang/Long long] - [Float java/lang/Float float] - [Double java/lang/Double double] - [String java/lang/String string] + [integer Integer U4] + [long Long .Int] + [float Float Nothing] + [double Double Frac] + [string String (Index UTF8)] ) + + (do-template [ ] + [(def: + (Format ) + (binary.adapt (|>> :abstraction) + (|>> :representation ) + ))] + + [long-format Long .int (<|) binary.bits/64] + [double-format Double number.bits-to-frac number.frac-to-bits binary.bits/64] + [string-format String (<|) (<|) //index.format] + ) + ) + +(type: #export Name-And-Type + {#name (Index UTF8) + #descriptor (Index (Descriptor Any))}) + +(type: #export Reference + {#class (Index Class) + #name-and-type (Index Name-And-Type)}) + +(do-template [ ] + [(def: #export + (Equivalence ) + ($_ equivalence.product + //index.Equivalence + //index.Equivalence)) + + (def: #export + (Format ) + ($_ binary.and + //index.format + //index.format))] + + [Name-And-Type Equivalence name-and-type-format] + [Reference Equivalence reference-format] ) (type: #export Constant (#UTF8 UTF8) - (#Class Class)) + (#Long Long) + (#Double Double) + (#Class Class) + (#String String) + (#Field Reference) + (#Method Reference) + (#Interface-Method Reference) + (#Name-And-Type Name-And-Type)) (def: #export Equivalence (Equivalence Constant) ($_ equivalence.sum + ## #UTF8 text.Equivalence - ..Equivalence)) + ## #Long + (..Equivalence number.Equivalence) + ## #Double + (..Equivalence number.Equivalence) + ## #Class + ..Equivalence + ## #String + (..Equivalence //index.Equivalence) + ## #Field + ..Equivalence + ## #Method + ..Equivalence + ## #Interface-Method + ..Equivalence + ## #Name-And-Type + ..Equivalence + )) (def: #export format (Format Constant) - (with-expansions [ (as-is [#UTF8 /tag.utf8 ..utf8-format] - [#Class /tag.class ..class-format])] + (with-expansions [ (as-is [#UTF8 /tag.utf8 ..utf8-format] + ## TODO: Integer + ## TODO: Float + [#Long /tag.long ..long-format] + [#Double /tag.double ..double-format] + [#Class /tag.class ..class-format] + [#String /tag.string ..string-format] + [#Field /tag.field ..reference-format] + [#Method /tag.method ..reference-format] + [#Interface-Method /tag.interface-method ..reference-format] + [#Name-And-Type /tag.name-and-type ..name-and-type-format] + ## TODO: Method-Handle + ## TODO: Method-Type + ## TODO: Invoke-Dynamic + )] {#binary.reader (do parser.Monad [tag (get@ #binary.reader /tag.format)] (`` (cond (~~ (do-template [ ] diff --git a/stdlib/source/lux/host/jvm/descriptor.lux b/stdlib/source/lux/host/jvm/descriptor.lux index 6127f7025..9b6e4088f 100644 --- a/stdlib/source/lux/host/jvm/descriptor.lux +++ b/stdlib/source/lux/host/jvm/descriptor.lux @@ -8,7 +8,6 @@ [type abstract]] [// - ["//." constant (#+ UTF8)] ["//." name (#+ Internal)]]) (abstract: #export Base' {} Any) @@ -80,6 +79,6 @@ (:representation output)))) (def: #export descriptor - (-> (Descriptor Any) UTF8) + (-> (Descriptor Any) Text) (|>> :representation)) ) -- cgit v1.2.3