Skip to content

Instantly share code, notes, and snippets.

@shannah
Created February 27, 2014 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/9257239 to your computer and use it in GitHub Desktop.
Save shannah/9257239 to your computer and use it in GitHub Desktop.
How to declare a new MirahMirror type..... this is just the beginning. Now that I have my mirror type, I can go to town.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ca.weblite.mirah.ant;
import java.util.ArrayList;
import java.util.Map;
import javax.xml.ws.handler.MessageContext;
import mirah.lang.ast.Node;
import org.mirah.jvm.mirrors.MirrorFuture;
import org.mirah.jvm.mirrors.MirrorProxy;
import org.mirah.jvm.mirrors.MirrorType;
import org.mirah.jvm.mirrors.debug.DebuggerInterface;
import org.mirah.tool.Mirahc;
import org.mirah.typer.FuturePrinter;
import org.mirah.typer.ResolvedType;
import org.mirah.typer.Scope;
import org.mirah.typer.TypeFuture;
import org.mirah.typer.TypeListener;
import org.mirah.typer.TypeSystem;
import org.mirah.typer.Typer;
import org.mirah.util.Context;
/**
*
* @author shannah
*/
public class MirahCompiler2 extends Mirahc {
private boolean javaSourceLoaded = false;
void loadJavaSource(Context context){
Typer typer = (Typer)context.get(Typer.class);
TypeSystem typeSystem = typer.type_system();
TypeFuture newType = typeSystem.defineType(null, null, "mypkg.JavaClass", null, new ArrayList());
if ( newType instanceof MirrorFuture ){
MirrorFuture mf = (MirrorFuture)newType;
ResolvedType rt = mf.inferredType();
if ( rt instanceof MirrorProxy ){
MirrorProxy mp = (MirrorProxy)rt;
MirrorType mt = mp.target(); // <----- AND HERE IT IS... Load this sucker up.
}
}
System.out.println(newType);
//System.out.println(node);
}
public MirahCompiler2(){
this.setDebugger(new DebuggerInterface() {
@Override
public void parsedNode(Node node) {
}
@Override
public void enterNode(Context cntxt, Node node, boolean bln) {
if ( !javaSourceLoaded ){
loadJavaSource(cntxt);
javaSourceLoaded = true;
}
}
@Override
public void exitNode(Context cntxt, Node node, TypeFuture tf) {
}
@Override
public void inferenceError(Context cntxt, Node node, TypeFuture tf) {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment