Personal TODO List: make the test_rand.rb work.

3 views
Skip to first unread message

sishen

unread,
Nov 5, 2007, 2:42:37 PM11/5/07
to xruby-devel
Hi, guys. I'm working on the builtin static method 'srand' and 'rand'.
Does there anybody do it now? If no, I'll try my best to make it
work, :). In fact, i don't know where to put the task in the todolist
wiki. I can't find a good place.

The main work i think:

1. copy the test_rand.rb to the sample directory, and turn it to the
proper format just like other tests.
2. implement RubyKernelModule#srand, RubyKernelModule#rand method
3. make the test pass. Also, RubyCompilerTest.java file should have
the related test.

Does that right? Or do i miss something? Thanks.

Xue Yong Zhi

unread,
Nov 5, 2007, 2:51:56 PM11/5/07
to xruby...@googlegroups.com
 
>
> Hi, guys. I'm working on the builtin static method 'srand' and 'rand'.
> Does there anybody do it now? If no, I'll try my best to make it
> work, :). In fact, i don't know where to put the task in the todolist
> wiki. I can't find a good place.

Please Feel free to add your personal notes to project Wiki:
http://code.google.com/p/xruby/wiki/TodoList
 
btw, You can edit wiki via SVN.


> The main work i think:
>
> 1. copy the test_rand.rb to the sample directory, and turn it to the
> proper format just like other tests.
> 2. implement RubyKernelModule#srand, RubyKernelModule#rand method
> 3. make the test pass. Also, RubyCompilerTest.java file should have
> the related test.
>

No need to move it to the other location, you can run it like this:
java -jar xruby-0.3.1.jar test\ruby\test_rand.rb
 
You will see lots of failure as srand and rand has not been implemented correctly.
 
 
 
 


Help yourself to FREE treats served up daily at the Messenger Café. Stop by today!

sishen

unread,
Nov 8, 2007, 4:00:38 AM11/8/07
to xruby...@googlegroups.com
Some questions:

1. srand, rand is the static method of RubyKernelModule class. But the implementation of srand, rand may have many methods. So this will make the RubyKernelModule class very large. Other static method of Kernel is in the same way.  Does their exists a default policy in xruby which  i can implement RubyRandom class, then inject the necessary methods to the RubyKernelModule?  Just as the c ruby does, a random.c file and then rb_define_global_function.

2. Ruby have its own random algorithm which is different from what's in java. We should implement the ruby random algorithm to keep compatible, shouldn't we?

3. There are two urls in the random.c about the random algorithm, http://www.math.keio.ac.jp/~matumoto/emt.html and http://www.math.keio.ac.jp/matumoto/emt.html. But I can't visit both. How about yours?  I want to know whether is banned by GFW. If you can, please give me a copy, thanks.

Xue Yong Zhi

unread,
Nov 8, 2007, 9:21:52 PM11/8/07
to xruby...@googlegroups.com
Sorry for the late reply, I have been traveling this week and has
lmited access of internet.

1. Dreamhead may know this better, would you please take a look of this one?
2. I think as long as the tests passes, it is ok to use a different algorithm.
3. I got 404 error for the two urls, it looks like the pages are no
longer there.

> > ------------------------------


> > Help yourself to FREE treats served up daily at the Messenger Café. Stop
> > by

> today!<http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline>
> > >
> >
>
> >
>

dreamhead

unread,
Nov 9, 2007, 12:31:33 AM11/9/07
to xruby...@googlegroups.com
1. You can define the same Ruby module/class in different Java classes
like this.

@RubyLevelModule(name="Kernel")
public class RubyRandom {
...
}

Currently, we need register this in RubyRuntime with
RubyTypeFactory.getModule. The code will be like this.
RubyTypeFactory.getModule(RubyRandom.class);

Ye Zheng

2007/11/9, Xue Yong Zhi <xue.yo...@gmail.com>:


--
Everything is simple!

sishen

unread,
Nov 10, 2007, 4:18:08 AM11/10/07
to xruby...@googlegroups.com
Yeah. It *partially* works. Now i met a problem.

Below is the result.  The first statement gives the expecting result, but the second not. It seems the name resolution is wrong.  You can get the latest code to see the effect.

