Krishna Krishnamaneni
2007-Oct-07 06:01 UTC
[Ironruby-core] How to extend builtin classes?
Hi How do we extend inbuilt classes. For example Float doesn''t have * method implemented. I tried adding this method: [RubyMethodAttribute("*", RubyMethodAttributes.PublicInstance)] public static object Multiply(double self, double value) { // TODO: overflow return self * value; } but did not work after compilation. It still complains that * method is not implemented on Float. Thank you. -- Regards, krishna krishnamaneni.
On 10/6/07, Krishna Krishnamaneni <kitti.k at gmail.com> wrote:> > > How do we extend inbuilt classes. For example Float doesn''t have * > method implemented. I tried adding this method:It''s not sufficient to add the method to the class definition. You also have to force the method information to be initialized by updating the file Initializer.Generated.cs. As its name suggests, this file is automatically generated from the source code by running the "ClassInitGenerator" program -- a batch file that does this is at Builtins\GenerateInitializers.cmd. Unfortunately, the version of the source that''s checked into RubyForge has a bunch of broken paths for this purpose -- at least when not using Visual Studio. I tried to use msbuild directly to build ClassInitGenerator.exe, and found that I had to make the following edits for things to work correctly: utils\ironruby.classinitgenerator\ClassInitGenerator.csproj add reference to ..\..\build\debug\Microsoft.Scripting.dll add reference to ..\..\build\debug\Ruby.dll fix the reference path for Microsoft.Scripting.csproj fix the reference path for Ruby.csproj src\ironruby\Ruby.csproj fix the reference path for Microsoft.Scripting.csproj src\ironruby\Builtins\GenerateInitializers.cmd fix the path to ClassInitGenerator.exe After making these changes, I ran GenerateInitializers.cmd and rebuilt IronRuby using the Rakefile. Your change then worked: F:\IronRuby>build\release\rbx.exe IronRuby Pre-Alpha (1.0.0.0) on .NET 2.0.50727.312 Copyright (c) Microsoft Corporation. All rights reserved.>>> 1.2 + 1.2=> 2.4>>> 1.2 * 1.2=> 1.44 -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071007/4c5863e0/attachment.html
Krishna Krishnamaneni
2007-Oct-07 19:00 UTC
[Ironruby-core] How to extend builtin classes?
Curt, Thank you for the reply. Looks like this is something that should be commited. Can you commit your changes to the SVN repository so that every one can get the changes? Thanks a lot. On 10/7/07, Curt Hagenlocher <curt at hagenlocher.org> wrote:> On 10/6/07, Krishna Krishnamaneni <kitti.k at gmail.com> wrote: > > > > How do we extend inbuilt classes. For example Float doesn''t have * > > method implemented. I tried adding this method: > > > It''s not sufficient to add the method to the class definition. You also > have to force the method information to be initialized by updating the file > Initializer.Generated.cs. As its name suggests, this file is automatically > generated from the source code by running the "ClassInitGenerator" program > -- a batch file that does this is at > Builtins\GenerateInitializers.cmd. > > Unfortunately, the version of the source that''s checked into RubyForge has a > bunch of broken paths for this purpose -- at least when not using Visual > Studio. I tried to use msbuild directly to build ClassInitGenerator.exe , > and found that I had to make the following edits for things to work > correctly: > > utils\ironruby.classinitgenerator\ClassInitGenerator.csproj > add reference to > ..\..\build\debug\Microsoft.Scripting.dll > add reference to ..\..\build\debug\Ruby.dll > fix the reference path for Microsoft.Scripting.csproj > fix the reference path for Ruby.csproj > src\ironruby\Ruby.csproj > fix the reference path for Microsoft.Scripting.csproj > src\ironruby\Builtins\GenerateInitializers.cmd > fix the path to ClassInitGenerator.exe > > After making these changes, I ran GenerateInitializers.cmd and rebuilt > IronRuby using the Rakefile. Your change then worked: > > F:\IronRuby>build\release\rbx.exe > IronRuby Pre-Alpha (1.0.0.0) on .NET 2.0.50727.312 > Copyright (c) Microsoft Corporation. All rights reserved. > >>> 1.2 + 1.2 > => 2.4 > >>> 1.2 * 1.2 > => 1.44 > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Regards, krishna krishnamaneni.
On 10/7/07, Krishna Krishnamaneni <kitti.k at gmail.com> wrote:> > > Thank you for the reply. Looks like this is something that should be > commited. Can you commit your changes to the SVN repository so that > every one can get the changes? Thanks a lot.I''m not sure what''s required to be able to do that; a patchfile with the changes can be downloaded from http://hagenlocher.org/software/classinitgen.patch.txt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071007/ff0f93f7/attachment.html
Thanks for making the patch, Curt! For folks on the outside, please use Curt''s patch until I get around to fixing the Rakefile. I need to add some code to transform paths within the .csproj files so that they recognize the difference in layouts between our internal environment and the external subversion layout. Thanks, -John I''m not sure what''s required to be able to do that; a patchfile with the changes can be downloaded from http://hagenlocher.org/software/classinitgen.patch.txt -- Curt Hagenlocher curt at hagenlocher.org<mailto:curt at hagenlocher.org> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071007/3fde7a34/attachment.html
Krishna Krishnamaneni
2007-Oct-07 23:17 UTC
[Ironruby-core] How to extend builtin classes?
Thanks for the patch. On 10/7/07, Curt Hagenlocher <curt at hagenlocher.org> wrote:> On 10/7/07, Krishna Krishnamaneni <kitti.k at gmail.com> wrote: > > > > Thank you for the reply. Looks like this is something that should be > > commited. Can you commit your changes to the SVN repository so that > > every one can get the changes? Thanks a lot. > > > I''m not sure what''s required to be able to do that; a patchfile with the > changes can be downloaded from > http://hagenlocher.org/software/classinitgen.patch.txt > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Regards, krishna krishnamaneni.
Florian Krüsch
2007-Oct-08 11:22 UTC
[Ironruby-core] "Common Language Runtime detected an invalid program" exception
Hi, I''m playing with IronRuby and love it. Playing around I obviously did something that''s not yet implemented and got the exception "Common Language Runtime detected an invalid program" The code is: result = (Proc.new { |value| value.to_s*2 }).call value I understand that IronRuby still has a way to go and that not everything''s fully implemented. However, I would expect another kind of exception... something along "Ruby syntax error" or the like... btw - it would be awesome to get a few pointers on the differences between the various methods/modes of execution (Exectue, ExecuteCommand etc) cheers Florian -- Florian Kr?sch http://www.planet-xaml.net
Florian Krüsch
2007-Oct-08 11:42 UTC
[Ironruby-core] "Common Language Runtime detected an invalid program" exception
Hi, I''m playing with IronRuby and love it. Playing around I obviously did something that''s not yet implemented and got the exception "Common Language Runtime detected an invalid program" The code is: result = (Proc.new { |value| value.to_s*2 }).call value I understand that IronRuby still has a way to go and that not everything''s fully implemented. However, I would expect another kind of exception... something along "Ruby syntax error" or the like... btw - it would be awesome to get a few pointers on the differences between the various methods/modes of execution (Exectue, ExecuteCommand etc) cheers Florian -- Florian Kr?sch http://www.planet-xaml.net
Curt Hagenlocher
2007-Oct-08 12:31 UTC
[Ironruby-core] "Common Language Runtime detected an invalid program" exception
On 10/8/07, Florian Kr?sch <florian at kruesch.de> wrote:> > > I''m playing with IronRuby and love it. > Playing around I obviously did something that''s not yet implemented and > got the exception "Common Language Runtime detected an invalid program" > The code is: > result = (Proc.new { |value| value.to_s*2 }).call valueThis looks very much like a bug and not an unimplemented feature. The error message suggests that there''s some invalid IL being emitted. If you split the code into two lines p = Proc.new{ |value| value.to_s*2} result = p.call value it works correctly. You can submit this as a bug here: http://rubyforge.org/tracker/?atid=16798&group_id=4359&func=browse -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071008/ee906a90/attachment.html
Tomas Matousek
2007-Oct-08 16:03 UTC
[Ironruby-core] "Common Language Runtime detected an invalid program" exception
This is a known bug (IL stack needs to be empty when entering try-catch). All "invalid programs" exception are due to this bug. The bug will take some time to fix. Until then, store values to locals if you combine calls with a block with other calls. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Florian Kr?sch Sent: Monday, October 08, 2007 4:42 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] "Common Language Runtime detected an invalid program" exception Hi, I''m playing with IronRuby and love it. Playing around I obviously did something that''s not yet implemented and got the exception "Common Language Runtime detected an invalid program" The code is: result = (Proc.new { |value| value.to_s*2 }).call value I understand that IronRuby still has a way to go and that not everything''s fully implemented. However, I would expect another kind of exception... something along "Ruby syntax error" or the like... btw - it would be awesome to get a few pointers on the differences between the various methods/modes of execution (Exectue, ExecuteCommand etc) cheers Florian -- Florian Kr?sch http://www.planet-xaml.net _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core