package org.jerlang.erts.emulator.op;

import org.jerlang.Module;
import org.jerlang.Process;
import org.jerlang.ProcessRegistry;
import org.jerlang.erts.emulator.Instruction;
import org.jerlang.type.Integer;
import org.jerlang.type.List;
import org.jerlang.type.PID;
import org.jerlang.type.Term;

/**
 * Send argument in x(1) as a message to the destination process in x(0).
 * The message in x(1) ends up as the result of the send in x(0).
 *
 * TODO: Original documentation says x(0) contains the message.
 */
public class Send {

    public static Term execute(Process proc, Module m, Instruction i, List params) {
        Term x = proc.getX(0);
        PID pid = proc.getX(0).toPID();
        Term message = proc.getX(1);
        Process destination = ProcessRegistry.resolve(pid);
        destination.send(message);
        proc.setX(Integer.of(0), message);
        return null;
    }

}

@@ -173,41 +173,8 @@
 on;%0A
-import org.jerlang.type.Integer;%0A
 impo
@@ -199,16 +199,16 @@
 e.List;%0A
+
 import o
@@ -407,75 +407,8 @@
 0).%0A
- *%0A * TODO: Original documentation says x(0) contains the message.%0A
  */%0A
@@ -517,39 +517,8 @@
 ) %7B%0A
-        Term x = proc.getX(0);%0A
     
@@ -707,21 +707,9 @@
 etX(
-Integer.of(0)
+0
 , me

send opcode impl contains unnecessary code