1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-09-19 20:14:58 +00:00

Merge pull request #30 from WFBarnes/main

Keyword updates: CINT, CDBL, CLNG, CSNG (partial)
This commit is contained in:
boxgaming 2022-06-16 19:54:57 -05:00 committed by GitHub
commit 2f981e3c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 35 deletions

View file

@ -40,7 +40,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
'_putimage', '_r2d', '_r2g', '_readbit', '_red', '_red32', '_resetbit', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
'_screenexists', '_sech', '_setbit', '_shl', '_shr', '_sinh', '_source', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_strcmp', '_stricmp', '_tanh',
'_title', '_trim', '_togglebit', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'draw', 'exp',
'_title', '_trim', '_togglebit', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'cdbl', 'cint', 'clng', 'csng', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'date', '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', 'randomize', 'read', 'restore', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr', 'window',

44
qb.js
View file

@ -616,7 +616,11 @@ var QB = new function() {
}
this.func__Round = function(value) {
return Math.round(value);
if (value < 0) {
return -Math.round(-value);
} else {
return Math.round(value);
}
};
this.func__ScreenExists = function() {
@ -832,6 +836,14 @@ var QB = new function() {
return result;
}
this.func_Date = function() {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
return mm + '-' + dd + '-' + yyyy;
}
this.sub_Draw = function(t) {
// Turn input string into array of characters.
@ -1261,6 +1273,33 @@ var QB = new function() {
return Math.log(value);
};
this.func_Cdbl = function(value) {
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer);
view.setFloat32(1, value);
return view.getFloat32(1);
};
this.func_Cint = function(value) {
if (value > 0) {
return Math.round(value);
} else {
return -Math.round(-value);
}
};
this.func_Clng = function(value) {
if (value > 0) {
return Math.round(value);
} else {
return -Math.round(-value);
}
};
this.func_Csng = function(value) {
return value; // TODO: Implement this.
};
this.sub_Circle = function(step, x, y, radius, color, startAngle, endAngle, aspect) {
var screen = _images[_activeImage];
@ -1783,7 +1822,7 @@ var QB = new function() {
}
this.sub_Restore = function(t) {
if (t == undefined || t.trim() == "") {
if ((t == undefined) || (t.trim() == "")) {
_readCursorPosition = 0;
} else {
_readCursorPosition = _dataLabelMap[t];
@ -1988,6 +2027,7 @@ var QB = new function() {
this.func_Val = function(value) {
var ret;
value = value.toString();
if (value.substring(0, 2) == "&H") {
ret = parseInt(value.slice(2), 16);
} else if (value.substring(0, 2) == "&O") {

View file

@ -30,8 +30,6 @@ async function _QBCompiler() {
var currentMethod = ''; // STRING
var currentModule = ''; // STRING
var programMethods = 0; // INTEGER
var dataTicker = 0; // INTEGER
dataTicker = 1;
if (QB.func_Command() != "" ) {
await sub_QBToJS( QB.func_Command(), FILE, "");
await sub_PrintJS();
@ -769,8 +767,8 @@ var ConvertRandomize = null;
if (((QB.func_UCase( (QB.func__Trim( (QB.func_Left( args, 5)))))) == "USING") ) {
uusing = "true";
theseed = (QB.func__Trim( (QB.func_Right( args, (QB.func_Len( args)) - 5))));
theseed = (await func_ConvertExpression( theseed));
}
theseed = (await func_ConvertExpression( theseed));
}
ConvertRandomize = (await func_CallMethod( m)) +"(" + uusing +", " + theseed +")";
return ConvertRandomize;
@ -2847,6 +2845,10 @@ if (QB.halted()) { return; }
await sub_AddQBMethod( "FUNCTION", "Atn", False);
await sub_AddQBMethod( "SUB", "Beep", False);
await sub_AddQBMethod( "FUNCTION", "Chr$", False);
await sub_AddQBMethod( "FUNCTION", "Cdbl", False);
await sub_AddQBMethod( "FUNCTION", "Cint", False);
await sub_AddQBMethod( "FUNCTION", "Clng", False);
await sub_AddQBMethod( "FUNCTION", "Csng", False);
await sub_AddQBMethod( "SUB", "Circle", False);
await sub_AddQBMethod( "SUB", "Cls", False);
await sub_AddQBMethod( "SUB", "Color", False);
@ -2855,6 +2857,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( "FUNCTION", "Date$", False);
await sub_AddQBMethod( "SUB", "Draw", False);
await sub_AddQBMethod( "FUNCTION", "Exp", False);
await sub_AddQBMethod( "FUNCTION", "Fix", False);

View file

@ -2,6 +2,8 @@ Option _Explicit
$Console:Only
'$ExeIcon:'./../gx/resource/gx.ico'
' In console, after creating qb2js.exe, run: qb2js qb2js.bas > ../qb2js.js
Const FILE = 1
Const TEXT = 2
Const False = 0
@ -68,8 +70,6 @@ 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
@ -858,8 +858,8 @@ Function ConvertRandomize$ (m As Method, args As String)
If (UCase$(_Trim$(Left$(args, 5))) = "USING") Then
uusing = "true"
theseed = _Trim$(Right$(args, Len(args) - 5))
theseed = ConvertExpression(theseed)
End If
theseed = ConvertExpression(theseed)
End If
ConvertRandomize = CallMethod(m) + "(" + uusing + ", " + theseed + ")"
End Function
@ -1718,19 +1718,6 @@ Function ReadLine (lineIndex As Integer, fline As String, rawJS As Integer)
ReadLine = rawJS
'If (_Trim$(LCase$(Left$(fline, 4))) = "data") Then
' 'AddLineTop dataTicker, fline
' 'AddSubLinesTop dataTicker, fline
' AddLine dataTicker, fline
' AddSubLines dataTicker, fline
' Exit Function
'End If
'If (_Trim$(LCase$(Left$(fline, 6))) = "_label") Then
' 'AddLineTop dataTicker, fline
' AddLine dataTicker, fline
' Exit Function
'End If
If _Trim$(fline) = "" Then Exit Function
Dim word As String
@ -2306,19 +2293,6 @@ 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
End Sub
@ -3038,6 +3012,10 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "Atn", False
AddQBMethod "SUB", "Beep", False
AddQBMethod "FUNCTION", "Chr$", False
AddQBMethod "FUNCTION", "Cdbl", False
AddQBMethod "FUNCTION", "Cint", False
AddQBMethod "FUNCTION", "Clng", False
AddQBMethod "FUNCTION", "Csng", False
AddQBMethod "SUB", "Circle", False
AddQBMethod "SUB", "Cls", False
AddQBMethod "SUB", "Color", False
@ -3046,6 +3024,7 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "Csrlin", False
AddQBMethod "FUNCTION", "Cvi", False
AddQBMethod "FUNCTION", "Cvl", False
AddQBMethod "FUNCTION", "Date$", False
AddQBMethod "SUB", "Draw", False
AddQBMethod "FUNCTION", "Exp", False
AddQBMethod "FUNCTION", "Fix", False