Skip to content

Commit

Permalink
Bytecode compiler refactoring to allow keywords override
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Nov 15, 2023
1 parent 574aea6 commit a2d856b
Show file tree
Hide file tree
Showing 12 changed files with 1,196 additions and 1,009 deletions.
2 changes: 1 addition & 1 deletion build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.maccasoft</groupId>
<artifactId>spin-tools-runtime</artifactId>
<version>0.32.1</version>
<version>0.33.0</version>
<packaging>pom</packaging>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion modules/spin-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.maccasoft</groupId>
<artifactId>spin-tools</artifactId>
<version>0.32.1</version>
<version>0.33.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5123,49 +5123,80 @@ void testBytesWordsLongs() throws Exception {
+ " b := words(\"1234\", byte 13, 10)\n"
+ " c := longs(\"1234\", word 13, 10)\n"
+ "\n"
+ " test(bytes(\"1234\", 13, 10))\n"
+ " test(words(\"1234\", 13, 10))\n"
+ " test(longs(\"1234\", 13, 10))\n"
+ "\n"
+ "PUB test(p)\n"
+ "\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 4)\n"
+ "00000 00000 08 00 00 80 Method main @ $00008 (0 parameters, 0 returns)\n"
+ "00004 00004 70 00 00 00 End\n"
+ "00000 00000 0C 00 00 80 Method main @ $0000C (0 parameters, 0 returns)\n"
+ "00004 00004 AD 00 00 81 Method test @ $000AD (1 parameters, 0 returns)\n"
+ "00008 00008 AF 00 00 00 End\n"
+ "' PUB main() | a, b, c\n"
+ "00008 00008 03 (stack size)\n"
+ "0000C 0000C 03 (stack size)\n"
+ "' a := bytes(\"1234\", 13, 10)\n"
+ "00009 00009 9E 06 31 32 33 BYTES\n"
+ "0000E 0000E 34 0D 0A\n"
+ "00011 00011 F0 VAR_WRITE LONG DBASE+$00000 (short)\n"
+ "0000D 0000D 9E 06 31 32 33 BYTES\n"
+ "00012 00012 34 0D 0A\n"
+ "00015 00015 F0 VAR_WRITE LONG DBASE+$00000 (short)\n"
+ "' b := words(\"1234\", 13, 10)\n"
+ "00012 00012 9E 0C 31 00 32 WORDS\n"
+ "00017 00017 00 33 00 34 00\n"
+ "0001C 0001C 0D 00 0A 00\n"
+ "00020 00020 F1 VAR_WRITE LONG DBASE+$00001 (short)\n"
+ "00016 00016 9E 0C 31 00 32 WORDS\n"
+ "0001B 0001B 00 33 00 34 00\n"
+ "00020 00020 0D 00 0A 00\n"
+ "00024 00024 F1 VAR_WRITE LONG DBASE+$00001 (short)\n"
+ "' c := longs(\"1234\", 13, 10)\n"
+ "00021 00021 9E 18 31 00 00 LONGS\n"
+ "00026 00026 00 32 00 00 00\n"
+ "0002B 0002B 33 00 00 00 34\n"
+ "00030 00030 00 00 00 0D 00\n"
+ "00035 00035 00 00 0A 00 00\n"
+ "0003A 0003A 00\n"
+ "0003B 0003B F2 VAR_WRITE LONG DBASE+$00002 (short)\n"
+ "00025 00025 9E 18 31 00 00 LONGS\n"
+ "0002A 0002A 00 32 00 00 00\n"
+ "0002F 0002F 33 00 00 00 34\n"
+ "00034 00034 00 00 00 0D 00\n"
+ "00039 00039 00 00 0A 00 00\n"
+ "0003E 0003E 00\n"
+ "0003F 0003F F2 VAR_WRITE LONG DBASE+$00002 (short)\n"
+ "' a := bytes(\"1234\", long 13, 10)\n"
+ "0003C 0003C 9E 09 31 32 33 BYTES\n"
+ "00041 00041 34 0D 00 00 00\n"
+ "00046 00046 0A\n"
+ "00047 00047 F0 VAR_WRITE LONG DBASE+$00000 (short)\n"
+ "00040 00040 9E 09 31 32 33 BYTES\n"
+ "00045 00045 34 0D 00 00 00\n"
+ "0004A 0004A 0A\n"
+ "0004B 0004B F0 VAR_WRITE LONG DBASE+$00000 (short)\n"
+ "' b := words(\"1234\", byte 13, 10)\n"
+ "00048 00048 9E 0B 31 00 32 WORDS\n"
+ "0004D 0004D 00 33 00 34 00\n"
+ "00052 00052 0D 0A 00\n"
+ "00055 00055 F1 VAR_WRITE LONG DBASE+$00001 (short)\n"
+ "0004C 0004C 9E 0B 31 00 32 WORDS\n"
+ "00051 00051 00 33 00 34 00\n"
+ "00056 00056 0D 0A 00\n"
+ "00059 00059 F1 VAR_WRITE LONG DBASE+$00001 (short)\n"
+ "' c := longs(\"1234\", word 13, 10)\n"
+ "00056 00056 9E 16 31 00 00 LONGS\n"
+ "0005B 0005B 00 32 00 00 00\n"
+ "00060 00060 33 00 00 00 34\n"
+ "00065 00065 00 00 00 0D 00\n"
+ "0006A 0006A 0A 00 00 00\n"
+ "0006E 0006E F2 VAR_WRITE LONG DBASE+$00002 (short)\n"
+ "0006F 0006F 04 RETURN\n"
+ "0005A 0005A 9E 16 31 00 00 LONGS\n"
+ "0005F 0005F 00 32 00 00 00\n"
+ "00064 00064 33 00 00 00 34\n"
+ "00069 00069 00 00 00 0D 00\n"
+ "0006E 0006E 0A 00 00 00\n"
+ "00072 00072 F2 VAR_WRITE LONG DBASE+$00002 (short)\n"
+ "' test(bytes(\"1234\", 13, 10))\n"
+ "00073 00073 00 ANCHOR\n"
+ "00074 00074 9E 06 31 32 33 BYTES\n"
+ "00079 00079 34 0D 0A\n"
+ "0007C 0007C 0A 01 CALL_SUB (1)\n"
+ "' test(words(\"1234\", 13, 10))\n"
+ "0007E 0007E 00 ANCHOR\n"
+ "0007F 0007F 9E 0C 31 00 32 WORDS\n"
+ "00084 00084 00 33 00 34 00\n"
+ "00089 00089 0D 00 0A 00\n"
+ "0008D 0008D 0A 01 CALL_SUB (1)\n"
+ "' test(longs(\"1234\", 13, 10))\n"
+ "0008F 0008F 00 ANCHOR\n"
+ "00090 00090 9E 18 31 00 00 LONGS\n"
+ "00095 00095 00 32 00 00 00\n"
+ "0009A 0009A 33 00 00 00 34\n"
+ "0009F 0009F 00 00 00 0D 00\n"
+ "000A4 000A4 00 00 0A 00 00\n"
+ "000A9 000A9 00\n"
+ "000AA 000AA 0A 01 CALL_SUB (1)\n"
+ "000AC 000AC 04 RETURN\n"
+ "' PUB test(p)\n"
+ "000AD 000AD 00 (stack size)\n"
+ "000AE 000AE 04 RETURN\n"
+ "000AF 000AF 00 Padding\n"
+ "", compile(text));
}

