FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

load and save using browser local storage; |ERA; now compatible with … · benchmarko/CPCBasic@855662f · GitHub

Commit 855662f

Browse files
committed
load and save using browser local storage; |ERA; now compatible with SliTaz tazweb browser
1 parent b65f09b commit 855662f

13 files changed

Lines changed: 948 additions & 490 deletions

‎BasicLexer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ BasicLexer.prototype = {
290290
addToken(sChar, sChar, iStartPos);
291291
sChar = advance();
292292
} else if (isRsx(sChar)) {
293+
sToken = sChar;
293294
sChar = advance();
294-
sToken = "";
295295
if (isIdentifierMiddle(sChar)) {
296-
sToken = advanceWhile(isIdentifierMiddle);
296+
sToken += advanceWhile(isIdentifierMiddle);
297297
addToken("|", sToken, iStartPos);
298298
}
299299
} else if (isStream(sChar)) { // stream can be an expression

‎BasicParser.js‎

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ BasicParser.mKeywords = {
133133
move: "c n n n0? n?",
134134
mover: "c n n n0? n?",
135135
"new": "c",
136-
next: "c v*", // v*
136+
next: "c v*",
137137
not: "o",
138138
on: "c", // on break cont, on break gosub, on break stop, on error goto, on <ex> gosub, on <ex> goto, on sq(n) gosub
139139
onBreakGosub: "c l", // special
@@ -519,12 +519,6 @@ BasicParser.prototype = {
519519
if (oExpression.type !== "identifier") {
520520
throw new BasicParser.ErrorObject("Variable expected at", oExpression.value, oExpression.pos, that.iLine);
521521
}
522-
/*
523-
if (oToken.type !== "identifier") {
524-
throw new BasicParser.ErrorObject("Variable expected at", oToken.value, oToken.pos, that.iLine);
525-
}
526-
oExpression = expression(0);
527-
*/
528522
} else if (sType.substr(0, 1) === "r") { // character or range of characters (defint, defreal, defstr)
529523
if (oToken.type !== "identifier") {
530524
throw new BasicParser.ErrorObject("Letter expected at", oToken.value, oToken.pos, that.iLine);
@@ -702,20 +696,12 @@ BasicParser.prototype = {
702696
left: oName, // identifier
703697
pos: oName.pos // same pos as identifier?
704698
};
705-
/*
706-
oValue = oPreviousToken; // identifier => fn
707-
oValue.type = "fn";
708-
oValue.args = [];
709-
oValue.left = oName; // //sName; // .value
710-
*/
711-
712699
return oValue;
713700
}
714701
}
715702

716703
if (oToken.type === "(" || oToken.type === "[") {
717704
oValue = oPreviousToken;
718-
//TTT oValue.type = "array"; // identifier => array
719705
oValue.args = (oToken.type === "(") ? fnGetArgsInParenthesis() : fnGetArgsInBrackets();
720706

721707
if (Utils.stringStartsWith(sName.toLowerCase(), "fn")) {
@@ -876,26 +862,6 @@ BasicParser.prototype = {
876862
return oValue;
877863
});
878864

879-
/*
880-
stmt("defint", function () {
881-
var oValue = fnCreateCmdCall();
882-
883-
return oValue;
884-
});
885-
886-
stmt("defreal", function () {
887-
var oValue = fnCreateCmdCall();
888-
889-
return oValue;
890-
});
891-
892-
stmt("defstr", function () {
893-
var oValue = fnCreateCmdCall();
894-
895-
return oValue;
896-
});
897-
*/
898-
899865
stmt("else", function () {
900866
var oValue = oPreviousToken,
901867
oString = {
@@ -1131,10 +1097,8 @@ BasicParser.prototype = {
11311097
oValue2 = oToken; // identifier
11321098
advance();
11331099
if (oToken.type === "(") {
1134-
//oValue2.type = "array";
11351100
oValue2.args = fnGetArgsInParenthesis();
11361101
} else if (oToken.type === "[") {
1137-
//oValue2.type = "array";
11381102
oValue2.args = fnGetArgsInBrackets();
11391103
}
11401104
oValue.args.push(oValue2);
@@ -1213,10 +1177,8 @@ BasicParser.prototype = {
12131177
oValue2 = oToken;
12141178
advance();
12151179
if (oToken.type === "(") {
1216-
//oValue2.type = "array";
12171180
oValue2.args = fnGetArgsInParenthesis();
12181181
} else if (oToken.type === "[") {
1219-
//oValue2.type = "array";
12201182
oValue2.args = fnGetArgsInBrackets();
12211183
}
12221184
oValue.args.push(oValue2);
@@ -1254,23 +1216,6 @@ BasicParser.prototype = {
12541216
return oValue;
12551217
});
12561218

1257-
/*
1258-
stmt("next", function () {
1259-
var oValue = oPreviousToken;
1260-
1261-
oValue.args = [];
1262-
1263-
while (oToken.type === "identifier") {
1264-
oValue.args.push(oToken);
1265-
advance();
1266-
if (oToken.type === ",") {
1267-
advance(",");
1268-
}
1269-
}
1270-
return oValue;
1271-
});
1272-
*/
1273-
12741219
stmt("on", function () {
12751220
var oValue = oPreviousToken,
12761221
oLeft;
@@ -1449,14 +1394,16 @@ BasicParser.prototype = {
14491394
return fnCreateCmdCall(sName);
14501395
});
14511396

1397+
/*
14521398
stmt("write", function () {
1453-
var oValue, oStream;
1399+
var oValue;
14541400
1455-
oStream = fnGetOptionalStream();
1401+
//oStream = fnGetOptionalStream();
14561402
oValue = fnCreateCmdCall("write");
1457-
oValue.args.unshift(oStream);
1403+
//oValue.args.unshift(oStream);
14581404
return oValue;
14591405
});
1406+
*/
14601407

14611408

14621409
// line

‎Canvas.js‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// https://benchmarko.github.io/CPCBasic/
44
//
55
/* globals Utils */
6-
/* globals ArrayBuffer Uint8ClampedArray Uint32Array Uint8Array */
6+
/* globals ArrayBuffer Uint8Array */
77

88
"use strict";
99

@@ -88,7 +88,7 @@ Canvas.prototype = {
8888

8989
init: function (options) {
9090
var iBorderWidth = 4,
91-
iWidth, iHeight, canvas, ctx;
91+
iWidth, iHeight, canvas, ctx, dataset;
9292

9393
this.options = Object.assign({}, options);
9494

@@ -112,12 +112,18 @@ Canvas.prototype = {
112112

113113
ctx = this.canvas.getContext("2d");
114114
this.imageData = ctx.getImageData(0, 0, iWidth, iHeight);
115-
this.buf = new ArrayBuffer(this.imageData.data.length);
116-
this.buf8 = new Uint8ClampedArray(this.buf);
117-
this.data = new Uint32Array(this.buf);
118-
119-
this.dataset = new ArrayBuffer(iWidth * iHeight);
120-
this.dataset8 = new Uint8Array(this.dataset); // array with pen values
115+
//buf = new ArrayBuffer(this.imageData.data.length);
116+
//this.buf8 = new Uint8ClampedArray(buf);
117+
//this.data = new Uint32Array(buf);
118+
this.buf8 = this.imageData.data; // use Uint8ClampedArray from canvas
119+
120+
dataset = new ArrayBuffer(iWidth * iHeight);
121+
if (typeof Uint8Array !== "undefined") { // in modern browsers we have it
122+
this.dataset8 = new Uint8Array(dataset); // array with pen values
123+
} else {
124+
Utils.console.warn("Canvas:init: Uint8Array not available. Using fallback.");
125+
this.dataset8 = dataset; // fallbaCK
126+
}
121127

122128
this.bNeedUpdate = false;
123129
this.oUpdateRect = {};
@@ -240,7 +246,7 @@ Canvas.prototype = {
240246
buf8[i + 3] = 255; // a
241247
}
242248
}
243-
this.imageData.data.set(buf8);
249+
// this.imageData.data.set(buf8); // already set
244250
ctx.putImageData(this.imageData, 0, 0);
245251
},
246252

‎CodeGeneratorJs.js‎

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ function CodeGeneratorJs(options) {
1818

1919
CodeGeneratorJs.prototype = {
2020
init: function (options) {
21-
this.options = options || {}; // e.g. tron
21+
this.options = options || {}; // e.g. tron, rsx
2222

2323
this.lexer = this.options.lexer;
2424
this.parser = this.options.parser;
25+
2526
this.reset();
2627
},
2728

@@ -302,32 +303,6 @@ CodeGeneratorJs.prototype = {
302303
},
303304

304305
mParseFunctions = {
305-
/*
306-
fnParseDefIntRealStr: function (node) {
307-
var reVarLetters = /^[A-Za-z]( - [A-Za-z])?$/,
308-
aNodeArgs, i, sArg;
309-
310-
oDevScopeArgs = {};
311-
bDevScopeArgsCollect = true;
312-
aNodeArgs = fnParseArgs(node.args);
313-
bDevScopeArgsCollect = false;
314-
oDevScopeArgs = null;
315-
316-
for (i = 0; i < aNodeArgs.length; i += 1) {
317-
sArg = aNodeArgs[i];
318-
if (sArg.indexOf("oNo") >= 0) { // need to replace modified "o" variable!
319-
sArg = sArg.replace(/oNo/g, "o");
320-
}
321-
if (!reVarLetters.test(sArg)) {
322-
throw new CodeGeneratorJs.ErrorObject("Wrong format for " + node.type, sArg, node.args.length ? node.args[0].pos : node.pos);
323-
// how to get correct position and length of expression?
324-
}
325-
aNodeArgs[i] = "o." + node.type + '("' + sArg + '")';
326-
}
327-
node.pv = aNodeArgs.join("; ");
328-
return node.pv;
329-
},
330-
*/
331306
fnParseDefIntRealStr: function (node) {
332307
var aNodeArgs, i, sArg;
333308

@@ -382,10 +357,18 @@ CodeGeneratorJs.prototype = {
382357
},
383358

384359
"|": function (node) { // rsx
385-
var sRsxName = "rsx" + Utils.stringCapitalize(node.value.toLowerCase()),
386-
aNodeArgs = fnParseArgs(node.args);
360+
var sRsxName, aNodeArgs, sLabel;
387361

388-
node.pv = "o." + sRsxName + "(" + aNodeArgs.join(", ") + ")";
362+
sRsxName = node.value.substr(1).toLowerCase().replace(/\./g, "_"); //sRsxName = "rsx" + Utils.stringCapitalize(node.value.toLowerCase()),
363+
aNodeArgs = fnParseArgs(node.args);
364+
if (that.options.rsx.rsxIsAvailable(sRsxName)) { // RSX available?
365+
sLabel = that.iLine + "s" + that.iStopCount; // we use stopCount
366+
that.iStopCount += 1;
367+
//node.pv = "o.rsx." + sAdaptedRsxName + "(" + aNodeArgs.join(", ") + ")";
368+
node.pv = "o.rsx." + sRsxName + "(" + aNodeArgs.join(", ") + "); o.goto(\"" + sLabel + "\"); break;\ncase \"" + sLabel + "\":"; // most RSX commands need goto (era, renum,...)
369+
} else {
370+
throw new CodeGeneratorJs.ErrorObject("Unknown RSX command", node.value, node.pos, that.iLine);
371+
}
389372
return node.pv;
390373
},
391374
number: function (node) {
@@ -458,23 +441,6 @@ CodeGeneratorJs.prototype = {
458441
node.pv = "null";
459442
return node.pv;
460443
},
461-
/*
462-
array: function (node) { // identifier with array; TOTO: extend identifier?
463-
var aNodeArgs = fnParseArgs(node.args),
464-
sName = fnAdaptVariableName(node.value, aNodeArgs.length),
465-
sVarType = fnDetermineStaticVarType(sName),
466-
sValue = sName + aNodeArgs.map(function (val) {
467-
return "[" + val + "]";
468-
}).join("");
469-
470-
if (sVarType.length > 1) {
471-
sVarType = sVarType.charAt(1);
472-
node.pt = sVarType;
473-
}
474-
node.pv = sValue;
475-
return node.pv;
476-
},
477-
*/
478444
assign: function (node) {
479445
// see also "let"
480446
var sName, sVarType, value, sValue;
@@ -550,6 +516,10 @@ CodeGeneratorJs.prototype = {
550516
node.pv = this.fnCommandWithGoto(node);
551517
return node.pv;
552518
},
519+
closeout: function (node) {
520+
node.pv = this.fnCommandWithGoto(node);
521+
return node.pv;
522+
},
553523
commaTab: function (node) {
554524
var aNodeArgs = fnParseArgs(node.args);
555525

@@ -979,6 +949,11 @@ CodeGeneratorJs.prototype = {
979949
node.pv = "o.return(); break;";
980950
return node.pv;
981951
},
952+
/*
953+
rsxEra: function (node) {
954+
return this.fnCommandWithGoto(node);
955+
},
956+
*/
982957
run: function (node) { // optional arg can be number or string
983958
if (node.args.length) {
984959
if (node.args[0].type === "linenumber" || node.args[0].type === "number") { // optional line number //TTT should be linenumber only

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL