[Tutorial] Choosing a compiler
#1

Choosing a compiler

Introduction


We'll start with basics. First of all, you need to know distinction between PAWNO, PAWN and pawncc.

What is PAWNO?
PAWNO is a text editor. Basically, Windows notepad, but with color highlighting of keywords, panel listing all native functions and convinient execution of the compiler from within the PAWNO. If you want more power, you can use more sophisticated text editor - Notepad++, VS Code, Atom, Sublime Text, and any editor for which community created PAWN syntax definitions. Some users even created full-fledged IDE's specifically for PAWN. I personally prefer Sublime Text, but have heard good things about each and every other editor I've listed.

What is PAWN?
It's a scripting language which compiles to machine readable bytecode (put in .amx file) which is then executed by your server. So, anything you will write for SAMP in your editor, be it PAWNO or any other editor - is in PAWN.

What is pawncc?
This is the proper compiler - this is where all the action happens. It takes a file (or stdin) written in PAWN, and churns out .amx file. It's important to know that this is one-way process - you can't get original file written in PAWN from .amx file.

You have to understand what compiler does exactly:

All lines starting with "#" are called preprocessor directives. The compiler scans the whole file looking for them (twice to be exact, that's why ALS hooks work at all). I won't go into detail about them, but just know that in this phase, the code goes through following transformation:

pawn Code:
// Before
#define HELLO_WORLD "I like PAWN"

print(HELLO_WORLD);
printf(HELLO_WORLD);

//After
print("I like PAWN");
print("I like PAWN");
<Side note>
That's why sometimes it's better to define your strings as "static const". Why?
In global scope, "static" keyword restricts the string to the file it's defined in, and "const" will trigger errors when you try to modify it somewhere by accident.
In function scope, "static" puts the string on the heap, so its value does not change between function calls.
So, the macro will allocate a new string each time it is used, while your const string will be allocated only once. Take a look at this:
pawn Code:
#include <a_samp>

static const str[] = "Hello world";

main() {
  print(str);
  print(str);
}
P-Code (compiled with -a flag)

pawn Code:
CODE 0  ; 0
;program exit point
  halt 0

DATA 0  ; 0
dump 48 65 6c 6c 6f 20 77 6f 72 6c 64 0

CODE 0  ; 8
  proc  ; main
  ; line 5
  break ; c
  ; line 6
  break ; 10
  const.pri 0
  push.pri
  ;$par
  push.c 4
  sysreq.c 0  ; print
  stack 8
  ;$exp
  ; line 7
  break ; 38
  const.pri 0
  push.pri
  ;$par
  push.c 4
  sysreq.c 0  ; print
  stack 8
  ;$exp
  zero.pri
  retn

STKSIZE 1000
</Side note>

You can see what preprocessor does, by compiling with "-l" flag. It will generate .lst file, which is code after preprocesing.

Next, the preprocessed file is compiled to P-code bytecode - code readable by our amx virtual machine. You can see one step before that, compling with -a flag - it will generate .asm file (this is _not_ assembly). You can write P-Code directly using preprocessor directive #emit - using it is black magic, only reserved for people like Y_Less, Zeex and Slice. Can you believe that Y_Less created inline functions just by using #emit? (which create function at run-time, as I said, black magic).

The good stuff


There are 3 compilers. We'll start with

Standard compiler

When you download samp-server from official site, it comes with PAWNO editor, and pawncc modified by Kalcor. It is the easiest choice, as you don't have to do anything, just fire up PAWNO, write some stuff, hit F5 and you get nice AMX. However, it has some bugs, listed here. When I was a beginner PAWN scripter, I was bit by them often (especially sizeof second dimension, as well as ternary with strings) and didn't know what to do.

Pros
  • No barrier to entry
  • Supported by official SAMP team
Cons
  • Has multiple bugs
  • Too mainstream
Download link
Source not available

SA-MP team doesn't really respond to users requests for bugfixes (except for the critical ones, thank God), so there is this guy Zeex who (I guess) got fed up by it, and created...

Zeex's compiler

It fixes most of the issues with standard compiler, however: It is not a drop-in replacement for standard compiler, except in compatibility mode. If you want just the bugfixes, you need to specify compability mode (-Z+ flag).

For me, the most important bug fix was changing behaviour of the sizeof operator for second dimension. For example, here's code from standard compiler:
pawn Code:
#include <a_samp>

enum E_TEST {
  E_TEST_WTF,
  E_TEST_STR[32]
}

new Test[MAX_PLAYERS][E_TEST];

main() {
  new abc[] = "Hello";
  strcat(Test[0][E_TEST_STR], abc);
}
This would fail, as third (default) argument of strcat is length of destination (first argument) - and in standard compiler it will return 1 instead of 32. You'd have to specify length:
pawn Code:
strcat(Test[0][E_TEST_STR], abc, 32);
In Zeex's compiler it works right away.

Now, what does it change? For one, in non-compat mode it removes the auto include guards. When you include a file in standard compiler, it creates something called include guard. It means that if file is included twice, the second include is not included. When using Zeex's compiler, this is no longer the case. And this can, and will bite you in the ass - all your dependencies have to create their own include guards, so for non-maintained includes you have to manually add them, or really watch out what includes what.

Another brilliant addition is nested ellipsis. Now you can do something standard compiler failed at:
pawn Code:
new Hello[][10] = { { 1, 2, ...}, ... };
For example, y_iterate uses this for multiterators, so you don't have to put Iter_Init in main() anymore.

Pros Cons
  • Zeex is busy doing other stuff
  • Not friendly to beginners
Download 1
Download 2 for windows, in case source is ahead of releases
Source (github)

Zeex started doing his own thing, and some guy tried to get his attention via github and email, but failed, got fed up because of it, and created...

Some russian's guy compiler

A new compiler. I heard about it few days ago, and gave it a try. It cut down from my compile time of 180 seconds (yes, that's what using YSI and a few years of work does to your compilation) to 15 seconds. For 30 second compilation it took 3 seconds. That's simply amazing. Quoting author:

Quote:

this version based on c++14, I don't think Zeex will merge speed changed

(...)

it's compile as cpp not c
unordered_map, unordered_set & std:tring

@zeex didn't answer about optimise on email & for thread

So, it's Zeex's compiler on steroids! I don't have much to say about it, except extreme compilation speed boost. I would not recommend it for production code - it hides some warnings, some libraries depend on. Some more discussion here. So, while prototyping your code feel free to use it, but when deploying for production/setting up continuous integration for your project, make at least official Zeex's compiler does not throw any errors.
Oh, and there's a possibility there's a virus either embedded in the compiler's own .exe, or injected into .amx. Virustotal does not report anything in the binary (but it is trivial to create fully undetectable malware as far as I know). .amx's report differences, and you should be wary that it's quite easy to exploit virtual amx machine used by samp-server (see Zeex's amx_assembly - ShellExecute is arbitrary code execution). Given all that warnings:

Download link (warning, I don't know who controls it, and it might change at any time, so watch out)
Mirror (same warnings as above)
Source not available

Pros
  • All of Zeex's compiler pros
  • Extreme (>10x) times compilation speed improvement
Cons
  • Some hidden warnings, which may cause some libraries to fail
  • May contain harmful code
  • One contributor
  • No source available
How to install the compiler?

The standard one is bundled with PAWNO, nothing needs to be done. For Zeex's compiler follow download links I provided, then dump those files in yourserver/pawno folder. Same thing for russian compiler

Summary


Are you a beginner? Use default pawncc bundled with server
You were bitten by any of the bugs in standard compiler but are cautious? Zeex's compiler with compatibility mode
You know what you are doing? Russian compiler for development, Zeex's compiler for CI and production-ready code

Have fun, and be safe!

UPDATE: I asked the creator of the russian compiler about opensourcing it, and he responded with
Quote:

Zeex enabled autism mode and ignore me at all
https://github.com/Zeex/pawn/issues/120
I don't disagree, but I know how easy it is to become too busy to do side-projects such as samp.
Reply
#2

Pardon me if I don't trust "random Russian guy". That compiler is not open source so god knows what might be contained inside it. His severe lack of English doesn't help either, the more so if you think about the fact that the compiler source is in English and all documentation (Implementer's Guide and all) is also in English. And then there's this. It doesn't give the warning anymore but still, use at your own risk.
Reply
#3

About the part of viruses: As far as I know, Antiviruses have a "database" of "virus signatures" (idk if this is the correct term) , VirusTotal uses a little api of multiple Antiviruses, so it is not that good like a complete Antivirus. Also I think that the little api detect functions from C / C++ headers that are for a specified OS (That makes viruses to be on multiple OSs).
Reply
#4

'Some Russian guys compiler'.
Rofl
Reply
#5

"Some russian's guy compiler", I don't know why people can't wait 30~120 seconds to compile, putting their own code in risk using the closed-source russian magic (not talking about viruses, talking about the libraries not working as they should).
Anyways it's a good tutorial!
Reply
#6

Quote:
Originally Posted by renatog
View Post
"Some russian's guy compiler", I don't know why people can't wait 30~120 seconds to compile, putting their own code in risk using the closed-source russian magic (not talking about viruses, talking about the libraries not working as they should).
Anyways it's a good tutorial!
I'm just going to leave this here:



Plus, why wait 30 seconds when you can wait 3?
Reply
#7

Not this topic again, I feel bad for Misiur as he will receive a shitstorm of useless comments debating which side is better to only conclude that everyone has their own opinion about this and no one is right or wrong.

If you don't want to use some "Russian compiler", here are a few steps to follow:
1) Mind your own business.
2) Use the default one or Zeex's!

If you want to use some "Russian compiler", here are a few steps to follow:
1) Mind your own business.
2) Use the "Russian compiler".


On topic:
Quote:
Cons
  • Zeex is busy doing other stuff
  • Not friendly to beginners
Who, Zeex or his compiler? xD

Nice comparence, good reading!
Reply
#8

Quote:
Originally Posted by Hansrutger
View Post
Not this topic again, I feel bad for Misiur as he will receive a shitstorm of useless comments debating which side is better to only conclude that everyone has their own opinion about this and no one is right or wrong.
You'll see that in a couple of days I guess, lol.
Reply
#9

Quote:
Originally Posted by Hansrutger
View Post
Not this topic again, I feel bad for Misiur as he will receive a shitstorm of useless comments debating which side is better to only conclude that everyone has their own opinion about this and no one is right or wrong.

If you don't want to use some "Russian compiler", here are a few steps to follow:
1) Mind your own business.
2) Use the default one or Zeex's!

If you want to use some "Russian compiler", here are a few steps to follow:
1) Mind your own business.
2) Use the "Russian compiler".


On topic:


Who, Zeex or his compiler? xD

Nice comparence, good reading!
The only person wrong here is you. What's bad about compiling scripts in less time with the 'same result'? Nothing, it's 1m times better!

For those who are going to say otherwise, gather your evidence about it doing bad things and reply. Keep your assumptions to yourselves otherwise.
Reply
#10

Well,

My opinion about 'Russian compiler' is following: It's faster and ignores couples of warnings but strange thing that I've noticed are errors. Using default compiler I get around 5 errors with Russian I do not get anything. The script works perfectly. Although I can say in general, I had a couple of 'line too long' errors so yeah.

It cuts compile time to half or less. It's really simple if you think it's bad to leave it if you think its good use it. End of the story. This can raise into an unlimited battle, Russian Compiler vs Default. Like MySQL vs Y_INI, Android vs iOS, God does exist vs God doesn't exist.
Reply
#11

Quote:
Originally Posted by Fratello
View Post
Well,

My opinion about 'Russian compiler' is following: It's faster and ignores couples of warnings but strange thing that I've noticed are errors. Using default compiler I get around 5 errors with Russian I do not get anything. The script works perfectly. Although I can say in general, I had a couple of 'line too long' errors so yeah.

It cuts compile time to half or less. It's really simple if you think it's bad to leave it if you think its good use it. End of the story. This can raise into an unlimited battle, Russian Compiler vs Default. Like MySQL vs Y_INI, Android vs iOS, God does exist vs God doesn't exist.
The Russian compiler is a modified version of Zeex's, you should not be getting line is too long errors. I have long lines in my GM which doesn't compile with stock compiler but with Zeek's and Russian's it does.

With the Russian compiler you should use #pragma to disable recursion and forward public functions before using them in the script. No other error/issue should arise afaik (tried it on a 50k+ script).
Reply
#12

Quote:
Originally Posted by Paulice
View Post
I'm just going to leave this here:


Plus, why wait 30 seconds when you can wait 3?
Can you not just post a link to the actual post instead of a screenshot? The argument about it not being open source is completely valid and the counterargument is bullshit. You choose to use a closed source because you trust its creator. And here is the thing: I don't trust the creator. But that doesn't automatically mean that every closed source application is bad.

Also the fact that it hides warnings and errors is really worrying. Can't wait for threads about random server crashes due to botched P-code. The errors and warnings are there to tell you that you fucked something up. They're there to help you, not to annoy you.
Reply
#13

If the Russian compiler has a malicious source, how will they do with someone who schedules a self-compilation (to troll) every 15 seconds when the GM has more than 100k + lines, adding the possibility that more people do the same troll xD ...

I was testing the compiler and it does not send signals of internet use when compiling.
Reply
#14

I really don't care much about my mode as it was an open source when I started back in 2016 (even though I've changed it totally with 99% more features) but there are people like Dignity who have developed their modes from scratch and still use this. They've been using it for years and haven't faced anything and nor did i (so far).

So yea I don't mind continuing using it.
Reply
#15

Quote:
Originally Posted by Vince
View Post
Can you not just post a link to the actual post instead of a screenshot? The argument about it not being open source is completely valid and the counterargument is bullshit. You choose to use a closed source because you trust its creator. And here is the thing: I don't trust the creator. But that doesn't automatically mean that every closed source application is bad.

Also the fact that it hides warnings and errors is really worrying. Can't wait for threads about random server crashes due to botched P-code. The errors and warnings are there to tell you that you fucked something up. They're there to help you, not to annoy you.
No-one would look at it if it was a link.

-----

I couldn't care less, it saves me time and it hasn't done anything bad so far. This is also SA-MP, so I couldn't care less more than I don't care already. Scripts can be recreated with ease (I could recreate the gm of a server and release/use it if I wanted to - so I see no point in not using it). It helps, and a gm isn't safe from being copied whatsoever.

Post real evidence if you can, for those who actually care about their code being leaked or errors appearing.
Reply
#16

Ah, for some reason the Zeex's version returns me the error of 'sscanf already being defined (pawn version possibly)'. Any way to fix it?
Reply
#17

Quote:
Originally Posted by Unrea1
View Post
I was testing the compiler and it does not send signals of internet use when compiling.
It doesn't send any packet or creating socket, alright, but for NOW!
Even that backdoor thing, it may doesn't add a backdoor in your script for now but what if he is waiting for us to trust him? I suggest that moderators here should stop it from spreading this anonymous program.
Your AntiVirus or firewall or WhateverWall may stop sending packets but what about backdoors?
Reply
#18

russian guy's one may crash ur server, it happened to my script.
Reply
#19

Russian compiler crashes while compiling, any idea why and how to fix it? My gamemode takes 250 seconds to compile now ...
Reply
#20

Haven't met with such an issue. Does the Zeex's compile normally the same code?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)