/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.xreate.grammatic.lisp; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.io.IOException; import java.lang.reflect.Method; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.antlr.runtime.*; import org.jllvm.*; import org.jllvm.bindings.*; import org.xreate.TestRunner2; /** * * @author pgess */ public class LispInterpreter { static Map htable; static Map ttable; public Map opcodes = Maps.newLinkedHashMap(); public Map functions = Maps.newLinkedHashMap(); protected LLVMInstructionBuilder builder = new LLVMInstructionBuilder(); protected LLVMModule module = new LLVMModule("script"); //"/private/prg/code/xreate/scripts/opcode.li" public void run(String filename) throws IOException, RecognitionException, Exception{ ANTLRStringStream in = new ANTLRFileStream(filename); Lexer l = new LispLexer(in); CommonTokenStream tokens = new CommonTokenStream(l); LispParser p = new LispParser(tokens); while (true){ ASTLispNode node = p.statement(null); handle(node); } } public void opcodeDef(ASTLispNode node){ ArrayList params = node.parameters; opcodes.put(params.get(0).caption, params.get(1).caption); } public void functionDef(ASTLispNode node) throws Exception{ ArrayList nodes_vars = node.get("vars-list").parameters; int nsize = nodes_vars.size(); LLVMType[] arg_types = new LLVMType[nsize]; for (int i=0; i() .put("opcode", "opcodeDef") .put("function", "functionDef") .put ("calculate", "calculate") .put("main", "main") .build(); /* * Types Table - хранит информацию о соответствии типов */ ttable = new ImmutableMap.Builder() .put ("i32", LLVMIntegerType.i32) .put ("i16", LLVMIntegerType.i16) .put ("i8", LLVMIntegerType.i8) .build(); } class Evaluator{ Map arguments; public Evaluator(String[] names, LLVMValue[] values) { int size = names.length; arguments = Maps.newHashMapWithExpectedSize(size); for(int i=0; i