Announcement

Collapse
No announcement yet.

FemtoBasic a tiny x64 compiler

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • FemtoBasic a tiny x64 compiler

    Here's the modified result of going through the "Let's Build a Compiler" pdf If anyone's interested.

    The source is here. Unless you really like copying and pasting you can download a zip file from here.

    Here's some of the differences:
    • Written in PowerBASIC not Pascal
    • Generates x64 applications not 68000
    • Language is "Basicish" instead of "Pacalish"
    • Some names were changed, made them longer and more applicable
    • Moved a few things to classes
    • The program was changed from Tiny11 to FemtoBasic


    You can target a new processor by implementing iCodeGen and creating your new code generator in Initialize.

    The input and output routines are in interfaces. If you implement a string based iInput, you could compile from memory or pipe the output to StdOut.

    It supports the following keywords:
    Code:
    Dim var1[, var2...]
    
    If expression Then
        statement
    Else
        statement
    EndIf
    
    While expression
        statement
    Wend
    
    Input var1[, var2...]
    
    Print [,]var1[{,|;}var2]
    
    PrintLine [,]var1[{,|;}var2]
    
    var = expression
    
    supported operators: +, -, *, /, (, ), AND, OR, NOT, <, <=, >, >=, <>, =
    The build process is a three step process:

    • Run FemtoBasic against your source to create an assmbly source output.
    • Run Jwasm against the assembly to create a .obj file
    • Run Jwlink against the .obj file to create an x64 .exe file.



    To run your program you'll need to download JWAsm and JWLink.


    If you want to run a debugger you'll need to download
    PellesC - http://www.christian-heffner.de/inde...wnload&lang=en

    Assembling
    jwasm -c -win64 -Zp8 -Sg -Ic:\asm\Include;c:\asm\MyInclude -Fl=%1.txt %1.asm
    Add -Zd -Zi for debugging

    JWLink linking
    jwlink.exe file %1.obj name %1.exe libpath c:\asm\Lib64 libpath c:\asm\MyLib64 runtime console
    PellesC linking - smallest output
    polink.exe %1.obj /OUT:%1.exe /libpath:c:\asm\Lib64 /libpath:c:\asm\MyLib64 /subsystem:console
    Add /debug for debugging

    To get stuff setup with a minimum of fuss:
    • Install jwasm, jwlink, and wininc in c:\asm
    • Add c:\asm to your search path
    • create c:\asm\MyInclude, copy curion.inc into it.
    • create c:\asm\MyLib, copy curion.lib into it.


    Compile a FemtoBasic program. For example to compile sample.bas:
    br sample

    If everything went well, you'll have sample.exe
    Last edited by Larry Charlton; 23 May 2014, 09:45 PM. Reason: Cleaning up formatting it was atrocious
    LarryC
    Website
    Sometimes life's a dream, sometimes it's a scream

  • #2
    Wow

    Wow Thank you for sharing, very interesting!

    Cheers,
    Colin

    Comment


    • #3
      Amazing! Thank you

      Comment


      • #4
        Larry

        Loved it being something different, thank you for your contribution.
        Peter Maroudas

        Comment


        • #5
          http://www.japheth.de/
          seems down
          thinBasic programming language
          Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

          Comment


          • #6
            Originally posted by Eros Olmi View Post
            Has been down for about a year I think and no one knows where he went off to.
            New updates at Hutch's site:
            http://www.masm32.com/board/index.php

            James

            Comment

            Working...
            X