mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-19 20:14:58 +00:00
Prototyped Data/Read/Restore system. Created temporary "Label" keyword.
This commit is contained in:
parent
aabda0a873
commit
bfec2ddf57
4 changed files with 137 additions and 7 deletions
|
@ -40,12 +40,12 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
||||
'_putimage', '_r2d', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_screenexists', '_sinh', '_source', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol',
|
||||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'draw', 'exp',
|
||||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'draw', 'exp',
|
||||
'fix', 'hex', 'input', 'inkey', 'instr', 'int', 'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'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']
|
||||
'export', 'from', 'import', 'label']
|
||||
|
||||
var builtinConsts = ['_off', '_smooth', '_stretch', '_squarepixels',
|
||||
'gx_true', 'gx_false', 'gxevent_init', 'gxevent_update', 'gxevent_drawbg', 'gxevent_drawmap', 'gxevent_drawscreen',
|
||||
|
|
33
qb.js
33
qb.js
|
@ -36,6 +36,9 @@ var QB = new function() {
|
|||
var _resizeWidth = 0;
|
||||
var _resizeHeight = 0;
|
||||
var _currScreenImage = null;
|
||||
var _dataBulk = [];
|
||||
var _readCursorPosition;
|
||||
var _dataLabelMap = new Map();
|
||||
|
||||
// Array handling methods
|
||||
// ----------------------------------------------------
|
||||
|
@ -632,6 +635,14 @@ 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);
|
||||
};
|
||||
|
@ -1194,6 +1205,10 @@ var QB = new function() {
|
|||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
this.sub_Label = function(t) {
|
||||
_dataLabelMap.set(t, _dataBulk.length);
|
||||
};
|
||||
|
||||
this.sub_Line = function(sstep, sx, sy, estep, ex, ey, color, style, pattern) {
|
||||
var screen = _images[_activeImage];
|
||||
var ctx = screen.ctx;
|
||||
|
@ -1588,6 +1603,21 @@ var QB = new function() {
|
|||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
this.sub_Read = function(values) {
|
||||
for (var i=0; i < values.length; i++) {
|
||||
values[i] = _dataBulk[_readCursorPosition];
|
||||
_readCursorPosition += 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.sub_Restore = function(t) {
|
||||
if (t == undefined) {
|
||||
_readCursorPosition = 0;
|
||||
} else {
|
||||
_readCursorPosition = (1.0)*_dataLabelMap.get(t);
|
||||
}
|
||||
};
|
||||
|
||||
this.func_Right = function(value, n) {
|
||||
if (value == undefined) {
|
||||
return "";
|
||||
|
@ -1647,7 +1677,6 @@ var QB = new function() {
|
|||
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0};
|
||||
_images[0].lastX = _images[0].canvas.width/2;
|
||||
_images[0].lastY = _images[0].canvas.height/2;
|
||||
//_images[0].lineWidth = _strokeLineThickness; // this line does nothing
|
||||
|
||||
// initialize the graphics
|
||||
_fgColor = _color(7);
|
||||
|
@ -1666,6 +1695,8 @@ var QB = new function() {
|
|||
_keyHitBuffer = [];
|
||||
_keyDownMap = {};
|
||||
|
||||
_readCursorPosition = 0;
|
||||
|
||||
};
|
||||
|
||||
this.func_Sgn = function(value) {
|
||||
|
|
53
qb2js.js
53
qb2js.js
|
@ -511,10 +511,14 @@ var ConvertSub = null;
|
|||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertPrint( args)) +");";
|
||||
} else if ( m.name == "Input" || m.name == "Line Input" ) {
|
||||
js = (await func_ConvertInput( m, args));
|
||||
} else if ( m.name == "Read" ) {
|
||||
js = (await func_ConvertRead( m, args));
|
||||
} else if ( m.name == "Swap" ) {
|
||||
js = (await func_ConvertSwap( m, args));
|
||||
} else if ( m.name == "Cls" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertCls( args)) +");";
|
||||
} else if ( m.name == "Data" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertData( args)) +");";
|
||||
} else if ( m.name == "_PutImage" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertPutImage( args)) +");";
|
||||
} else if ( m.name == "Window" ) {
|
||||
|
@ -727,6 +731,51 @@ var bgcolor = ''; // STRING
|
|||
ConvertCls = method +", " + bgcolor;
|
||||
return ConvertCls;
|
||||
}
|
||||
async function func_ConvertData(args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertData = null;
|
||||
var argc = 0; // INTEGER
|
||||
var parts = QB.initArray([{l:1,u:0}], ''); // STRING
|
||||
argc = (await func_ListSplit( args, parts));
|
||||
var i = 0; // INTEGER
|
||||
var r = ''; // STRING
|
||||
r = "[";
|
||||
for ( i= 1; i <= argc; i= i + 1) { if (QB.halted()) { return; }
|
||||
r = r +QB.arrayValue(parts, [ i]).value;
|
||||
if (( i < argc) ) {
|
||||
r = r +",";
|
||||
}
|
||||
}
|
||||
ConvertData = r +"]";
|
||||
return ConvertData;
|
||||
}
|
||||
async function func_ConvertRead(m/*METHOD*/,args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertRead = null;
|
||||
var js = ''; // STRING
|
||||
var vname = ''; // STRING
|
||||
var pcount = 0; // INTEGER
|
||||
var parts = QB.initArray([{l:1,u:0}], ''); // STRING
|
||||
var vars = QB.initArray([{l:1,u:0}], ''); // STRING
|
||||
var vcount = 0; // INTEGER
|
||||
var p = ''; // STRING
|
||||
pcount = (await func_ListSplit( args, parts));
|
||||
var i = 0; // INTEGER
|
||||
for ( i= 1; i <= pcount; i= i + 1) { if (QB.halted()) { return; }
|
||||
p = (QB.func__Trim( QB.arrayValue(parts, [ i]).value));
|
||||
vcount = (QB.func_UBound( vars)) + 1;
|
||||
QB.resizeArray(vars, [{l:1,u:vcount}], '', true); // STRING
|
||||
QB.arrayValue(vars, [ vcount]).value = p;
|
||||
}
|
||||
vname = await func_GenJSVar();
|
||||
js = "var " + vname +" = new Array(" +(QB.func_Str( (QB.func_UBound( vars)))) +");" +await func_LF();
|
||||
js = js +(await func_CallMethod( m)) +"(" + vname +");" +await func_LF();
|
||||
for ( i= 1; i <= (QB.func_UBound( vars)); i= i + 1) { if (QB.halted()) { return; }
|
||||
js = js +(await func_ConvertExpression( QB.arrayValue(vars, [ i]).value)) +" = " + vname +"[" +(QB.func_Str( i - 1)) +"];" +await func_LF();
|
||||
}
|
||||
ConvertRead = js;
|
||||
return ConvertRead;
|
||||
}
|
||||
async function func_ConvertCoordParam(param/*STRING*/,hasEndCoord/*INTEGER*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertCoordParam = null;
|
||||
|
@ -2734,6 +2783,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "Csrlin", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Cvi", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Cvl", False);
|
||||
await sub_AddQBMethod( "SUB", "Data", False);
|
||||
await sub_AddQBMethod( "SUB", "Draw", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Exp", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Fix", False);
|
||||
|
@ -2742,6 +2792,7 @@ 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);
|
||||
|
@ -2760,8 +2811,10 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "SUB", "PReset", False);
|
||||
await sub_AddQBMethod( "SUB", "Print", True);
|
||||
await sub_AddQBMethod( "SUB", "PSet", False);
|
||||
await sub_AddQBMethod( "SUB", "Restore", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Right$", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "RTrim$", False);
|
||||
await sub_AddQBMethod( "SUB", "Read", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Rnd", False);
|
||||
await sub_AddQBMethod( "SUB", "Screen", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Sgn", False);
|
||||
|
|
|
@ -601,12 +601,18 @@ Function ConvertSub$ (m As Method, args As String)
|
|||
ElseIf m.name = "Input" Or m.name = "Line Input" Then
|
||||
js = ConvertInput(m, args)
|
||||
|
||||
ElseIf m.name = "Read" Then
|
||||
js = ConvertRead(m, args)
|
||||
|
||||
ElseIf m.name = "Swap" Then
|
||||
js = ConvertSwap(m, args)
|
||||
|
||||
ElseIf m.name = "Cls" Then
|
||||
js = CallMethod(m) + "(" + ConvertCls(args) + ");"
|
||||
|
||||
ElseIf m.name = "Data" Then
|
||||
js = CallMethod(m) + "(" + ConvertData(args) + ");"
|
||||
|
||||
ElseIf m.name = "_PutImage" Then
|
||||
js = CallMethod(m) + "(" + ConvertPutImage(args) + ");"
|
||||
|
||||
|
@ -810,6 +816,45 @@ Function ConvertCls$ (args As String)
|
|||
ConvertCls$ = method + ", " + bgcolor
|
||||
End Function
|
||||
|
||||
Function ConvertData$ (args As String)
|
||||
Dim argc As Integer
|
||||
ReDim parts(0) As String
|
||||
argc = ListSplit(args, parts())
|
||||
Dim i As Integer
|
||||
Dim r As String
|
||||
r = "["
|
||||
For i = 1 To argc
|
||||
r = r + parts(i)
|
||||
If (i < argc) Then r = r + ","
|
||||
Next
|
||||
ConvertData$ = r + "]"
|
||||
End Function
|
||||
|
||||
Function ConvertRead$ (m As Method, args As String)
|
||||
Dim js As String
|
||||
Dim vname As String
|
||||
Dim pcount As Integer
|
||||
ReDim parts(0) As String
|
||||
ReDim vars(0) As String
|
||||
Dim vcount As Integer
|
||||
Dim p As String
|
||||
pcount = ListSplit(args, parts())
|
||||
Dim i As Integer
|
||||
For i = 1 To pcount
|
||||
p = _Trim$(parts(i))
|
||||
vcount = UBound(vars) + 1
|
||||
ReDim _Preserve As String vars(vcount)
|
||||
vars(vcount) = p
|
||||
Next i
|
||||
vname = GenJSVar
|
||||
js = "var " + vname + " = new Array(" + Str$(UBound(vars)) + ");" + LF
|
||||
js = js + CallMethod(m) + "(" + vname + ");" + LF
|
||||
For i = 1 To UBound(vars)
|
||||
js = js + ConvertExpression(vars(i)) + " = " + vname + "[" + Str$(i - 1) + "];" + LF
|
||||
Next i
|
||||
ConvertRead$ = js
|
||||
End Function
|
||||
|
||||
Function ConvertCoordParam$ (param As String, hasEndCoord As Integer)
|
||||
If _Trim$(param) = "" Then
|
||||
If hasEndCoord Then
|
||||
|
@ -964,7 +1009,6 @@ Function ConvertInput$ (m As Method, args As String)
|
|||
preventNewline = "true"
|
||||
Else
|
||||
addQuestionPrompt = "true"
|
||||
|
||||
End If
|
||||
ElseIf StartsWith(p, Chr$(34)) Then
|
||||
prompt = p
|
||||
|
@ -986,7 +1030,6 @@ Function ConvertInput$ (m As Method, args As String)
|
|||
ConvertInput = js
|
||||
End Function
|
||||
|
||||
|
||||
Function ConvertSwap$ (m As Method, args As String)
|
||||
Dim js As String
|
||||
Dim swapArray As String: swapArray = GenJSVar
|
||||
|
@ -2872,6 +2915,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "Csrlin", False
|
||||
AddQBMethod "FUNCTION", "Cvi", False
|
||||
AddQBMethod "FUNCTION", "Cvl", False
|
||||
AddQBMethod "SUB", "Data", False
|
||||
AddQBMethod "SUB", "Draw", False
|
||||
AddQBMethod "FUNCTION", "Exp", False
|
||||
AddQBMethod "FUNCTION", "Fix", False
|
||||
|
@ -2880,6 +2924,7 @@ 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
|
||||
|
@ -2898,8 +2943,10 @@ Sub InitQBMethods
|
|||
AddQBMethod "SUB", "PReset", False
|
||||
AddQBMethod "SUB", "Print", True
|
||||
AddQBMethod "SUB", "PSet", False
|
||||
AddQBMethod "SUB", "Restore", False
|
||||
AddQBMethod "FUNCTION", "Right$", False
|
||||
AddQBMethod "FUNCTION", "RTrim$", False
|
||||
AddQBMethod "SUB", "Read", False
|
||||
AddQBMethod "FUNCTION", "Rnd", False
|
||||
AddQBMethod "SUB", "Screen", False
|
||||
AddQBMethod "FUNCTION", "Sgn", False
|
||||
|
@ -2919,7 +2966,6 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "Varptr", False
|
||||
AddQBMethod "SUB", "Window", False
|
||||
|
||||
|
||||
' QBJS-only language features
|
||||
' --------------------------------------------------------------------------------
|
||||
AddQBMethod "SUB", "IncludeJS", True
|
||||
|
|
Loading…
Reference in a new issue