From 18d553c416424a5eb2553754ab2faa6cc05d1dcb Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 26 Dec 2016 00:26:45 -0400 Subject: - Now trimming unnecessary 0s when encoding Frac numbers, and missing zeroes won't be taken into account when decoding them. --- luxc/src/lux/compiler/host.clj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'luxc') 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) -- cgit v1.2.3