HuubGitHub / dwscript

Automatically exported from code.google.com/p/dwscript
1 stars 0 forks source link

It should be possible to use an external var symbol as command. #492

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Possible usage of external var:
  1. Write value: EXTVAR := s;
  2. Read value:  s := EXTVAR;
  3. Read value (and discard Result): EXTVAR;

Currently only 1 and 2 are possible.

Since EXTVAR is not just a simple storage, but has code, it is desireable to 
run the associated code without caring for the result.

Justification
ReadExternalVar is called with IsWrite=true on the assumption that an 
assignment operator would follow.
When this assumption is proven wrong the compiler should assume the script 
writer wants to read from the external var (even if the result is discarded).

I suggest changing TdwsCompiler.ReadExternalVar

from:
  if Writing:
      if followed by ttASSIGN:
          return write-function
      if (not followed by ttASSIGN) and (type-is-one-that-should-be-read):
          return read-function
  if Reading:
      return read-function

to:
  if Writing:
      if followed by ttASSIGN:
          return assign-function
      if not followed by ttASSIGN:   // imply read if name is not assigned to.
          return read-function
  if Reading:
      return read-function

Original issue reported on code.google.com by redlichk...@gmail.com on 3 Nov 2014 at 1:25

GoogleCodeExporter commented 8 years ago
Would it really be desirable or is it more likely to lead to faulty code not 
generating compile time errors?

The external vars were more intended to act as a bridge to outside-of-script 
data, so to follow the "principle of minimum surprise", they should ideally 
have no side-effect (like property reads/getters), and thus such use would 
likely be an error.

Original comment by zar...@gmail.com on 3 Nov 2014 at 4:44