Package st.gravel.support.compiler.jvm

Source Code of st.gravel.support.compiler.jvm.JVMBlockCompiler

package st.gravel.support.compiler.jvm;

/*
  This file is automatically generated from typed smalltalk source. Do not edit by hand.
  (C) AG5.com
*/

import java.math.BigInteger;
import st.gravel.support.jvm.NonLocalReturn;
import st.gravel.support.compiler.jvm.JVMClassCompiler;
import st.gravel.support.compiler.jvm.BlockInnerClass;
import st.gravel.support.compiler.jvm.JVMDefinedObjectType;
import st.gravel.support.compiler.jvm.JVMClass;
import st.gravel.support.compiler.jvm.JVMMethod;
import st.gravel.support.compiler.jvm.JVMField;
import st.gravel.support.compiler.jvm.JVMMethodCompiler;
import st.gravel.support.compiler.jvm.JVMVariable;
import st.gravel.support.compiler.jvm.BlockSendArgument;
import java.util.List;
import st.gravel.support.compiler.jvm.JVMInstruction;
import st.gravel.support.compiler.jvm.Load;
import st.gravel.support.compiler.jvm.JVMLocalDeclaration;
import java.util.ArrayList;
import st.gravel.support.compiler.jvm.PutField;
import st.gravel.support.compiler.jvm.InvokeSpecial;
import st.gravel.support.compiler.jvm.JVMType;
import st.gravel.support.compiler.jvm.Return;

public class JVMBlockCompiler extends Object implements Cloneable {

  public static JVMBlockCompiler_Factory factory = new JVMBlockCompiler_Factory();

  BlockInnerClass _block;

  JVMClassCompiler _parent;

  public static class JVMBlockCompiler_Factory extends st.gravel.support.jvm.SmalltalkFactory {

    public JVMBlockCompiler basicNew() {
      JVMBlockCompiler newInstance = new JVMBlockCompiler();
      newInstance.initialize();
      return newInstance;
    }

    public JVMBlockCompiler parent_block_(final JVMClassCompiler _aJVMClassCompiler, final BlockInnerClass _aBlockInnerClass) {
      return this.basicNew().initializeParent_block_(_aJVMClassCompiler, _aBlockInnerClass);
    }
  }

  static public JVMBlockCompiler _parent_block_(Object receiver, final JVMClassCompiler _aJVMClassCompiler, final BlockInnerClass _aBlockInnerClass) {
    return factory.parent_block_(_aJVMClassCompiler, _aBlockInnerClass);
  }

  public BlockInnerClass block() {
    return _block;
  }

  public JVMDefinedObjectType blockSuperType_(final int _anInteger) {
    return JVMDefinedObjectType.factory.block_(_anInteger);
  }

  public JVMClass compileBlock() {
    final JVMMethod _m;
    final JVMField[] _fields;
    final JVMMethodCompiler _methodCompiler;
    final JVMClass _jvmClass;
    _fields = st.gravel.support.jvm.ArrayExtensions.collect_(_block.copiedVariables(), ((st.gravel.support.jvm.Block1<JVMField, JVMVariable>) (new st.gravel.support.jvm.Block1<JVMField, JVMVariable>() {

      @Override
      public JVMField value_(final JVMVariable _each) {
        return (JVMField) _each.asField_isStatic_(_block.ownerType(), false);
      }
    })));
    _methodCompiler = JVMMethodCompiler.factory.parent_(_parent);
    _methodCompiler.isStatic_(false);
    _m = _methodCompiler.buildBlock_copiedVariables_blockType_(_block.blockNode(), _fields, _block.ownerType());
    _jvmClass = JVMClass.factory.type_superType_fields_methods_astConstants_(_block.ownerType(), this.superType(), _fields, st.gravel.support.jvm.ArrayFactory.with_with_(_m, this.createInit()), new BlockSendArgument[] {});
    if (_block.blockNode().sourcePosition() != null) {
      _jvmClass.source_(_block.blockNode().sourcePosition().sourceFile().name());
    }
    return _jvmClass;
  }

  public JVMBlockCompiler copy() {
    try {
      JVMBlockCompiler _temp1 = (JVMBlockCompiler) this.clone();
      _temp1.postCopy();
      return _temp1;
    } catch (CloneNotSupportedException e) {
      throw new RuntimeException(e);
    }
  }

  public JVMMethod createInit() {
    final List<JVMInstruction>[] _instructions;
    final Load[] _read0;
    final JVMLocalDeclaration[] _locals;
    _instructions = new List[1];
    _read0 = new Load[1];
    _instructions[0] = new java.util.ArrayList();
    _read0[0] = Load.factory.index_type_(0, _block.ownerType());
    for (int _temp1 = 0; _temp1 < _block.copiedVariables().length; _temp1++) {
      final int _i = _temp1 + 1;
      final JVMVariable _elem = _block.copiedVariables()[_temp1];
      _instructions[0].add(_read0[0]);
      _instructions[0].add(Load.factory.index_type_(_i, _elem.type()));
      _instructions[0].add(PutField.factory.ownerType_name_type_(_block.ownerType(), _elem.varName(), _elem.type()));
    }
    _instructions[0].add(_read0[0]);
    _instructions[0].add(InvokeSpecial.factory.init_voidArguments_(this.superType(), new JVMType[] {}));
    _instructions[0].add(Return.factory.basicNew());
    _locals = st.gravel.support.jvm.ArrayExtensions.copyWithFirst_(st.gravel.support.jvm.ArrayExtensions.keysAndValuesCollect_(_block.copiedVariables(), new st.gravel.support.jvm.Block2<JVMLocalDeclaration, Integer, JVMVariable>() {

      @Override
      public JVMLocalDeclaration value_value_(final Integer _i, final JVMVariable _var) {
        return (JVMLocalDeclaration) _var.asLocalDeclaration_(_i);
      }
    }), JVMLocalDeclaration.factory.blockSelf());
    return JVMMethod.factory.name_locals_instructions_isStatic_signature_("<init>", _locals, _instructions[0].toArray(new JVMInstruction[_instructions[0].size()]), false, _block.initSignature());
  }

  public JVMBlockCompiler_Factory factory() {
    return factory;
  }

  public JVMBlockCompiler initialize() {
    return this;
  }

  public JVMBlockCompiler initializeParent_block_(final JVMClassCompiler _aJVMClassCompiler, final BlockInnerClass _aBlockInnerClass) {
    _parent = _aJVMClassCompiler;
    _block = _aBlockInnerClass;
    this.initialize();
    return this;
  }

  public JVMClassCompiler parent() {
    return _parent;
  }

  public JVMBlockCompiler postCopy() {
    return this;
  }

  public JVMDefinedObjectType superType() {
    return this.blockSuperType_(_block.blockNode().numArgs());
  }
}
TOP

Related Classes of st.gravel.support.compiler.jvm.JVMBlockCompiler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.