GameMonkey Script

GameMonkey Script Forums
It is currently Mon Nov 20, 2017 3:32 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon May 28, 2012 5:23 am 
Offline

Joined: Sun Oct 16, 2011 7:24 pm
Posts: 7
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..


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 02, 2012 1:12 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 05, 2012 6:22 pm 
Offline

Joined: Sun Oct 16, 2011 7:24 pm
Posts: 7
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 06, 2012 3:42 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 09, 2012 1:32 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
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();


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 12, 2012 1:48 pm 
Offline

Joined: Sun Oct 16, 2011 7:24 pm
Posts: 7
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group