package org.hummingbirdlang;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Exception;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.nodes.Node;

import org.hummingbirdlang.parser.ParserWrapper;

@TruffleLanguage.Registration(name = "Hummingbird", version = "0.1", mimeType = HBLanguage.MIME_TYPE)
public final class HBLanguage extends TruffleLanguage<HBContext> {
  public static final String MIME_TYPE = "application/x-hummingbird";

  public static final HBLanguage INSTANCE = new HBLanguage();

  private HBLanguage() {
  }

  @Override
  protected HBContext createContext(Env env) {
    BufferedReader in = new BufferedReader(new InputStreamReader(env.in()));
    PrintWriter out = new PrintWriter(env.out(), true);
    return new HBContext(env, in, out);
  }

  @Override
  protected CallTarget parse(ParsingRequest request) throws Exception {
    Source source = request.getSource();
    Object program = ParserWrapper.parse(source);
    return null;
  }

  @Override
  protected CallTarget parse(Source source, Node node, String... argumentNames) throws Exception {
    Object program = ParserWrapper.parse(source);
    System.out.println(program.toString());
    return null;
  }

  // Called when some other language is seeking for a global symbol.
  @Override
  protected Object findExportedSymbol(HBContext context, String globalName, boolean onlyExplicit) {
    return null;
  }

  @Override
  protected Object getLanguageGlobal(HBContext context) {
    // Context is the highest level global.
    return context;
  }

  @Override
  protected boolean isObjectOfLanguage(Object object) {
    return false;
  }
}

@@ -1130,32 +1130,99 @@
 turn null;%0A  %7D%0A%0A
+  // TODO: Fully remove this deprecated implementation.:%0A  //%0A  // 
   @Override%0A  pr
@@ -1209,32 +1209,37 @@
  //   @Override%0A
+  // 
   protected Call
@@ -1317,24 +1317,29 @@
 Exception %7B%0A
+  // 
     Object p
@@ -1376,20 +1376,25 @@
 ource);%0A
+  //
     
+ 
 System.o
@@ -1421,24 +1421,29 @@
 oString());%0A
+  // 
     return n
@@ -1439,32 +1439,37 @@
    return null;%0A
+  // 
   %7D%0A%0A  // Called

Comment out deprecated implementation