aboutsummaryrefslogtreecommitdiff
path: root/luxc/src
diff options
context:
space:
mode:
authorEduardo Julian2016-12-26 00:26:45 -0400
committerEduardo Julian2016-12-26 00:26:45 -0400
commit18d553c416424a5eb2553754ab2faa6cc05d1dcb (patch)
tree7c8a70cff0f1acc98c789aa117520d5722bd5a06 /luxc/src
parent6130c650d29e6b09e65fcd3269b0b4bdb2fc27a0 (diff)
- Now trimming unnecessary 0s when encoding Frac numbers, and missing zeroes won't be taken into account when decoding them.
Diffstat (limited to 'luxc/src')
-rw-r--r--luxc/src/lux/compiler/host.clj15
1 files changed, 14 insertions, 1 deletions
diff --git a/luxc/src/lux/compiler/host.clj b/luxc/src/lux/compiler/host.clj
index 4c2ff9d24..eb2b0b889 100644
--- a/luxc/src/lux/compiler/host.clj
+++ b/luxc/src/lux/compiler/host.clj
@@ -1047,6 +1047,11 @@
(.visitLdcInsn ".")
(.visitInsn Opcodes/SWAP)
(.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "concat" "(Ljava/lang/String;)Ljava/lang/String;")
+ ;; Trim unnecessary 0s at the end...
+ (.visitLdcInsn "0*$")
+ (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "split" "(Ljava/lang/String;)[Ljava/lang/String;")
+ (.visitLdcInsn (int 0))
+ (.visitInsn Opcodes/AALOAD)
(.visitInsn Opcodes/ARETURN)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1086,7 +1091,10 @@
$next-iteration (new Label)]
(doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "frac_text_to_digits" "(Ljava/lang/String;)[B" nil nil)
(.visitCode)
- (.visitLdcInsn (int (dec frac-bits)))
+ (.visitVarInsn Opcodes/ALOAD 0)
+ (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "length" "()I")
+ (.visitLdcInsn (int 1))
+ (.visitInsn Opcodes/ISUB)
(.visitVarInsn Opcodes/ISTORE 1) ;; Index
(.visitLdcInsn (int frac-bits))
(.visitIntInsn Opcodes/NEWARRAY Opcodes/T_BYTE)
@@ -1276,6 +1284,11 @@
(.visitLdcInsn ".")
(.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "startsWith" "(Ljava/lang/String;)Z")
(.visitJumpInsn Opcodes/IFEQ $bad-format)
+ ;; Check if size is valid
+ (.visitVarInsn Opcodes/ALOAD 0)
+ (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "length" "()I")
+ (.visitLdcInsn (int (inc frac-bits))) ;; It's increased, to account for the prefix .
+ (.visitJumpInsn Opcodes/IF_ICMPGT $bad-format)
;; Initialization
(.visitTryCatchBlock $from $to $handler "java/lang/Exception")
(.visitVarInsn Opcodes/ALOAD 0)