Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.dynjs.compiler.bytecode;
  
  import static me.qmx.jitescript.util.CodegenUtils.*;
  
  import java.util.List;
 
 
 
     
     private AtomicInteger counter = new AtomicInteger();
 
     public BytecodeBasicBlockCompiler(Config configCodeGeneratingVisitorFactory factory) {
         super(configfactory);
     }
 
     @Override
     public BasicBlock compile(final CompilationContext contextfinal String gristfinal Statement bodyboolean strict) {
         
         int statementNumber = body.getStatementNumber();
         Entry entry = context.getBlockManager().retrieve(statementNumber);
         BasicBlock code = entry.getCompiled();
         if ( code instanceof BytecodeBasicBlock ) {
             return code;
         }
         
         String className = nextClassName(grist);
 
         final JiteClass cls = new JiteClass(className,
                 p(BytecodeBasicBlock.class),
                 new String[] {});
 
         cls.defineMethod("<init>".sig(void.classString.classboolean.classList.classList.class ),
                 new CodeBlock()
                     .aload(.)
                     // this
                     .aload(1)
                     // this filename
                     .iload(2)
                     // this filename strict
                     .aload(3)
                     // this filename strict vardecls
                     .aload(4)
                     // this filename strict vardecls fndecls
                     .invokespecial(p(BytecodeBasicBlock.class), "<init>",
                                   sig(void.classString.classboolean.classList.classList.class) )
                     // <empty>
                     .aload. )
                     // this
                     .invokevirtual(cls.getClassName().replace('.''/'), "initializeCode"sig(void.class))
                     // <empty>
                     .voidreturn()
                 );
 
         CompilationPlanner planner = new CompilationPlanner(getConfig(), context.getClassLoader(), getFactory());
 
         PartialCompiler compiler = null;
         if (body instanceof BlockStatement) {
             compiler = planner.plan((BlockStatementbody);
         } else {
             compiler = planner.plan(new BlockStatement(Collections.singletonList(body)));
         }
 
         compiler.define(clscontextfalse);
         Class<BytecodeBasicBlockblockClass = defineClass(context.getClassLoader(), cls);
 
         Position position = body.getPosition();
 
         String fileName = (position != null ? position.getFileName() : "eval");
         
         try {
             Constructor<BytecodeBasicBlockctor = blockClass.getDeclaredConstructor(String.classboolean.classList.classList.class);
             BasicBlock block = ctor.newInstance(fileNamestrictbody.getVariableDeclarations(), body.getFunctionDeclarations());
             entry.setCompiled(block);
             return block;
             throw new IllegalStateException(e);
         }
    }
    
    public String nextClassName(String grist) {
        return getConfig().getBasePackage().replace('.''/') + "/" + grist + nextCounterValue();
    }
    private int nextCounterValue() {
        return this..getAndIncrement();
    }
New to GrepCode? Check out our FAQ X