Author Topic: Would a "higher level" AGI compiler be useful?  (Read 29353 times)

0 Members and 1 Guest are viewing this topic.

Offline Mokalus of Borg

Would a "higher level" AGI compiler be useful?
« on: March 18, 2002, 04:07:30 AM »
I was just wondering about my next project after AGI2SCI - does anyone think that it's time we could write code for AGI in a higher-level language? Coding in this assembly-like language is bound to be a pain (I've never actually done it myself), and I'm sure it would make AGI development more accessible. Also, I'd be fairly confident in betting that the original development system didn't require coding the way we do.
The proposed compiler would natively support more data structures, like the arrays discussed elsewhere on this board, but as for the larger-scale syntax and so forth, I'd need the input of experienced AGI programmers. So here's your chance: go nuts! Tell me everything you'd wish from your ideal AGI-HLL compiler. Eventually, I'll get around to working it up, either between AGI2SCI components or afterwards.

Mokalus of Borg

PS - Unless this has been done already?
PPS - I really think this will be a Good Thing.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »



Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #1 on: March 18, 2002, 05:35:53 AM »
The big problem with a higher level language for AGI is the limited resources. How would the compiler manage them? Would the user be able to specify that the compiler may use variables in a certain range as temporaries and that it must leave the rest alone? To add the ability to evaluate expressions into the AGI language, they'd either have to be limited in form, or the complexity of the expression would be limited by how many temporary variables are allocated to the compiler. I may be mistaken, because I haven't worked this out a great deal, but I believe that evaluating nested parentheses requires a stack, and there's nowhere to put the thing except in the var area of memory. I'm not saying that it wouldn't still be useful, but it's something to take into consideration. I definitely think AGI should be able to handle expressions like v1 = v2 + v3 + v4;, but when you get into expressions like v1 = v2 + (v3 + (v4 + (v5 + (v6 + v7) * v8) + v9) * v10) + v11; it gets a little ugly.

Array syntax becomes problematic, as well, especially when you get into multidimensional arrays.

There are some additions/changes I'd like to see to the AGI syntax, though. For example:

the ability to print out vars by name, as in something like
#define vTemp v202
print("%vTemp");

switch statements

more C++ like syntax, where function names don't have dots in them (for example AddToPic() instead of add.to.pic()), and along with this I think it would be good if we could have object.method style syntax where appropriate;

for example,
#define ego o0
#define oSomeOtherObject o1

instead of
animate.obj(o0);
animate.obj(o1);
set.view(o0);
set.view(o1, 10);
draw(o0);
draw(o1);

something like
ego.Animate();
oSomeOtherObject.Animate();
ego.SetView(0);
oSomeOtherObject.SetView(10);
ego.Draw();
oSomeOtherObject.Draw();

There are probably other things I could think of, but that's all I can for right now.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

eidolon

  • Guest
Re: Would a "higher level" AGI compiler be useful?
« Reply #2 on: March 18, 2002, 05:59:17 AM »
On the spur of the moment I think this sounds like a fabulous idea!
The first things that cross my mind are:

- Control statements: switch, advanced if..else if, for, while, break...

- Recursive expressions: v59 = ( v122 + 16 ) * 4;

- Boolean type parsing:  v44 = ( v99 > v22 ); if( v44 )...

- Function definitions ( with parameters and return values )


Even wilder ideas:

- Other datatypes: 16 and 32 bit integers

- Objectoriented syntax

- Point & Click programming through a specially designed application suited for beginners. With a highly flexible GUI, game developers could create anything from room descriptions to motion patterns for monsters.


However, it all comes down to this - what you gain on abstraction you lose on precision. And implementing all this into the code would certainly eat resources. AGI is such a limited system that programming it almost feels like doing demos on the C64 in machinecode. Furthermore, care for details is not far from inevitable when it comes to optimizations, and I think that is one of the actual pleasures of this retro craze.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #3 on: March 18, 2002, 01:08:28 PM »
I think I tried suggesting some of these things in the older agi board but not as many people were receptive.
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Andrew_Baker

Re: Would a "higher level" AGI compiler be useful?
« Reply #4 on: March 18, 2002, 01:58:22 PM »
Two cents...

- User-defined functions could just be macros, either defined in defines.txt or some other file.  Of course, it would be beneficial if this could be accessed from the AGIStudio environment.

- Since arrays are stored linearly on any computer system, then interpreting and handling them could just be a matter of making a macro-type command that accepts arguments and is compiled into interpreter data by the Studio.  The same with referencing them (because it would be absolutely necessary to be able to reference arrays by both integer values as well as vars.).  Not to say this would be easy, though...  but I don't think anyone would need arrays of more than two dimensions for an adventure game, no matter how advanced.

- Also, if there are going to be any improvements to AGI coding, I think most of them could be done in AGIStudio.  Nailhead has done a great job on his version, but there are still bits missing (Like sound, tricky, tricky, tricky).  I think that a lot of problems like room and logic generation could just be integrated into the studio, but I'm the kind of nerd who likes to hand-craft code (f'rinstance, a monster's motion pattern could be defined as a series of loops.  Plotting a square motion pattern would be like 4 nested loops, I think.  I know I could write it in AGI, but I'm not sure I would trust an automated logic generator to do it for me.).  Still, I think if there was a way to add new third-party development tools to the main Studio environment without having to rewrite the Studio every time someone released a new tool, I would actually weep with joy.

- For loops, for loops, for loops!

