none
Internal workings of Smallbasic RRS feed

  • General discussion

  • Hi everyone,

    This topic is aimed more at the experienced developers of SmallBasic but everyone is welcome to ask questions if they are interested.

    How does SmallBasic work internally I understand what .NET languages are compiled then interpretered, would I be correct in saying so?
    Does SmallBasic translate into VB or C# when pressing RUN then compile into MSIL?

    Is the compiler accessiable from outside of the SB IDE?

    Thanks,

    Kirk.

    Wednesday, May 9, 2012 2:17 PM

All replies

  • SmallBasic compiles directly to MSIL.

    Look here for JIT compilation used my MSIL and .Net.

    The program SmallBasicCompiler.exe in the installation directory can be used standalone to compile code.

    Also you can decompile this exe with ILSpy to see how it works, although it is quite complicated.  Each statement is parsed and the MSIL code generated instruction by instruction.  While you can decompile it, this will be a little different from the original code and perhaps harder to read.  This is how Fremy created the SmallBasicExtensionCompiler I expect.

    Wednesday, May 9, 2012 5:35 PM
    Moderator
  • Let me see if I have understood correctly, SmallBasic compiles directly to MSIL and during runtime interpreted into machine code for the computer to understand just like how java compiles to bytecode then the JVM intpretes the byte code.

    Does this mean Smallbasic runs under the CLR hence why it requires .NET.

    Thanks.

    Wednesday, May 9, 2012 6:58 PM
  • Yes, basically that's it. 

    My understanding (I'm no expert on this, so if you are interested I suggest more reading) the JIT compiler turns the MSIL into native instructions using CLR .NET feeding the processor as required (hence JIT: Just In Time).  I expect it is somewhat more complicated for performance reasons (for example repeated calls to code are not recompiled to native, as an interpreter might).

    Wednesday, May 9, 2012 7:15 PM
    Moderator
  • If you wanted to, you could decompile the compiler.

    From what I can tell, SmallBasicCompiler.exe is written in some .NET language, most likely C#, and can be decompiled with any .NET decompiler. Same goes for the SmallBasic IDE (SB.exe), and the SmallBasic Library (SmallBasicLibrary.dll). I would assume that you could freely decompile SmallBasicCompiler.exe for educational purposes, so long as you do not claim ownership.


    Thursday, May 10, 2012 6:29 PM
  • As all .NET languages end up the same once compiled including Smallbasic - Would it be possible to create an extension that has access to the XNA framework and compiles?

    http://create.msdn.com/en-US/


    • Edited by Kirkkaf Saturday, June 9, 2012 1:04 AM
    Saturday, June 9, 2012 1:03 AM