Instantly share code, notes, and snippets.

View any_attribute_error_in_the_stack.py
class A(object):
def __getattr__(s,i):
raise Exception('wth')
def raises(self):
"aoeu".nonexistent
@property
def yep(self):
self.raises()
A().yep
View better.mirah
macro def self.protected(methods_proxy:NodeList)
__straw_man__.expanded_children(methods_proxy).each do |c|
next unless c.kind_of? MethodDefinition
__straw_man__.add_modifiers_to(c, access: 'PROTECTED')
end
end
View list.md

TODO List For 1.0

  • Finish closures
    • wrap new closure implementation so that this isn't an issue: https://github.com/mirah/mirah/issues/276
    • stabby lambdas
      • potato: add to parser w/ compiler error
    • non-local return
      • potato: just disallow return inside blocks converted into closures that aren't lambdas
    • nested bindings: they should work nicely
    • Java 8 MetaLambdaing when targeting 8. It'd be cool if we could use Java 8's lambda impl when on 8
View mirah_extension_proposal.md

Extensions

Extensions are the way that Mirah adds methods to existing classes. When you call methods like each on collections, you are actually using extensions. They are helpful when you want to write DSLs and when you want to make a library you are using feel more Mirah-ish.

How do you use them?

Mirah comes with a number of built in extensions for Java's base types. For example, the methods each, map and empty are added to Collections. The built in extensions need no special invocation to be taken advantage of, they're already available. If you want to use extensions from a library, or optional extensions, you'll need to tell Mirah which ones you want to use.

The way you do that is by "using" the extension. using works just like import, but instead of making an imported class available, they extend other classes. For example, say you wanted to pluralize a string using an activesupport-like library. You could do it like so:

View notify_on_long_exec.sh
export NOTIFY_TIME=10
function timer_start {
previous_command=$this_command
if [ "$BASH_COMMAND" != "timer_stop" ]
then
this_command=$BASH_COMMAND
fi
timer=${timer:-$SECONDS}
View dynamical.rb
class Dynamical
define_method :works_fine do |&block|
5.times { |n| block.call(n) }
end
def self.defn name
define_method name do |&block|
5.times { |n| yield n }
end
end
View extensionmethods.mirah
package cool.extensions
extension StringExt[String]
def toInt
Integer.parseInt(self)
end
end
# or, less overloaded w/ generics
View mirah_constant.md

constants work by being translated into field accesses / assigns.

to ensure that constants that are seen before they are assigned can be resolved, the mirror typer keeps a hash of fields that it has seen, but haven't been assigned or declared yet.

View dreams_of_mirah_1.0.md

Dreams of Mirah 1.0

What is Mirah?

Runtimeless JVM language that tries as hard as possible to feel like writing Ruby without cheating.

  • Should produce class files that are drop in replacements for Java.
  • Should interop well with Java and Java tools
  • It'd be nice if it interopped well with JRuby too, as well as other JVM langs, through compiler extensions.
  • It should have an extensible compiler
View jvmls_day_one_notes.md

JVMLS Notes Day 1

Mirah NLR + yield

Thought I came up w/ talking w/ headius + kotlin dev

Have nonlocal return allowed only for blocks passed to fns that are either: macros, or take a specialized type that's generated from a yield