Re: [fpc-devel] First pas2js public release

2017-12-17 Thread Michael Van Canneyt



On Sun, 17 Dec 2017, Benito van der Zander wrote:


Hi,



Naturally, any memory pointer operation is not possible in Javascript. Code 
that relies on this will not work.



it would be great, if pointers were added.


I really don't see the point of that. As Mattias pointed out, pointers to 
classes
exist. Very likely pointers to records will be added (because they are
object literals this is relatively easy), but that's about it.
Even so, pointer math is not possible, so I really don't see the benefit.

The idea is to be able to program the browser using a reasonable subset of
Object Pascal, not to port arbitrary pascal code. So if time must be allocated 
on new features, it most likely will not be on emulating pointers, but

rather on more high-level features.

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] First pas2js public release

2017-12-17 Thread Mattias Gaertner
On Sun, 17 Dec 2017 21:43:45 +0100
Benito van der Zander  wrote:

> Hi,
> 
> >
> > Naturally, any memory pointer operation is not possible in Javascript. 
> > Code that relies on this will not work.  
> 
> 
> it would be great, if pointers were added.

There are pointers already. For example references to class and
arrays. 
It seems you want to emulate pointer of integer.

 
> One trick would be to wrap every variable that is accessed by a pointer 
> in an array (or object).

That would be quite a slow down.
Isn't speed the main idea of using pointers?

Also what if var and @var are in different units?
And what about pointer of pointer?

You may want to take a look at asm.js, which has a working
model for emulating pointers in JavaScript. It would be possible to add
a pas2js target for that. But then again there is webassembly
as well and it seems to have better support.

Mattias

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] First pas2js public release

2017-12-17 Thread Benito van der Zander

Hi,



Naturally, any memory pointer operation is not possible in Javascript. 
Code that relies on this will not work.



it would be great, if pointers were added.


One trick would be to wrap every variable that is accessed by a pointer 
in an array (or object).  The array can then be used as reference.


For example:

var a: integer;
  b: pinteger;

begin

 a := 10;
 b := @a;
 b^ := 11;
 writeln(a);
 writeln(b^);

end;

becomes

 var a,b
 a = [10]
 b = a
 b[0] = 11;
 alert(a[0])
 alert(b[0])


For pointer arithmetic or pointers inside array elements, it would need 
an additional index:


For example:

var a: integer = 10;
    ar: array[0..1] of integer = (1,2);
    b: pinteger;

begin
 b := @a;
 b^ := 11;
 b := @ar[1]
 b^ := 12;
 dec(b);
 b^ := 13;
end;

becomes

 var a,b,bi,ar
 a = [10]
 ar = [1,2]
 b = a; bi = 0
 b[bi] = 11;
 b = ar; bi = 1
 b[bi] = 12;
 bi--;
 b[bi] = 13;

It does not cover pointers of mixed sizes (e.g. getting a pbyte of an 
integer, or converting double to int64), but the most common things 
should work. pchars should probably get special treatment, too. When it 
is not modified, there is no need to wrap a string in an array, but just 
keep a string reference plus index. Perhaps there need to be two type of 
pchars, readonly and writeable. Only writeable need wrapping.


And then there needs to be some kind of static analysis that only wraps 
those variables/fields in arrays whose address is actually taken anywhere.



Best,
Benito



Am 16.12.2017 um 17:36 schrieb Michael Van Canneyt:


Hello fellow Pascal enthousiasts,

It is with great pleasure that I can finally announce the first publicly
available version of pas2js. A "beta" version, version 0.8.39.
The endpoint (for the time being) of nearly 10 years of (slow) 
development.


pas2js is a Object Pascal to Javascript transpiler. It compiles Object
pascal, and emits Javascript. The javascript is usable in the browser, 
and

in Node.js.

It is open source, and part of FPC/Lazarus. This makes Free Pascal a 
full-stack development environment for Web Development:
You can use it to program the server and the browser alike, all from 
within

the environment you love so much :)

What does pas2js include ?
--

* On the language level:

It supports basically Delphi 7 syntax, interfaces excepted.
Naturally, any memory pointer operation is not possible in Javascript. 
Code that relies on this will not work.


This is just the first version, we of course want to add the same 
language features that exist in Delphi and FPC today.


* On the runtime level:

Beside the compiler itself, there is a basic Object Pascal RTL, and 
several units from the FPC Packages are also available:


system
sysutils
Math
strutils
rtlconst
classes
contnrs
DB (yes, TDataset)
fpcunit testsuite
custapp
restconnection
js (javascript system objects)
web (browser provided objects)
libjquery (jquery is available too)
nodejs (basic node runtime environment)
typeinfo
objpas
browserconsole (support for writeln)
dateutils
browserapp
nodejsapp

* Debugging:

Obviously, the browser debugger can be used to debug the Javascript.
But there is more: the compiler can emit a source map, and this means 
that

if the browser finds the source file, it will display the original source
file instead of the javascript. You can debug Object pascal in the 
browser.


* Demoes ?

The package has several demoes, including FPReport, TDataset, JQuery and
Bootstrap.

* Documentation  ?

As befits an open source project, docs are lagging behind :/

But a WIKI page has been started, it will be expanded as time permits:

http://wiki.freepascal.org/pas2js

* Sources ?

The pas2js compiler sources and RTL sources have been checked in in 
FPC's subversion repository. The page describes where to find it in SVN.


* Binaries ?

A snapshot is available:
http://www.freepascal.org/~michael/pas2js/pas2js-demo-0.8.39.zip

* Reporting bugs ?

The FPC bugtracker has now a 'pas2js' project, it can be used to report
bugs.

* Can you help ?

Yes, of course. There is still a lot of work to be done. Feel free to 
contact me or Mattias Gaertner with questions.


What about Lazarus ?


Lazarus "understands" the extensions to object pascal (for importing 
Javascript

classes) that were borrowed from the JVM version of the compiler, so the
code completion will continue to work.

Using the pre-compiler command, CTRL-F9 just works. On error, you will be
shown the error location etc.

Further and deeped integration of pas2js into lazarus is expected. In 
the first place, IDE integration. Later on, a real widget set for the 
browser can (and hopefully will) be created.


But that is not all !
-

In the very near future, a major Delphi component vendor will announce a
complete package for RAD web development in the Delphi IDE. The 
expectation is