Next language feature for pas2js...

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Next language feature for pas2js...

Ingemar Ragnemalm
Michael Van Canneyt <[hidden email]> wrote:

> Hello,
>
> Now that interface support has been added to the list of implemented language
> features of pas2js, we're looking to get feedback on what best to tackle next.
>
> This time, the poll is not on the forum, so you do not need to have an
> account to vote.
>
> Here is a link to the poll:
>
> https://docs.google.com/forms/d/e/1FAIpQLScPVu6Y_X1QhOrYLWia4TVeKoZ3wiu-_PiMqJ0Zm8KW39FdCQ/viewform?usp=sf_link
>
> Michael.

I am very happy with pas2js and couldn't select any particular feature.
What I want the most are more APIs, but I have been quite successful in
implementing the ones I need so far. However, WebGL (which is
interesting for me) is a big API so if anyone is working on that, or
have figured out a way to auto-convert or something, I am interested.

Have I mentioned that I used pas2js on this year's Global Game Jam?
Successfully!

/Ingemar

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt


On Wed, 25 Apr 2018, Ingemar Ragnemalm wrote:

> Michael Van Canneyt <[hidden email]> wrote:
>> Hello,
>>
>> Now that interface support has been added to the list of implemented
> language
>> features of pas2js, we're looking to get feedback on what best to tackle
> next.
>>
>> This time, the poll is not on the forum, so you do not need to have an
>> account to vote.
>>
>> Here is a link to the poll:
>>
>>
> https://docs.google.com/forms/d/e/1FAIpQLScPVu6Y_X1QhOrYLWia4TVeKoZ3wiu-_PiMqJ0Zm8KW39FdCQ/viewform?usp=sf_link
>>
>> Michael.
>
> I am very happy with pas2js and couldn't select any particular feature.
> What I want the most are more APIs, but I have been quite successful in
> implementing the ones I need so far. However, WebGL (which is
> interesting for me) is a big API so if anyone is working on that, or
> have figured out a way to auto-convert or something, I am interested.

Ah, webgl...

I had a look at this some time ago, and got depressed.
Quickly closed the browser and didn't look back.
Same for webaudio :(

We have a test project that helps with converting APIs,
but it's still very rudimentary and needs lots of help.
Check democlasstopas.pas in the demos.

>
> Have I mentioned that I used pas2js on this year's Global Game Jam?
> Successfully!

Glad to hear it, we need more such success stories !

If you could make a new wiki page with some information about it, and link
to it from the main pas2js page, that would be hugely appreciated !

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Reimar Grabowski
On Wed, 25 Apr 2018 16:43:30 +0200 (CEST)
Michael Van Canneyt <[hidden email]> wrote:

> Ah, webgl...
>
> I had a look at this some time ago, and got depressed.
Can you elaborate?

R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt


On Wed, 25 Apr 2018, Reimar Grabowski wrote:

> On Wed, 25 Apr 2018 16:43:30 +0200 (CEST)
> Michael Van Canneyt <[hidden email]> wrote:
>
>> Ah, webgl...
>>
>> I had a look at this some time ago, and got depressed.
> Can you elaborate?

Nothing special, simply the sheer size of it :(

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph
In reply to this post by Michael Van Canneyt


> On Apr 25, 2018, at 9:43 PM, Michael Van Canneyt <[hidden email]> wrote:
>
> Ah, webgl...
>
> I had a look at this some time ago, and got depressed. Quickly closed the browser and didn't look back. Same for webaudio :(

I’m actually a little curious about this myself because I’ve been using OpenGL often recently. I’ve seen the Ingemar’s demos but I only slightly grasp how it’s working.

The wiki says you’re actually parsing the Pascal (not compiling it) and outputting JavaScript. If that’s the case then how does porting libraries work in practice? For examples lets say I want to translate a single OpenGL function, how does that look?


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michalis Kamburelis-3
2018-05-01 4:50 GMT+02:00 Ryan Joseph <[hidden email]>:
>
>
>> On Apr 25, 2018, at 9:43 PM, Michael Van Canneyt <[hidden email]> wrote:
>>
>> Ah, webgl...
>>
>> I had a look at this some time ago, and got depressed. Quickly closed the browser and didn't look back. Same for webaudio :(

The API of WebGL is actually mostly a subset of OpenGLES which is a
subset of OpenGL. WebGL is quite small, if you compare it to other
graphic APIs :) OpenGL(ES), Direct3D, Vulkan, Metal are way more
complicated and larger.

>
> I’m actually a little curious about this myself because I’ve been using OpenGL often recently. I’ve seen the Ingemar’s demos but I only slightly grasp how it’s working.
>
> The wiki says you’re actually parsing the Pascal (not compiling it) and outputting JavaScript. If that’s the case then how does porting libraries work in practice? For examples lets say I want to translate a single OpenGL function, how does that look?
>

I suspect that we will have a unit like WebGL in pas2js that exposes
the necessary JS functions for Pascal applications. Engine like Castle
Game Engine will used this unit when compiled with pas2js (instead of
GL when compiled with FPC for desktop, or GLES20 when compiled with
FPC for mobile). And then CGE can expose an API that looks the same
(both in pas2js and FPC).

(Yes, I want to port Castle Game Engine one day to pas2js :) )

Regards,
Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph


> On May 1, 2018, at 11:27 AM, Michalis Kamburelis <[hidden email]> wrote:
>
> I suspect that we will have a unit like WebGL in pas2js that exposes
> the necessary JS functions for Pascal applications.

Sure but how does the porting process look? I’m reading the wiki and it looks like it wraps JavaScript classes by doing stuff like:

TJSFunction = class external name 'Function'(TJSObject)

where “Function” is the JavaScript class name.

Looking at https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API I see WebGLRenderingContext has the entire OpenGL API (I think). Does that mean we just do something like:

const
  GLfloat = MAP_TO_SOMETHING; // do we have external consts?

type
  TWebGLRenderingContext = class external name 'WebGLRenderingContext' (TJSObject)
    procedure clearColor (red, green, blue, alpha: GLfloat); external name 'clearColor';
  end;

var
  context:
begin
  context := GetCurrentContext; // document.getElementById(‘canvas’).getContext()
  context.clearColor(0, 0, 0, 0);

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt
In reply to this post by Michalis Kamburelis-3


On Tue, 1 May 2018, Michalis Kamburelis wrote:

>>>
>>> I had a look at this some time ago, and got depressed. Quickly closed the browser and didn't look back. Same for webaudio :(
>
> The API of WebGL is actually mostly a subset of OpenGLES which is a
> subset of OpenGL. WebGL is quite small, if you compare it to other
> graphic APIs :) OpenGL(ES), Direct3D, Vulkan, Metal are way more
> complicated and larger.

Somehow this doesn't really lift my spirits. :)

>> I’m actually a little curious about this myself because I’ve been using OpenGL often recently. I’ve seen the Ingemar’s demos but I only slightly grasp how it’s working.
>>
>> The wiki says you’re actually parsing the Pascal (not compiling it) and outputting JavaScript. If that’s the case then how does porting libraries work in practice? For examples lets say I want to translate a single OpenGL function, how does that look?
>>
>
> I suspect that we will have a unit like WebGL in pas2js that exposes
> the necessary JS functions for Pascal applications.

Correct.

> Engine like Castle
> Game Engine will used this unit when compiled with pas2js (instead of
> GL when compiled with FPC for desktop, or GLES20 when compiled with
> FPC for mobile). And then CGE can expose an API that looks the same
> (both in pas2js and FPC).
>
> (Yes, I want to port Castle Game Engine one day to pas2js :) )

Good to hear it :)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt
In reply to this post by Ryan Joseph


On Tue, 1 May 2018, Ryan Joseph wrote:

>
>
>> On May 1, 2018, at 11:27 AM, Michalis Kamburelis <[hidden email]> wrote:
>>
>> I suspect that we will have a unit like WebGL in pas2js that exposes
>> the necessary JS functions for Pascal applications.
>
> Sure but how does the porting process look? I’m reading the wiki and it looks like it wraps JavaScript classes by doing stuff like:
>
> TJSFunction = class external name 'Function'(TJSObject)
>
> where “Function” is the JavaScript class name.
This is actually a less good example, it's a little tricky.

>
> Looking at https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API I see WebGLRenderingContext has the entire OpenGL API (I think). Does that mean we just do something like:
>
> const
>  GLfloat = MAP_TO_SOMETHING; // do we have external consts?

Of sorts.
   MyClass = Class external name 'my'
   const
     MyConst : integer
   end;

Will emit MyClass.MyConst. The compiler needs to know the type.

>
> type
>  TWebGLRenderingContext = class external name 'WebGLRenderingContext' (TJSObject)
>    procedure clearColor (red, green, blue, alpha: GLfloat); external name 'clearColor';
>  end;
>
> var
>  context :
> begin
>  context := GetCurrentContext; // document.getElementById(‘canvas’).getContext()
>  context.clearColor(0, 0, 0, 0);
That seems about correct.
You don't need the "external name 'n'" if the name is typed correctly.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph


> On May 1, 2018, at 2:03 PM, Michael Van Canneyt <[hidden email]> wrote:
>
> Of sorts.
>  MyClass = Class external name 'my'
>  const
>    MyConst : integer
>  end;
>
> Will emit MyClass.MyConst. The compiler needs to know the type.

I’m confused now. The class is named WebGLRenderingContext in JS (I think that’s what it’s called by JS doesn’t really have classes does it?) so how does it look?

// no external name because the names are the same
type
  WebGLRenderingContext = class
    procedure clearColor (red, green, blue, alpha: GLfloat);
  end;

So constants must be part of the class? In the example below gl.COLOR_BUFFER_BIT is scoped to WebGLRenderingContext so I guess that’s the reason.

Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need to since the names are the same?

How does this JS translate to Pascal then? drawingBufferWidth are read only properties but no type is specified so how does Pascal handle all the untyped variables we see in JS?

var canvas = document.createElement("canvas");
var gl = canvas.getContext("webgl")
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Mattias Gaertner
In reply to this post by Ryan Joseph
On Tue, 1 May 2018 12:11:37 +0700
Ryan Joseph <[hidden email]> wrote:

>[...]
> const
>   GLfloat = MAP_TO_SOMETHING; // do we have external consts?

GLFloat is a type, not a const.

type GLFloat = double;

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph

> On May 1, 2018, at 2:55 PM, Mattias Gaertner <[hidden email]> wrote:
>
> GLFloat is a type, not a const.
>
> type GLFloat = double;

Yeah I mistyped. We shouldn’t be redefining GLfloat though (I doubt it’s a double in OpenGLES/WebGL either) so how does this (or other types) translate for the parser?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Mattias Gaertner
On Tue, 1 May 2018 15:03:30 +0700
Ryan Joseph <[hidden email]> wrote:

> > On May 1, 2018, at 2:55 PM, Mattias Gaertner <[hidden email]> wrote:
> >
> > GLFloat is a type, not a const.
> >
> > type GLFloat = double;  
>
> Yeah I mistyped. We shouldn’t be redefining GLfloat though (I doubt it’s a double in OpenGLES/WebGL either) so how does this (or other types) translate for the parser?

JS only knows double for numbers.

At compile time you can use almost all the normal types: byte,
word, longint, etc.
pas2js has an alias single, but because internally it is a double this
gives warnings.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt
In reply to this post by Ryan Joseph


On Tue, 1 May 2018, Ryan Joseph wrote:

>
>
>> On May 1, 2018, at 2:03 PM, Michael Van Canneyt <[hidden email]> wrote:
>>
>> Of sorts.
>>  MyClass = Class external name 'my'
>>  const
>>    MyConst : integer
>>  end;
>>
>> Will emit MyClass.MyConst. The compiler needs to know the type.
>
> I’m confused now.  The class is named WebGLRenderingContext in JS (I think
> that’s what it’s called by JS doesn’t really have classes does it?) so how
> does it look?

See below.

>
> // no external name because the names are the same

That is only so for methods and fields. I corrected the class below:

type
   WebGLRenderingContext = class external name 'WebGLRenderingContext'
     procedure clearColor (red, green, blue, alpha: GLfloat);
   end;

>
> So constants must be part of the class? In the example below gl.COLOR_BUFFER_BIT is scoped to WebGLRenderingContext so I guess that’s the reason.

Yes.

Constants without expression can only exist in an external class.

>
> Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need to since the names are the same?

You need to define types.

type
   GLfloat = double;

>
> How does this JS translate to Pascal then? drawingBufferWidth are read only properties but no type is specified so how does Pascal handle all the untyped variables we see in JS?

This is pascal. You need a type.

https://www.khronos.org/registry/webgl/specs/latest/1.0/

shows that drawingBufferWidth has type GLsizei, which is a long.

If you don't know the type, use JSValue. It's the 'unknown type'. It has
limited possibilities, in essence you'll need to typecast a JSValue before
using it. You can assign JSValues of course.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph
In reply to this post by Mattias Gaertner


> On May 1, 2018, at 3:17 PM, Mattias Gaertner <[hidden email]> wrote:
>
> JS only knows double for numbers.
>
> At compile time you can use almost all the normal types: byte,
> word, longint, etc.
> pas2js has an alias single, but because internally it is a double this
> gives warnings.

what do we do for records then? We often need to pass arrays of specific types for functions such as glBufferData.

type
  TVec2f = record
    x, y: GLfloat;
  end;

type
  TVec2b = record
    x, y: GLubyte;
  end;

var
  verts: array[0..2] of TVec2f;
begin
  glBufferData(GL_ARRAY_BUFFER, sizeof(TVec2f) * 3, @verts, GL_STATIC_DRAW); // pass an array of TVec2 but how does JS know this?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Mattias Gaertner
In reply to this post by Ryan Joseph
On Tue, 1 May 2018 14:20:12 +0700
Ryan Joseph <[hidden email]> wrote:

> > On May 1, 2018, at 2:03 PM, Michael Van Canneyt <[hidden email]> wrote:
> >
> > Of sorts.
> >  MyClass = Class external name 'my'
> >  const
> >    MyConst : integer
> >  end;
> >
> > Will emit MyClass.MyConst. The compiler needs to know the type.  
>
> I’m confused now.

I think you confused Michael. ;)

At the moment you can define external const like this:
var
  NaN: Double; external name 'NaN';
  Infinity: Double; external name 'Infinity';
  NegInfinity: Double; external name '-Infinity';

Note that the 'var' is a workaround till eventually pas2js supports
external 'const' without expression.

A const inside an external class already works:

type
  TMyExt = class external name 'Bla'
    const LoVersion: GLFloat;
    const HiVersion: GLFloat; external name 'hiversion';
  end;


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Ryan Joseph
In reply to this post by Michael Van Canneyt


> On May 1, 2018, at 3:17 PM, Michael Van Canneyt <[hidden email]> wrote:
>
>> So constants must be part of the class? In the example below gl.COLOR_BUFFER_BIT is scoped to WebGLRenderingContext so I guess that’s the reason.
>
> Yes.
>
> Constants without expression can only exist in an external class.

Just curious but why can’t you declare a const anywhere for any reasons?

>
>>
>> Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need to since the names are the same?
>
> You need to define types.
>
> type
>  GLfloat = double;

Why do we need to redefine the type if it’s already defined in the JS library? GLfloat isn’t a double also but see my other reply.

From the link you posted there are these types. Is that even JavaScript? I don’t remember there being typedefs in it or void functions.

typedef unsigned long  GLenum;
typedef boolean        GLboolean;
typedef unsigned long  GLbitfield;
typedef byte           GLbyte;         /* 'byte' should be a signed 8 bit type. */
typedef short          GLshort;
typedef long           GLint;
typedef long           GLsizei;
typedef long long      GLintptr;
typedef long long      GLsizeiptr;
// Ideally the typedef below would use 'unsigned byte', but that doesn't currently exist in Web IDL.
typedef octet          GLubyte;        /* 'octet' should be an unsigned 8 bit type. */
typedef unsigned short GLushort;
typedef unsigned long  GLuint;
typedef unrestricted float GLfloat;
typedef unrestricted float GLclampf;

There’s other types also like dictionaries and interface. How do those work? I don’t remember those being in JS either….

dictionary WebGLContextAttributes
 {
    GLboolean alpha = true;
    GLboolean depth = true;
    GLboolean stencil = false;
    GLboolean antialias = true;
    GLboolean premultipliedAlpha = true;
    GLboolean preserveDrawingBuffer = false;
    WebGLPowerPreference powerPreference = "default";
    GLboolean failIfMajorPerformanceCaveat = false;
};

interface WebGLActiveInfo
 {
    readonly attribute GLint size;
    readonly attribute GLenum type;
    readonly attribute DOMString name;
};

>
>>
>> How does this JS translate to Pascal then? drawingBufferWidth are read only properties but no type is specified so how does Pascal handle all the untyped variables we see in JS?
>
> This is pascal. You need a type.
>
> https://www.khronos.org/registry/webgl/specs/latest/1.0/
>
> shows that drawingBufferWidth has type GLsizei, which is a long.
>
> If you don't know the type, use JSValue. It's the 'unknown type'. It has
> limited possibilities, in essence you'll need to typecast a JSValue before
> using it. You can assign JSValues of course.