@RubyLevelModule(name="Kernel")
public class RubyRandom {
}
and
RandomModule = RubyTypeFactory.getModule(RubyRandom.class); to register in RubyRuntime.java

Also, can you share the experience about the debugging tips when you meet such problems.

Thanks.


sishen@sishen:~/Study/XRuby/xruby$ java -jar xruby-0.3.1.jar -e "puts Kernel.rand"
0.5570698346620913
sishen@sishen:~/Study/XRuby/xruby$ java -jar xruby-0.3.1.jar -e "puts rand"
Exception in thread "main" undefined method 'rand' for Object
        at com.xruby.runtime.builtin.RubyKernelModule.methodMissing(RubyKernelModule.java:598)
        at com.xruby.runtime.builtin.RubyKernelModule$methodMissing$Invoker.run (Unknown Source)
        at com.xruby.runtime.lang.RubyMethod.invoke(RubyMethod.java:78)
        at com.xruby.runtime.lang.RubyAPI.callMethodMissing(RubyAPI.java:152)
        at com.xruby.runtime.lang.RubyAPI.callNoArgMethod (RubyAPI.java:177)
        at xruby.STDIN.main.run(Unknown Source)
        at com.xruby.runtime.lang.RubyProgram.invoke(RubyProgram.java:18)
        at com.xruby.runtime.lang.RubyProgram.invoke(RubyProgram.java:14)
        at com.xruby.Main.run(Main.java:122)
        at com.xruby.Main.run(Main.java:49)
        at com.xruby.Main.main(Main.java:156)

dreamhead

unread,
Nov 10, 2007, 6:01:32 AM11/10/07
to xruby...@googlegroups.com
Have you submitted your code? I've tried current code in SVN, but it
works. I can't reproduce you problem.

Ye Zheng

2007/11/10, sishen <yedin...@gmail.com>:


--
Everything is simple!

sishen

unread,
Nov 10, 2007, 6:12:57 AM11/10/07
to xruby...@googlegroups.com
Yes. I do submit the codes.

On Nov 10, 2007 7:01 PM, dreamhead <dreamh...@gmail.com> wrote:

Have you submitted your code? I've tried current code in SVN, but it
works. I can't reproduce you problem.
What's the meaning of  'works'? Do you mean that you can get the correct answer while executing the command
java -jar xruby-0.3.1.jar -e "puts Kernel.rand" and java -jar xruby-0.3.1.jar -e "puts rand"?

What's your environment?

dreamhead

unread,
Nov 10, 2007, 6:24:47 AM11/10/07
to xruby...@googlegroups.com
Both of the code work in my machine. I use Windows to test these code.
I modify the RubyRuntime, but I don't think it's a big problem. You
can checkout my code from SVN.

2007/11/10, sishen <yedin...@gmail.com>:


--
Everything is simple!

sishen

unread,
Nov 10, 2007, 6:39:35 AM11/10/07
to xruby...@googlegroups.com
I found the problem. It's due to the version of java. Java5 pass the test, while 6 doesn't.

Thanks.

> com.xruby.runtime.lang.RubyProgram.invoke (RubyProgram.java:18)

dreamhead

unread,
Nov 10, 2007, 8:35:09 AM11/10/07
to xruby...@googlegroups.com
Really? Could you give us more detailed explanation?

Ye Zheng


--
Everything is simple!

sishen

unread,
Nov 10, 2007, 9:34:47 AM11/10/07
to xruby...@googlegroups.com
Er.......    I can't re-produce it... Maybe nothing is wrong...

> com.xruby.runtime.lang.RubyAPI.callMethodMissing (RubyAPI.java:152)
> > > > >         at
> > > com.xruby.runtime.lang.RubyAPI.callNoArgMethod
> > > > > (RubyAPI.java:177)
> > > > >         at xruby.STDIN.main.run (Unknown Source)

> > > > >         at
> > > > >
> > > com.xruby.runtime.lang.RubyProgram.invoke
> (RubyProgram.java:18)
> > > > >         at
> > > > >
> > >
> com.xruby.runtime.lang.RubyProgram.invoke(RubyProgram.java:14)
> > > > >         at com.xruby.Main.run(Main.java :122)
> > > > >         at com.xruby.Main.run (Main.java:49)
Reply all
Reply to author
Forward
0 new messages