From 00d5ccbc043960037f644d4ff09b6a46fd0093d0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 12 Oct 2020 20:22:31 -0400 Subject: Type-checking macros via the Macro' type from the standard library. --- lux-jvm/source/luxc/lang/directive/jvm.lux | 2 +- lux-jvm/source/luxc/lang/host/jvm.lux | 6 +- lux-jvm/source/luxc/lang/host/jvm/def.lux | 196 ++++++++++----------- lux-jvm/source/luxc/lang/host/jvm/inst.lux | 10 +- lux-jvm/source/luxc/lang/translation/jvm.lux | 8 +- .../luxc/lang/translation/jvm/extension/common.lux | 10 +- .../source/luxc/lang/translation/jvm/primitive.lux | 6 +- .../source/luxc/lang/translation/jvm/structure.lux | 4 +- lux-jvm/source/program.lux | 6 +- 9 files changed, 124 insertions(+), 124 deletions(-) (limited to 'lux-jvm') diff --git a/lux-jvm/source/luxc/lang/directive/jvm.lux b/lux-jvm/source/luxc/lang/directive/jvm.lux index 23d2fb6d5..798cf8298 100644 --- a/lux-jvm/source/luxc/lang/directive/jvm.lux +++ b/lux-jvm/source/luxc/lang/directive/jvm.lux @@ -37,7 +37,7 @@ ["." jvm (#+ Inst) ["_" inst]]]]) -(import: #long org/objectweb/asm/Label +(import: org/objectweb/asm/Label (new [])) (def: (literal literal) diff --git a/lux-jvm/source/luxc/lang/host/jvm.lux b/lux-jvm/source/luxc/lang/host/jvm.lux index 9301ab4ae..6d2e49b22 100644 --- a/lux-jvm/source/luxc/lang/host/jvm.lux +++ b/lux-jvm/source/luxc/lang/host/jvm.lux @@ -31,14 +31,14 @@ (import: org/objectweb/asm/ClassWriter) -(import: #long org/objectweb/asm/Label +(import: org/objectweb/asm/Label (new [])) (type: #export Def - (-> ClassWriter ClassWriter)) + (-> org/objectweb/asm/ClassWriter org/objectweb/asm/ClassWriter)) (type: #export Inst - (-> MethodVisitor MethodVisitor)) + (-> org/objectweb/asm/MethodVisitor org/objectweb/asm/MethodVisitor)) (type: #export Label org/objectweb/asm/Label) diff --git a/lux-jvm/source/luxc/lang/host/jvm/def.lux b/lux-jvm/source/luxc/lang/host/jvm/def.lux index f274da61f..642f42018 100644 --- a/lux-jvm/source/luxc/lang/host/jvm/def.lux +++ b/lux-jvm/source/luxc/lang/host/jvm/def.lux @@ -26,8 +26,8 @@ (def: descriptor (|>> type.descriptor descriptor.descriptor)) (def: class-name (|>> type.descriptor descriptor.class-name name.read)) -(import: #long java/lang/Object) -(import: #long java/lang/String) +(import: java/lang/Object) +(import: java/lang/String) (import: org/objectweb/asm/Opcodes (#static ACC_PUBLIC int) @@ -68,15 +68,15 @@ (#static COMPUTE_MAXS int) (#static COMPUTE_FRAMES int) (new [int]) - (visit [int int String String String [String]] void) + (visit [int int java/lang/String java/lang/String java/lang/String [java/lang/String]] void) (visitEnd [] void) - (visitField [int String String String Object] FieldVisitor) - (visitMethod [int String String String [String]] MethodVisitor) + (visitField [int java/lang/String java/lang/String java/lang/String java/lang/Object] org/objectweb/asm/FieldVisitor) + (visitMethod [int java/lang/String java/lang/String java/lang/String [java/lang/String]] org/objectweb/asm/MethodVisitor) (toByteArray [] [byte])) (def: (string-array values) (-> (List Text) (Array Text)) - (let [output (host.array String (list.size values))] + (let [output (host.array java/lang/String (list.size values))] (exec (list@map (function (_ [idx value]) (host.array-write idx value output)) (list.enumerate values)) @@ -85,43 +85,43 @@ (def: (version-flag version) (-> //.Version Int) (case version - #//.V1_1 (Opcodes::V1_1) - #//.V1_2 (Opcodes::V1_2) - #//.V1_3 (Opcodes::V1_3) - #//.V1_4 (Opcodes::V1_4) - #//.V1_5 (Opcodes::V1_5) - #//.V1_6 (Opcodes::V1_6) - #//.V1_7 (Opcodes::V1_7) - #//.V1_8 (Opcodes::V1_8))) + #//.V1_1 (org/objectweb/asm/Opcodes::V1_1) + #//.V1_2 (org/objectweb/asm/Opcodes::V1_2) + #//.V1_3 (org/objectweb/asm/Opcodes::V1_3) + #//.V1_4 (org/objectweb/asm/Opcodes::V1_4) + #//.V1_5 (org/objectweb/asm/Opcodes::V1_5) + #//.V1_6 (org/objectweb/asm/Opcodes::V1_6) + #//.V1_7 (org/objectweb/asm/Opcodes::V1_7) + #//.V1_8 (org/objectweb/asm/Opcodes::V1_8))) (def: (visibility-flag visibility) (-> //.Visibility Int) (case visibility - #//.Public (Opcodes::ACC_PUBLIC) - #//.Protected (Opcodes::ACC_PROTECTED) - #//.Private (Opcodes::ACC_PRIVATE) + #//.Public (org/objectweb/asm/Opcodes::ACC_PUBLIC) + #//.Protected (org/objectweb/asm/Opcodes::ACC_PROTECTED) + #//.Private (org/objectweb/asm/Opcodes::ACC_PRIVATE) #//.Default +0)) (def: (class-flags config) (-> //.Class-Config Int) ($_ i.+ - (if (get@ #//.finalC config) (Opcodes::ACC_FINAL) +0))) + (if (get@ #//.finalC config) (org/objectweb/asm/Opcodes::ACC_FINAL) +0))) (def: (method-flags config) (-> //.Method-Config Int) ($_ i.+ - (if (get@ #//.staticM config) (Opcodes::ACC_STATIC) +0) - (if (get@ #//.finalM config) (Opcodes::ACC_FINAL) +0) - (if (get@ #//.synchronizedM config) (Opcodes::ACC_SYNCHRONIZED) +0) - (if (get@ #//.strictM config) (Opcodes::ACC_STRICT) +0))) + (if (get@ #//.staticM config) (org/objectweb/asm/Opcodes::ACC_STATIC) +0) + (if (get@ #//.finalM config) (org/objectweb/asm/Opcodes::ACC_FINAL) +0) + (if (get@ #//.synchronizedM config) (org/objectweb/asm/Opcodes::ACC_SYNCHRONIZED) +0) + (if (get@ #//.strictM config) (org/objectweb/asm/Opcodes::ACC_STRICT) +0))) (def: (field-flags config) (-> //.Field-Config Int) ($_ i.+ - (if (get@ #//.staticF config) (Opcodes::ACC_STATIC) +0) - (if (get@ #//.finalF config) (Opcodes::ACC_FINAL) +0) - (if (get@ #//.transientF config) (Opcodes::ACC_TRANSIENT) +0) - (if (get@ #//.volatileF config) (Opcodes::ACC_VOLATILE) +0))) + (if (get@ #//.staticF config) (org/objectweb/asm/Opcodes::ACC_STATIC) +0) + (if (get@ #//.finalF config) (org/objectweb/asm/Opcodes::ACC_FINAL) +0) + (if (get@ #//.transientF config) (org/objectweb/asm/Opcodes::ACC_TRANSIENT) +0) + (if (get@ #//.volatileF config) (org/objectweb/asm/Opcodes::ACC_VOLATILE) +0))) (def: param-signature (-> (Type Class) Text) @@ -154,8 +154,8 @@ (def: class-computes Int ($_ i.+ - (ClassWriter::COMPUTE_MAXS) - ## (ClassWriter::COMPUTE_FRAMES) + (org/objectweb/asm/ClassWriter::COMPUTE_MAXS) + ## (org/objectweb/asm/ClassWriter::COMPUTE_FRAMES) )) (def: binary-name (|>> name.internal name.read)) @@ -165,25 +165,25 @@ definitions) (-> //.Version //.Visibility //.Class-Config Text (List Constraint) (Type Class) (List (Type Class)) //.Def (host.type [byte])) - (let [writer (|> (do-to (ClassWriter::new class-computes) - (ClassWriter::visit (version-flag version) - ($_ i.+ - (Opcodes::ACC_SUPER) - - (visibility-flag visibility) - (class-flags config)) - (..binary-name name) - (constraints-signature constraints super interfaces) - (..class-name super) - (|> interfaces - (list@map ..class-name) - string-array))) + (let [writer (|> (do-to (org/objectweb/asm/ClassWriter::new class-computes) + (org/objectweb/asm/ClassWriter::visit (version-flag version) + ($_ i.+ + (org/objectweb/asm/Opcodes::ACC_SUPER) + + (visibility-flag visibility) + (class-flags config)) + (..binary-name name) + (constraints-signature constraints super interfaces) + (..class-name super) + (|> interfaces + (list@map ..class-name) + string-array))) definitions) - _ (ClassWriter::visitEnd writer)] - (ClassWriter::toByteArray writer)))] + _ (org/objectweb/asm/ClassWriter::visitEnd writer)] + (org/objectweb/asm/ClassWriter::toByteArray writer)))] [class +0] - [abstract (Opcodes::ACC_ABSTRACT)] + [abstract (org/objectweb/asm/Opcodes::ACC_ABSTRACT)] ) (def: $Object @@ -194,84 +194,84 @@ definitions) (-> //.Version //.Visibility //.Class-Config Text (List Constraint) (List (Type Class)) //.Def (host.type [byte])) - (let [writer (|> (do-to (ClassWriter::new class-computes) - (ClassWriter::visit (version-flag version) - ($_ i.+ - (Opcodes::ACC_SUPER) - (Opcodes::ACC_INTERFACE) - (visibility-flag visibility) - (class-flags config)) - (..binary-name name) - (constraints-signature constraints $Object interfaces) - (..class-name $Object) - (|> interfaces - (list@map ..class-name) - string-array))) + (let [writer (|> (do-to (org/objectweb/asm/ClassWriter::new class-computes) + (org/objectweb/asm/ClassWriter::visit (version-flag version) + ($_ i.+ + (org/objectweb/asm/Opcodes::ACC_SUPER) + (org/objectweb/asm/Opcodes::ACC_INTERFACE) + (visibility-flag visibility) + (class-flags config)) + (..binary-name name) + (constraints-signature constraints $Object interfaces) + (..class-name $Object) + (|> interfaces + (list@map ..class-name) + string-array))) definitions) - _ (ClassWriter::visitEnd writer)] - (ClassWriter::toByteArray writer))) + _ (org/objectweb/asm/ClassWriter::visitEnd writer)] + (org/objectweb/asm/ClassWriter::toByteArray writer))) (def: #export (method visibility config name type then) (-> //.Visibility //.Method-Config Text (Type Method) //.Inst //.Def) (function (_ writer) - (let [=method (ClassWriter::visitMethod ($_ i.+ - (visibility-flag visibility) - (method-flags config)) - (..binary-name name) - (..descriptor type) - (..signature type) - (string-array (list)) - writer) - _ (MethodVisitor::visitCode =method) + (let [=method (org/objectweb/asm/ClassWriter::visitMethod ($_ i.+ + (visibility-flag visibility) + (method-flags config)) + (..binary-name name) + (..descriptor type) + (..signature type) + (string-array (list)) + writer) + _ (org/objectweb/asm/MethodVisitor::visitCode =method) _ (then =method) - _ (MethodVisitor::visitMaxs +0 +0 =method) - _ (MethodVisitor::visitEnd =method)] + _ (org/objectweb/asm/MethodVisitor::visitMaxs +0 +0 =method) + _ (org/objectweb/asm/MethodVisitor::visitEnd =method)] writer))) (def: #export (abstract-method visibility config name type) (-> //.Visibility //.Method-Config Text (Type Method) //.Def) (function (_ writer) - (let [=method (ClassWriter::visitMethod ($_ i.+ - (visibility-flag visibility) - (method-flags config) - (Opcodes::ACC_ABSTRACT)) - (..binary-name name) - (..descriptor type) - (..signature type) - (string-array (list)) - writer) - _ (MethodVisitor::visitEnd =method)] + (let [=method (org/objectweb/asm/ClassWriter::visitMethod ($_ i.+ + (visibility-flag visibility) + (method-flags config) + (org/objectweb/asm/Opcodes::ACC_ABSTRACT)) + (..binary-name name) + (..descriptor type) + (..signature type) + (string-array (list)) + writer) + _ (org/objectweb/asm/MethodVisitor::visitEnd =method)] writer))) (def: #export (field visibility config name type) (-> //.Visibility //.Field-Config Text (Type Value) //.Def) (function (_ writer) - (let [=field (do-to (ClassWriter::visitField ($_ i.+ - (visibility-flag visibility) - (field-flags config)) - (..binary-name name) - (..descriptor type) - (..signature type) - (host.null) - writer) - (FieldVisitor::visitEnd))] + (let [=field (do-to (org/objectweb/asm/ClassWriter::visitField ($_ i.+ + (visibility-flag visibility) + (field-flags config)) + (..binary-name name) + (..descriptor type) + (..signature type) + (host.null) + writer) + (org/objectweb/asm/FieldVisitor::visitEnd))] writer))) (template [ ] [(def: #export ( visibility config name value) (-> //.Visibility //.Field-Config Text //.Def) (function (_ writer) - (let [=field (do-to (ClassWriter::visitField ($_ i.+ - (visibility-flag visibility) - (field-flags config)) - (..binary-name name) - (..descriptor ) - (..signature ) - ( value) - writer) - (FieldVisitor::visitEnd))] + (let [=field (do-to (org/objectweb/asm/ClassWriter::visitField ($_ i.+ + (visibility-flag visibility) + (field-flags config)) + (..binary-name name) + (..descriptor ) + (..signature ) + ( value) + writer) + (org/objectweb/asm/FieldVisitor::visitEnd))] writer)))] [boolean-field Bit type.boolean function.identity] diff --git a/lux-jvm/source/luxc/lang/host/jvm/inst.lux b/lux-jvm/source/luxc/lang/host/jvm/inst.lux index b673c7d7e..69f822591 100644 --- a/lux-jvm/source/luxc/lang/host/jvm/inst.lux +++ b/lux-jvm/source/luxc/lang/host/jvm/inst.lux @@ -39,15 +39,15 @@ (def: reflection (|>> type.reflection reflection.reflection)) ## [Host] -(import: #long java/lang/Object) -(import: #long java/lang/String) +(import: java/lang/Object) +(import: java/lang/String) (syntax: (declare {codes (p.many s.local-identifier)}) (|> codes (list@map (function (_ code) (` ((~' #static) (~ (code.local-identifier code)) (~' int))))) wrap)) -(`` (import: #long org/objectweb/asm/Opcodes +(`` (import: org/objectweb/asm/Opcodes (#static NOP int) ## Conversion @@ -122,10 +122,10 @@ (~~ (declare RETURN IRETURN LRETURN FRETURN DRETURN ARETURN)) )) -(import: #long org/objectweb/asm/Label +(import: org/objectweb/asm/Label (new [])) -(import: #long org/objectweb/asm/MethodVisitor +(import: org/objectweb/asm/MethodVisitor (visitCode [] void) (visitMaxs [int int] void) (visitEnd [] void) diff --git a/lux-jvm/source/luxc/lang/translation/jvm.lux b/lux-jvm/source/luxc/lang/translation/jvm.lux index 0ffea0e42..30a130150 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm.lux @@ -41,16 +41,16 @@ ["." inst]]]] ) -(import: #long java/lang/reflect/Field +(import: java/lang/reflect/Field (get [#? java/lang/Object] #try #? java/lang/Object)) -(import: #long (java/lang/Class a) +(import: (java/lang/Class a) (getField [java/lang/String] #try java/lang/reflect/Field)) -(import: #long java/lang/Object +(import: java/lang/Object (getClass [] (java/lang/Class java/lang/Object))) -(import: #long java/lang/ClassLoader) +(import: java/lang/ClassLoader) (type: #export ByteCode Binary) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux index 383415c0a..0388c5c7f 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux @@ -53,8 +53,8 @@ (phase.throw extension.invalid-syntax [extension-name %synthesis input])))) (import: java/lang/Double - (#static MIN_VALUE Double) - (#static MAX_VALUE Double)) + (#static MIN_VALUE java/lang/Double) + (#static MAX_VALUE java/lang/Double)) (def: $String (type.class "java.lang.String" (list))) (def: $CharSequence (type.class "java.lang.CharSequence" (list))) @@ -164,9 +164,9 @@ (Nullary Inst) (|>> (_.wrap )))] - [f64::smallest (_.double (Double::MIN_VALUE)) type.double] - [f64::min (_.double (f.* -1.0 (Double::MAX_VALUE))) type.double] - [f64::max (_.double (Double::MAX_VALUE)) type.double] + [f64::smallest (_.double (java/lang/Double::MIN_VALUE)) type.double] + [f64::min (_.double (f.* -1.0 (java/lang/Double::MAX_VALUE))) type.double] + [f64::max (_.double (java/lang/Double::MAX_VALUE)) type.double] ) (template [ ] diff --git a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux index 24eeef49e..d8ab2cbee 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux @@ -22,11 +22,11 @@ (function (_ value) (operation@wrap (_.GETSTATIC Boolean (if value "TRUE" "FALSE") Boolean))))) -(import: #long java/lang/Byte +(import: java/lang/Byte (#static MAX_VALUE byte) (#static MIN_VALUE byte)) -(import: #long java/lang/Short +(import: java/lang/Short (#static MAX_VALUE short) (#static MIN_VALUE short)) @@ -63,7 +63,7 @@ (|> value .int _.long))] (operation@wrap (|>> constantI (_.wrap type.long)))))) -(import: #long java/lang/Double +(import: java/lang/Double (#static doubleToRawLongBits #manual [double] int)) (def: d0-bits diff --git a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux index c61f96bb8..4a4c30e0f 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux @@ -60,11 +60,11 @@ (_.array //runtime.$Value) membersI)))) -(import: #long java/lang/Byte +(import: java/lang/Byte (#static MAX_VALUE byte) (#static MIN_VALUE byte)) -(import: #long java/lang/Short +(import: java/lang/Short (#static MAX_VALUE short) (#static MIN_VALUE short)) diff --git a/lux-jvm/source/program.lux b/lux-jvm/source/program.lux index 1114dd3b6..61d97a9c7 100644 --- a/lux-jvm/source/program.lux +++ b/lux-jvm/source/program.lux @@ -65,13 +65,13 @@ ["#/." program] ["translation" extension]]]]]) -(import: #long java/lang/reflect/Method +(import: java/lang/reflect/Method (invoke [java/lang/Object [java/lang/Object]] #try java/lang/Object)) -(import: #long (java/lang/Class c) +(import: (java/lang/Class c) (getMethod [java/lang/String [(java/lang/Class java/lang/Object)]] #try java/lang/reflect/Method)) -(import: #long java/lang/Object +(import: java/lang/Object (getClass [] (java/lang/Class java/lang/Object))) (def: _object-class -- cgit v1.2.3