Pre-compiler
#1

I've been thinking about creating a pre-compiler for quite a while now.. I did create something similar here, but it's written in PHP and isn't flexible enough.

Design
I'm thinking Node.js would be great for this. In fact, I've already written libraries to run servers, compile scripts, and modify anything in an AMX file.

Are you good at JavaScript? Participate!

"Hooking" the compile process
I think the best way to deal with the preprocessor is let it do its thing, then step in.
  1. Compile with the -l flag (only preprocess)
  2. Do the pre-compilation magic
  3. Include the runtime script
  4. Compile the resulting script
  5. Open the AMX and modify debug information and the header for additional customization
Runtime
The compiler would include a plain Pawn script containing functions that would be used throughout the script.
These functions could help with memory allocation, string manipulation, managing data structures, and so on.

Plugins
This is where I think the compiler could grow in strength. Support loading JavaScript plugins that does, well, whatever you want to your code. Anyone can make them, and anyone can use them.

Ideas
  • OO!
  • Pointers!
  • Improved enums (fix issues, store info on keys). This would allow easily saving/loading data in enums without having to modify code every time the enum is changed.
  • Improved runtime introspection (allow people like Y_Less and I to make more cool stuff).
Edit: I've created an initial version now.

Source code
Here's the GitHub repository:
https://github.com/oscar-broman/Prawn
Reply
#2

someone explain for plain noobs what this thread is really about?
Reply
#3

Quote:
Originally Posted by mastermax7777
View Post
someone explain for plain noobs what this thread is really about?
Add new functions to the compiler. The compiler is what converts your code into an AMX file that you load in the server.

It's hard to explain without any practical examples, but imagine something like this:
pawn Code:
enum E_VEHICLE {
    Id,
    Model,
    Owner,
    Float:X,
    Float:Y,
    Float:Z,
    Float:Angle
}

new g_Vehicles[2000][E_VEHICLE];

public OnGameModeInit() {
    // Load all vehicles from a file into the variable g_Vehicles
    LoadFromFile(g_Vehicles, "vehicles.txt");

    // Create all the loaded vehicles
    for (vehicle in g_Vehicles) {
        CreateVehicle(vehicle[Model], vehicle[X], vehicle[Y], vehicle[Z], vehicle[Angle], -1, -1, 800);
    }
}

public OnGameModeExit() {
    // Save the variable g_Vehicles into a file
    // It could have been modified in any way
    SaveToFile(g_Vehicles, "vehicles.txt");
}
Reply
#4

Make it, it will be very usefull.
Reply
#5

So this would be like, writing functions that natively don't exist but the compiler converts them in the background, right? LoadFromFile(g_Vehicles, "vehicles.txt"); would become multiple lines of code but the actual programmer won't see this as it is done by the precompiler.

That sounds absolutely amazing. I'm fairly good at JavaScript, unforunately we're covering Node.js and JSon this semester so I won't be able to help with the really advanced stuff, which I imagine will be all of this.

Make it, please
Reply
#6

Quote:
Originally Posted by Sinner
View Post
So this would be like, writing functions that natively don't exist but the compiler converts them in the background, right? LoadFromFile(g_Vehicles, "vehicles.txt"); would become multiple lines of code but the actual programmer won't see this as it is done by the precompiler.

That sounds absolutely amazing. I'm fairly good at JavaScript, unforunately we're covering Node.js and JSon this semester so I won't be able to help with the really advanced stuff, which I imagine will be all of this.

Make it, please
In the case of LoadFromFile, it would somehow be informed of the enum structure of "g_Vehicles", then save the data in a file also containing the key names (so the enum can be modified and data will still be loaded properly).
Saving enums automatically is actually currently doable, but only as raw data, which would be corrupted when the enum is modified (and it can't be manually modified unless you're a robot or a Y_Less).

Node.js is just like in the browser, but with different idioms and structuring (arguably). It's super-easy to get started with and lots of fun!
JSON is a JavaScript object stored as a string (essentially), so now you've learned all you need about JSON!
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
Who said anything about "or"?

This does sound very good, though I have one question: the output of -l isn't actually valid PAWN that can be recompiled as it contains #file and #line directives that aren't read properly, how are you going to get around that problem?

As for everything else, sounds awesome and you can count me in!
Awesome!

The #line directives are valid, actually.

As for the #file directives, I'll split up the code into files and make one main file that will #include them all. That'll also make static variables work as they should.
After the final compilation I'll simply modify the files table in the AMX debug information to the proper files and paths.

I'll create a repo on GitHub soon.
Reply
#8

I have been thinking about this a lot.
I think you should focus on project development (including flexible hooking, function rewriting, etc) rather than simple lazy tricks. Things like Object Orientation, Pointers, Memory Typing are good things, but I don't believe these embedded in Pawn would do any good for people trying to learn/trying to program for life.
(Yes, I did read your commend about Node.js)
Reply
#9

Maybe, but these are my main points of interest:

Quote:
Originally Posted by Slice
Посмотреть сообщение
  • Improved enums (fix issues, store info on keys). This would allow easily saving/loading data in enums without having to modify code every time the enum is changed.
  • Improved runtime introspection (allow people like Y_Less and I to make more cool stuff).
Those and the ability to manipulate functions so I can do things like make "inline" first-class etc.

Edit: Actually Slice, at this level the concept of static variables is good and bad. You want the variables to be able to be rewritten across file boundaries without errors (e.g. to merge hooks in to one function), yet still have errors detected from cross-file uses by the player - I'm not sure how to achieve that at this point!
Reply
#10

JS? Something much more familiar to me than pawn. Waiting for git repo
Reply
#11

Wait.. what?

As far as I understand a custom compiler...

Well, I hope this works out

Would be cool to do
pawn Code:
new& max_players = *(unsigned int*)(max_players_address_in_samp);
max_players = 32000;
Nah, just kidding haha, but OO would really be cool. and dynamic memory?
Reply
#12

To be honest, when I actually looked at the topic title, I imagined something like an auto compiler which automatically compiles as you type each line! (Which, I think is quite impossible?) But it's not. Sad. But I do see some ambitious projects, good luck for them!
Reference vars would also be awesome You could use it for the above use ! Haha
Reply
#13

Quote:
Originally Posted by Slice
Посмотреть сообщение
Ideas
  • OO!
  • Pointers!
I would love to see this in pawn.
Reply
#14

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
To be honest, when I actually looked at the topic title, I imagined something like an auto compiler which automatically compiles as you type each line! (Which, I think is quite impossible?) But it's not. Sad. But I do see some ambitious projects, good luck for them!
Reference vars would also be awesome You could use it for the above use ! Haha
PAWN already has references!
Reply
#15

Really? I didn't know that, because it gave an error when I used &g_var! Is there a different way for doing it, in PAWN? Since I did this (considering C++)!
Reply
#16

Where did you do that? And have you actually read the documentation?
Reply
#17

Why don't you build on the top of the Pawn compiler that is delivered with the server? https://github.com/jte/samp-compiler
Reply
#18

Quote:
Originally Posted by Dan..
Посмотреть сообщение
Why don't you build on the top of the Pawn compiler that is delivered with the server? https://github.com/jte/samp-compiler
That's a re-write of the compiler - not the one delivered with the server. The one delivered with the server has no source code. There were quite a few undocumented modifications to it, and the source code for those is lost.

I have yet to see a compiler except the one bundled with the server that successfully compiles YSI, among other libraries.
Reply
#19

That's pretty much because I know a lot of that exact compiler version's corner cases and exploit them extensively.
Reply
#20

Quote:
Originally Posted by Slice
Посмотреть сообщение
That's a re-write of the compiler - not the one delivered with the server. The one delivered with the server has no source code. There were quite a few undocumented modifications to it, and the source code for those is lost.

I have yet to see a compiler except the one bundled with the server that successfully compiles YSI, among other libraries.
Oh. I didn't know that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)