97 Commits

Author SHA1 Message Date
Zeex
d8f824357f Don't remove unused public variables
But still warn about them unless they are marked as stock.

Fixes #71
2015-06-20 16:58:11 +06:00
Zeex
88f78aa882 Don't declare public constants as constants
Public constants must be declared as variables, like it was done
before the previous commit, because they must be visible by the
amx_XXXPubVar API.
2015-06-20 10:01:37 +06:00
Zeex
39828f23f2 Fix error when static/stock/public constant used as array size
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 -----
2015-06-19 21:49:40 +06:00
Zeex
1cca8af0d2 Fix indirection vector calculation
It was broken in commit d14f4870a8069ca446c0528a39b75e7d081ba3d5.

Fixes #63
2015-05-09 13:00:16 +06:00
Zeex
56262f42cd Fix compile warning 2015-05-03 01:34:00 +06:00
Zeex
d14f4870a8 Fix 4d array initialization
adjust_indirectiontables() generated wrong values for certain array
dimensions in 4d arrays.

Fixes #43
2015-05-01 16:16:59 +06:00
Zeex
10a021b51e Tiny consistency fix 2015-05-01 09:40:40 +06:00
Zeex
3594c6170d Fix previous fix 2015-04-26 02:06:06 +06:00
Zeex
85f849ba08 Fix symbol nesting level not remembered for 2d+ arrays
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
2015-04-25 15:49:10 +06:00
Zeex
9191803370 Set version to 3.10
Now it's consistent with the __Pawn constant (0x030A == 3.10).
2015-04-12 21:25:10 +06:00
Zeex
669aef06ef Remove remaining string expansion business from optimizer
This makes optimization work again.

Fixed #56
2015-04-11 22:48:52 +06:00
Zeex
9036614bcb Fix broken 2d ellipsis after another array fix
Some tests would really help I guess...

See commit 7314b56.
2015-04-07 22:15:53 +06:00
Zeex
6b3c30aa9e Add new built-in constant __compat
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`.
2015-04-06 18:08:27 +06:00
Zeex
898e02b771 Fix MSVC compile warnings 2015-04-06 17:36:10 +06:00
Zeex
e5de4b15ef Remove unnecessary assignment 2015-04-06 17:11:35 +06:00
Zeex
2e162eae9c Fix string array initialization
It's been broken since commit e1082f64bc4171884316621f6f62a49c45d97e81

Fixes #53 (one more time)
2015-04-06 15:26:02 +06:00
Zeex
7314b56579 Fix error on multi-dimensional array initialization
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
2015-04-06 12:35:08 +06:00
Zeex
568c277b03 Fix unused fread() return value warnings 2015-04-05 01:39:44 +06:00
Zeex
12afdf16c2 Refactor temporary source file creation
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.
2015-04-04 18:14:26 +06:00
Oscar Broman
8afb73c00c make it compile on OS X 2015-04-04 17:54:00 +06:00
Zeex
932efdfad9 Fix 2d ellips initializer not increasing on next element
Closes #48.
2015-04-04 14:36:11 +06:00
Zeex
128c56df3f Revert "Reset pc_compat before second pass"
This reverts commit 3c22187fb494592a51162c3863b3521cf1d74cc3.

That commit broke the -Z compile flag. The idea was to allow having
different compat modes for regions of code.
2015-04-03 23:55:20 +06:00
Zeex
35190f55fb Incremental ... initialization of 2d arrays
This is fully supported now:

    new arr[3][3] = {{0, 1, ...}, {0, 2, ...}, ...};

will produce:

    {{0, 1, 2}, {0, 2, 4}, {0, 3, 6}}

and this:

    new arr[3][3] = {{0, 1, ...}, ...};

will yield:

    {{0, 1, 2}, {0, 1, 2}, {0, 1, 2}}

Refs #48
2015-04-03 23:19:12 +06:00
Zeex
e1082f64bc Add partial support for ... inintialization of 2d arrays
Refs #48
2015-04-03 12:06:12 +06:00
Zeex
eeefc4ba3b Fix compile warnings 2015-04-02 15:58:00 +06:00
Zeex
3c22187fb4 Reset pc_compat before second pass 2015-04-02 12:51:02 +06:00
Zeex
b74b481c80 Don't change __Pawn in compat mode
__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
2015-04-02 12:33:10 +06:00
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