20 Commits

Author SHA1 Message Date
Zeex
5cf3b0977b Add missing quotes around #file names in preprocessor output 2014-08-05 00:03:13 +07:00
Zeex
1af47f05c3 Remove stupid assert
It triggers if you use an undefined symbol as array dimension size.
The error is actually reported during the second pass.
2014-08-03 15:39:50 +07:00
Zeex
014528254b Fix value of cellmin/cellmax in x64 Linux build
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.
2014-04-26 04:17:11 +07:00
Zeex
cb0bd85053 Fuck trailing comma 2014-04-23 02:05:20 +07:00
Zeex
dbe21979e4 Fix another error 33 crash
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 -----
2014-04-21 17:06:42 +07:00
Zeex
7f30a03f94 Ignore #pragma tabsize with non-positive arguments
#pragma tabsize X will now have no effect for X <= 0. Same goes for
the -t option (will display usage instead).

Closes #24.
2014-04-09 19:46:42 +07:00
Zeex
9744fca241 Fix trailing comma breaking array init vectors
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 -----
2014-04-04 20:50:51 +07:00
Zeex
350dfdf7ea Add some missing bits from upstream trailing comma patch
https://code.google.com/p/pawnscript/source/detail?r=33

There's still a problem with trailing commas in array initialization:

http://forum.sa-mp.com/showpost.php?p=2975468&postcount=55
2014-04-04 18:37:02 +07:00
Zeex
7ee5e98e30 Introduce compatibility mode
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.
2014-03-29 21:31:53 +07:00
Zeex
a272a7e43e Fix faulty assert
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.
2014-03-16 13:06:18 +07:00
Zeex
d23e03e7ba Allow trailing comma in array initializers
This was adapted form upstream Pawn r4032/r33:

https://code.google.com/p/pawnscript/source/detail?r=33

Fixes #14.
2014-02-01 16:12:32 +07:00
Zeex
5b0dec0b3d Fix read of uninitialized variable
This fixes a copy & paste mistake in commit
53221dd2ccf29fc5e357ffb67363ca7461d24193.
2014-01-12 19:34:02 +07:00
Zeex
605ae7f4d3 Backport __line from Pawn 4.0
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.
2014-01-05 20:18:45 +07:00
Zeex
53221dd2cc Introduce #pragma naked
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.
2014-01-05 01:26:10 +07:00
Zeex
80eceb586d Fix compile crash on unknown assembly instruction
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.
2014-01-04 16:00:52 +07:00
Zeex
c923c9a026 Change value of__Pawn to 0x030A
This fixes #5.
2014-01-04 04:37:58 +07:00
Zeex
6592db03fd Force a reparse when encountering a late forward
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 -----
2014-01-03 21:57:54 +07:00
Zeex
1d1244c2f0 Fix runtime error in variadic functions that return strings
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 -----
2014-01-03 16:14:09 +07:00
Zeex
6133e9d183 Fix compile crash when returning a string literal
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 -----
2014-01-01 16:49:55 +07:00
Zeex
766b96bcf3 Lower case directory names 2013-09-19 13:06:46 +07:00