-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.0 of the SNUSP interpreter. It correctly interprets Modular…
… SNUSP.
- Loading branch information
akm
committed
Mar 16, 2007
0 parents
commit 802b320
Showing
12 changed files
with
498 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>SNUSP Interpreter</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ATOI ITOA | ||
/!/@@@-@-----# /=!/=++++++++\ | ||
| | /--------/ | |/++++++++/ | ||
, , \--------\ | |\++++++++\ | ||
| | /--------/ | |/++++++++/ | ||
| | \--------\ | |\++++++++\ | ||
| > #--------/ | |#++++++++/ | ||
| | > < | ||
| | | | | ||
$=@/@/==!/==?\=<\/@/.@/.# | ||
| - || | ||
\>+</ |\======================\ | ||
| | | ||
| | | ||
/====>+<=======!\==========================\ | ||
| | | | ||
| /+=!/+=!/+=!/+=!/+=!/+=!/+=!/+=!/+==/ | | ||
| | | | | | | | | | ! | | ||
\==-\!?-\!?-\!?-\!?-\!?-\!?-\!?-\!?-\!?-\!?/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.malloys.akm.snusp; | ||
|
||
public class DeadThreadException extends RuntimeException | ||
{ | ||
|
||
public DeadThreadException() | ||
{ | ||
super(); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public DeadThreadException(String message, Throwable cause) | ||
{ | ||
super(message, cause); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public DeadThreadException(String message) | ||
{ | ||
super(message); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public DeadThreadException(Throwable cause) | ||
{ | ||
super(cause); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.malloys.akm.snusp; | ||
|
||
public enum Direction | ||
{ | ||
UP, | ||
DOWN, | ||
LEFT, | ||
RIGHT, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.malloys.akm.snusp; | ||
|
||
public enum SnuspInstruction | ||
{ | ||
NOOP, LEFT, RIGHT, ADD, SUB, LURD, DLUR, SKIP, SKIP_ZERO, CALL, RETURN, BEGIN, READ, WRITE; | ||
|
||
public static SnuspInstruction get(char c) | ||
{ | ||
switch (c) { | ||
case '<': | ||
return LEFT; | ||
case '>': | ||
return RIGHT; | ||
case '+': | ||
return ADD; | ||
case '-': | ||
return SUB; | ||
case '\\': | ||
return LURD; | ||
case '/': | ||
return DLUR; | ||
case '!': | ||
return SKIP; | ||
case '?': | ||
return SKIP_ZERO; | ||
case '@': | ||
return CALL; | ||
case '#': | ||
return RETURN; | ||
case '$': | ||
return BEGIN; | ||
case ',': | ||
return READ; | ||
case '.': | ||
return WRITE; | ||
default: | ||
return NOOP; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.malloys.akm.snusp; | ||
|
||
import org.malloys.akm.util.Pair; | ||
|
||
public class SnuspInstructionPointer implements Cloneable | ||
{ | ||
public SnuspInstructionPointer(Direction direction, | ||
Pair<Integer, Integer> position) | ||
{ | ||
this.direction = direction; | ||
this.position = position; | ||
} | ||
|
||
public void doLurd() | ||
{ | ||
direction = | ||
direction == Direction.LEFT ? Direction.UP : | ||
direction == Direction.UP ? Direction.LEFT : | ||
direction == Direction.DOWN ? Direction.RIGHT : | ||
Direction.DOWN; | ||
} | ||
|
||
public void doDlur() | ||
{ | ||
direction = | ||
direction == Direction.LEFT ? Direction.DOWN : | ||
direction == Direction.DOWN ? Direction.LEFT : | ||
direction == Direction.UP ? Direction.RIGHT : | ||
Direction.UP; | ||
} | ||
|
||
public SnuspInstructionPointer clone() | ||
{ | ||
try { | ||
SnuspInstructionPointer result = (SnuspInstructionPointer)super.clone(); | ||
result.position = position.clone(); | ||
return result; | ||
} catch (CloneNotSupportedException e) { | ||
return null; | ||
} | ||
} | ||
|
||
public Direction getDirection() | ||
{ | ||
return direction; | ||
} | ||
|
||
public Pair<Integer, Integer> getPosition() | ||
{ | ||
return position; | ||
} | ||
|
||
public void setDirection(Direction direction) | ||
{ | ||
this.direction = direction; | ||
} | ||
|
||
public void setPosition(Pair<Integer, Integer> position) | ||
{ | ||
this.position = position; | ||
} | ||
|
||
/** | ||
* Move the instruction pointer one unit in the current direction, regardless | ||
* of the content of the current instruction. Should only be called after the | ||
* instruction has been handled. | ||
*/ | ||
public void advance() | ||
{ | ||
if (direction == Direction.UP) | ||
position.y--; | ||
else if (direction == Direction.LEFT) | ||
position.x--; | ||
else if (direction == Direction.RIGHT) | ||
position.x++; | ||
else if (direction == Direction.DOWN) | ||
position.y++; | ||
} | ||
|
||
Direction direction; | ||
|
||
Pair<Integer, Integer> position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.malloys.akm.snusp; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class SnuspLauncher | ||
{ | ||
/** | ||
* @param args | ||
* @throws | ||
* @throws IOException | ||
*/ | ||
public static void main(String[] args) throws IOException | ||
{ | ||
SnuspProgram program = new SnuspProgram(new FileInputStream(args[0])); | ||
program.run(); | ||
} | ||
|
||
} |
Oops, something went wrong.