Skip to content

Commit

Permalink
simplify. improve disassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Apr 7, 2017
1 parent 2f2b774 commit 6a11bba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
22 changes: 11 additions & 11 deletions simple-virtual-machine.ipr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
Expand All @@ -13,21 +11,23 @@
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="" />
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="IdProvider" IDEtalkID="97D7DBFBCE4D11CA285C5356222AF1E5" />
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
</profile>
<version value="1.0" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.1" />
</component>
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
Expand Down Expand Up @@ -154,7 +154,7 @@
<module fileurl="file://$PROJECT_DIR$/simple-virtual-machine.iml" filepath="$PROJECT_DIR$/simple-virtual-machine.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="VcsDirectoryMappings">
Expand Down
2 changes: 1 addition & 1 deletion src/vm/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class Test {

public static void main(String[] args) {
VM vm = new VM(factorial, 0, factorial_metadata);
vm.trace = false;
vm.trace = true;
vm.exec(factorial_metadata[0].address);

vm = new VM(f, 2, f_metadata);
Expand Down
16 changes: 7 additions & 9 deletions src/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ protected void cpu() {
case ICONST:
stack[++sp] = code[ip++]; // push operand
break;
case LOAD : // load local or arg; 1st local is fp+1, args are fp-3, fp-4, fp-5, ...
load();
case LOAD : // load local or arg
regnum = code[ip++];
stack[++sp] = ctx.locals[regnum];
break;
case GLOAD :// load from global memory
addr = code[ip++];
Expand Down Expand Up @@ -159,12 +160,6 @@ protected void cpu() {
if ( trace ) dumpDataMemory();
}

private void load() {
int regnum;
regnum = code[ip++];
stack[++sp] = ctx.locals[regnum];
}

protected String stackString() {
StringBuilder buf = new StringBuilder();
buf.append("stack=[");
Expand Down Expand Up @@ -195,7 +190,10 @@ protected String disInstr() {
StringBuilder buf = new StringBuilder();
buf.append(String.format("%04d:\t%-11s", ip, opName));
int nargs = Bytecode.instructions[opcode].n;
if ( nargs>0 ) {
if ( opcode==CALL ) {
buf.append(metadata[code[ip+1]].name);
}
else if ( nargs>0 ) {
List<String> operands = new ArrayList<String>();
for (int i=ip+1; i<=ip+nargs; i++) {
operands.add(String.valueOf(code[i]));
Expand Down

0 comments on commit 6a11bba

Please sign in to comment.