Created
April 8, 2011 22:07
-
-
Save NilsHaldenwang/910833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface AttributeAccessorExtension do | |
| macro def attr_reader(attr, type) | |
| quote do | |
| def `attr`:`type` | |
| @`attr` | |
| end | |
| end | |
| end | |
| macro def attr_writer(attr, type) | |
| attr_name = attr.string_value | |
| quote do | |
| def `"#{attr_name}_set"`(val:`type`) | |
| @`attr` = val | |
| end | |
| end | |
| end | |
| macro def attr_accessor(attr, type) | |
| attr_name = attr.string_value | |
| quote do | |
| def `"#{attr_name}_set"`(val:`type`) | |
| @`attr` = val | |
| end | |
| def `attr`:`type` | |
| @`attr` | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mirahc attribute_accessor_extension.mirah | |
| Parsing... | |
| attribute_accessor_extension.mirah | |
| Inferring types... | |
| Compiling... | |
| attribute_accessor_extension.mirah | |
| Done! | |
| nils:~/blog/posts/mirah_intro> mirahc person.mirah | |
| Parsing... | |
| person.mirah | |
| Inferring types... | |
| person.mirah:1: java.lang.NoClassDefFoundError: duby/lang/compiler/Macro | |
| class Person | |
| ^^^^^^^^^^^^^^ | |
| implements AttributeAccessorExtension | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| ^ | |
| attr_accessor :name, :String | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| end | |
| ^^^ | |
| error on ClassDefinition(Person)(2000) | |
| Mirah::InternalCompilerError: java.lang.NoClassDefFoundError: duby/lang/compiler/Macro | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/typer.rb:300 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/ast/structure.rb:35 | |
| each at org/jruby/RubyArray.java:1572 | |
| each_with_index at org/jruby/RubyEnumerable.java:905 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/ast/structure.rb:33 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/typer.rb:295 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/ast/structure.rb:266 | |
| resolve_if at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/ast.rb:227 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/ast/structure.rb:261 | |
| infer at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/typer.rb:295 | |
| infer_asts at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/impl.rb:146 | |
| each at org/jruby/RubyArray.java:1572 | |
| infer_asts at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/impl.rb:146 | |
| generate at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/impl.rb:92 | |
| compile at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah/impl.rb:54 | |
| compile at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/lib/mirah.rb:45 | |
| (root) at /home/nils/.rvm/gems/jruby-1.6.0/gems/mirah-0.0.7-java/bin/mirahc:25 | |
| load at org/jruby/RubyKernel.java:1062 | |
| (root) at /home/nils/.rvm/gems/jruby-1.6.0/bin/mirahc:19 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| implements AttributeAccessorExtension | |
| attr_accessor :name, :String | |
| end | |
| m = Person.new | |
| m.name = "Nils" | |
| puts "My name is #{m.name}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment