[Scripter]
* BUG Fix EXTERN definitions correctly outside generated main() definition in lazy scripts(no main) * BUG Fix Ensure externs are after all structures in lazy script(no main) * BUG Fix Enum and Const to be outside before Structures in lazy scripts(no main) * NEW Added two new testscripts to project to test structures and externs with and without main() defined
This commit is contained in:
parent
6588c9c1e6
commit
88367440fc
8 changed files with 152 additions and 12 deletions
|
@ -8,8 +8,8 @@ Component=gb.eval
|
||||||
Component=gb.pcre
|
Component=gb.pcre
|
||||||
Description="Gambas Script"
|
Description="Gambas Script"
|
||||||
Authors="Fabien Bodard, Benoit Minisini, Brian G"
|
Authors="Fabien Bodard, Benoit Minisini, Brian G"
|
||||||
Arguments=[["--help"],["--use","'gb.notify,gb.web'","-e","For i as Integer = 0 To 10:Print \"Hello World\":Next"],["~/bin/who"],["-c","-T","~/bin/mytest"],["-v","TestApp"],["--verbose","TestAppWithMain"],["--verbose","TestLazyApp"],["-c","~/testerror.gbs"],["~/Scripts/TestQuoteAtEnd"],["-c","~/Scripts/AForm"],["-c","-v","-w","~/Scripts/GambasHelpSearch"],["-c","-v","-w","~/Scripts/AMain"],["-c","-v","-w","~/Scripts/gshoutput"],["-c","-v","-w","~/Scripts/TestSets/TestWebApp.gbs"],["--convert-project","~/Projects/TestPrograms/testerror"],["--convert-project","~/Projects/TestPrograms/testusingtxthighlight","~/Scripts/TestSets"],["-c","-v","~/Scripts/TestSets/testusingtxthighlight.gbs"],["-l","library"],["-c","-v","-w","~/Scripts/TestScripterNoMain"],["-c","-v","-w","~/Scripts/TestGUI.gbs"],["-c","-v","-w","~/Scripts/TestSets/CPU_Test.gbs"],["-c","-v","-w","~/Scripts/TestSets/TestWebPage.gbs"],["-c","-v","-w","--convert-script","~/Scripts/TestSets/CPU_Test.gbs","~/Scripts"],["-c","-v","-w","~/Scripts/CPU_Test"],["-c","-v","-w","-p","~/Scripts/TestPlugin","~/myplugins"],["-c","-v","-w","~/Scripts/RunComponent"],["-c","-v","-w","~/Scripts/testshell.gbs"],["-v","~/Projects/TestTimer"],["-c","-v","-w","~/gbs3testwithclass.gbs"],["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"]]
|
Arguments=[["--help"],["--use","'gb.notify,gb.web'","-e","For i as Integer = 0 To 10:Print \"Hello World\":Next"],["~/bin/who"],["-c","-T","~/bin/mytest"],["-v","TestApp"],["--verbose","TestAppWithMain"],["--verbose","TestLazyApp"],["-c","~/testerror.gbs"],["~/Scripts/TestQuoteAtEnd"],["-c","~/Scripts/AForm"],["-c","-v","-w","~/Scripts/GambasHelpSearch"],["-c","-v","-w","~/Scripts/AMain"],["-c","-v","-w","~/Scripts/gshoutput"],["-c","-v","-w","~/Scripts/TestSets/TestWebApp.gbs"],["--convert-project","~/Projects/TestPrograms/testerror"],["--convert-project","~/Projects/TestPrograms/testusingtxthighlight","~/Scripts/TestSets"],["-c","-v","~/Scripts/TestSets/testusingtxthighlight.gbs"],["-l","library"],["-c","-v","-w","~/Scripts/TestScripterNoMain"],["-c","-v","-w","~/Scripts/TestGUI.gbs"],["-c","-v","-w","~/Scripts/TestSets/CPU_Test.gbs"],["-c","-v","-w","~/Scripts/TestSets/TestWebPage.gbs"],["-c","-v","-w","--convert-script","~/Scripts/TestSets/CPU_Test.gbs","~/Scripts"],["-c","-v","-w","~/Scripts/CPU_Test"],["-c","-v","-w","-p","~/Scripts/TestPlugin","~/myplugins"],["-c","-v","-w","~/Scripts/RunComponent"],["-c","-v","-w","~/Scripts/testshell.gbs"],["-v","~/Projects/TestTimer"],["-c","-v","-w","~/gbs3testwithclass.gbs"],["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"],["-c","-v","-w","TestExternStructNoMain.gbs"],["-c","-v","-w","TestExternStructWithMain.gbs"]]
|
||||||
CurrentArgumentList=["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"]
|
CurrentArgumentList=["-c","-v","-w","TestExternStructWithMain.gbs"]
|
||||||
TabSize=2
|
TabSize=2
|
||||||
Translate=1
|
Translate=1
|
||||||
Language=en_US
|
Language=en_US
|
||||||
|
|
|
@ -13,12 +13,13 @@ Public $bArchiveOutput As Boolean = False ' Indicates that the user want
|
||||||
|
|
||||||
Public $bScriptSourceStdIn As Boolean = False ' If file name is - or no filename is provided input from file.in(stdin)
|
Public $bScriptSourceStdIn As Boolean = False ' If file name is - or no filename is provided input from file.in(stdin)
|
||||||
|
|
||||||
Public $sPreambleHeader As String ' contains comments and such to be put before the file
|
Public $sPreambleHeader As String ' contains comments and such to be put before the file
|
||||||
Public $sProgramHeader As String ' Contains statements and variable definitions needed before pubic sub main is defined
|
Public $sProgramHeader As String ' Contains statements and variable definitions needed before pubic sub main is defined
|
||||||
|
Public $sExternals As String ' Contains all the externals defined in a script
|
||||||
Public $sCompilerOptions As String ' Contains all the compiler options -- fast, unsafe etc
|
Public $sCompilerOptions As String ' Contains all the compiler options -- fast, unsafe etc
|
||||||
Public $sStructures As String ' Public structs that are global and outside and before the public sub main definition
|
Public $sStructures As String ' Public structs that are global and outside and before the public sub main definition
|
||||||
Public $sFinalProgram As String ' The final program Assembled from the script file to be written before compile is invoked
|
Public $sFinalProgram As String ' The final program Assembled from the script file to be written before compile is invoked
|
||||||
Public $bClassAsStartup As Boolean = False ' This indicates that the startup is a class not a module we create
|
Public $bClassAsStartup As Boolean = False ' This indicates that the startup is a class not a module we create
|
||||||
|
|
||||||
Public $bBuildOnly As Boolean ' add support to have scripter build the project only and print out the source files
|
Public $bBuildOnly As Boolean ' add support to have scripter build the project only and print out the source files
|
||||||
'Public $bPrecompiler As Boolean ' precompiler is enabled on the command line programs {i}var1 = 3 -> Dim Var1 as integer : var1 = 3
|
'Public $bPrecompiler As Boolean ' precompiler is enabled on the command line programs {i}var1 = 3 -> Dim Var1 as integer : var1 = 3
|
||||||
|
|
|
@ -41,6 +41,9 @@ Public Sub _Call($oContext As Context, Path As String, sPrjPath As String)
|
||||||
'If Not cReader.bModuleStartup Then
|
'If Not cReader.bModuleStartup Then
|
||||||
If cReader.IsMainDefined() Then
|
If cReader.IsMainDefined() Then
|
||||||
$oContext.$sFinalProgram = cReader.GetProgram()
|
$oContext.$sFinalProgram = cReader.GetProgram()
|
||||||
|
Verbose("Before Compile--------------------------------------------------")
|
||||||
|
Verbose(MakeListing.GenListing($oContext, $oContext.$sFinalProgram))
|
||||||
|
Verbose("_____________________________________________")
|
||||||
Else If cReader.HasPublicOrSub() Then
|
Else If cReader.HasPublicOrSub() Then
|
||||||
cReader.DisplayWarnings()
|
cReader.DisplayWarnings()
|
||||||
If $oContext.$bAllowLazyScript Then
|
If $oContext.$bAllowLazyScript Then
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
' Gambas module file
|
' Gambas module file
|
||||||
|
|
||||||
Private aDefWords As Collection = ["PUBLIC": True, "STATIC": True, "STRUCT": True, "FAST": True, "UNSAFE": True, "PRIVATE": True, "ENUM": True]
|
Private aDefWords As Collection = ["PUBLIC": True, "STATIC": True, "STRUCT": True, "FAST": True, "UNSAFE": True, "PRIVATE": True, "ENUM": True, "EXTERN": True, "CONST": True]
|
||||||
Private aDefFunc As Collection = ["SUB": True, "PROCEDURE": True, "FUNCTION": True]
|
Private aDefFunc As Collection = ["SUB": True, "PROCEDURE": True, "FUNCTION": True]
|
||||||
Private aSpecial As Collection = ["STRUCT": True, "ENUM": True]
|
Private aSpecial As Collection = ["STRUCT": True, "ENUM": True, "EXTERN": True, "CONST": True]
|
||||||
|
|
||||||
Private $iAdjustedOffset As Integer
|
Private $iAdjustedOffset As Integer
|
||||||
|
|
||||||
|
@ -45,12 +45,21 @@ Public Sub _call(oContext As Context, Program As Reader) As String
|
||||||
If s = "ENUM" Then
|
If s = "ENUM" Then
|
||||||
Dim DefEnum As String = ProcessVariable(Program, i - $iAdjustedOffset)
|
Dim DefEnum As String = ProcessVariable(Program, i - $iAdjustedOffset)
|
||||||
If Upper(DefEnum) Begins "ENUM" Then DefEnum = "Public " & DefEnum
|
If Upper(DefEnum) Begins "ENUM" Then DefEnum = "Public " & DefEnum
|
||||||
DefOutPut &= DefEnum & "\n"
|
oContext.$sProgramHeader &= DefEnum & "\n"
|
||||||
|
Break
|
||||||
|
Else If s = "CONST" Then
|
||||||
|
Dim DefConst As String = ProcessVariable(Program, i - $iAdjustedOffset)
|
||||||
|
If Upper(DefCONST) Begins "CONST" Then DefConst = "Public " & DefConst
|
||||||
|
oContext.$sProgramHeader &= DefConst & "\n"
|
||||||
|
Break
|
||||||
|
Else If s = "EXTERN" Then
|
||||||
|
Dim DefExtern As String = AdjustProgram(Program, i - $iAdjustedOffset, i - $iAdjustedOffset)
|
||||||
|
oContext.$sExternals &= DefExtern & "\n"
|
||||||
Break
|
Break
|
||||||
Else
|
Else
|
||||||
Dim DefStruct As String = ProcessBlock(Program, i - $iAdjustedOffset, ["END", "STRUCT"])
|
Dim DefStruct As String = ProcessBlock(Program, i - $iAdjustedOffset, ["END", "STRUCT"])
|
||||||
If Upper(DefStruct) Begins "STRUCT" Then DefStruct = "Public " & DefStruct
|
If Upper(DefStruct) Begins "STRUCT" Then DefStruct = "Public " & DefStruct
|
||||||
DefOutPut &= DefStruct & "\n"
|
oContext.$sStructures &= DefStruct & "\n"
|
||||||
Break
|
Break
|
||||||
Endif
|
Endif
|
||||||
Endif
|
Endif
|
||||||
|
@ -59,7 +68,7 @@ Public Sub _call(oContext As Context, Program As Reader) As String
|
||||||
|
|
||||||
MainOutPut &= Program.ProgramLines.Join("\n") & "\nEND\n"
|
MainOutPut &= Program.ProgramLines.Join("\n") & "\nEND\n"
|
||||||
Verbose("Before Compile--------------------------------------------------")
|
Verbose("Before Compile--------------------------------------------------")
|
||||||
Verbose(MakeListing.GenListing(oContext, DefOutput & MainOutPut))
|
Verbose(MakeListing.GenListing(oContext, oContext.$sProgramHeader & oContext.$sStructures & oContext.$sExternals & DefOutput & MainOutPut))
|
||||||
Verbose("_____________________________________________")
|
Verbose("_____________________________________________")
|
||||||
Return DefOutput & MainOutPut
|
Return DefOutput & MainOutPut
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ Public Sub _Call($oContext As Context, sPath As String, Optional sProjectLocatio
|
||||||
$oContext.$sStructures = ""
|
$oContext.$sStructures = ""
|
||||||
$oContext.$sProgramHeader = ""
|
$oContext.$sProgramHeader = ""
|
||||||
$oContext.$sCompilerOptions = ""
|
$oContext.$sCompilerOptions = ""
|
||||||
|
$oContext.$sExternals = ""
|
||||||
|
|
||||||
If $oContext.$bCreateProject Then
|
If $oContext.$bCreateProject Then
|
||||||
Dim sPathInfo As String = File.Dir(sPath)
|
Dim sPathInfo As String = File.Dir(sPath)
|
||||||
|
@ -102,6 +103,7 @@ Public Sub _Call($oContext As Context, sPath As String, Optional sProjectLocatio
|
||||||
If $oContext.$sPreambleHeader <> "" Then Print #$hOutFile, $oContext.$sPreambleHeader
|
If $oContext.$sPreambleHeader <> "" Then Print #$hOutFile, $oContext.$sPreambleHeader
|
||||||
If $oContext.$sCompilerOptions <> "" Then Print #$hOutFile, $oContext.$sCompilerOptions
|
If $oContext.$sCompilerOptions <> "" Then Print #$hOutFile, $oContext.$sCompilerOptions
|
||||||
If $oContext.$sStructures <> "" Then Print #$hOutFile, $oContext.$sStructures
|
If $oContext.$sStructures <> "" Then Print #$hOutFile, $oContext.$sStructures
|
||||||
|
If $oContext.$sExternals <> "" Then Print #$hOutFile, $oContext.$sExternals
|
||||||
If $oContext.$sProgramHeader <> "" Then Print #$hOutFile, $oContext.$sProgramHeader
|
If $oContext.$sProgramHeader <> "" Then Print #$hOutFile, $oContext.$sProgramHeader
|
||||||
If $oContext.$bPlugin Then Print #$hOutFile, PluginInfo()
|
If $oContext.$bPlugin Then Print #$hOutFile, PluginInfo()
|
||||||
If $oContext.$sFinalProgram <> "" Then Print #$hOutFile, $oContext.$sFinalProgram
|
If $oContext.$sFinalProgram <> "" Then Print #$hOutFile, $oContext.$sFinalProgram
|
||||||
|
|
|
@ -99,7 +99,8 @@ Private Sub GetFile(SourceFile As String) As String
|
||||||
|
|
||||||
End
|
End
|
||||||
|
|
||||||
Private $cKeywords As Collection = ["PRIVATE": True, "PUBLIC": True, "STATIC": True, "SUB": True, "FUNCTION": True, "PROCEDURE": True, "STRUCT": True, "ENUM": True, "CLASSREF": True]
|
Private $cKeywords As Collection = ["PRIVATE": True, "PUBLIC": True, "STATIC": True, "SUB": True, "FUNCTION": True, "PROCEDURE": True, "STRUCT": True, "ENUM": True, "CLASSREF": True,
|
||||||
|
"EXTERN": True, "CONST": True]
|
||||||
Private $cFuncDef As Collection = ["SUB": True, "FUNCTION": True, "PROCUDURE": True]
|
Private $cFuncDef As Collection = ["SUB": True, "FUNCTION": True, "PROCUDURE": True]
|
||||||
Private $cAllowedInSub As Collection = ["STATIC": True]
|
Private $cAllowedInSub As Collection = ["STATIC": True]
|
||||||
|
|
||||||
|
|
62
app/src/gbs3/TestExternStructNoMain.gbs
Normal file
62
app/src/gbs3/TestExternStructNoMain.gbs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/gbs3
|
||||||
|
' Gambas module file
|
||||||
|
|
||||||
|
Public Struct newit
|
||||||
|
x[20] As Byte
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Public Struct byeit
|
||||||
|
c As Integer
|
||||||
|
b As Float
|
||||||
|
e[20] As Struct Newit
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Public Struct Hello
|
||||||
|
b As Integer
|
||||||
|
c As Integer
|
||||||
|
d As Long
|
||||||
|
e As Float
|
||||||
|
f As Struct Byeit
|
||||||
|
g[20] As Struct Byeit
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Enum er, et, ey = 20
|
||||||
|
|
||||||
|
' We will use memcpy for two purposes , get the real address of the data, actually copy the data
|
||||||
|
Extern memcpy(dest As Hello, src As Hello, len As Integer) As Pointer In "libc:6"
|
||||||
|
Extern Arraymemcpy(dest As Pointer, src As Pointer, len As Integer) As Pointer In "libc:6" Exec "memcpy"
|
||||||
|
Const unitcount As Integer = 20
|
||||||
|
|
||||||
|
Public b As Struct Hello
|
||||||
|
Public c[20] As Struct Hello
|
||||||
|
|
||||||
|
Sub test()
|
||||||
|
'Static xx As Struct Hello
|
||||||
|
Print "Test Sub"
|
||||||
|
End
|
||||||
|
|
||||||
|
'Public Sub Main()
|
||||||
|
b.b = 43
|
||||||
|
Dim a As Variant = b
|
||||||
|
Dim e As Hello = c[1] ' these just set pointers
|
||||||
|
Dim f As Hello = c[2]
|
||||||
|
Dim g As Hello = c[3]
|
||||||
|
g.d = 500
|
||||||
|
g.e = 3.67
|
||||||
|
c[3].g[0].e[0].x[0] = 32
|
||||||
|
' Calc Struct length do pointer math c[1]-c[0]
|
||||||
|
Dim iStructLen As Integer = memcpy(c[1], c[1], 0) - memcpy(c[0], c[0], 0)
|
||||||
|
|
||||||
|
Print "Struct len = "; iStructLen, "Dest Values before copy ", f.d, f.e, f.g[0].e[0].x[0]
|
||||||
|
'Copy one entry to another
|
||||||
|
memcpy(f, g, iStructLen)
|
||||||
|
Print c[2].d, c[2].e, c[2].g[0].e[0].x[0] ' g = c[3] f = c[2]
|
||||||
|
a.b = 45
|
||||||
|
|
||||||
|
Print a.b, b.b
|
||||||
|
' Display the actual address Of Each element And root
|
||||||
|
Print memcpy(a, a, 0), memcpy(b, b, 0), arraymemcpy(VarPtr(c), VarPtr(c), 0), memcpy(e, e, 0), memcpy(f, f, 0), memcpy(g, g, 0)
|
||||||
|
Print VarPtr(a), VarPtr(b), VarPtr(c)
|
||||||
|
Print "Hello world"
|
||||||
|
|
||||||
|
'End
|
62
app/src/gbs3/TestExternStructWithMain.gbs
Normal file
62
app/src/gbs3/TestExternStructWithMain.gbs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/gbs3
|
||||||
|
' Gambas module file
|
||||||
|
|
||||||
|
Public Struct newit
|
||||||
|
x[20] As Byte
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Public Struct byeit
|
||||||
|
c As Integer
|
||||||
|
b As Float
|
||||||
|
e[20] As Struct Newit
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Public Struct Hello
|
||||||
|
b As Integer
|
||||||
|
c As Integer
|
||||||
|
d As Long
|
||||||
|
e As Float
|
||||||
|
f As Struct Byeit
|
||||||
|
g[20] As Struct Byeit
|
||||||
|
End Struct
|
||||||
|
|
||||||
|
Enum er, et, ey = 20
|
||||||
|
|
||||||
|
' We will use memcpy for two purposes , get the real address of the data, actually copy the data
|
||||||
|
Extern memcpy(dest As Hello, src As Hello, len As Integer) As Pointer In "libc:6"
|
||||||
|
Extern Arraymemcpy(dest As Pointer, src As Pointer, len As Integer) As Pointer In "libc:6" Exec "memcpy"
|
||||||
|
Const unitcount As Integer = 20
|
||||||
|
|
||||||
|
Public b As Struct Hello
|
||||||
|
Public c[20] As Struct Hello
|
||||||
|
|
||||||
|
Sub test()
|
||||||
|
'Static xx As Struct Hello
|
||||||
|
Print "Test Sub"
|
||||||
|
End
|
||||||
|
|
||||||
|
Public Sub Main()
|
||||||
|
b.b = 43
|
||||||
|
Dim a As Variant = b
|
||||||
|
Dim e As Hello = c[1] ' these just set pointers
|
||||||
|
Dim f As Hello = c[2]
|
||||||
|
Dim g As Hello = c[3]
|
||||||
|
g.d = 500
|
||||||
|
g.e = 3.67
|
||||||
|
c[3].g[0].e[0].x[0] = 32
|
||||||
|
' Calc Struct length do pointer math c[1]-c[0]
|
||||||
|
Dim iStructLen As Integer = memcpy(c[1], c[1], 0) - memcpy(c[0], c[0], 0)
|
||||||
|
|
||||||
|
Print "Struct len = "; iStructLen, "Dest Values before copy ", f.d, f.e, f.g[0].e[0].x[0]
|
||||||
|
'Copy one entry to another
|
||||||
|
memcpy(f, g, iStructLen)
|
||||||
|
Print c[2].d, c[2].e, c[2].g[0].e[0].x[0] ' g = c[3] f = c[2]
|
||||||
|
a.b = 45
|
||||||
|
|
||||||
|
Print a.b, b.b
|
||||||
|
' Display the actual address Of Each element And root
|
||||||
|
Print memcpy(a, a, 0), memcpy(b, b, 0), arraymemcpy(VarPtr(c), VarPtr(c), 0), memcpy(e, e, 0), memcpy(f, f, 0), memcpy(g, g, 0)
|
||||||
|
Print VarPtr(a), VarPtr(b), VarPtr(c)
|
||||||
|
Print "Hello world"
|
||||||
|
|
||||||
|
End
|
Loading…
Reference in a new issue