<commit_before>/*
	Leola Programming Language
	Author: <NAME>
	See license.txt
*/
package leola.vm.types;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import leola.vm.VM;
import leola.vm.asm.Bytecode;
import leola.vm.asm.Symbols;


/**
 * A {@link LeoGenerator} is an object that behaves like a function, but
 * is "resumeable" from a yield statement.  That is, after successive invocations
 * it will pick up executing the function after the yield statement.
 * 
 * <p>
 * Example:
 * <pre>
 *   var talk = gen() {
 *     var i = 0
 *     yield "Hello: " + i
 *     i += 1
 *     yield "World: " + i
 *   }
 *   
 *   println( talk() ) // prints Hello: 0
 *   println( talk() ) // prints World: 1
 *   println( talk() ) // prints null, the function is done computing
 *   
 * </pre>
 *
 * @author Tony
 *
 */
public class LeoGenerator extends LeoOuterObject {

	/**
	 * Arguments
	 */
	private int numberOfArgs;

	/**
	 * Body
	 */
	private Bytecode bytecode;

	/**
	 * The environment it was created in
	 */
	private LeoObject env;
	
	/**
	 * The locals that need to be saved with this
	 * generator
	 */
	private LeoObject[] locals;
	
	/**
	 * @param type
	 * @param numberOfArgs
	 * @param body
	 */
	public LeoGenerator(LeoObject env, Bytecode bytecode) {
		super(LeoType.FUNCTION, bytecode.numOuters);
		
		this.env = env;
		this.bytecode = bytecode;
		this.numberOfArgs = bytecode.numArgs;
		this.locals = new LeoObject[bytecode.numLocals];
	}
	
	/* (non-Javadoc)
	 * @see leola.vm.types.LeoObject#add(leola.vm.types.LeoObject)
	 */
	@Override
	public LeoObject $add(LeoObject other) {
		if (other.isString()) {
			return LeoString.valueOf(toString() + other.toString());
		}
		return super.$add(other);
	}
	
	/**
	 * @return the locals
	 */
	public LeoObject[] getLocals() {
		return locals;
	}
	
	/* (non-Javadoc)
	 * @see leola.vm.types.LeoObject#isGenerator()
	 */
	@Override<commit_msg>Changed type to Generator<commit_after>/*
	Leola Programming Language
	Author: <NAME>
	See license.txt
*/
package leola.vm.types;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import leola.vm.VM;
import leola.vm.asm.Bytecode;
import leola.vm.asm.Symbols;


/**
 * A {@link LeoGenerator} is an object that behaves like a function, but
 * is "resumeable" from a yield statement.  That is, after successive invocations
 * it will pick up executing the function after the yield statement.
 * 
 * <p>
 * Example:
 * <pre>
 *   var talk = gen() {
 *     var i = 0
 *     yield "Hello: " + i
 *     i += 1
 *     yield "World: " + i
 *   }
 *   
 *   println( talk() ) // prints Hello: 0
 *   println( talk() ) // prints World: 1
 *   println( talk() ) // prints null, the function is done computing
 *   
 * </pre>
 *
 * @author Tony
 *
 */
public class LeoGenerator extends LeoOuterObject {

	/**
	 * Arguments
	 */
	private int numberOfArgs;

	/**
	 * Body
	 */
	private Bytecode bytecode;

	/**
	 * The environment it was created in
	 */
	private LeoObject env;
	
	/**
	 * The locals that need to be saved with this
	 * generator
	 */
	private LeoObject[] locals;
	
	/**
	 * @param type
	 * @param numberOfArgs
	 * @param body
	 */
	public LeoGenerator(LeoObject env, Bytecode bytecode) {
		super(LeoType.GENERATOR, bytecode.numOuters);
		
		this.env = env;
		this.bytecode = bytecode;
		this.numberOfArgs = bytecode.numArgs;
		this.locals = new LeoObject[bytecode.numLocals];
	}
	
	/* (non-Javadoc)
	 * @see leola.vm.types.LeoObject#add(leola.vm.types.LeoObject)
	 */
	@Override
	public LeoObject $add(LeoObject other) {
		if (other.isString()) {
			return LeoString.valueOf(toString() + other.toString());
		}
		return super.$add(other);
	}
	
	/**
	 * @return the locals
	 */
	public LeoObject[] getLocals() {
		return locals;
	}
	
	/* (non-Javadoc)
	 * @see leola.vm.types.LeoObject#isGenerator()
	 */
	@Override
{'fraction_non_alphanumeric': 0.13487773487773488, 'fraction_numerical': 0.002059202059202059, 'mean_word_length': 2.9734151329243352, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2960697', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1295, 'n_words': 360}