GameMonkey Script
http://www.gmscript.com/gamemonkey/forum/

Increment and decrement operators?
http://www.gmscript.com/gamemonkey/forum/viewtopic.php?f=6&t=605
Page 1 of 1

Author:  Downsider [ Mon May 28, 2012 5:23 am ]
Post subject:  Increment and decrement operators?

I've spent a lot of time messing with Flex, Bison and GameMonkey trying to get an increment operator working. I haven't been able to work it out :/

Is it just one of those things that would require an entirely different VM structure? Is it even remotely possible in GameMonkey's current state without huge alterations? If so, can someone give me a hand? It'd make for code that's quite a bit cleaner..

Author:  Greg [ Sat Jun 02, 2012 1:12 am ]
Post subject:  Re: Increment and decrement operators?

The very first version of GM implemented inc and dec operators. I just compared source with v1.0 and unfortunately it seems the first public release was slightly too late and did not include the code. In hind sight removing those operators was wrong. Although the idea of preventing assignment in selection statements is noble, one goal of GM was to be friendly to C/C++ programmers, and that means supporting as much of the classic C syntax as possible. I do recall Matt saying that removing those operators significantly simplified the code, however I don't recall how much was grammar and how much was code gen code. I'll report back if I can find any more details on this.

Author:  Downsider [ Tue Jun 05, 2012 6:22 pm ]
Post subject:  Re: Increment and decrement operators?

Greg wrote:
The very first version of GM implemented inc and dec operators. I just compared source with v1.0 and unfortunately it seems the first public release was slightly too late and did not include the code. In hind sight removing those operators was wrong. Although the idea of preventing assignment in selection statements is noble, one goal of GM was to be friendly to C/C++ programmers, and that means supporting as much of the classic C syntax as possible. I do recall Matt saying that removing those operators significantly simplified the code, however I don't recall how much was grammar and how much was code gen code. I'll report back if I can find any more details on this.


I haven't looked too far into it, but I was trying to add my own operator to both the VM and lexer much in the manner that the "!" operator is added. I'm not sure if this is the best approach, but it seemed like the most reasonable at the time. I was not, however, able to get it working, even though everything appeared to be implemented correctly, in that the lexer was successfully parsing the data and the VM was finding and using the opcode in the expected manner. I was just unable to actually do anything as far as changing any variables once the VM triggered the operation.

Author:  Greg [ Wed Jun 06, 2012 3:42 am ]
Post subject:  Re: Increment and decrement operators?

I've found a pre v1.0 build with pre inc and pre dec operators intact. I aim to post some code soon.
I might try reintegrating the changes and putting them inside a #define for experimentation.

Author:  Greg [ Sat Jun 09, 2012 1:32 pm ]
Post subject:  Re: Increment and decrement operators?

Please check out beta 1.29.3. I've restored the v0.9 pre inc and dec operators as an experiment. Note that the post inc and dec are currently not supported, otherwise it seems to work quite well. It currently works with int, float value on locals, tables and this. I have not investigated further, only restored the old code and surrounded in #if GM_USE_INCDECOPERATORS.

The following code is now valid:
Code:
for(i = 0; i < 10; ++i)
  { print("i=",i); }

t = {};
for(t.value = 0.5; t.value < 10.5; ++t.value)
  {  print("t.value=",t.value); }

f = function()
{
  for(.value = 0; .value < 10; ++.value) 
    { print(".value=",.value); }
};

t:f();

Author:  Downsider [ Tue Jun 12, 2012 1:48 pm ]
Post subject:  Re: Increment and decrement operators?

Greg wrote:
Please check out beta 1.29.3. I've restored the v0.9 pre inc and dec operators as an experiment. Note that the post inc and dec are currently not supported, otherwise it seems to work quite well. It currently works with int, float value on locals, tables and this. I have not investigated further, only restored the old code and surrounded in #if GM_USE_INCDECOPERATORS.

The following code is now valid:
Code:
for(i = 0; i < 10; ++i)
  { print("i=",i); }

t = {};
for(t.value = 0.5; t.value < 10.5; ++t.value)
  {  print("t.value=",t.value); }

f = function()
{
  for(.value = 0; .value < 10; ++.value) 
    { print(".value=",.value); }
};

t:f();


Wow! Thanks! This is more than I had expected from the get-go :P

Hopefully with these changes it'll shed some light as to how I can add some of my own operators as well.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/