Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The L-BASIC compiler
#11
Now I know what the message means: "codegen: Bad expr type 18". This does not mean a line number. I noticed it just now when I got the message again.

Code: (Select All)
'LBasic - 7. Jen. 2023

Dim As Double purchasePrice, valueAddedTax, totalPrice

Input "Purchase price : ", purchasePrice
Input "Value added tax: ", valueAddedTax

totalPrice = ((purchasePrice / 100) * valueAddedTax) + purchasePrice

Print totalPrice

End

PS D:\Lab\Lukebasic> lbasic LBasicKaufpreis.bas
codegen: Bad expr type 18

There is still a lot to try and learn.  Big Grin
Reply
#12
Last try for today:

Code: (Select All)
'LBasic, zwei Zahlen addieren - 7. Jan. 2023

Dim As Integer zahl1, zahl2, summe

zahl1 = 10
zahl2 = 15

summe = zahl1 + zahl2
Print summe

End

PS: @Luke - You are using the Clang compiler, why not the GCC (Linux), or the MingW for Windows?

[Image: Linker-Fehler2023-01-07-211441.jpg]

PS2: Could it be that the Clang compiler is missing here? I have installed the MingW64.
[Image: MingW.jpg]
Reply
#13
(01-07-2023, 04:01 PM)Kernelpanic Wrote:
Code: (Select All)
Option _Explicit

Dim PS As Double, KW As Double
Dim Auswahl As Integer

Print "1 -- PS in Kilowatt"
Print "2 -- Kilowatt in PS"
Print
Input "Ihre Wahl: ", Auswahl
Print

If Auswahl = 1 Then
  Input "Anzahl PS: ", PS
  KW = PS / 1.36

  Print -- Fehler?
  Print KW
Else
  Input "Anzahl Kilowatt: ", KW
  PS = KW * 1.36

  Print
  Print PS
End If

End

This line:
Code: (Select All)
Print -- Fehler?

The stuff after "Print" needs to be surrounded by double quotation marks.

I'm not able to run Luke's creation straight away but the "bad integer" or something like that might point to the "LOCATE , 2" line, might have to use "CSRLIN" function to get the current cursor line and fill in the "LOCATE row, column" instead of leaving out the row.

If not, it could be your using the apostrophe at the end of code lines.
Reply
#14
The "bad expr type 18" error is because it doesn't know how to build code for the INPUT statement. I wasn't kidding when I said it has very poor support for most commands. It also doesn't know how to compile arrays, or LOCATE (though arrays and user defined TYPEs are probably next on the list).

The error about clang not found is a genuine bug though, looks like it doesn't handle being on the %PATH% very well. You might be able to work around that by setting the LLVM_ROOT environment variable to point to the llvm directory.

Thanks for trying it out, and sorry it's so limited for now. So many commands...

P.S The gcc/clang/mingw situation is complicated, but basically mingw is a set of libraries that is combined with either gcc or clang to build a windows compiler and toolchain. For lbasic you could probably replace clang-mingw with gcc-mingw and it'd be okay, but the more vital file is the libLLVM-14.dll which contains all the logic for generating machine code that lbasic calls directly. Unlike QB64, lbasic isn't generating C code and compiling it. It emits actual machine code object files, then calls clang to link it with the runtime library. I could call the linker (ld) directly but clang adds all the correct flags to make life easier. To compare it with QuickBasic, running BC.EXE is the equivalent of doing "lbasic -e obj". Without -e obj, lbasic will do the equivalent of also running LINK.EXE and linking against BCOM45.LIB.
Reply
#15
Clang is found like this, but what does this mean: Parser: Line 2: "

I know how to call the QuickBasic compiler and linker using a bat file from before, because I had noticed that some programs were about 1/3 smaller in this way than created by the IDE.
One reason could be the Linux-style path specification. So it could be that the clang compiler is not found for this reason.

Code: (Select All)
Dim As Integer zahl1, zahl2, summe

zahl1 = 10
zahl2 = 15

summe = zahl1 + zahl2
Print summe

End

[Image: LBasic-Clang-nicht-gefunden.jpg]

I think I now know where the error could lie in part. The compilation of "hello-luke" only worked because the source file was in the same directory as "lbasic". But with two other programs it didn't work again. - Complicated! 

[Image: Linker-Fehler2023-01-07-211441.jpg]
Reply
#16
(01-06-2023, 10:59 PM)mnrvovrfc Wrote: One of the "QB64 Samples" programs is a LISP interpreter. I should have taken some time to play with it, instead of trying to dive into Racket.

Racket was released as Flatpak about two weeks ago, I have just discovered. Shy

Kernelpanic the "Dim" line has to be changed to:
Code: (Select All)
Dim zahl1 as Integer, zahl2 as Integer, summe as Integer
Reply
#17
(01-08-2023, 08:22 PM)mnrvovrfc Wrote: Kernelpanic the "Dim" line has to be changed to:
Code: (Select All)
Dim zahl1 as Integer, zahl2 as Integer, summe as Integer

Unfortunately it doesn't work either.

[Image: LBasic-Linker2.jpg]
Reply
#18
You're nearly there! It doesn't know how to compile END, but it does know SYSTEM so you can use that instead.
Reply
#19
(01-08-2023, 09:55 PM)luke Wrote: You're nearly there! It doesn't know how to compile END, but it does know SYSTEM so you can use that instead.

Ok, this works without end now, with "two numbers...". The next program doesn't work again: "KW-PS2.bas". - The devil is in the details!

Quote:D:\Programme\lbasic>lbasic Zwei-Zahlen-addieren.bas

D:\Programme\lbasic>Zwei-Zahlen-addieren
25

D:\Programme\lbasic>lbasic KW-PS2.bas
codegen: Bad expr type 18

D:\Programme\lbasic>

KW-PS2.bas
Code: (Select All)
Option _Explicit

Dim PS As Double, KW As Double
Dim Auswahl As Integer

Print "1 -- PS in Kilowatt"
Print "2 -- Kilowatt in PS"
Print
Input "Ihre Wahl: ", Auswahl
Print

If Auswahl = 1 Then
  Input "Anzahl PS: ", PS
  KW = PS / 1.36

  Rem Print Fehler!
  Print KW
Else
  Input "Anzahl Kilowatt: ", KW
  PS = KW * 1.36

  Print
  Print PS
End If
Reply
#20
This is awesome Luke! I saw this project on your GitHub a long time ago and starred it. At that time, I was wondering why you would write yet another BASIC transpiler. I never knew at that time that you were generating LLVM IR. I bet your end goal is to make this self-hosting. I wish you all the best and will keep an eye on this project.
Reply




Users browsing this thread: 4 Guest(s)