Skip to content

Commit

Permalink
Some minor improvements to Maker. Notably, prototypes no longer shado…
Browse files Browse the repository at this point in the history
…w other prototypes (which never made sense), there's a handy new --traceLive feature for seeing more detail about runtime state than you ever wanted and CodeMatcher has a new optimization pattern for the idiom 'drop false'.
  • Loading branch information
JohnEarnest committed Jun 10, 2012
1 parent b5eb777 commit d1f1593
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/CodeMatcher.java
Expand Up @@ -180,6 +180,10 @@ private void optimize() {
if (null != (r = match("tail call", Ops.Ret, Ops.Call, A))) {
addSeq(Ops.Jump, r.get(A));
}
if (null != (r = match("drop false", Ops.Const, 0, Ops.Drop))) {
addSeq(Ops.Dup);
addSeq(Ops.Xor);
}
}

private Map<Object, Integer> match(String name, Object... pattern) {
Expand Down
11 changes: 9 additions & 2 deletions src/Maker.java
Expand Up @@ -27,6 +27,7 @@ public static void main(String[] args) {
boolean quiet = pluckArg(argList, "--quiet") || pluckArg(argList, "-q");
boolean listing = pluckArg(argList, "--listing") || pluckArg(argList, "-l");
boolean trace = pluckArg(argList, "--trace");
boolean traceLive = pluckArg(argList, "--traceLive");
boolean showOpt = pluckArg(argList, "--showOpt");
boolean noOpt = pluckArg(argList, "--noOpt");
boolean gCode = pluckArg(argList, "--guardCode");
Expand Down Expand Up @@ -79,6 +80,7 @@ public static void main(String[] args) {
int[] mem = compiler.rom.toArray();
try {
Mako.trace = trace;
Mako.traceLive = traceLive;
Mako.guardCode = gCode;
Mako.guardStacks = gStack;
Mako.exec(mem, fuzz, compiler.rom);
Expand Down Expand Up @@ -262,6 +264,7 @@ else if (token.equals(":vector")) {
wordName = tokens.remove().toString();
defineWord(wordName, rom.size());
rom.addJump(rom.size()+2);
rom.setType(rom.size()-1, MakoRom.Type.Data);
}
else if (token.equals(";")) {
compiling = false;
Expand Down Expand Up @@ -364,11 +367,15 @@ else if (token.equals(":include")) {
}
else if (token.equals(":proto")) {
String wordName = tokens.remove().toString();
prototypes.put(wordName, new ArrayList<Integer>());
if (!prototypes.containsKey(wordName)) {
prototypes.put(wordName, new ArrayList<Integer>());
}
}
else if (token.equals(":ref")) {
String varName = tokens.remove().toString();
references.put(varName, new ArrayList<Integer>());
if (!references.containsKey(varName)) {
references.put(varName, new ArrayList<Integer>());
}
}

// branching constructs
Expand Down
35 changes: 35 additions & 0 deletions src/Mako.java
Expand Up @@ -28,6 +28,7 @@ public static void main(String[] args) {
}

public static boolean trace = false;
public static boolean traceLive = false;
public static boolean guardCode = false;
public static boolean guardStacks = false;

Expand Down Expand Up @@ -75,6 +76,20 @@ public static void exec(int[] rom, boolean fuzz, MakoRom traceRom) {
}
}

if (traceLive) {
int pc = view.vm.m[MakoConstants.PC];
int op = view.vm.m[pc];
int a = view.vm.m[pc+1];
int ra = view.vm.m[view.vm.m[MakoConstants.RP]-1];

if (op == MakoConstants.OP_CALL) {
System.out.format("%-16s@%05d:\t( %s )%n", traceRom.getLabel(a), a, traceStack(datMin, retMin, rom));
}
if (op == MakoConstants.OP_RETURN) {
System.out.format("RET %05d:\t( %s )%n", ra, traceStack(datMin, retMin, rom));
}
}

if (guardCode) {
int pc = view.vm.m[MakoConstants.PC];
int op = view.vm.m[pc];
Expand Down Expand Up @@ -192,6 +207,18 @@ public int compare(String o1, String o2) {
);
System.out.println();
}

private static String traceStack(int datMin, int retMin, int[] rom) {
String dstack = "";
for(int x = rom[MakoConstants.DP] - 1; x >= datMin; x--) {
dstack = rom[x] + " " + dstack;
}
String rstack = "";
for(int x = rom[MakoConstants.RP] - 1; x >= retMin; x--) {
rstack = rstack + " " + rom[x];
}
return String.format("%20s|%-30s", dstack, rstack);
}
}

class MakoPanel extends JPanel implements KeyListener, MakoConstants {
Expand Down Expand Up @@ -271,6 +298,14 @@ public void keyReleased(KeyEvent k) {
if (k.getKeyCode() == KeyEvent.VK_F5) {
showTicks = !showTicks;
}
if (k.getKeyCode() == KeyEvent.VK_F7) {
System.out.println("!");
Mako.traceLive = !Mako.traceLive;
}
if (k.getKeyCode() == KeyEvent.VK_F8) {
System.out.println("Interrupted!");
vm.m[MakoConstants.PC] = Integer.MAX_VALUE;
}
if (masks.containsKey(k.getKeyCode())) { keys &= (~masks.get(k.getKeyCode())); }
}
public void keyTyped(KeyEvent k) {
Expand Down

0 comments on commit d1f1593

Please sign in to comment.