Handling Long parameters

9 views
Skip to first unread message

James Caska

unread,
Sep 4, 2014, 4:22:32 PM9/4/14
to boo...@googlegroups.com
Things have been running well but now I am hitting some barriers.

I need to be able to work with Long's, for example Thread.sleep(long)

Problem 1: The emitter was generating Llong; as the parameter type, I was able to fix this by extending _primativeMappings with long

_primitiveMappings = {
typeSystem.CharType: CHAR_TYPE.getDescriptor(),
typeSystem.BoolType: BOOLEAN_TYPE.getDescriptor(),
typeSystem.IntType: INT_TYPE.getDescriptor(),
typeSystem.VoidType: VOID_TYPE.getDescriptor(),
typeSystem.LongType: LONG_TYPE.getDescriptor(), #<<< Added to generate long param's
}

Problem 2: The emitter is generating integer literals for long parameters

eg. 
44:   iconst_0 <<<<<<<<<<< should be lconst
45:   invokestatic java.lang.Thread.sleep (J)V (61)

I have added a LCONST generator

def LCONST(value as int):
if value == 0 :
emitInstruction Opcodes.LCONST_0
elif value == 1 :
emitInstruction Opcodes.LCONST_1
else:
LDC java.lang.Long(value)

and extended 'OnIntegerLiteralExpression'

override def OnIntegerLiteralExpression(node as IntegerLiteralExpression):
if node.IsLong :
LCONST node.Value
else:
ICONST node.Value

But now I am stuck. I need a suggestion of how to use the parameter signatures to generate a long LiteralExpression

Thanks for any suggestions.




Rodrigo B. de Oliveira

unread,
Sep 4, 2014, 10:17:04 PM9/4/14
to boo...@googlegroups.com
Your changes look good.

About the literal expression I think it makes sense to handle literal
integer to long promotion during the InjectCasts step somewhere around
https://github.com/bamboo/boojay/blob/master/src/Boojay.Compilation/Steps/InjectCasts.boo#L83
> --
> You received this message because you are subscribed to the Google Groups
> "boojay" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to boojay+un...@googlegroups.com.
> To post to this group, send email to boo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/boojay.
> For more options, visit https://groups.google.com/d/optout.

James Caska

unread,
Sep 25, 2014, 12:27:07 PM9/25/14
to boo...@googlegroups.com
Thanks, I was able to inject cast mappings to and from all the different types and added double and long etc also.

It's nice how Boo has already figured out the lhs/rhs expression and casting can be implicit

Reply all
Reply to author
Forward
0 new messages