view core/src/luan/impl/BinaryOpExpr.java @ 652:067d9470184d

compile SetStmt and ForStmt
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Apr 2016 23:26:06 -0600
parents 8e8c30b72e9b
children
line wrap: on
line source

package luan.impl;

import luan.Luan;
import luan.LuanTable;
import luan.LuanFunction;
import luan.LuanException;


abstract class BinaryOpExpr extends CodeImpl implements Expr {
	final Expr op1;
	final Expr op2;

	BinaryOpExpr(Expr op1,Expr op2) {
		this.op1 = op1;
		this.op2 = op2;
	}

	Object arithmetic(LuanStateImpl luan,String op,Object o1,Object o2) throws LuanException {
		LuanFunction fn = Luan.getBinHandler(op,o1,o2);
		if( fn != null )
			return Luan.first(fn.call(luan,new Object[]{o1,o2}));
		String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2);
		throw new LuanException("attempt to perform arithmetic on a "+type+" value");
	}

}