Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / February 2004

Tip: Looking for answers? Try searching our database.

Another bug in Oolong ?

Thread view: 
Dasch - 03 Feb 2004 18:53 GMT
Hi,

it's me again ;)

If you don't remember: I use Oolong (Assembly language presented by
Joshua Engel to generate Bytecode) to generate my class files.

This time I tried to compile this simple Oolong line and it doesn't work
:(

The line is:
ldc 1.234

As you see, I just want to put on the stack a float which value is equal
to 1.234.

When I try with ldc 1.0, it works without any problem, but each time I
try another float number (1.2, 13.14, etc.), it doesn't work and the
Oolong compiler complains saying:

"Bug.j:20:invalid argument to ldc"

I suspect this is another bug in Oolong but I have no idea how to fix it.
Any help would be greatly appreciated :)

I already tried the following syntax with no success:
ldc 1.2F
ldc 1.2f

Thanks in advance,
Dasch.
Boudewijn Dijkstra - 03 Feb 2004 21:43 GMT
> it's me again ;)

And it's me again, too!
(I snipped some.)

> This time I tried to compile this simple Oolong line and it doesn't work
> :(
[quoted text clipped - 7 lines]
>
> "Bug.j:20:invalid argument to ldc"

Well, there is a very questionable method in COM.sootNsmoke.oolong.Lexer:

   static boolean isFloat(String s)
   {
       String val = s;
       try {
           if(val.endsWith("D") || val.endsWith("d"))
               return false;
           double d = Double.valueOf(val).doubleValue();
           if(d == (float) d)
               return true;
       }
       catch(Exception e) {}
       return false;
   }

Apart from unnessecary reference copying, this method seems OK.  But I ask
you: would you use the same manner of determining wheter a given string
represents a float?
Anyway, I think the real problem is in this fragment of
COM.sootNsmoke.oolong.Oolong:

       if(mnemonic.equals("ldc") ||
          mnemonic.equals("ldc_w"))
       {
           String word = nextWord();
           if(lexer.ttype == '"')
               return new Ldc(lexer.sval);
           if(lexer.isInt(word))
               return new Ldc((int) lexer.parseLong(word));
           else if(lexer.isFloat(word))
               return new Ldc((float) lexer.parseDouble(word));
           throw new SyntaxError(this, "invalid argument to ldc");
       }

There is absolutely no support for longs or doubles!  However, like our last
problem, this one is also easy to solve: just add the appropriate checks.
It is now safe to assume that your "1.234" string wasn't recognized as
float, because there is no way a float (or double?) can exactly represent
"0.234"!

> I already tried the following syntax with no success:
> ldc 1.2F
> ldc 1.2f

This also didn't help, because the final 'f' is never checked in isFloat()!
You might also want to change that.
Dasch - 04 Feb 2004 18:05 GMT
Hi,

first of all, I'd like to thank you for the time and effort you put in
handling my posts :)

Now, here is my "long" answer:

>> Apart from unnessecary reference copying, this method seems OK.  But I ask
>> you: would you use the same manner of determining wheter a given string
>> represents a float?

No, but I'm not sure that my way of writing it is better. Anyway, here
is how I re-wrote isFloat():

public boolean isFloat(String s) {
  try {
    Float.parseFloat(s);
    return true;
  } catch(Exception e) {}
  return false;
}

>> There is absolutely no support for longs or doubles!

I'm not sure, but I think it's normal ! Because ldc and ldc_w should
only be used with int and float.
If you want to use double or long, you should use ldc2_w which follows
in the code...

Finally, I fixed the code (for the float problem) this way (I hope it is
now correct) :

1/ I add a call to lexer.parseFloat in the following lines:

if(mnemonic.equals("ldc") ||
            mnemonic.equals("ldc_w"))
         {
             String word = nextWord();
             if(lexer.ttype == '"')
                 return new Ldc(lexer.sval);
             if(lexer.isInt(word))
                 return new Ldc((int) lexer.parseLong(word));
             else if(lexer.isFloat(word))
                 return new Ldc((float) lexer.parseFloat(word));
             throw new SyntaxError(this, "invalid argument to ldc");
         }

2/ I wrote a method parseFloat in the Lexer class:

public float parseFloat(String s) {
  return Float.parseFloat(s);
}

I know it's an ugly fixing patch (I call Float.parseFloat(s) 2 times
instead of one) but it seems to work and I don't have time to re-write
all the Oolong framework ;)

Thanks again for your help,
Dasch

snipped

> Well, there is a very questionable method in COM.sootNsmoke.oolong.Lexer:
>
[quoted text clipped - 36 lines]
> float, because there is no way a float (or double?) can exactly represent
> "0.234"!

snipped
Boudewijn Dijkstra - 04 Feb 2004 20:39 GMT
> Hi,
>
> first of all, I'd like to thank you for the time and effort you put in
> handling my posts :)

Well, these two were kinda fun, but I'm starting to wonder why you couldn't
solve these problems by yourself.  Especially since I never heard about
Oolong before you started about it.  No offence, just curious.  :-)

> Now, here is my "long" answer:
>
[quoted text clipped - 12 lines]
>    return false;
> }

This code also returns true for doubles, because every valid floating point
number string can be represented by an instance of float, including 0.0 and
infinities.  I don't think that does any harm, though.
Your re-write is adequate, but of course it doesn't produce the fastest
running code.

> >> There is absolutely no support for longs or doubles!
>
> I'm not sure, but I think it's normal ! Because ldc and ldc_w should
> only be used with int and float.
> If you want to use double or long, you should use ldc2_w which follows
> in the code...

You are right, I overlooked that.  ldc(_w) should only push 32 bits on the
stack.

> Finally, I fixed the code (for the float problem) this way (I hope it is
> now correct) :
[quoted text clipped - 71 lines]
> >
> snipped
Slimane Zouggari - 05 Feb 2004 09:41 GMT
 > Well, these two were kinda fun, but I'm starting to wonder why you
couldn't
 > solve these problems by yourself.  Especially since I never heard about
 > Oolong before you started about it.  No offence, just curious.  :-)

It's just because I am really busy right now and I didn't had the
courage to look into Oolong source code. So, you can say it's just
laziness ;) but, it's also due to my busy schedule. When I decided to
use Oolong, it was to develop my soft faster not to look at its source
code each time I suspected a bug :) And I didn't suspected so much and
annoying bugs (cf. the stack size limits not well computed for instance)

 > This code also returns true for doubles, because every valid floating
point
 > number string can be represented by an instance of float, including
0.0 and
 > infinities.  I don't think that does any harm, though.
 > Your re-write is adequate, but of course it doesn't produce the fastest
 > running code.

I know, but for the moment I don't need doubles and longs, so I'll leave
the code that way...

> "Dasch" <none@spam.com> schreef in bericht
news:40213469.6020302@spam.com...

>>Hi,
>>
>>first of all, I'd like to thank you for the time and effort you put in
>>handling my posts :)
>
> Well, these two were kinda fun, but I'm starting to wonder why you
couldn't
> solve these problems by yourself.  Especially since I never heard about
> Oolong before you started about it.  No offence, just curious.  :-)
[quoted text clipped - 17 lines]
>
> This code also returns true for doubles, because every valid floating
point
> number string can be represented by an instance of float, including
0.0 and
> infinities.  I don't think that does any harm, though.
> Your re-write is adequate, but of course it doesn't produce the fastest
[quoted text clipped - 8 lines]
>
> You are right, I overlooked that.  ldc(_w) should only push 32 bits
on the
> stack.

snipped
Dasch - 06 Feb 2004 09:26 GMT
Hi,

>>Hi,
>>
[quoted text clipped - 4 lines]
> solve these problems by yourself.  Especially since I never heard about
> Oolong before you started about it.  No offence, just curious.  :-)

Let's say my main problem is a huge lack of time right now ;)
So, I didn't want to jump in the source code

snipped

> This code also returns true for doubles, because every valid floating point
> number string can be represented by an instance of float, including 0.0 and
> infinities.  I don't think that does any harm, though.
> Your re-write is adequate, but of course it doesn't produce the fastest
> running code.

so, I'll keep it :)

>>snipped


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.