mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-19 20:14:58 +00:00
More experimentation with Data/Read/Restore....
This commit is contained in:
parent
4b513aee17
commit
0549282fad
4 changed files with 122 additions and 15 deletions
|
@ -45,7 +45,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'read', 'restore', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr', 'window',
|
||||
// QBJS-specific
|
||||
'export', 'from', 'import', 'label']
|
||||
'export', 'from', 'import', '_label']
|
||||
|
||||
var builtinConsts = ['_off', '_smooth', '_stretch', '_squarepixels',
|
||||
'gx_true', 'gx_false', 'gxevent_init', 'gxevent_update', 'gxevent_drawbg', 'gxevent_drawmap', 'gxevent_drawscreen',
|
||||
|
|
18
qb.js
18
qb.js
|
@ -635,14 +635,6 @@ var QB = new function() {
|
|||
}, 200);
|
||||
};
|
||||
|
||||
this.sub_Data = function(dat) {
|
||||
if (_dataBulk.length == 0) {
|
||||
_dataBulk = dat;
|
||||
} else {
|
||||
_dataBulk.push.apply(_dataBulk, dat);
|
||||
}
|
||||
};
|
||||
|
||||
this.func_Chr = function(charCode) {
|
||||
return String.fromCharCode(charCode);
|
||||
};
|
||||
|
@ -1205,7 +1197,7 @@ var QB = new function() {
|
|||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
this.sub_Label = function(t) {
|
||||
this.sub__Label = function(t) {
|
||||
_dataLabelMap.set(t, _dataBulk.length);
|
||||
};
|
||||
|
||||
|
@ -1603,6 +1595,14 @@ var QB = new function() {
|
|||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
this.sub_Data = function(dat) {
|
||||
if (_dataBulk.length == 0) {
|
||||
_dataBulk = dat;
|
||||
} else {
|
||||
_dataBulk.push.apply(_dataBulk, dat);
|
||||
}
|
||||
};
|
||||
|
||||
this.sub_Read = function(values) {
|
||||
for (var i=0; i < values.length; i++) {
|
||||
values[i] = _dataBulk[_readCursorPosition];
|
||||
|
|
61
qb2js.js
61
qb2js.js
|
@ -1,5 +1,7 @@
|
|||
async function _QBCompiler() {
|
||||
|
||||
dataTicker = 1;
|
||||
dataTicker = 1;
|
||||
// Option _Explicit
|
||||
// $Console
|
||||
// Only
|
||||
|
@ -27,6 +29,7 @@ async function _QBCompiler() {
|
|||
var currentMethod = ''; // STRING
|
||||
var currentModule = ''; // STRING
|
||||
var programMethods = 0; // INTEGER
|
||||
var dataTicker = 0; // INTEGER
|
||||
if (QB.func_Command() != "" ) {
|
||||
await sub_QBToJS( QB.func_Command(), FILE, "");
|
||||
await sub_PrintJS();
|
||||
|
@ -739,9 +742,17 @@ var ConvertData = null;
|
|||
argc = (await func_ListSplit( args, parts));
|
||||
var i = 0; // INTEGER
|
||||
var r = ''; // STRING
|
||||
var q = ''; // STRING
|
||||
r = "[";
|
||||
for ( i= 1; i <= argc; i= i + 1) { if (QB.halted()) { return; }
|
||||
r = r +QB.arrayValue(parts, [ i]).value;
|
||||
q = QB.arrayValue(parts, [ i]).value;
|
||||
if (((QB.func_Left( (QB.func_LTrim( q)), 1)) != (QB.func_Chr( 34))) ) {
|
||||
q = (QB.func_Chr( 34)) + q;
|
||||
}
|
||||
if (((QB.func_Right( (QB.func_RTrim( q)), 1)) != (QB.func_Chr( 34))) ) {
|
||||
q = q +(QB.func_Chr( 34));
|
||||
}
|
||||
r = r + q;
|
||||
if (( i < argc) ) {
|
||||
r = r +",";
|
||||
}
|
||||
|
@ -1591,6 +1602,15 @@ var ReadLine = null;
|
|||
}
|
||||
}
|
||||
ReadLine = rawJS;
|
||||
if (((QB.func__Trim( (QB.func_LCase( (QB.func_Left( fline, 4)))))) == "data") ) {
|
||||
await sub_AddLineTop( dataTicker, fline);
|
||||
await sub_AddSubLinesTop( dataTicker, fline);
|
||||
return ReadLine;
|
||||
}
|
||||
if (((QB.func__Trim( (QB.func_LCase( (QB.func_Left( fline, 6)))))) == "_label") ) {
|
||||
await sub_AddLineTop( dataTicker, fline);
|
||||
return ReadLine;
|
||||
}
|
||||
if ((QB.func__Trim( fline)) == "" ) {
|
||||
return ReadLine;
|
||||
}
|
||||
|
@ -1669,6 +1689,29 @@ if (QB.halted()) { return; }
|
|||
}
|
||||
await sub_AddLine( lineIndex, fline);
|
||||
}
|
||||
async function sub_AddSubLinesTop(lineIndex/*INTEGER*/,fline/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var quoteDepth = 0; // INTEGER
|
||||
quoteDepth = 0;
|
||||
var i = 0; // INTEGER
|
||||
for ( i= 1; i <= (QB.func_Len( fline)); i= i + 1) { if (QB.halted()) { return; }
|
||||
var c = ''; // STRING
|
||||
c = (QB.func_Mid( fline, i, 1));
|
||||
if ( c == (QB.func_Chr( 34)) ) {
|
||||
if ( quoteDepth == 0) {
|
||||
quoteDepth = 1;
|
||||
} else {
|
||||
quoteDepth = 0;
|
||||
}
|
||||
}
|
||||
if ( quoteDepth == 0 && c == ":" ) {
|
||||
await sub_AddLineTop( lineIndex, (QB.func_Left( fline, i - 1)));
|
||||
fline = (QB.func_Right( fline, (QB.func_Len( fline)) - i));
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
await sub_AddLineTop( lineIndex, fline);
|
||||
}
|
||||
async function sub_FindMethods() {
|
||||
if (QB.halted()) { return; }
|
||||
var i = 0; // INTEGER
|
||||
|
@ -2066,6 +2109,20 @@ if (QB.halted()) { return; }
|
|||
m.name = mname;
|
||||
await sub_AddMethod( m, "QB.", sync);
|
||||
}
|
||||
async function sub_AddLineTop(lineIndex/*INTEGER*/,fline/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var lcount = 0; // INTEGER
|
||||
lcount = (QB.func_UBound( lines)) + 1;
|
||||
QB.resizeArray(lines, [{l:1,u:lcount}], {line:0,text:''}, true); // CODELINE
|
||||
var j = 0; // INTEGER
|
||||
for ( j=(QB.func_UBound( lines)) ; j >= dataTicker; j= j + -1) { if (QB.halted()) { return; }
|
||||
QB.arrayValue(lines, [ j]).value .line = QB.arrayValue(lines, [ j - 1]).value .line;
|
||||
QB.arrayValue(lines, [ j]).value .text = QB.arrayValue(lines, [ j - 1]).value .text;
|
||||
}
|
||||
QB.arrayValue(lines, [ dataTicker]).value .line = dataTicker;
|
||||
QB.arrayValue(lines, [ dataTicker]).value .text = fline;
|
||||
dataTicker = dataTicker + 1;
|
||||
}
|
||||
async function sub_AddLine(lineIndex/*INTEGER*/,fline/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
await sub___AddLine( lineIndex, fline);
|
||||
|
@ -2792,7 +2849,6 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "InKey$", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "InStr", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Int", False);
|
||||
await sub_AddQBMethod( "SUB", "Label", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "LBound", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Left$", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "LCase$", False);
|
||||
|
@ -2834,6 +2890,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "Varptr", False);
|
||||
await sub_AddQBMethod( "SUB", "Window", False);
|
||||
await sub_AddQBMethod( "SUB", "IncludeJS", True);
|
||||
await sub_AddQBMethod( "SUB", "_Label", False);
|
||||
await sub_AddSystemType( "FETCHRESPONSE", "ok:INTEGER,status:INTEGER,statusText:STRING,text:STRING");
|
||||
await sub_AddQBMethod( "FUNCTION", "Fetch", True);
|
||||
await sub_AddQBMethod( "SUB", "Fetch", True);
|
||||
|
|
|
@ -61,6 +61,8 @@ Dim Shared modLevel As Integer
|
|||
Dim Shared As String currentMethod
|
||||
Dim Shared As String currentModule
|
||||
Dim Shared As Integer programMethods
|
||||
Dim Shared As Integer dataTicker
|
||||
dataTicker = 1
|
||||
|
||||
' Only execute the conversion from the native version if we have been passed the
|
||||
' source file to convert on the command line
|
||||
|
@ -822,9 +824,13 @@ Function ConvertData$ (args As String)
|
|||
argc = ListSplit(args, parts())
|
||||
Dim i As Integer
|
||||
Dim r As String
|
||||
Dim q As String
|
||||
r = "["
|
||||
For i = 1 To argc
|
||||
r = r + parts(i)
|
||||
q = parts(i)
|
||||
If (Left$(LTrim$(q), 1) <> Chr$(34)) Then q = Chr$(34) + q
|
||||
If (Right$(RTrim$(q), 1) <> Chr$(34)) Then q = q + Chr$(34)
|
||||
r = r + q
|
||||
If (i < argc) Then r = r + ","
|
||||
Next
|
||||
ConvertData$ = r + "]"
|
||||
|
@ -1684,8 +1690,17 @@ Function ReadLine (lineIndex As Integer, fline As String, rawJS As Integer)
|
|||
|
||||
ReadLine = rawJS
|
||||
|
||||
If _Trim$(fline) = "" Then Exit Function
|
||||
If (_Trim$(LCase$(Left$(fline, 4))) = "data") Then
|
||||
AddLineTop dataTicker, fline
|
||||
AddSubLinesTop dataTicker, fline
|
||||
Exit Function
|
||||
End If
|
||||
If (_Trim$(LCase$(Left$(fline, 6))) = "_label") Then
|
||||
AddLineTop dataTicker, fline
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
If _Trim$(fline) = "" Then Exit Function
|
||||
|
||||
Dim word As String
|
||||
Dim words(0) As String
|
||||
|
@ -1765,6 +1780,29 @@ Sub AddSubLines (lineIndex As Integer, fline As String)
|
|||
AddLine lineIndex, fline
|
||||
End Sub
|
||||
|
||||
Sub AddSubLinesTop (lineIndex As Integer, fline As String)
|
||||
Dim quoteDepth As Integer
|
||||
quoteDepth = 0
|
||||
Dim i As Integer
|
||||
For i = 1 To Len(fline)
|
||||
Dim c As String
|
||||
c = Mid$(fline, i, 1)
|
||||
If c = Chr$(34) Then
|
||||
If quoteDepth = 0 Then
|
||||
quoteDepth = 1
|
||||
Else
|
||||
quoteDepth = 0
|
||||
End If
|
||||
End If
|
||||
If quoteDepth = 0 And c = ":" Then
|
||||
AddLineTop lineIndex, Left$(fline, i - 1)
|
||||
fline = Right$(fline, Len(fline) - i)
|
||||
i = 0
|
||||
End If
|
||||
Next i
|
||||
|
||||
AddLineTop lineIndex, fline
|
||||
End Sub
|
||||
|
||||
Sub FindMethods
|
||||
Dim i As Integer
|
||||
|
@ -2210,6 +2248,18 @@ Sub AddQBMethod (mtype As String, mname As String, sync As Integer)
|
|||
AddMethod m, "QB.", sync
|
||||
End Sub
|
||||
|
||||
Sub AddLineTop (lineIndex As Integer, fline As String)
|
||||
Dim lcount As Integer: lcount = UBound(lines) + 1
|
||||
ReDim _Preserve As CodeLine lines(lcount)
|
||||
Dim j As Integer
|
||||
For j = UBound(lines) To dataTicker Step -1
|
||||
lines(j).line = lines(j - 1).line
|
||||
lines(j).text = lines(j - 1).text
|
||||
Next
|
||||
lines(dataTicker).line = dataTicker
|
||||
lines(dataTicker).text = fline
|
||||
dataTicker = dataTicker + 1
|
||||
End Sub
|
||||
|
||||
Sub AddLine (lineIndex As Integer, fline As String)
|
||||
__AddLine lineIndex, fline
|
||||
|
@ -2924,7 +2974,6 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "InKey$", False
|
||||
AddQBMethod "FUNCTION", "InStr", False
|
||||
AddQBMethod "FUNCTION", "Int", False
|
||||
AddQBMethod "SUB", "Label", False
|
||||
AddQBMethod "FUNCTION", "LBound", False
|
||||
AddQBMethod "FUNCTION", "Left$", False
|
||||
AddQBMethod "FUNCTION", "LCase$", False
|
||||
|
@ -2969,6 +3018,7 @@ Sub InitQBMethods
|
|||
' QBJS-only language features
|
||||
' --------------------------------------------------------------------------------
|
||||
AddQBMethod "SUB", "IncludeJS", True
|
||||
AddQBMethod "SUB", "_Label", False
|
||||
|
||||
' Undocumented at present
|
||||
AddSystemType "FETCHRESPONSE", "ok:INTEGER,status:INTEGER,statusText:STRING,text:STRING"
|
||||
|
|
Loading…
Reference in a new issue