use of suite.node.Atom in project suite by stupidsing.
the class FunInstructionExecutor method handle.
@Override
protected void handle(Exec exec, Instruction insn) {
Activation current = exec.current;
Frame frame = current.frame;
Object[] regs = frame != null ? frame.registers : null;
Object[] ds = exec.stack;
int dsp = exec.sp;
Node n0, n1, result;
Data<?> data;
switch(insn.insn) {
case CALLINTRINSIC_:
data = (Data<?>) ds[--dsp];
List<Node> ps = new ArrayList<>(3);
for (int i = 1; i < insn.op1; i++) ps.add((Node) ds[--dsp]);
result = Data.<Intrinsic>get(data).invoke(intrinsicCallback, ps);
break;
case COMPARE_______:
n0 = (Node) ds[--dsp];
n1 = (Node) ds[--dsp];
result = Int.of(comparer.compare(n0, n1));
break;
case CONSLIST______:
n0 = (Node) ds[--dsp];
n1 = (Node) ds[--dsp];
result = Tree.of(TermOp.OR____, n0, n1);
break;
case CONSPAIR______:
n0 = (Node) ds[--dsp];
n1 = (Node) ds[--dsp];
result = Tree.of(TermOp.AND___, n0, n1);
break;
case DATACHARS_____:
result = new Data<>(To.chars(((Str) regs[insn.op1]).value));
break;
case GETINTRINSIC__:
Atom atom = (Atom) ds[--dsp];
String intrinsicName = atom.name.split("!")[1];
result = new Data<>(Intrinsics.intrinsics.get(intrinsicName));
break;
case HEAD__________:
result = Tree.decompose((Node) ds[--dsp]).getLeft();
break;
case ISCONS________:
result = atom(Tree.decompose((Node) ds[--dsp]) != null);
break;
case TAIL__________:
result = Tree.decompose((Node) ds[--dsp]).getRight();
break;
default:
result = Fail.t("unknown instruction " + insn);
}
exec.sp = dsp;
regs[insn.op0] = result;
}
use of suite.node.Atom in project suite by stupidsing.
the class InstructionExtractor method extract.
private Instruction extract(List<Node> rs) {
String insnName = ((Atom) rs.get(0)).name;
Insn insn;
if (Objects.equals(insnName, "EVALUATE")) {
Atom atom = (Atom) rs.remove(3);
TermOp operator = TermOp.find(atom.name);
insn = InstructionUtil.getEvalInsn(operator);
} else
insn = InstructionUtil.getInsn(insnName);
if (insn != null) {
Instruction instruction = new //
Instruction(//
insn, //
getRegisterNumber(rs, 1), //
getRegisterNumber(rs, 2), getRegisterNumber(rs, 3));
if (insn == Insn.FRAMEBEGIN____)
frameBegins.push(instruction);
else if (insn == Insn.FRAMEEND______)
frameBegins.pop();
return instruction;
} else
return Fail.t("unknown opcode " + insnName);
}
Aggregations