Jump to content

Referencing Pascal vars in asm block


Recommended Posts

Background:

When in an asm block, with included native javascript code, a coder can use the '@' symbol to reference a pascal string. This ensures that the compiler keeps the variable name to be the same inside the asm block as outside.

 

Issue: It doesn't seem to be possible to access properties of the pascal variable. Imagine a variable AVar : TMyClass. And TMyClass has property of Name, then trying to access length seems to cause problems:

 

asm

@AVar.Name = 'hello';

end;

 

Consider also the following code:

 

asm

var s2=@Str;

var splitStr = s2.split(@ADelim);

end;

 

If put into the code above, should @Str.split(@ADelim) be legal? .split is a javascript thing, not a pascal thing.

 

So I see the @ as potentially ambiguous. Does it refer only to the main variable, or to '.' elements that are connected to it?

 

Proposal: Allow parentheses to encapsulate the pascal part, so one could do this

@(AVar.Name).split(@ADelim)

 

Any thoughts? Am I missing the way this already works differently?

 

Kevin

Link to post
Share on other sites

Currently only "immediate" references are allowed, ie. variables and fields.

 

It should be possible to extend the support for simple (non-indexed) properties, but only in some cases, like property reads or functions calls.

 

Property assignments on the other hand would be problematic, as they are function calls in disguise, so

 

asm

@AVar.Name = ‘hello’;

end;

 

would actually be equivalent to

 

asm

ClassOfSelf.SetName(@Self, 'hello');

end;

 

if SetName is static (and something more complex if SetName is virtual, or if Self is an interface etc.)

 

Also in the more general asm context, it's legal to have JS like

 

asm

var v = @AVar.Name = someFunc('hello');

end;

 

which doesn't have any trivial output (as "someFunc" could have side effects, and so could "SetName"), so it would need to be fully parsed and recompiled, and so it would no longer be asm.

 

The current approach is the have "asm" be as "hands off" as possible from a compiler POV.

 

> should @Str.split(@ADelim) be legal?

 

It will error if Str doesn't have a split field on the Delphi side, however (@Str).split(@ADelim) is allowed and safe.

 

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...