Expand Down Expand Up @@ -6195,6 +6226,101 @@ void testChainedAssignments() throws Exception {
+ "", compile(text));
}

@Test
void testMethodKeywordsOverride() throws Exception {
String text = ""
+ "PUB start()\n"
+ "\n"
+ " bytes(1, 2)\n"
+ "\n"
+ "PUB bytes(a, b)\n"
+ "\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 4)\n"
+ "00000 00000 0C 00 00 80 Method start @ $0000C (0 parameters, 0 returns)\n"
+ "00004 00004 13 00 00 82 Method bytes @ $00013 (2 parameters, 0 returns)\n"
+ "00008 00008 15 00 00 00 End\n"
+ "' PUB start()\n"
+ "0000C 0000C 00 (stack size)\n"
+ "' bytes(1, 2)\n"
+ "0000D 0000D 00 ANCHOR\n"
+ "0000E 0000E A2 CONSTANT (1)\n"
+ "0000F 0000F A3 CONSTANT (2)\n"
+ "00010 00010 0A 01 CALL_SUB (1)\n"
+ "00012 00012 04 RETURN\n"
+ "' PUB bytes(a, b)\n"
+ "00013 00013 00 (stack size)\n"
+ "00014 00014 04 RETURN\n"
+ "00015 00015 00 00 00 Padding\n"
+ "", compile(text));
}