I see, that reference I used wasn’t complete.



Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt


On Tue, 1 May 2018, Ryan Joseph wrote:

>
>
>> On May 1, 2018, at 3:17 PM, Michael Van Canneyt <[hidden email]> wrote:
>>
>>> So constants must be part of the class? In the example below gl.COLOR_BUFFER_BIT is scoped to WebGLRenderingContext so I guess that’s the reason.
>>
>> Yes.
>>
>> Constants without expression can only exist in an external class.
>
> Just curious but why can’t you declare a const anywhere for any reasons?
As far as I know, all consts in Javascript are scoped ?

If this is not the case, then of course we should allow it.

>
>>
>>>
>>> Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need to since the names are the same?
>>
>> You need to define types.
>>
>> type
>>  GLfloat = double;
>
> Why do we need to redefine the type if it’s already defined in the JS library? GLfloat isn’t a double also but see my other reply.
You must define the type to something the compiler knows, so the compiler knows what operations it can do.

Imagine:

Type
   MyOpaqueType external;

Var
   I : MyOpaqueType;

begin
   // What can I do with I ?  Can I add it ? Can I multiply it ?...
end.

If you really do not know the type, use JSValue. But there is little you can
do with a JSValue except assign or typecast it.

>
> From the link you posted there are these types. Is that even JavaScript? I don’t remember there being typedefs in it or void functions.

The link is a spec. All javascript constructs have such a spec, and they are
a form of IDL, which does specifie types.

>
> interface WebGLActiveInfo
> {
>    readonly attribute GLint size;
>    readonly attribute GLenum type;
>    readonly attribute DOMString name;
> };
>>
>>>
>>> How does this JS translate to Pascal then? drawingBufferWidth are read only properties but no type is specified so how does Pascal handle all the untyped variables we see in JS?
You are mistaken where that is concerned.

See above: Most APIs _do_ specify a type. You must look it up. Have a look
at the web.pas or js.pas or even libjquery.pas units. Most identifiers have
a type, the use of JSValue is quite limited.

Read-only Attributes can be translated to read-only properties.

The above would be

Type
    WebGLActiveInfo = class external name 'WebGLActiveInfo'
    Private
     fSize : GLint; external name 'size';
     ftype: GLEnum; external name 'type';
     fName : DOMString ; external name 'name';
   Public
     Property size : GLInt Read FSize;
     Property &type : GLEnum Read fType;
     Propert Name : DomString read FName;
   end;

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Michael Van Canneyt
In reply to this post by Mattias Gaertner


On Tue, 1 May 2018, Mattias Gaertner wrote:

> On Tue, 1 May 2018 14:20:12 +0700
> Ryan Joseph <[hidden email]> wrote:
>
>> > On May 1, 2018, at 2:03 PM, Michael Van Canneyt <[hidden email]> wrote:
>> >
>> > Of sorts.
>> >  MyClass = Class external name 'my'
>> >  const
>> >    MyConst : integer
>> >  end;
>> >
>> > Will emit MyClass.MyConst. The compiler needs to know the type.
>>
>> I’m confused now.
>
> I think you confused Michael. ;)
>
> At the moment you can define external const like this:
> var
>  NaN: Double; external name 'NaN';
>  Infinity: Double; external name 'Infinity';
>  NegInfinity: Double; external name '-Infinity';
>
> Note that the 'var' is a workaround till eventually pas2js supports
> external 'const' without expression.
Well, I specially did not mention this, because I consider it a dirty hack.
a var doesn't protect you from assigning to it (it's a variable, after all).

One preferably shouldn't teach people bad habits. :)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Next language feature for pas2js...

Mattias Gaertner
In reply to this post by Ryan Joseph
On Tue, 1 May 2018 15:36:59 +0700
Ryan Joseph <[hidden email]> wrote:

>[...]
> > Constants without expression can only exist in an external class.  
>
> Just curious but why can’t you declare a const anywhere for any reasons?

You can.


> >> Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need to since the names are the same?  
> >
> > You need to define types.
> >
> > type
> >  GLfloat = double;  
>
> Why do we need to redefine the type if it’s already defined in the JS library?

JS has (almost) no types. WebGL has some intrinsic types. The unit
webgl will be defining the corresponding Pascal types.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
12