- Ultimately, I would support an upgrade to the compiler in any way I can (which probably wouldn't be much, but...), but part of the charm of AGI for me is making a good chunk of code using a difficult language with limited resources.

I wish y'all luck, you beautiful monsters!
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
I hope you realize that one day I will devour the Earth.

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #5 on: March 18, 2002, 02:07:16 PM »
I just think a separate compiler that's called by AGI Studio would be easier to replace.  I was also thinking that Joel's logic template generator could be added as well (i know they borrowed it for linux agi studio I believe).  The template generator could be integrated with the pic/view code, so you could manually place views on the picture background itself.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #6 on: March 18, 2002, 02:41:54 PM »
I would also like to see conditional compilation. Ya know,

#if defined(DEBUG)

log("whatever");

#endif

that kind of stuff. I'm more supportive of changes that are mostly just rearrangements or trivial additions to the original syntax. Although I'd like to see syntax such as ego.StopCycling(), I see no reason why the same compiler couldn't continue to handle stop.cycling(ego); Switch statements can essentially compile down to if statements as a simple implementation.

But especially in a limited resource environment, with the addition of expressions and array syntax and function calls, this higher-level compiler wouldn't just be a compiler. It would require a code optimizer. And if the user doesn't have control over which variables the compiler is allowed to use for temporaries, then the compiler has to manage all the memory for the entire game.

Function calls are probably possible, but they require temporary space for parameters at best and entire activation records at worst (and more likely, especially if functions can call other functions). AGI has no "call" command for labels as far as I know, so if functions can call other functions, then the compiler has to keep track of the location where the function call was made, and when the function returns, it has to jump back to that location. If you have a 5x5 two dimensional array, you've knocked out 25 of your memory locations right there. Add in expression evaluation, you've got an unknown number of temporaries necessary (you don't even have to have parentheses to need temporaries...e.g., v1 = 2 + 3 * 7;) Function calls just create more of a headache.

States wouldn't necessarily help in this regard. It's standard optimization to reuse variables that are no longer needed, but you don't have an expression-evaluating state or a function-calling state, and either of those can require an arbitrary amount of memory. Another potential problem, because what if you start calling too many functions from functions and you start overwriting your game data?
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #7 on: March 18, 2002, 04:28:39 PM »
The states would be useful if the programmer didn't want to have to manually figure out which variables he could overwrite..  If the compiler had control over the assignment of variables, it could set aside some for spare variables in arithmetic.

we could define similar "object orientated" function names for the menu, screen, script, input.. to help separate them into groups.

I'd actually like the compiler to manage the memory for the entire game.  Considering how some people don't use defines and then forget that they're already using a variable in other logics, it would make things a lot simpler.

AGI does have save.scan.start and restore.scan.start.. but it's not recursive.  AGI doesn't have functions, but you can call other logics and then return back from them.. so it's not a stretch to set a variable to define a function, call a logic containing lots of functions and goto the specific function.. (via a switch, if implemented).

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline df

Re: Would a "higher level" AGI compiler be useful?
« Reply #8 on: March 18, 2002, 10:17:09 PM »
if you cant write it in logic, you cant do it in a higher level compiler. The agi logic itself is what is lacking here... What really needs to happen is say, replace the logic with 8051 or 6502 code (something nice, small and easily interpreted!)...

replace logic with cpu emulation. have a logic-to-code convert then you can write your AGI game in C or whatever, or just beef up existing logic code.

« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Mokalus of Borg

Re: Would a "higher level" AGI compiler be useful?
« Reply #9 on: March 19, 2002, 04:48:34 PM »
Okay, so it sounds like the extreme position of a whole new, very high-level, optimising, super-happy-magic compiler is out, but we'd like some better control structures and syntax in the compilers we currently use. So, is the source code available for either AGIC or MATS? If not, are there any other AGI compilers around, with source, that I can get my greasy paws onto?
And the conditional compilation could be fairly easily done with a C preprocessor.

Mokalus of Borg

PS - I don't know when I'll start this.
PPS - I'm still busy with AGI2SCI and work and study...
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #10 on: March 19, 2002, 08:21:50 PM »
if there's any chance, I'd like to help with the compiler too..  are you planning on writing in C or python?

I we think we should define the correct syntax first before doing any recoding.  We should check out the feasibility of any of the suggestions (macros and #ifdef's should definately be in.. also with "%v"varname"")

How about the way we define variables.. does anybody have any ideas about that?  should we still manually define every variable in defines.txt?

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #11 on: March 19, 2002, 09:34:30 PM »
That depends on what you mean...I changed all the defines in my defines.txt so that they're more consistent with my own coding style (I don't like using underscores to separate words in variable names; I also corrected the misspelled "input_recieved"). It's fine, I guess, if the compiler recognizes the define names from the template game without them being explicitly defined, as long as I can also change the names if I want to. On the other hand, you don't want to be breaking people's current code by flagging a redefinition error or anything if they continue to use defines.txt.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #12 on: March 19, 2002, 09:57:01 PM »
I was thinking more, associate a variable number with your definations (for system/template or other variables) and let the compiler organise the rest..  as soon as you do that, you need to change the msg handling as well to support var names..

so are we planning on having backwards compatible with older source too?  how about a header to define the script version?

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #13 on: March 20, 2002, 01:01:05 AM »
I knocked up a summary of this discussion.. it explains the basics of the logic format and all the suggestions so far in a list..

Compiler Discussion Summary

I've put up links to the AGIC page, and downloads for AGIC and MATS (they both have source)..

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Mokalus of Borg

Re: Would a "higher level" AGI compiler be useful?
« Reply #14 on: March 20, 2002, 02:33:41 AM »
I'd rather write in Python, but it's probably not fast enough. Maybe I could write the basis in Python and have someone else who's much more C-savvy translate it.
That's if we start from scratch. We already have two fully-functional compilers available, and it might be enough to just add a bit to them.
Now, if we have all variables defined in advance (perhaps with separate scopes for game-wide and room-specific), we'd know how much space we have to spare for expression evaluation and data structures. I think it can be done.
Overall, I envisage a source code format that reflects the structure of the game more clearly, is easier to understand and use, and gives more power to the programmer.

Mokalus of Borg

PS - I promise at least to work up a grammar over the next two days.
PPS - You spelled my name wrong on that page: "Mokulus".
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.038 seconds with 15 queries.