[Pas2js] @pointer/reference inside ASM block - missing feature
Michael Van Canneyt
michael at freepascal.org
Sat Jun 9 16:14:46 CEST 2018
On Sat, 9 Jun 2018, warleyalex via Pas2js wrote:
> I came across an issue when using the ASM block/section: "you have to
> initialize the variables reference" before you use that reference iniside
> the ASM block.
> for instance:
> ---------------------
> var
> s: string;
> Begin
> s = 'Hello World!';
> ASM
> console.log(s);
> End;
> ---------------------
> transpiles to:
> ---------------------
> var $mod = this;
> this.s = '';
> $mod.$main = function(){
> $mod.s = "Hello World!";
> console.log(s);
> };
> ---------------------
>
> Pas2JS does not support @ prefix with the ASM Block:
> ----------------------------------------------------
> Since the pas2js compiler does neither parse, nor check the syntax of the
> JS, it does not understand the prefix@ inside the ASM section, for instance:
> -------------
> function getSomeData: JSValue;
> begin
> asm
> /* return a data structure */
> @Result = {first:"hello",second:"hello2"}
> end;
> end;
> ------------
> You'll get "unexpected token ILLEGAL".
Ehm. Why do you need @ ?
function getSomeData: JSValue;
begin
asm
/* return a data structure */
return {first:"hello",second:"hello2"}
end;
end;
or
function getSomeData: JSValue;
begin
asm
/* return a data structure */
Result= {first:"hello",second:"hello2"}
end;
end;
Should do what you need.
In each case, parsing the javascript is not planned for the near future.
Michael.
More information about the Pas2js
mailing list