@Test
void testLocalVariableKeywordsOverride() throws Exception {
String text = ""
+ "PUB start()\n"
+ "\n"
+ " test(bytes(1, 2))\n"
+ "\n"
+ "PUB test(bytes) | a, i\n"
+ "\n"
+ " a := byte[bytes][i]\n"
+ "\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 4)\n"
+ "00000 00000 0C 00 00 80 Method start @ $0000C (0 parameters, 0 returns)\n"
+ "00004 00004 15 00 00 81 Method test @ $00015 (1 parameters, 0 returns)\n"
+ "00008 00008 1C 00 00 00 End\n"
+ "' PUB start()\n"
+ "0000C 0000C 00 (stack size)\n"
+ "' test(bytes(1, 2))\n"
+ "0000D 0000D 00 ANCHOR\n"
+ "0000E 0000E 9E 02 01 02 BYTES\n"
+ "00012 00012 0A 01 CALL_SUB (1)\n"
+ "00014 00014 04 RETURN\n"
+ "' PUB test(bytes) | a, i\n"
+ "00015 00015 02 (stack size)\n"
+ "' a := byte[bytes][i]\n"
+ "00016 00016 E0 VAR_READ LONG DBASE+$00000 (short)\n"
+ "00017 00017 E2 VAR_READ LONG DBASE+$00002 (short)\n"
+ "00018 00018 63 80 MEM_READ BYTE INDEXED\n"
+ "0001A 0001A F1 VAR_WRITE LONG DBASE+$00001 (short)\n"
+ "0001B 0001B 04 RETURN\n"
+ "", compile(text));
}

@Test
void testGlobalVariableKeywordsOverride() throws Exception {
String text = ""
+ "VAR\n"
+ "\n"
+ " long words[2]\n"
+ "\n"
+ "PUB start()\n"
+ "\n"
+ " words := longs(1, 2)\n"
+ "\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 12)\n"
+ "00000 00000 08 00 00 80 Method start @ $00008 (0 parameters, 0 returns)\n"
+ "00004 00004 16 00 00 00 End\n"
+ "' PUB start()\n"
+ "00008 00008 00 (stack size)\n"
+ "' words := longs(1, 2)\n"
+ "00009 00009 9E 08 01 00 00 LONGS\n"
+ "0000E 0000E 00 02 00 00 00\n"
+ "00013 00013 C1 81 VAR_WRITE LONG VBASE+$00001 (short)\n"
+ "00015 00015 04 RETURN\n"
+ "00016 00016 00 00 Padding\n"
+ "", compile(text));
}

String compile(String text) throws Exception {
return compile(text, false);
}
Expand Down
62 changes: 31 additions & 31 deletions modules/spin-tools/src/com/maccasoft/propeller/SourceEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,45 +653,45 @@ public void mouseHover(MouseEvent e) {
}

