All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prompto.literal.TextLiteral Maven / Gradle / Ivy

The newest version!
package prompto.literal;

import prompto.compiler.Flags;
import prompto.compiler.IConstantOperand;
import prompto.compiler.MethodInfo;
import prompto.compiler.Opcode;
import prompto.compiler.ResultInfo;
import prompto.compiler.StringConstant;
import prompto.runtime.Context;
import prompto.transpiler.Transpiler;
import prompto.type.IType;
import prompto.type.TextType;
import prompto.utils.StringUtils;
import prompto.value.TextValue;


public class TextLiteral extends Literal {

	public TextLiteral(String text) {
		super(text, new TextValue(StringUtils.unescape(text)));
	}

	@Override
	public IType check(Context context) {
		return TextType.instance();
	}
	

	@Override
	public ResultInfo compile(Context context, MethodInfo method, Flags flags) {
		IConstantOperand operand = new StringConstant(value.getStorableData());
		method.addInstruction(Opcode.LDC_W, operand);
		return new ResultInfo(String.class);
	}
	
	@Override
	public void declare(Transpiler transpiler) {
		// nothing to do
	}
	
	@Override
	public boolean transpile(Transpiler transpiler) {
		transpiler.append(this.text.get());
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy