Freebasic to JavaScript-Converter ?

Emscripten, WASM, and asm.js related questions
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Freebasic to JavaScript-Converter ?

Post by marcov »

dkl wrote:FB is about native code from the beginning (thinking about pointers, C ABI compatibility, inline ASM), so naturally it can't work in virtual/scripting environments, at least not without removing/disallowing lots of these things. But then a lot of FB programs won't work in that environment.
Generally I agree of course, but doesn't have FB some level of abstraction in the CG to deal with the native vs GCC backends? That could be seen as a first step to also add a asm.js backend :-)
quartex
Posts: 3
Joined: May 12, 2014 13:54

Re: Freebasic to JavaScript-Converter ?

Post by quartex »

I can code that!

I recently spent 2 years creating the exact same thing for Object Pascal (Delphi, freePascal language). So you have FULL compilation to HTML5 with an IDE to handle everything. But it also required a completely new RTL. Head over to http://www.smartmobilestudio.com, download and check the RTL and compiler for yourself.

NOTE: Im not trying to push a product here, i am actually coding a basic parser/compiler right now which compiles to object pascal.

SMS took 2 years of my life, but the results were worth it. Completely 100% component based, object oriented HTML5. You even get interfaces, polymorphism and everything you expect from C++ or Object Pascal (we implemented a full VMT (virtual method table) in javascript). You can create your own components and even wrap typescript libraries directly from the IDE.

But yes, it was hard work! And thankfully I had some help from my friends to deal with everything. Especially the remote data-access layer and RPC client/server stuff.

But, I could create a HTML5 compiler and RTL for the basic language -- but someone would have to invest in the project and secure a paycheck for the time it takes. Since I have done this for Object Pascal and C++, it will be done faster (since i know how to do it), so it would probably take only a year to prototype, implement and test.
This would include a full RTL written from scratch that provides OOP access to the DOM.

Example, creating your own components that you can re-use later becomes VERY easy:

Code: Select all

module myComponentStuff

public class MyComponent(CustomComponent)

  overrides protected sub mouseDown(byval source as Object, _
  byval xPos as Integer, byval yPos as Integer, _
  byval ShiftState as System.ShiftState)

End class

protected sub MyComponent.mouseDown(byval source as Object, _
  byval xPos as Integer, byval yPos as Integer, _
  byval ShiftState as System.ShiftState)

  showmessageFormat("you clicked %d,%d",[xPos,yPos])

end 
Whatever syntax you prefer.. it's not that hard to parse.

The hard part is creating an IDE and the RTL. You want to be able to import JS libraries, handle typescript declaration files and deal with Databases over the internet. You also want to have native access visa phonegap (for mobile projects).

Well, PM me -- but I wont start on this unless someone secures at least 12 months of payed work.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Freebasic to JavaScript-Converter ?

Post by marcov »

quartex wrote:I can code that!

I recently spent 2 years creating the exact same thing for Object Pascal (Delphi, freePascal language). So you have FULL compilation to HTML5 with an IDE to handle everything. But it also required a completely new RTL. Head over to http://www.smartmobilestudio.com, download and check the RTL and compiler for yourself.
To what exactly? To Javascript or asm.js ? Usually these js things only support a very small subset of the language, but asm.js has the potential to go a bit further I guess.

What existing code can you actually recompile? Or is it just the "feel" of the language?

P.s. You do realize I'm a FPC core member don't you? :-)
quartex
Posts: 3
Joined: May 12, 2014 13:54

Re: Freebasic to JavaScript-Converter ?

Post by quartex »

It is compiled into javascript directly. It does not target any spesific library -- so there is no function mapping.
The RTL is actually written in pascal, but each line of pascal is translated into javascript.
The same can be done for basic, C, or whatever.

I have also started on a pascal to C++ codegen, so I can use GCC for compilation rather than delphi/fpc (just an experiment).

Anyways, SMS compiles everything into raw javascript. If you want to use a JS snippet you can recycle the ASM section :)

Code: Select all

procedure TMyForm.DoSomething;
Begin
  asm
    (* Use JS code here *)
  end;
end;
Which is compiled into:

Code: Select all

$TMyForm.DoSomeThing(self) = {
  /* Where "self" is the instance structure */
}
Most people dont realize what we did with the SMS pascal compiler. It is a true compiler. It does not cheat or depend on any JS library.
It does not simply map a set of commands to a fixed RTL (like blitzbasic or monkey does), but actually compiles whatever you write in pascal into pure, optimized javascript. It also allows for the full spectrum of object pascal to be used. Concepts like interfaces, inheritance, var params, class helpers, partial classes -- these things are not a part of javascript, not even a fraction of them. Because they require a fairly complex virtual method table to be realized.

