Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Tarn
GURU


Joined: 10 Oct 2000
Posts: 853
Location: USA

PostPosted: Tue Jun 06, 2006 4:01 pm   

Compiler - references/binding
 
Sorry if this is obvious.

You've provided a bit of documentation and discussion on when variables get expanded, and documented it over at
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2214

When do references to things like aliases, commands, and functions get bound? Because of the normal default behavior of sending text to the server when it doesn't match an alias, I'm not sure what to expect from something like the following under CMud. Does it fully compile everything when an alias/trigger is defined, and turn non-commands/aliases into implicit direct send commands? Or does it wait until each execution of an alias to look for references?

Under zMud,
#alias dostuff {foo;bar}
dostuff
will process "foo" and "bar" as commands.
Later defining
#alias bar {bar1;bar2}
dostuff
will process "foo", "bar1", and "bar2" because everything is evaluated when "dostuff" is entered by the user (no compiling).

How does the CMud compiler handle things like that?

-Tarn
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Jun 06, 2006 5:17 pm   
 
If I understand everything correctly it will process

"foo", "bar1" and "bar2" when you evaluate dostuff. This is because scripts, aliases etc are recompiled when edited then there is a reference check done and where applicable those scripts, aliases etc. are compiled.

Of course I'm sure Zugg will soon rule in with a definitive answer.
_________________
Asati di tempari!
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 853
Location: USA

PostPosted: Tue Jun 06, 2006 5:35 pm   
 
Tech wrote:
If I understand everything correctly it will process

"foo", "bar1" and "bar2" when you evaluate dostuff. This is because scripts, aliases etc are recompiled when edited then there is a reference check done and where applicable those scripts, aliases etc. are compiled.


Yes, I've seen the posts with Zugg's description of recompiling when something changes.

In the example I gave, though, the first alias did not change and was not edited when the second was created (nor does it have any variables that changed), so I'm not sure how the compiler would know that the first alias in particular (among all of the other aliases and scripts) needed to be recompiled.

The answer might be that aliases are part of script execution, not compiling.

-Tarn
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23377
Location: Colorado, USA

PostPosted: Tue Jun 06, 2006 7:13 pm   
 
Yep, everyone is correct. When something is changed, it gets recompiled the next time it is used. In your example, your original "dostuff" alias is compiled as:
Code:
ALIAS foo
ALIAS bar

When this code is executed, if "foo" is not yet defined as an alias, then CMUD just sends it to the MUD as text. But when "foo" later gets defined, then "dostuff" is already set up to execute foo as an alias. So changing "foo" doesn't cause "dostuff" to get recompiled (because dostuff hasn't actually changed). But the "foo" reference now points to a real alias and that alias gets executed instead of just sending text to the MUD.

So Tarn was right...the aliases are part of script execution, not compiling.

What happens at the low-level is during the compilation, if the variable (or alias) exists, then the compiler stores both the name *and* the pointer to the variable record. When executing, if this pointer is available, then it is used. If this pointer doesn't exist, then the name is used to perform a lookup at runtime.

So having your variables and aliases defined before hand gives you a more efficient compiled script since it doesn't need to perform the name lookups at runtime.

Also, since the name lookups are usually relative to the "current class", the compiler also stores the value of the current class. If the current class has changed, then the runtime execution will also ignore the compiler pointer and will perform a new lookup based upon the name.

Yeah, the low-level details get complicated! But it all works as you'd expect. It's a nice combination of the speed advantages of compiling, while still having some of the flexibility of being interpreted.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Tue Jun 06, 2006 7:44 pm   
 
I know it's been mentioned before, but it's been buried in other threads by now, so I'll ask again here... When would the settings be re-compiled then? If we edit the settings and save the file, does it compile everything as part of the save operation? Would we have to close everything out and reload the settings for the compilation of all changes to occur? If the latter, will there be a button for forcing a re-compile or at least some indication of what's compiled and what isn't (or just that there exist some uncompiled settings somewhere, maybe)? It's not a big deal, really, because it'll all work as expected, as you say. I'm just curious to know how the compilation works with editing and saving and all that.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23377
Location: Colorado, USA

PostPosted: Wed Jun 07, 2006 2:11 am   
 
No, it doesn't recompile when you save. When you do something that changes the *value* of an alias, trigger, variable, etc, then CMUD sets a flag (something like RecompileNeeded). Then, the next time CMUD needs to execute that setting, before executing it checks to see if it needs to recompile. If not, it uses the cached code from the last recompile.

You can currently force a recompile of an alias because there is a new tab called "compiled code" which displays the results of the compiler for debugging purposes. Clicking this tab forces a recompile. But this tab will eventually go away as there is no need to see the compiled code.

Also, remember that CMUD doesn't save any of the compiled code. So when you first load a file, everything is marked as "RecompileNeeded".

But don't worry, you won't notice any of this. The compiler is very fast. Whenever you type something on the command line, it gets compiled and then executed. And it does this faster than the old parser could work.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net