mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-12 22:16:05 +09:00
BasicAST: ability to distinguish two different separators
This commit is contained in:
@@ -2,21 +2,51 @@ println("TERRAN Megatrends inc.");
|
|||||||
//println("Main RAM:"+(system.maxmem() >> 10)+" KBytes");
|
//println("Main RAM:"+(system.maxmem() >> 10)+" KBytes");
|
||||||
|
|
||||||
var memptr = 0;
|
var memptr = 0;
|
||||||
var memtestptn = [0xAA,0x55,0xAA,0x55 , 0x00,0xFF,0x00,0xFF , 0x01,0x02,0x04,0x08 , 0x10,0x20,0x40,0x80];
|
var memtestptn = [
|
||||||
|
// Overclockers will LOVE this!
|
||||||
|
[0x00,0x00,0x00,0x00 , 0xFF,0xFF,0xFF,0xFF , 0x00,0x00,0x00,0x00 , 0xFF,0xFF,0xFF,0xFF],
|
||||||
|
|
||||||
|
[0xAA,0x55,0xAA,0x55 , 0xAA,0x55,0xAA,0x55 , 0xAA,0x55,0xAA,0x55 , 0xAA,0x55,0xAA,0x55],
|
||||||
|
[0x00,0xFF,0x00,0xFF , 0xFF,0x00,0xFF,0x00 , 0x00,0xFF,0x00,0xFF , 0xFF,0x00,0xFF,0x00],
|
||||||
|
|
||||||
|
[0x69,0x69,0x69,0x69 , 0xA5,0xA5,0xA5,0xA5 , 0x69,0x69,0x69,0x69 , 0xA5,0xA5,0xA5,0xA5],
|
||||||
|
[0x0F,0x0F,0x0F,0x0F , 0x1E,0x1E,0x1E,0x1E , 0x3C,0x3C,0x3C,0x3C , 0x78,0x78,0x78,0x78],
|
||||||
|
|
||||||
|
[0xC7,0x1C,0x71,0xC7 , 0x8E,0x38,0xE3,0x8E , 0x1C,0x71,0xC7,0x1C , 0x38,0xE3,0x8E,0x38],
|
||||||
|
[0x71,0xC7,0x1C,0x71 , 0xE3,0x8E,0x38,0xE3 , 0x01,0x02,0x04,0x08 , 0x10,0x20,0x40,0x80],
|
||||||
|
|
||||||
|
//[0x00,0x00,0xFF,0xFF , 0x00,0x00,0xFF,0xFF , 0x00,0x01,0xFF,0xFE , 0x00,0x01,0xFF,0xFE],
|
||||||
|
//[0x00,0x03,0xFF,0xFC , 0x00,0x03,0xFF,0xFC , 0x00,0x07,0xFF,0xF8 , 0x00,0x07,0xFF,0xF8],
|
||||||
|
//[0x00,0x0F,0xFF,0xF0 , 0x00,0x0F,0xFF,0xF0 , 0x00,0x1F,0xFF,0xE0 , 0x00,0x1F,0xFF,0xE0],
|
||||||
|
//[0x00,0x3F,0xFF,0xC0 , 0x00,0x3F,0xFF,0xC0 , 0x00,0x7F,0xFF,0x80 , 0x00,0x7F,0xFF,0x80],
|
||||||
|
//[0x00,0xFF,0xFF,0x00 , 0x00,0xFF,0xFF,0x00 , 0x01,0xFF,0xFE,0x00 , 0x01,0xFF,0xFE,0x00],
|
||||||
|
//[0x03,0xFF,0xFC,0x00 , 0x03,0xFF,0xFC,0x00 , 0x07,0xFF,0xF8,0x00 , 0x07,0xFF,0xF8,0x00],
|
||||||
|
//[0x0F,0xFF,0xF0,0x00 , 0x0F,0xFF,0xF0,0x00 , 0x1F,0xFF,0xE0,0x00 , 0x1F,0xFF,0xE0,0x00],
|
||||||
|
//[0x3F,0xFF,0xC0,0x00 , 0x3F,0xFF,0xC0,0x00 , 0x7F,0xFF,0x80,0x00 , 0x7F,0xFF,0x80,0x00],
|
||||||
|
|
||||||
|
[0xFF,0xFF,0xFF,0xFF , 0xFF,0xFF,0xFF,0xFF , 0xFF,0xFF,0xFF,0xFF , 0xFF,0xFF,0xFF,0xFF]
|
||||||
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (memptr < (8 << 20)) {
|
while (memptr < (8 << 20)) {
|
||||||
// just print a number
|
// just print a number
|
||||||
con.move(2,1);
|
con.move(2,1);
|
||||||
print(memptr >> 10);
|
var memptrtext = ""+((memptr + 1) >> 10);
|
||||||
|
print((memptrtext < 10) ? "00"+memptrtext : (memptrtext < 100) ? "0"+memptrtext : memptrtext);
|
||||||
|
|
||||||
// perform memory test
|
// perform memory test
|
||||||
memtestptn.forEach(function(v,i,arr) {
|
for (var ptn = 0; ptn < memtestptn.length; ptn++) {
|
||||||
sys.poke(memptr + i, v);
|
for (var bi = 0; bi < memtestptn[ptn].length; bi++) {
|
||||||
if (v != sys.peek(memptr + i)) throw "Memory Error";
|
sys.poke(memptr + bi, memtestptn[ptn][bi]);
|
||||||
});
|
if (memtestptn[ptn][bi] != sys.peek(memptr + bi)) throw "Memory Error";
|
||||||
|
}
|
||||||
|
for (var bi = 0; bi < memtestptn[ptn].length; bi++) {
|
||||||
|
sys.poke(memptr + bi, 255 - memtestptn[ptn][bi]);
|
||||||
|
if (255 - memtestptn[ptn][bi] != sys.peek(memptr + bi)) throw "Memory Error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memptr += memtestptn.length;
|
memptr += memtestptn[0].length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ Operators
|
|||||||
+ - Just as in JS; concatenates two strings
|
+ - Just as in JS; concatenates two strings
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
if (system.maxmem() < 8192) {
|
||||||
|
println("Out of memory. BASIC requires 8K or more User RAM");
|
||||||
|
throw new Error("Out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
var vmemsize = system.maxmem() - 5236;
|
var vmemsize = system.maxmem() - 5236;
|
||||||
|
|
||||||
@@ -43,6 +47,9 @@ lang.errorinline = function(line, stmt, errobj) {
|
|||||||
lang.parserError = function(line, errorobj) {
|
lang.parserError = function(line, errorobj) {
|
||||||
return "Parser error in " + line + ": " + errorobj;
|
return "Parser error in " + line + ": " + errorobj;
|
||||||
};
|
};
|
||||||
|
lang.outOfMem = function(line) {
|
||||||
|
return "Out of memory in " + line;
|
||||||
|
};
|
||||||
Object.freeze(lang);
|
Object.freeze(lang);
|
||||||
|
|
||||||
function getUsedMemSize() {
|
function getUsedMemSize() {
|
||||||
@@ -105,6 +112,7 @@ function BasicAST() {
|
|||||||
this.lnum = 0;
|
this.lnum = 0;
|
||||||
this.depth = 0;
|
this.depth = 0;
|
||||||
this.leaves = [];
|
this.leaves = [];
|
||||||
|
this.seps = [];
|
||||||
this.value = undefined;
|
this.value = undefined;
|
||||||
this.type = "null"; // literal, operator, string, number, function, null
|
this.type = "null"; // literal, operator, string, number, function, null
|
||||||
|
|
||||||
@@ -115,6 +123,8 @@ function BasicAST() {
|
|||||||
sb += "| ".repeat(this.depth+1) + "leaves: "+(this.leaves.length)+"\n";
|
sb += "| ".repeat(this.depth+1) + "leaves: "+(this.leaves.length)+"\n";
|
||||||
sb += "| ".repeat(this.depth+1) + "value: "+this.value+" (type: "+typeof this.value+")\n";
|
sb += "| ".repeat(this.depth+1) + "value: "+this.value+" (type: "+typeof this.value+")\n";
|
||||||
for (var k = 0; k < this.leaves.length; k++) {
|
for (var k = 0; k < this.leaves.length; k++) {
|
||||||
|
if (k > 0)
|
||||||
|
sb += "| ".repeat(this.depth+1) + " " + this.seps[k - 1] + "\n";
|
||||||
sb += this.leaves[k].toString(); + "\n";
|
sb += this.leaves[k].toString(); + "\n";
|
||||||
}
|
}
|
||||||
sb += "| ".repeat(this.depth) + "`-----------------\n";
|
sb += "| ".repeat(this.depth) + "`-----------------\n";
|
||||||
@@ -402,7 +412,7 @@ basicFunctions._isParen = function(code) {
|
|||||||
return basicFunctions._isParenOpen(code) || basicFunctions._isParenClose(code);
|
return basicFunctions._isParenOpen(code) || basicFunctions._isParenClose(code);
|
||||||
};
|
};
|
||||||
basicFunctions._isSeparator = function(code) {
|
basicFunctions._isSeparator = function(code) {
|
||||||
return code == 0x2C;
|
return code == 0x2C || code == 0x3B;
|
||||||
};
|
};
|
||||||
basicFunctions._operatorPrecedence = {
|
basicFunctions._operatorPrecedence = {
|
||||||
// function call in itself has highest precedence
|
// function call in itself has highest precedence
|
||||||
@@ -411,7 +421,7 @@ basicFunctions._operatorPrecedence = {
|
|||||||
"*":2,"/":2,
|
"*":2,"/":2,
|
||||||
"MOD":3,
|
"MOD":3,
|
||||||
"+":4,"-":4,
|
"+":4,"-":4,
|
||||||
";":5,
|
//";":5,
|
||||||
"<<":6,">>":6,
|
"<<":6,">>":6,
|
||||||
"==":7,"<>":7,"><":7,"<":7,">":7,"<=":7,"=<":7,">=":7,"=>":7,
|
"==":7,"<>":7,"><":7,"<":7,">":7,"<=":7,"=<":7,">=":7,"=>":7,
|
||||||
"BAND":8,
|
"BAND":8,
|
||||||
@@ -1092,6 +1102,7 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
if (_debugSyntaxAnalysis) println("function name: "+treeHead.value);
|
if (_debugSyntaxAnalysis) println("function name: "+treeHead.value);
|
||||||
|
|
||||||
var leaves = [];
|
var leaves = [];
|
||||||
|
var seps = [];
|
||||||
|
|
||||||
// if there is no paren (this part deals with unary ops ONLY!)
|
// if there is no paren (this part deals with unary ops ONLY!)
|
||||||
if (parenStart == -1 && parenEnd == -1) {
|
if (parenStart == -1 && parenEnd == -1) {
|
||||||
@@ -1122,9 +1133,11 @@ for input "DEFUN sinc(x) = sin(x) / x"
|
|||||||
|
|
||||||
leaves.push(basicFunctions._parseTokens(lnum, subtkn, substa, recDepth + 1));
|
leaves.push(basicFunctions._parseTokens(lnum, subtkn, substa, recDepth + 1));
|
||||||
}
|
}
|
||||||
|
separators.slice(1, separators.length - 1).forEach(function(v) { if (v !== undefined) seps.push(tokens[v]); });
|
||||||
}
|
}
|
||||||
else throw lang.syntaxfehler(lnum, lang.badFunctionCallFormat);
|
else throw lang.syntaxfehler(lnum, lang.badFunctionCallFormat);
|
||||||
treeHead.leaves = leaves;//.filter(function(__v) { return __v !== undefined; });
|
treeHead.leaves = leaves;//.filter(function(__v) { return __v !== undefined; });
|
||||||
|
treeHead.seps = seps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1232,7 +1245,7 @@ basicFunctions._executeSyntaxTree = function(lnum, syntaxTree, recDepth) {
|
|||||||
};
|
};
|
||||||
// @returns: line number for the next command, normally (lnum + 1); if GOTO or GOSUB was met, returns its line number
|
// @returns: line number for the next command, normally (lnum + 1); if GOTO or GOSUB was met, returns its line number
|
||||||
basicFunctions._interpretLine = function(lnum, cmd) {
|
basicFunctions._interpretLine = function(lnum, cmd) {
|
||||||
var _debugprintHighestLevel = false;
|
var _debugprintHighestLevel = true;
|
||||||
|
|
||||||
// TOKENISE
|
// TOKENISE
|
||||||
var tokenisedObject = basicFunctions._tokenise(lnum, cmd);
|
var tokenisedObject = basicFunctions._tokenise(lnum, cmd);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import javax.swing.WindowConstants
|
|||||||
class Memvwr(val vm: VM) : JFrame() {
|
class Memvwr(val vm: VM) : JFrame() {
|
||||||
|
|
||||||
val memArea = JTextArea()
|
val memArea = JTextArea()
|
||||||
|
var columns = 16
|
||||||
|
|
||||||
fun composeVwrText() {
|
fun composeVwrText() {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
@@ -67,6 +68,45 @@ class Memvwr(val vm: VM) : JFrame() {
|
|||||||
sb.append("== Port ${port + 1}: ${status.toString(2).padStart(8, '0')}\n")
|
sb.append("== Port ${port + 1}: ${status.toString(2).padStart(8, '0')}\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.append("\n== First 4 kbytes of User RAM ==\n")
|
||||||
|
sb.append("ADRESS : 0 1 2 3| 4 5 6 7| 8 9 A B| C D E F\n")
|
||||||
|
for (i in 0L..4095L) {
|
||||||
|
if (i % columns == 0L) {
|
||||||
|
sb.append(i.toString(16).toUpperCase().padStart(6, '0')) // mem addr
|
||||||
|
sb.append(" : ") // separator
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sb.append(vm.peek(i)!!.toUint().toString(16).toUpperCase().padStart(2, '0'))
|
||||||
|
if (i % 16L in longArrayOf(3L, 7L, 11L)) {
|
||||||
|
sb.append('|') // mem value
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sb.append(' ') // mem value
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASCII viewer
|
||||||
|
if (i % columns == 15L) {
|
||||||
|
sb.append("| ")
|
||||||
|
|
||||||
|
for (x in -15..0) {
|
||||||
|
val mem = vm.peek(i + x)!!.toUint()
|
||||||
|
|
||||||
|
if (mem < 32) {
|
||||||
|
sb.append('.')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sb.append(mem.toChar())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x + 15 in intArrayOf(3, 7, 11))
|
||||||
|
sb.append('|')
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("|\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memArea.text = sb.toString()
|
memArea.text = sb.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +122,6 @@ class Memvwr(val vm: VM) : JFrame() {
|
|||||||
this.isVisible = true
|
this.isVisible = true
|
||||||
this.add(javax.swing.JScrollPane(memArea), BorderLayout.CENTER)
|
this.add(javax.swing.JScrollPane(memArea), BorderLayout.CENTER)
|
||||||
this.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
|
this.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
|
||||||
this.size = Dimension(800, 960)
|
this.size = Dimension(820, 960)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ import java.io.StringReader
|
|||||||
|
|
||||||
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
|
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
|
||||||
|
|
||||||
val vm = VM(1024.kB())
|
val vm = VM(64.kB())
|
||||||
lateinit var gpu: GraphicsAdapter
|
lateinit var gpu: GraphicsAdapter
|
||||||
|
|
||||||
lateinit var batch: SpriteBatch
|
lateinit var batch: SpriteBatch
|
||||||
|
|||||||
BIN
tsvm_graphics_mockup2.kra
LFS
Normal file
BIN
tsvm_graphics_mockup2.kra
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user