So we made a VMT in javascript and built a whole new RTL around it to deal with DOM on handle basis.
So all HTML elements you might use, be it a button or a custom-control, are created by code by the JS you write. There is no pre-fabrication or layout templates. The reference to the HTML elements (like say, a DIV object) is used as the handle. Just like native winapi objects are controlled from the handle returned by the OS.

Writing custom controls is more or less identical to Delphi:

Code: Select all

type
 
TW3HeaderControl = Class(TW3CustomControl)
private
  FLabel:     TW3Label;
  FBackBtn:   TW3ToolButton;
  FNextBtn:   TW3ToolButton;
Protected
  Procedure   Resize;Override;
protected
  Procedure   InitializeObject;override;
  Procedure   FinalizeObject;override;
  Procedure   StyleTagObject;override;
End;

Procedure TW3HeaderControl.InitializeObject;
Begin
  inherited;
  FLabel:=TW3Label.Create(self);
  FLabel.BorderStyle:=bsDotted;
end;
 
Procedure TW3HeaderControl.FinalizeObject;
Begin
  FLabel.free;
 
  if assigned(FBackBtn) then
  FBackBtn.free;
 
  if assigned(FNextBtn) then
  FNextBtn.free;
 
  inherited;
end;
 
Procedure TW3HeaderControl.StyleTagObject;
Begin
  inherited StyleTagObject;
end;
 
Procedure TW3HeaderControl.Resize;
var
  wd,hd:  Integer;
  mTemp:  Integer;
  dx:     Integer;
Begin
  wd:=Width;
  hd:=Height;
 
  mTemp:=wd;
  dx:=4;
  dec(mTemp,4); //left margin
  dec(mTemp,4); //Right margin
 
  if  assigned(FBackBtn)
  and (FBackBtn.Visible) then
  Begin
    //space between "back" & label
    dec(mTemp,FBackBtn.width);
    dec(mTemp,2);
 
    //offset the left edge of the label
    inc(dx,FBackBtn.Width);
    inc(dx,2);
 
    // position the back-button
    FBackBtn.Left:=4;
    FBackBtn.Top:=4;
  end;
 
  if  assigned(FNextBtn)
  and (FNextBtn.Visible) then
  Begin
    //space between label & "next" button
    dec(mTemp,FNextBtn.width);
    dec(mTemp,2);
    FNextBtn.Left:=mTemp;
    FNextBtn.Top:=4;
  end;
 
  FLabel.left:=dx;
  FLabel.top:=4;
  FLabel.Width:=mTemp;
  FLabel.Height:=Height-8;
end;
And then you can register the component in a package to get it on the toolbar palette :)
And yes, we render the HTML "live" using chrome inside the IDE so you can see what it looks like.

As you can probably guess this is a massive undertaking. The RTL i designed starts at the bottom, wrapping handle based elements - all the way up to TCustomControl and further into TCustomForm. It has to deal with everything: touch, css effects, transitions, mouse events, key events, scrolling, late callback for "live" controls (scrollbars that fade out).
And the entire RTL is written in SMS pascal with no dependencies on anything else.

To date, not even Microsoft have anything like this. TypeScript is almost there, but our technology is actually both faster and more advanced.

So you run the freepascal stuff to?
Cool!
Then you have probably talked to me earlier.
When i was debating that FPC could be used to create the compiler, and also that FPC was being used by Embarcadero, the FPC forums got a visit from Embarcadero on the forum (first time i think) that acknowledged what i was saying.
The forum became silent when people realized I was telling the truth.

And I am telling the truth now as well, I can code this :)
quartex
Posts: 3
Joined: May 12, 2014 13:54

Re: Freebasic to JavaScript-Converter ?

Post by quartex »

I have a small website dedicated to the quartex IDE, which is the research project for compilers (both basic and pascal).
You can find it at: quartexpascal.wordpress.com

PM me if any1 finds this interesting!
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: Freebasic to JavaScript-Converter ?

Post by Coolman »

to see this link here (sorry in french):

http://linuxfr.org/news/retour-d-experience-sur-sql-js

port sqlite to javascript. gives an idea of ​​the power of emscripten which can compile a source file c (about 5 mo) directly in javascript without any other intervention ...

emscripten seems to be the solution for the conversion FreeBasic / c c++ / javascript ...

https://github.com/kripken/emscripten/w ... ripten-SDK
Post Reply