if (token != null && helpProvider != null) {
String text = helpProvider.getString(context != null ? context.getClass().getSimpleName() : null, token.getText().toLowerCase());
if (text == null) {
text = tokenMarker.getMethod(token.getText());
if (text == null && token.getText().startsWith("@")) {
text = tokenMarker.getMethod(token.getText().substring(1));
}
if (text == null && token.getText().startsWith(".")) {
int line = styledText.getLineAtOffset(offset);
int lineOffset = styledText.getOffsetAtLine(line);
String lineText = styledText.getLine(line);
int endIndex = token.start - lineOffset - 1;
if (lineText.charAt(endIndex) == ']') {
int depth = -1;
while (endIndex >= 0) {
if (lineText.charAt(endIndex) == ']') {
depth++;
}
else if (lineText.charAt(endIndex) == '[') {
if (depth == 0) {
break;
}
depth--;
String text = tokenMarker.getMethod(token.getText());
if (text == null && token.getText().startsWith("@")) {
text = tokenMarker.getMethod(token.getText().substring(1));
}
if (text == null && token.getText().startsWith(".")) {
int line = styledText.getLineAtOffset(offset);
int lineOffset = styledText.getOffsetAtLine(line);
String lineText = styledText.getLine(line);
int endIndex = token.start - lineOffset - 1;
if (lineText.charAt(endIndex) == ']') {
int depth = -1;
while (endIndex >= 0) {
if (lineText.charAt(endIndex) == ']') {
depth++;
}
else if (lineText.charAt(endIndex) == '[') {
if (depth == 0) {
break;
}
endIndex--;
depth--;
}
endIndex--;
}
if (endIndex >= 0) {
Token objectToken = tokenMarker.getTokenAt(endIndex + lineOffset);
if (objectToken != null) {
String qualifiedName = objectToken.getText() + token.getText();
text = tokenMarker.getMethod(qualifiedName);
if (text == null && qualifiedName.startsWith("@")) {
text = tokenMarker.getMethod(qualifiedName.substring(1));
}
endIndex--;
}
if (endIndex >= 0) {
Token objectToken = tokenMarker.getTokenAt(endIndex + lineOffset);
if (objectToken != null) {
String qualifiedName = objectToken.getText() + token.getText();
text = tokenMarker.getMethod(qualifiedName);
if (text == null && qualifiedName.startsWith("@")) {
text = tokenMarker.getMethod(qualifiedName.substring(1));
}
}
}
}
if (text == null) {
text = helpProvider.getString(context != null ? context.getClass().getSimpleName() : null, token.getText().toLowerCase());
}
if (text != null && !"".equals(text)) {
popupWindow = new Shell(styledText.getShell(), SWT.RESIZE | SWT.ON_TOP);
FillLayout layout = new FillLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
public class SpinTools {

public static final String APP_TITLE = "Spin Tools IDE";
public static final String APP_VERSION = "0.32.1";
public static final String APP_VERSION = "0.33.0";

static final File defaultSpin1Examples = new File(System.getProperty("APP_DIR"), "examples/P1").getAbsoluteFile();
static final File defaultSpin2Examples = new File(System.getProperty("APP_DIR"), "examples/P2").getAbsoluteFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int getReturns() {
static {
descriptors.put("HUBSET", new Descriptor(0x19, 0x54, 1, 0));
descriptors.put("CLKSET", new Descriptor(0x19, 0x56, 2, 0));
descriptors.put("CLKFREQ", new Descriptor(0x19, 0x58, 0, 1));
//descriptors.put("CLKFREQ", new Descriptor(0x19, 0x58, 0, 1));
//descriptors.put("COGSPIN", new Descriptor(0x19, 0x5A, 3));
descriptors.put("COGCHK", new Descriptor(0x19, 0x5C, 1, 1));
descriptors.put("REGEXEC", new Descriptor(0x19, 0x60, 1, 0));
Expand Down
Loading

0 comments on commit a2d856b

Please sign in to comment.