aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/field.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/target/jvm/field.lux')
-rw-r--r--stdlib/source/library/lux/target/jvm/field.lux70
1 files changed, 70 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/target/jvm/field.lux b/stdlib/source/library/lux/target/jvm/field.lux
new file mode 100644
index 000000000..aa71794a5
--- /dev/null
+++ b/stdlib/source/library/lux/target/jvm/field.lux
@@ -0,0 +1,70 @@
+(.module:
+ [library
+ [lux (#- Type static)
+ [abstract
+ [equivalence (#+ Equivalence)]
+ ["." monad (#+ do)]]
+ [data
+ ["." product]
+ [format
+ [".F" binary (#+ Writer) ("#\." monoid)]]
+ [collection
+ ["." row (#+ Row)]]]]]
+ ["." // #_
+ ["." modifier (#+ Modifier modifiers:)]
+ ["#." constant (#+ UTF8)
+ ["#/." pool (#+ Pool Resource)]]
+ ["#." index (#+ Index)]
+ ["#." attribute (#+ Attribute)]
+ ["#." type (#+ Type)
+ [category (#+ Value)]
+ [descriptor (#+ Descriptor)]]])
+
+(type: #export #rec Field
+ {#modifier (Modifier Field)
+ #name (Index UTF8)
+ #descriptor (Index (Descriptor Value))
+ #attributes (Row Attribute)})
+
+(modifiers: Field
+ ["0001" public]
+ ["0002" private]
+ ["0004" protected]
+ ["0008" static]
+ ["0010" final]
+ ["0040" volatile]
+ ["0080" transient]
+ ["1000" synthetic]
+ ["4000" enum]
+ )
+
+(def: #export equivalence
+ (Equivalence Field)
+ ($_ product.equivalence
+ modifier.equivalence
+ //index.equivalence
+ //index.equivalence
+ (row.equivalence //attribute.equivalence)))
+
+(def: #export (writer field)
+ (Writer Field)
+ (`` ($_ binaryF\compose
+ (~~ (template [<writer> <slot>]
+ [(<writer> (get@ <slot> field))]
+
+ [modifier.writer #modifier]
+ [//index.writer #name]
+ [//index.writer #descriptor]
+ [(binaryF.row/16 //attribute.writer) #attributes]))
+ )))
+
+(def: #export (field modifier name type attributes)
+ (-> (Modifier Field) UTF8 (Type Value) (Row Attribute)
+ (Resource Field))
+ (do //constant/pool.monad
+ [@name (//constant/pool.utf8 name)
+ @descriptor (//constant/pool.descriptor (//type.descriptor type))]
+ (wrap {#modifier modifier
+ #name @name
+ #descriptor @descriptor
+ #attributes attributes})))