/* --------------------------------------------------------- *
* __________ D E L T A S C R I P T *
* (_________() *
* / === / - A fast, dynamic scripting language *
* | == | - Version 4.13.11.0 *
* / === / - Developed by Adam R. Nelson *
* | = = | - 2011-2013 *
* / === / - Distributed under GNU LGPL v3 *
* (________() - http://github.com/ar-nelson/deltascript *
* *
* --------------------------------------------------------- */
package com.sector91.delta.script.instrs;
import com.sector91.delta.script.DScriptErr;
import com.sector91.delta.script.DScriptExecutor;
import com.sector91.delta.script.Operator;
import com.sector91.delta.script.objects.DS_Boolean;
import com.sector91.delta.script.objects.DS_Object;
import com.sector91.delta.script.objects.DS_Scope;
final class OpInstr extends DSInstr
{
public final Operator operator;
protected OpInstr(int start, short len, String head, DSInstr[] tail)
{
super(start, len, head, tail);
if (tail.length == 1)
operator = Operator.getUnaryOperator(head);
else
operator = Operator.getBinaryOperator(head);
}
public DS_Object exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
try
{
final DS_Object o1 = tail[0].exec(scope, executor);
final DS_Object o2 = (tail.length == 2) ?
tail[1].exec(scope, executor) : null;
return o1.operator(operator, o2);
}
catch (DScriptErr ex)
{throw rethrow(ex);}
catch (RuntimeException ex)
{throw rethrow(ex);}
}
public InstrType type()
{return InstrType.OP;}
}
final class TypeChkInstr extends DSInstr
{
public TypeChkInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).is(
tail[1].exec(scope, executor)));
}
public InstrType type()
{return InstrType.TYPECHK;}
}
final class EqInstr extends DSInstr
{
public EqInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).equals(
tail[1].exec(scope, executor)));
}
public InstrType type()
{return InstrType.EQ;}
}
final class NeInstr extends DSInstr
{
public NeInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(!tail[0].exec(scope, executor).equals(
tail[1].exec(scope, executor)));
}
public InstrType type()
{return InstrType.NE;}
}
final class LtInstr extends DSInstr
{
public LtInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).compare(
tail[1].exec(scope, executor)) < 0);
}
public InstrType type()
{return InstrType.LT;}
}
final class LeInstr extends DSInstr
{
public LeInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).compare(
tail[1].exec(scope, executor)) <= 0);
}
public InstrType type()
{return InstrType.LE;}
}
final class GtInstr extends DSInstr
{
public GtInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).compare(
tail[1].exec(scope, executor)) > 0);
}
public InstrType type()
{return InstrType.GT;}
}
final class GeInstr extends DSInstr
{
public GeInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
return DS_Boolean.box(tail[0].exec(scope, executor).compare(
tail[1].exec(scope, executor)) >= 0);
}
public InstrType type()
{return InstrType.GE;}
}
final class NotInstr extends DSInstr
{
public NotInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Boolean exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{return DS_Boolean.box(!tail[0].exec(scope, executor).booleanValue());}
public InstrType type()
{return InstrType.NOT;}
}
final class AndInstr extends DSInstr
{
public AndInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Object exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
final DS_Object o1 = tail[0].exec(scope, executor);
return o1.booleanValue() ? tail[1].exec(scope, executor) : o1;
}
public InstrType type()
{return InstrType.AND;}
}
final class OrInstr extends DSInstr
{
public OrInstr(int start, short len, String head, DSInstr... tail)
{super(start, len, head, tail);}
public DS_Object exec(DS_Scope scope, DScriptExecutor executor)
throws DScriptErr
{
final DS_Object o1 = tail[0].exec(scope, executor);
return o1.booleanValue() ? o1 : tail[1].exec(scope, executor);
}
public InstrType type()
{return InstrType.OR;}
}