Question: Please complete number 1 only. We need to add 3 byte code files as mentioned LINE, FUNCTION AND FORMAL. One example of such code is
Please complete number 1 only. One example of such code is CallCode.java provided below: /* import interpreter.VirtualMachine;
We need to add 3 byte code files as mentioned LINE, FUNCTION AND FORMAL.
* Transfer control to the indicated function
*/
package interpreter.ByteCode;
import java.util.ArrayList;
public class CallCode extends BranchCode {
protected String functionName;
protected int targetAddress;
protected int value;
public void init(ArrayList args) {
functionName = args.get(0);
}
public void execute(VirtualMachine vm) {
vm.returnAddrs.push(vm.pc);
vm.pc = targetAddress;
value = vm.runStack.peek();
//verify if the dump is on
if("ON".equals(vm.dumpMode)) {
int n = functionName.indexOf("String temp;
if(ntemp = functionName;
}else{
temp = functionName.substring(0,n);
}
System.out.println("CALL " + functionName + " " + temp + "(" + value + ")");
}
}
public int getTargetAddress(){
return targetAddress;
}
public void setTargetAddress(int n){
targetAddress = n;
}
public String getLabel(){
return functionName;
}
}
New Implementation 1. You must add three new byte codes - LINE, FUNCTION, and FORMAL - to the set of byte codes we are implementing. All existing byte codes should continue to function, and may need to add behavior to support debugging. Bytecode Example Description LINE LINE n LINE 5 n is the current source line number; the generated byte codes for line n will follow this code. FUNCTION FUNCTION name start end FUNCTION 9 1 20 name is the name of the function, FORMAL FORMAL name offset FORMAL f1 0 start is the source code line that this function starts on, and end is the source code line that this function ends on. name is the name of the formal parameter, offset is the stack offset for the variable. a. The FUNCTION and FORMAL byte codes will be generated as a header for each function declaration. The byte codes generated for each function will begin with: LABEL namel LINE n FUNCTION name start end FORMAL f1 0 FORMAL f2 1 - - - branch label for function call start of function definition name of function with source line number boundaries given by start and end fl is first formal with offset 0 f2 is second formal with offset 1 b. When debugging, we will not need to dump(), so no dump behavior is required for these byte codes. 2. You must implement the FunctionEnvironment Record that will be used to track the current
Step by Step Solution
3.53 Rating (150 Votes )
There are 3 Steps involved in it
1 LINE Bytecode Purpose Marks the starting line number for subsequent bytecode instructions Class Structure Java package interpreterByteCode public class LineCode extends ByteCode private int lineNumb... View full answer
Get step-by-step solutions from verified subject matter experts
