freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

FreeBASIC version 0.0

 
Post new topic   Reply to topic    freebasic.net Forum Index -> Community Discussion
View previous topic :: View next topic  
Author Message
v1ctor
Site Admin
PostPosted: Jul 26, 2009 15:57    Post subject: FreeBASIC version 0.0 Reply with quote

Hi, guys, long time since i posted something new (yeap, i still alive :).

Actually this won't be anything new. I got a email from Yahoo - Geocities (RIP) saying they are going to remove my personal site (that never had anything other than a "In construction!" sign) and that i had to copy any important file stored there.

For my surprise, i found a rar archive with the FB sources, stored for backup purposes (there was no version control or whatever being used at that time). This version needs VBDOS to be built, because FB couldn't even self-compile - nor with -lang qb it could now, unfortunately, ENUM is disallowed.

So, for entertaining, educational (right..) and nostalgic reasons, here is it:

FreeBASIC v0.0

Don't try to do anything complex with it (like writing a self-hosting compiler using it, heh).

Bye...
 
Back to top
View user's profile Visit poster's website MSN Messenger
vdecampo
Hero
PostPosted: Jul 26, 2009 17:23    Post subject: Reply with quote

Hi v1ctor! Nice to hear from you whether it's something new or old. For me it is a moral booster for the FB community.

Anyways, thanks for posting this. I am desperately trying to wrap my mind around building lexer/parser/compiler stuff because I want to eventually take a shot at my own compiler. Your code provides some great insight. I wish we had a set of tutorials like Crenshaw (or better) to walk through creating a basic compiler, in FB of course! :)

Hope all is well with you.

-Vince
 
Back to top
View user's profile Visit poster's website
angros47
Sr. Member
PostPosted: Jul 26, 2009 19:16    Post subject: Reply with quote

Hi V1c! And thanks for your work.

Well, you are not the only one to remove your basic compiler from geocities...

Ultrabasic compiler (I tried to continue the abandoned work of Gabriel Fernandez) were on www.geocities.com/angros47, now I made a backup on http://ultrabasic.sourceforge.net/

I discontinued it when FB was born, because FB was much better.
 
Back to top
View user's profile
Dr_D
Hero
PostPosted: Jul 26, 2009 21:29    Post subject: Reply with quote

Funky!
 
Back to top
View user's profile Visit poster's website
counting_pine
Site Admin
PostPosted: Aug 08, 2009 9:57    Post subject: Reply with quote

Now you can compile it in recent versions of FB, without the makefile.

I wrote a program that makes various minor hackish changes to the code, and compiles the result directly using fbc -lang fblite.


I haven't really tested the resulting exe, but it at least shows the help screen when run without params.

Code:
#include "file.bi"
Const FBC0DIR = "./src/compiler"
Const FBC = "fbc"

Function replace( Byref s As String, Byref s1 As String, Byref s2 As String ) As String
   
    Dim As Integer i = 1
    Dim As String t = s
    Do
        i = Instr(i, t, s1)
        If i = 0 Then Return t
        t = Left(t, i-1) & s2 & Mid(t, i + Len(s1))
        i += Len(s2)
    Loop
   
End Function

Sub fixfile( Byref fn As String )
   
    Dim As String f, b
    Dim As Integer i, i2, i3, i4
   
    If fileexists(fn & ".bak") Then Kill fn Else Name fn As fn & ".bak"

    Open fn & ".bak" For Binary As #1
        f = Space(Lof(1))
        Get #1, 1, f
    Close #1

    '' remove periods from consts/enums
    i = 1
    Do
        i2 = Instr(i, f, "FB.")
        i3 = Instr(i, f, "IR.")
        i4 = Instr(i, f, "EMIT.")
        i = i2
        If i = 0 Or (i > i3 And i3 > 0) Then i = i3
        If i = 0 Or (i > i4 And i4 > 0) Then i = i4
       
        If i = 0 Then Exit Do
       
        i2 = Instr(i, f, ".")
        i3 = i2+1
        While Mid(f, i3, 1) <> "."
            b = Mid(f, i3, 1)
            If Ucase(b) = Lcase(b) Then If b <> "_" Then i = i3: Continue Do
            i3 += 1
        Wend
        i4 = i3+1
        While Mid(f, i4, 1) <> "."
            b = Mid(f, i4, 1)
            If Ucase(b) = Lcase(b) Then If b <> "_" Then i4 = 0: Exit While
            i4 += 1
        Wend
        Mid(f, i2, 1) = "_"
        Mid(f, i3, 1) = "_"
        i = i3+1
        If i4 >= 1 Then Mid(f, i4, 1) = "_": i = i4+1
    Loop

    '' rename variable 'class'
    f = replace(f, "class", "class_")
   
    '' couple of duplicate '+'s in string concatenation
    f = replace(f, "+  +", "+")
    f = replace(f, "+ +", "+")
   
    '' peek problem...
    f = replace(f, "peek( varptr( ctx.tbuff ) + ctx.tbuffptr )", "ctx.tbuff[ ctx.tbuffptr ]")
   
    '' exit sub from function
    i = 1
    Do
        i = Instr(i + 1, f, "exit function")
        If i = 0 Then Exit Do
        If instrrev(Lcase(f), !"\nsub ", i) > instrrev(Lcase(f), !"\nfunction ", i) Then
            f = Left(f, i-1) & "exit sub" & Mid(f, i + Len("exit function"))
        End If
    Loop

    '' exit function from sub
    i = 1
    Do
        i = Instr(i + 1, f, "exit sub")
        If i = 0 Then Exit Do
        If instrrev(Lcase(f), !"\nfunction ", i) > instrrev(Lcase(f), !"\nsub ", i) Then
            f = Left(f, i-1) & "exit function" & Mid(f, i + Len("exit sub"))
        End If
    Loop


    Open fn For Binary As #2
        Put #2, 1, f
    Close #2
   
End Sub

Dim d As String

Chdir FBC0DIR

d = dir( "*.bas" )
Do While Len(d)
    Print d
    fixfile( d )
    d = dir()
Loop

Chdir "inc"

d = dir( "*.bi" )
Do While Len(d)
    Print d
    fixfile( d )
    d = dir()
Loop

Chdir ".."

Shell FBC & " -lang fblite -v -e -x ../../fbcv0.exe " _
    "fbc.bas ast.bas ir.bas parser2.bas parser5.bas rtl.bas " _
     "emit.bas hash.bas lex.bas parser3.bas parser6.bas strpool.bas " _
     "emitdbg.bas hlp.bas parser1.bas parser4.bas reg.bas symb.bas"
This code should work OK as-is, if you run it from the freebas_v0.0/ folder, with fbc in your PATH. Otherwise it should just be a matter of adjusting the consts at the start.

EDIT: Sorry, if anyone was having problems with this - I remembered I'd deleted dag.bas_ from the folder because it was getting caught in the *.bas in the compile command. I've hardcoded the module list now, so that shouldn't be necessary.
 
Back to top
View user's profile Send e-mail
v1ctor
Site Admin
PostPosted: Aug 08, 2009 22:12    Post subject: Reply with quote

Cool, counting_pine, thanks for that. I made a change in the compiler to allow enums and periods in -lang qb but it was hackish and could start to break things later, so i gave up trying to get it to build.

Now only if it could self-compile.. heh, only version 0.1 could, never mind.

Anybody noticed that there are no pointers there? Only VBDOS could build it so arrays were used everywhere.
 
Back to top
View user's profile Visit poster's website MSN Messenger
Leonheart

PostPosted: Aug 10, 2009 12:56    Post subject: Meh.... Reply with quote

Oh, it's you XD.
I started make VFB.....
But everyone hates me a lot cuz we have same name... :P
V1c shake V1c.....

V1c runz!
 
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Community Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode