From bae39f32cddb816a6123697269c20dbf4a65ac19 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 9 Oct 2020 01:16:47 -0400 Subject: Also using BIPUSH and SIPUSH during JVM generation. --- .../source/luxc/lang/translation/jvm/structure.lux | 62 ++++++++++++++++------ 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'lux-jvm/source/luxc/lang/translation/jvm/structure.lux') diff --git a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux index 049c1549a..c61f96bb8 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux @@ -1,12 +1,14 @@ (.module: [lux (#- Type) + ["." host (#+ import:)] [abstract ["." monad (#+ do)]] [control - ["ex" exception (#+ exception:)]] + ["." exception (#+ exception:)]] [data [number - ["n" nat]] + ["n" nat] + ["i" int]] [text ["%" format (#+ format)]] [collection @@ -34,8 +36,9 @@ ["#." runtime]]) (exception: #export (not-a-tuple {size Nat}) - (ex.report ["Expected size" ">= 2"] - ["Actual size" (%.nat size)])) + (exception.report + ["Expected size" ">= 2"] + ["Actual size" (%.nat size)])) (def: #export (tuple generate archive members) (Generator (List Synthesis)) @@ -57,26 +60,51 @@ (_.array //runtime.$Value) membersI)))) -(def: (flagI right?) +(import: #long java/lang/Byte + (#static MAX_VALUE byte) + (#static MIN_VALUE byte)) + +(import: #long java/lang/Short + (#static MAX_VALUE short) + (#static MIN_VALUE short)) + +(def: #export (tagI lefts right?) + (-> Nat Bit Inst) + (case (if right? + (.inc lefts) + lefts) + 0 _.ICONST_0 + 1 _.ICONST_1 + 2 _.ICONST_2 + 3 _.ICONST_3 + 4 _.ICONST_4 + 5 _.ICONST_5 + tag (let [tag (.int tag)] + (cond (and (i.>= (java/lang/Byte::MIN_VALUE) tag) + (i.<= (java/lang/Byte::MAX_VALUE) tag)) + (_.BIPUSH tag) + + (and (i.>= (java/lang/Short::MIN_VALUE) tag) + (i.<= (java/lang/Short::MAX_VALUE) tag)) + (_.SIPUSH tag) + + ## else + (_.int tag))))) + +(def: #export leftI _.NULL) +(def: #export rightI (_.string "")) + +(def: #export (flagI right?) (-> Bit Inst) (if right? - (_.string "") - _.NULL)) + ..rightI + ..leftI)) (def: #export (variant generate archive [lefts right? member]) (Generator [Nat Bit Synthesis]) (do phase.monad [memberI (generate archive member) - #let [tagI (case (if right? - (.inc lefts) - lefts) - 0 _.ICONST_0 - 1 _.ICONST_1 - 2 _.ICONST_2 - 3 _.ICONST_3 - 4 _.ICONST_4 - 5 _.ICONST_5 - tag (_.int (.int tag)))]] + #let [tagI (..tagI lefts right?)]] (wrap (|>> tagI (flagI right?) memberI -- cgit v1.2.3