Created
August 5, 2011 02:31
-
-
Save tanob/1126814 to your computer and use it in GitHub Desktop.
Trying to write a macro
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
Parsing... | |
macro.mirah | |
Inferring types... | |
Inference Error: | |
Could not infer typing for nodes: | |
FunctionalCall(find_class) | |
Call(parent) | |
Field(call) at line 14 (child of LocalAssignment(name = class_node, scope = MethodDefinition(_expand), captured = false)) | |
macro.mirah:12: Could not infer typing for nodes: | |
FunctionalCall(find_class) | |
Call(parent) | |
Field(call) at line 14 (child of LocalAssignment(name = class_node, scope = MethodDefinition(_expand), captured = false)) | |
macro def do_something | |
^^^^^^^^^^^^^^^^^^^^^^^^^ | |
class_node = find_class(@call.parent) | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
class_name = class_node.string_value | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
quote do | |
^^^^^^^^^^^^^ | |
def `"blah_#{class_name}"` | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
x = 2 | |
^^^^^^^^^^^^^^^^^^ | |
end | |
^^^^^^^^^^^^ | |
end | |
^^^^^^^^ | |
end | |
^^^^^ | |
Cannot find instance method do_something() on Foo | |
macro.mirah:22: Cannot find instance method do_something() on Foo | |
do_something | |
^^^^^^^^^^^^^^ |
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
import duby.lang.compiler.ClassDefinition | |
import duby.lang.compiler.Node | |
class Foo | |
def find_class(node:Node):ClassDefinition | |
while node && !node.kind_of?(ClassDefinition) | |
node = node.parent | |
end | |
ClassDefinition(node) | |
end | |
macro def do_something | |
class_node = find_class(@call.parent) | |
class_name = class_node.string_value | |
quote do | |
def `"blah_#{class_name}"` | |
x = 2 | |
end | |
end | |
end | |
do_something | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment