Fixes#70
--------- test code --------
native printf(const format[], ...);
static const a = 1;
static stock const b = 2;
stock const c = 3;
public const d = 4;
main() {
static const e = 5;
new aa[a];
new ab[b];
new ac[c];
new ad[d];
new ae[e];
printf("%d", sizeof(aa), aa);
printf("%d", sizeof(ab), ab);
printf("%d", sizeof(ac), ac);
printf("%d", sizeof(ad), ad);
printf("%d", sizeof(ae), ae);
}
----- end of test code -----
This fixes a bug where defining a 2d+ array variable in different
blocks at the same nesting level would trigger a symbol redefinition
error. For example:
main() {
new x;
if (x) {
new a[10][11];
} else {
new a[10][12]; // error 021: symbol already defined: "a"
}
}
It turned out that the compiler defines a separate symbol for each
of the array dimensions but it only was setting sym->compound for the
first of them, causing delete_symbols() to not delete the remaining
dimension symbols. Now it sets the compound field for all dimensions.
Fixes#60
The __compat constant is set to 0 when compatibility mode is disabled
and 1 (or some non-zero value) if enabled, either by using -Z or with
`#pragma compat`.
The 2d ellipsis patch broke normal array initialization:
// error 052: multi-dimensional arrays must be fully initialized
new foo[3][2][] = {
{"Bar","Bar"},
{"Boo","Boo"},
{"Bee","Bee"}
};
// This one caused an assert error:
new foo[3][2][4] = {
{"Bar","Bar"},
{"Boo","Boo"},
{"Bee","Bee"}
};
Fixes#53
This adds a new function pc_createtmpsrc() that creates a temporary
source file for writing. Also, mkstemp() is now used not only on Mac
OS X but on Linux (and other Unixes) as well.
This reverts commit 3c22187fb494592a51162c3863b3521cf1d74cc3.
That commit broke the -Z compile flag. The idea was to allow having
different compat modes for regions of code.
__Pawn is now fixed at 0x030A, i.e. the new value that was used in
non-compat mode.
I've come to realize that setting it to the old value doesn't really
make much sense - we still allow the use of the new features but at
the same time pretend to be the old compiler which of course doesn't
have those features.
Maybe we should add another built-in constant for that, perhaps call
it __compat or something similar and define it only when running in
compat mode. The users could then check if the compiler is in compat
mode like this:
#if defined __compat
...
#endif
When built with PAWN_CELL_SIZE==32 cellmin anx cellmax were set
to LONG_MIN anx LONG_MAX respectively, but long is 64 bits wide
on 64-bit Linux systems (as opposed to Win64).
Fixes#17.
This fixes the same coding mistake as in the previous commit (4d2c600):
"sym->name!=NULL" should be "sym!=NULL" as sym->name can't be NULL.
--------- test code --------
main() {
if ("string") {}
}
----- end of test code -----
This patch fixes a bug in commit d23e03e "Allow trailing comma in array
initializers" where initarray() did an extra loop iteration hoping that
initvector() would fail nicely and ultimately inserted an extra cell
into the literal queue.
--------- test code --------
native printf(const format[], ...);
new const a[][] = {
{"hello"},
{"world"}
};
main() {
printf("%s", a[0]); // hello
printf("%d", sizeof(a)); // 2
printf("%d", sizeof(a[])); // 6
printf("%d", sizeof(a[][])); // 1
}
----- end of test code -----
The compiler now has a new command-line option (-Z) that toggles
between normal mode and "compatibility" mode.
When this mode is on the compiler attempts to be compatible with
the current SA-MP compiler, which allows compiling old SA-MP scripts
that would not compile otherwise and at the same time benefiting
from new features and bug fixes.
In particular, this allows compiling code that relies on the auto
generated #include guard symbols (_inc_filename).
And in case you're wondering, the Z in "-Z" does not stand for "Zeex",
it just means "a letter that is unlikely to be ever taken by another
option".
This closes#23.
It is allowed for symbol names to be up to sNAMEMAX characters but
the assert() restricted them to sNAMEMAX-1 characters, so it would
fail for any long enough name.
Ran across this investigating #21.
This patch introduces a new built-in constant called "__line" that is set
to the current line number during compile time. I've taken the code from
Pawn 4.0 though I'm pretty sure it was implemented prior to 4.0 as I've
seen __line mentioned in the language documentation for 3.x.
When applied to a function #pragma naked merely disables the "should return
a value" warning for the function. It's intended to be used with functions
that return a value via #emit instead of the normal return statement.
This pragma works only on function definitions, not declarations. It's also
pretty stupid - the function may be defined way after this directive and it
won't stop on things coming in between.
For example, here all declarations between #pragma naked and f() are
effectively ignored:
#pragma naked
new x; // ignored
forward g(); // ignored
native n(); // ignored
f() {
// f() becomes naked
}
Note that #pragma naked does not affect generated code in any way, unlike
e.g. __declspec(naked) or __attribute__((naked)) in C/C++ where the compiler
omits the code for the prolog and epilog.
Make the assembler fail with a fatal error 104 "invalid assembler instruction"
if met an unknown instruction. It won't tell a correct line number though.
This hopefully fixes a bug where code for a custom assignment operator
wasn't being generated because the compiler thought that it's not used
but it still generated a call (which resulting in infinite recursion).
It happened only if some function returned a tagged result and wasn't
forwarded before its first use. Interestingly the compiler didn't issue
a reparse when it encountered the forward declaration and no warning
was printed. Perhaps the authors forgot to do this when they were adding
the forward syntax (it certainly was added after what is now called
"old-style prototypes").
See 8) here: http://forum.sa-mp.com/showthread.php?t=355877
--------- test code --------
#include <a_samp>
_:operator=(Taggg:a)
{
return _:a + 5;
}
main()
{
new a = d();
printf("%d", a);
}
forward Taggg:d();
Taggg:d()
{
return Taggg:5;
}
----- end of test code -----
This fixes a bug where returning a string from a variadic function caused
an invalid memory access error during runtime. It seems like they forgot
to update existing string return code for variadic functions.
See 11) here: http://forum.sa-mp.com/showthread.php?t=355877
--------- test code --------
native print(const s[]);
stock f(...)
{
new a, b, c;
new str[] = "hello";
return str;
}
main() {
print(f(1, 2, 3));
}
----- end of test code -----
This fixes a crash during compile-time when returning a string or array
literal from a function. Now the compiler will give an error instead.
See 1) here: http://forum.sa-mp.com/showthread.php?t=355877
--------- test code --------
native use(...);
return_string() {
new string[] = "string";
return string;
}
return_string_literal() {
return "string"; // error 029: invalid expression, assumed zero
}
return_number() {
return 0;
}
main() {
new n = return_number(); // OK
new s[100];
s = return_string(); // OK
s = return_string_literal(); // error 033: array must be indexed (variable "s")
use(n, s);
}
----- end of test code -----