aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-06-22 12:37:03 -0400
committerEduardo Julian2019-06-22 12:37:03 -0400
commit7dd8c1778c23121fddc1707f21df95194ed9a550 (patch)
tree004a1b13ba0af27e3f74151706f44475f1f29065
parent8685b0ee8bdff85807e20393242a8b088d9ddcc9 (diff)
Added almost all the remaining instructions.
-rw-r--r--stdlib/source/lux/target/jvm/code.lux236
-rw-r--r--stdlib/source/lux/target/jvm/constant.lux4
-rw-r--r--stdlib/source/lux/target/jvm/descriptor.lux2
3 files changed, 204 insertions, 38 deletions
diff --git a/stdlib/source/lux/target/jvm/code.lux b/stdlib/source/lux/target/jvm/code.lux
index 6217a1c6c..480999e93 100644
--- a/stdlib/source/lux/target/jvm/code.lux
+++ b/stdlib/source/lux/target/jvm/code.lux
@@ -14,10 +14,13 @@
[format
[".F" binary (#+ Mutation Specification)]]]
[macro
- ["." template]]]
+ ["." template]]
+ [type
+ abstract]]
["." // #_
["#." index (#+ Index)]
- [constant (#+ Class Field)]
+ ["#." descriptor (#+ Field Method)]
+ ["#." constant (#+ Class Reference)]
[encoding
["#." unsigned (#+ U1 U2 U4)]]]
["." / #_
@@ -90,6 +93,74 @@
[(n/+ 5 size)
(|>> mutation ((unary/4' code input0)))])
+(def: (binary/11' code input0 input1)
+ (-> Nat U1 U1 Mutation)
+ (function (_ [offset binary])
+ [(n/+ 3 offset)
+ (error.assume
+ (do error.monad
+ [_ (binary.write/8 offset code binary)
+ _ (binary.write/8 (n/+ 1 offset) (//unsigned.nat input0) binary)]
+ (binary.write/8 (n/+ 2 offset) (//unsigned.nat input1) binary)))]))
+
+(def: (binary/11 code input0 input1 [size mutation])
+ (-> Nat U1 U1 (-> Specification Specification))
+ [(n/+ 3 size)
+ (|>> mutation ((binary/11' code input0 input1)))])
+
+(def: (binary/21' code input0 input1)
+ (-> Nat U2 U1 Mutation)
+ (function (_ [offset binary])
+ [(n/+ 4 offset)
+ (error.assume
+ (do error.monad
+ [_ (binary.write/8 offset code binary)
+ _ (binary.write/16 (n/+ 1 offset) (//unsigned.nat input0) binary)]
+ (binary.write/8 (n/+ 3 offset) (//unsigned.nat input1) binary)))]))
+
+(def: (binary/21 code input0 input1 [size mutation])
+ (-> Nat U2 U1 (-> Specification Specification))
+ [(n/+ 4 size)
+ (|>> mutation ((binary/21' code input0 input1)))])
+
+(def: (trinary/211' code input0 input1 input2)
+ (-> Nat U2 U1 U1 Mutation)
+ (function (_ [offset binary])
+ [(n/+ 5 offset)
+ (error.assume
+ (do error.monad
+ [_ (binary.write/8 offset code binary)
+ _ (binary.write/16 (n/+ 1 offset) (//unsigned.nat input0) binary)
+ _ (binary.write/8 (n/+ 3 offset) (//unsigned.nat input1) binary)]
+ (binary.write/8 (n/+ 4 offset) (//unsigned.nat input2) binary)))]))
+
+(def: (trinary/211 code input0 input1 input2 [size mutation])
+ (-> Nat U2 U1 U1 (-> Specification Specification))
+ [(n/+ 5 size)
+ (|>> mutation ((trinary/211' code input0 input1 input2)))])
+
+(abstract: #export Primitive-Array-Type
+ {}
+
+ U1
+
+ (def: code
+ (-> Primitive-Array-Type U1)
+ (|>> :representation))
+
+ (template [<code> <name>]
+ [(def: #export <name> (|> <code> //unsigned.u1 :abstraction))]
+
+ [04 t-boolean]
+ [05 t-char]
+ [06 t-float]
+ [07 t-double]
+ [08 t-byte]
+ [09 t-short]
+ [10 t-int]
+ [11 t-long]
+ ))
+
## https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5
(with-expansions [<constants> (template [<code> <name> <output-size>]
[[<code> <name> [] [] 0 <output-size> []]]
@@ -104,6 +175,9 @@
["07" iconst-4 1]
["08" iconst-5 1]
+ ["09" lconst-0 2]
+ ["0A" lconst-1 2]
+
["0B" fconst-0 1]
["0C" fconst-1 1]
["0D" fconst-2 1]
@@ -113,12 +187,24 @@
<local-loads> (template [<code> <name> <output-size>]
[[<code> <name> [[local Local]] [local] 0 <output-size> [[local]]]]
+ ["15" iload 1]
+ ["16" lload 2]
["17" fload 1]
["18" dload 2]
["19" aload 1])
<simple-local-loads> (template [<code> <name> <output-size> <local-end>]
[[<code> <name> [] [] 0 <output-size> [[(//unsigned.u1 <local-end>)]]]]
+ ["1A" iload-0 1 0]
+ ["1B" iload-1 1 1]
+ ["1C" iload-2 1 2]
+ ["1D" iload-3 1 3]
+
+ ["1E" lload-0 2 1]
+ ["1F" lload-1 2 2]
+ ["20" lload-2 2 3]
+ ["21" lload-3 2 4]
+
["22" fload-0 1 0]
["23" fload-1 1 1]
["24" fload-2 1 2]
@@ -136,12 +222,24 @@
<local-stores> (template [<code> <name> <input-size>]
[[<code> <name> [[local Local]] [local] <input-size> 0 [[local]]]]
+ ["36" istore 1]
+ ["37" lstore 2]
["38" fstore 1]
["39" dstore 2]
["3A" astore 1])
<simple-local-stores> (template [<code> <name> <input-size> <local-end>]
[[<code> <name> [] [] <input-size> 0 [[(//unsigned.u1 <local-end>)]]]]
+ ["3B" istore-0 1 0]
+ ["3C" istore-1 1 1]
+ ["3D" istore-2 1 2]
+ ["3E" istore-3 1 3]
+
+ ["3F" lstore-0 2 1]
+ ["40" lstore-1 2 2]
+ ["41" lstore-2 2 3]
+ ["42" lstore-3 2 4]
+
["43" fstore-0 1 0]
["44" fstore-1 1 1]
["45" fstore-2 1 2]
@@ -159,27 +257,50 @@
<array-loads> (template [<code> <name> <output-size>]
[[<code> <name> [] [] 2 <output-size> []]]
- ["2e" iaload 1]
+ ["2E" iaload 1]
+ ["2F" laload 2]
["30" faload 1]
["31" daload 2]
["32" aaload 1]
["33" baload 1]
- ["34" caload 1])
+ ["34" caload 1]
+ ["35" saload 1])
<array-stores> (template [<code> <name> <input-size>]
[[<code> <name> [] [] <input-size> 0 []]]
["4f" iastore 3]
+ ["50" lastore 4]
["51" fastore 3]
["52" dastore 4]
["53" aastore 3]
["54" bastore 3]
- ["55" castore 3])
+ ["55" castore 3]
+ ["56" sastore 3])
<arithmetic> (template [<code> <name> <input-size> <output-size>]
[[<code> <name> [] [] <input-size> <output-size> []]]
["60" iadd 2 1]
+ ["64" isub 2 1]
+ ["68" imul 2 1]
["6c" idiv 2 1]
+ ["70" irem 2 1]
+ ["74" ineg 1 1]
+ ["78" ishl 2 1]
+ ["7a" ishr 2 1]
+ ["7c" iushr 2 1]
["7e" iand 2 1]
+ ["80" ior 2 1]
+ ["82" ixor 2 1]
+
+ ["61" ladd 4 2]
+ ["65" lsub 4 2]
+ ["69" lmul 4 2]
+ ["6D" ldiv 4 2]
+ ["71" lrem 4 2]
+ ["75" lneg 2 2]
+ ["7F" land 4 2]
+ ["81" lor 4 2]
+ ["83" lxor 4 2]
["62" fadd 2 1]
["66" fsub 2 1]
@@ -197,6 +318,10 @@
<conversions> (template [<code> <name> <input-size> <output-size>]
[[<code> <name> [] [] <input-size> <output-size> []]]
+ ["88" l2i 2 1]
+ ["89" l2f 2 1]
+ ["8A" l2d 2 2]
+
["8B" f2i 1 1]
["8C" f2l 1 2]
["8D" f2d 1 2]
@@ -214,6 +339,8 @@
<comparisons> (template [<code> <name> <input-size>]
[[<code> <name> [] [] <input-size> 1 []]]
+ ["94" lcmp 4]
+
["95" fcmpl 2]
["96" fcmpg 2]
@@ -222,34 +349,45 @@
<returns> (template [<code> <name> <input-size>]
[[<code> <name> [] [] <input-size> 0 []]]
+ ["AC" ireturn 1]
+ ["AD" lreturn 2]
["AE" freturn 1]
["AF" dreturn 2]
["B0" areturn 1]
+ ["B1" return 0]
)
- <jumps> (template [<code> <name> <input-size>]
- [[<code> <name> [[label Label]] [label] <input-size> 0 []]]
-
- ["99" ifeq 2]
- ["9A" ifne 2]
- ["9B" iflt 2]
- ["9C" ifge 2]
- ["9D" ifgt 2]
- ["9E" ifle 2]
+ <jumps> (template [<code> <name> <input-size> <output-size>]
+ [[<code> <name> [[label Label]] [label] <input-size> <output-size> []]]
+
+ ["99" ifeq 2 0]
+ ["9A" ifne 2 0]
+ ["9B" iflt 2 0]
+ ["9C" ifge 2 0]
+ ["9D" ifgt 2 0]
+ ["9E" ifle 2 0]
- ["9F" if-icmpeq 2]
- ["A0" if-icmpne 2]
- ["A1" if-icmplt 2]
- ["A2" if-icmpge 2]
- ["A3" if-icmpgt 2]
- ["A4" if-icmple 2]
+ ["9F" if-icmpeq 2 0]
+ ["A0" if-icmpne 2 0]
+ ["A1" if-icmplt 2 0]
+ ["A2" if-icmpge 2 0]
+ ["A3" if-icmpgt 2 0]
+ ["A4" if-icmple 2 0]
- ["A5" if-acmpeq 2]
- ["A6" if-acmpne 2]
+ ["A5" if-acmpeq 2 0]
+ ["A6" if-acmpne 2 0]
- ["A7" goto 2]
-
- ["C6" ifnull 1]
- ["C7" ifnonnull 1])]
+ ["A7" goto 0 0]
+ ["A8" jsr 0 1]
+
+ ["C6" ifnull 1 0]
+ ["C7" ifnonnull 1 0])
+ <fields> (template [<code> <name> <input-size> <output-size>]
+ [[<code> <name> [[index (Index (Reference Field))]] [(//index.number index)] <input-size> <output-size> []]]
+
+ ["B2" getstatic/1 0 1] ["B2" getstatic/2 0 2]
+ ["B3" putstatic/1 1 1] ["B3" putstatic/2 1 2]
+ ["B4" getfield/1 1 1] ["B4" getfield/2 1 2]
+ ["B5" putfield/1 2 1] ["B5" putfield/2 2 2])]
(template [<arity> <definitions>]
[(with-expansions [<definitions>' (template.splice <definitions>)]
(template [<code> <name> <instruction-inputs> <arity-inputs> <consumes> <produces> <locals>]
@@ -280,40 +418,68 @@
[..nullary
[["00" nop [] [] 0 0 []]
+ <constants>
+ ["57" pop [] [] 1 0 []]
+ ["58" pop2 [] [] 2 0 []]
["59" dup [] [] 1 2 []]
["5A" dup-x1 [] [] 2 3 []]
["5B" dup-x2 [] [] 3 4 []]
["5C" dup2 [] [] 2 4 []]
["5D" dup2-x1 [] [] 3 5 []]
["5E" dup2-x2 [] [] 4 6 []]
- <constants>
+ ["5F" swap [] [] 2 2 []]
<simple-local-loads>
<array-loads>
<simple-local-stores>
<array-stores>
<arithmetic>
+ ["79" lshl [] [] 3 2 []]
+ ["7B" lshr [] [] 3 2 []]
+ ["7D" lushr [] [] 3 2 []]
<conversions>
<comparisons>
<returns>
["BE" arraylength [] [] 1 1 []]
- ["BF" athrow [] [] 1 0 []]]]
+ ["BF" athrow [] [] 1 0 []]
+ ["C2" monitorenter [] [] 1 0 []]
+ ["C3" monitorexit [] [] 1 0 []]]]
[..unary/1
[["10" bipush [[byte U1]] [byte] 0 1 []]
+ ["12" ldc [[index U1]] [index] 0 1 []]
<local-loads>
- <local-stores>]]
+ <local-stores>
+ ["A9" ret [[local Local]] [local] 0 0 [[local]]]
+ ["BC" newarray [[type Primitive-Array-Type]] [(..code type)] 1 1 []]]]
[..unary/2
- [<jumps>
+ [["11" sipush [[short U2]] [short] 0 1 []]
+ ["13" ldc-w/integer [[index (Index //constant.Integer)]] [(//index.number index)] 0 1 []]
+ ["13" ldc-w/float [[index (Index //constant.Float)]] [(//index.number index)] 0 1 []]
+ ["14" ldc2-w/long [[index (Index //constant.Long)]] [(//index.number index)] 0 1 []]
+ ["14" ldc2-w/double [[index (Index //constant.Double)]] [(//index.number index)] 0 1 []]
+ <jumps>
+ <fields>
+ ["BB" new [[index (Index Class)]] [(//index.number index)] 0 1 []]
["BD" anewarray [[index (Index Class)]] [(//index.number index)] 1 1 []]
["C0" checkcast [[index (Index Class)]] [(//index.number index)] 1 1 []]
- ["B2" getstatic/1 [[index (Index Field)]] [(//index.number index)] 0 1 []]
- ["B2" getstatic/2 [[index (Index Field)]] [(//index.number index)] 0 2 []]
- ["B4" getfield/1 [[index (Index Field)]] [(//index.number index)] 1 1 []]
- ["B4" getfield/2 [[index (Index Field)]] [(//index.number index)] 1 2 []]]]
+ ["C1" instanceof [[index (Index Class)]] [(//index.number index)] 1 1 []]
+ ["B6" invokevirtual [[index (Index (Reference Method))] [count U1] [output-count U1]] [(//index.number index)] (//unsigned.nat count) (//unsigned.nat output-count) []]
+ ["B7" invokespecial [[index (Index (Reference Method))] [count U1] [output-count U1]] [(//index.number index)] (//unsigned.nat count) (//unsigned.nat output-count) []]
+ ["B8" invokestatic [[index (Index (Reference Method))] [count U1] [output-count U1]] [(//index.number index)] (//unsigned.nat count) (//unsigned.nat output-count) []]]]
[..unary/4
- [["C8" goto-w [[label Wide-Label]] [label] 0 0 []]]]
+ [["C8" goto-w [[label Wide-Label]] [label] 0 0 []]
+ ["C9" jsr-w [[label Wide-Label]] [label] 0 1 []]]]
+
+ [..binary/11
+ [["84" iinc [[local Local] [byte U1]] [local byte] 0 0 [[local]]]]]
+
+ [..binary/21
+ [["C5" multianewarray [[index (Index Class)] [count U1]] [(//index.number index) count] (//unsigned.nat count) 1 []]]]
+
+ [..trinary/211
+ [["B9" invokeinterface [[index (Index (Reference Method))] [count U1] [output-count U1]] [(//index.number index) count (//unsigned.u1 0)] (//unsigned.nat count) (//unsigned.nat output-count) []]]]
))
(structure: #export monoid
diff --git a/stdlib/source/lux/target/jvm/constant.lux b/stdlib/source/lux/target/jvm/constant.lux
index 4dc021a3d..31dfe3bbb 100644
--- a/stdlib/source/lux/target/jvm/constant.lux
+++ b/stdlib/source/lux/target/jvm/constant.lux
@@ -136,15 +136,13 @@
[Reference reference-equivalence reference-parser reference-writer]
)
-(type: #export Field (//descriptor.Value Any))
-
(type: #export Constant
(#UTF8 UTF8)
(#Long Long)
(#Double Double)
(#Class Class)
(#String String)
- (#Field (Reference Field))
+ (#Field (Reference //descriptor.Field))
(#Method (Reference //descriptor.Method))
(#Interface-Method (Reference //descriptor.Method))
(#Name-And-Type (Name-And-Type Any)))
diff --git a/stdlib/source/lux/target/jvm/descriptor.lux b/stdlib/source/lux/target/jvm/descriptor.lux
index a5bd8599c..c0cb20a61 100644
--- a/stdlib/source/lux/target/jvm/descriptor.lux
+++ b/stdlib/source/lux/target/jvm/descriptor.lux
@@ -28,6 +28,8 @@
(type: #export (Value kind) (Return (Value' kind)))
(type: #export Void (Return Void'))
+ (type: #export Field (Value Any))
+
(template [<refined>]
[(with-expansions [<raw> (template.identifier [<refined> "'"])]
(abstract: #export <raw> {} Any)