[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] BiteScript 0.0.1 - a DSL for JVM bytecode

Charles Oliver Nutter

3/28/2009 7:11:00 PM

BiteScript is a Ruby DSL for generating JVM bytecode and classes. It is
used by the Duby programming language and by the upcoming "compiler2"
Ruby-to-Java compiler in JRuby.

Project page: http://kenai.com/projects...

Install: gem install bitescript

Dependencies: JRuby 1.2 or higher

Changes:

* First public release. Most features up to Java 1.4 are supported plus
Java 5 annotations.

Sample code:

require 'bitescript'

include BiteScript

fb = FileBuilder.build(__FILE__) do
public_class "SimpleLoop" do
public_static_method "main", void, string[] do
aload 0
push_int 0
aaload
label :top
dup
aprintln
goto :top
returnvoid
end
end
end

fb.generate do |filename, class_builder|
File.open(filename, 'w') do |file|
file.write(class_builder.generate)
end
end

5 Answers

Charles Oliver Nutter

3/28/2009 7:21:00 PM

0

I should have mentioned I'm open to suggestions for API/DSL
improvements, and obviously bug reports are welcome. There's mailing
lists and an issue tracker at the kenai project page.

Charles Oliver Nutter wrote:
> BiteScript is a Ruby DSL for generating JVM bytecode and classes. It is
> used by the Duby programming language and by the upcoming "compiler2"
> Ruby-to-Java compiler in JRuby.
>
> Project page: http://kenai.com/projects...
>
> Install: gem install bitescript
>
> Dependencies: JRuby 1.2 or higher
>
> Changes:
>
> * First public release. Most features up to Java 1.4 are supported plus
> Java 5 annotations.
>
> Sample code:
>
> require 'bitescript'
>
> include BiteScript
>
> fb = FileBuilder.build(__FILE__) do
> public_class "SimpleLoop" do
> public_static_method "main", void, string[] do
> aload 0
> push_int 0
> aaload
> label :top
> dup
> aprintln
> goto :top
> returnvoid
> end
> end
> end
>
> fb.generate do |filename, class_builder|
> File.open(filename, 'w') do |file|
> file.write(class_builder.generate)
> end
> end
>


Charles Oliver Nutter

3/28/2009 7:43:00 PM

0

And blogged, with a bit more information and links to JVM spec docs,
opcode quickref, and more examples:

http://blog.headius.com/2009/03/bitescript-001-ruby-dsl-fo...

Charles Oliver Nutter wrote:
> BiteScript is a Ruby DSL for generating JVM bytecode and classes. It is
> used by the Duby programming language and by the upcoming "compiler2"
> Ruby-to-Java compiler in JRuby.
>
> Project page: http://kenai.com/projects...
>
> Install: gem install bitescript
>
> Dependencies: JRuby 1.2 or higher
>
> Changes:
>
> * First public release. Most features up to Java 1.4 are supported plus
> Java 5 annotations.
>
> Sample code:
>
> require 'bitescript'
>
> include BiteScript
>
> fb = FileBuilder.build(__FILE__) do
> public_class "SimpleLoop" do
> public_static_method "main", void, string[] do
> aload 0
> push_int 0
> aaload
> label :top
> dup
> aprintln
> goto :top
> returnvoid
> end
> end
> end
>
> fb.generate do |filename, class_builder|
> File.open(filename, 'w') do |file|
> file.write(class_builder.generate)
> end
> end
>


Tony Arcieri

3/29/2009 4:26:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Sat, Mar 28, 2009 at 1:11 PM, Charles Oliver Nutter <
charles.nutter@sun.com> wrote:

> Sample code:
>
> require 'bitescript'
>
> include BiteScript
>
> fb = FileBuilder.build(__FILE__) do
> public_class "SimpleLoop" do
> public_static_method "main", void, string[] do
> aload 0
> push_int 0
> aaload
> label :top
> dup
> aprintln
> goto :top
> returnvoid
> end
> end
> end
>
> fb.generate do |filename, class_builder|
> File.open(filename, 'w') do |file|
> file.write(class_builder.generate)
> end
> end
>

That's some awesome use of blocks

--
Tony Arcieri
medioh.com

Charles Oliver Nutter

3/29/2009 5:28:00 AM

0

Tony Arcieri wrote:
> On Sat, Mar 28, 2009 at 1:11 PM, Charles Oliver Nutter <
>> fb = FileBuilder.build(__FILE__) do
>> public_class "SimpleLoop" do
>> public_static_method "main", void, string[] do
>> aload 0
>> push_int 0
...
> That's some awesome use of blocks

Thanks! I know the instance_eval'ed pattern for executing blocks is
sometimes considered bad form, but it makes the code look so nice here I
figured I'd go for it. If you want to use it as a normal API, you can do
that just as easily; you just have to "start" and "stop" the method body
yourself:

fb = FileBuilder.build(__FILE__) do
cls = fb.public_class "SimpleLoop"
m = cls.public_static_method "main", void, string[]
m.start
m.aload 0
m.push_int 0
m.aaload
m.label :top
m.dup
m.aprintln
m.goto :top
m.returnvoid
m.stop

- Charlie

Radoslaw Bulat

3/29/2009 11:21:00 AM

0

On Sun, Mar 29, 2009 at 7:28 AM, Charles Oliver Nutter
<charles.nutter@sun.com> wrote:
> Thanks! I know the instance_eval'ed pattern for executing blocks is
> sometimes considered bad form, but it makes the code look so nice here I
> figured I'd go for it. If you want to use it as a normal API, you can do
> that just as easily; you just have to "start" and "stop" the method body
> yourself:
>
> fb =3D FileBuilder.build(__FILE__) do
> cls =3D fb.public_class "SimpleLoop"
> m =3D cls.public_static_method "main", void, string[]
> m.start
> m.aload 0
> m.push_int 0
> m.aaload
> m.label :top
> m.dup
> m.aprintln
> m.goto :top
> m.returnvoid
> m.stop

Charlie, you can also use some 'trick' to allow programmers choose if
he wants instance_eval or 'normal' version:

class Foo
def initialize(*args, &block)
if block_given?
if block.arity =3D=3D 1
block.call(self)
else
instance_eval(&block)
end
end
end
end

Foo.new do |foo|
puts "self =3D #{self}"
puts "foo =3D #{foo}"
end

Foo.new do
puts "self =3D #{self}"
end

--=20
Pozdrawiam

Rados=B3aw Bu=B3at
http://radarek... - m=F3j blog