85 Commits

Author SHA1 Message Date
Zeex
7eba1d6bc6 Fix freeze when include file is a directory
This adds an extra check in plungequalifiedfile() that ensures that
the file being includes is not a directory. It seems to be the only
place where we need to check that, in other places files are opened
by exact name.

The bug appears to be specific to the Linux compiler. On Windows
fopen() will return NULL if trying to open a directory.

Fixes #41.
2015-03-31 01:17:54 +06:00
Zeex
d0f3a9a8df Allow use of backslash in #include in compatibility mode
This allows you to use \ as a directory separator on non-Windows
platforms. It was adopted from another patch by Slice:

534cd02895
2015-03-31 00:15:24 +06:00
Zeex
67a29b927e Revert "Fix freeze when include file is a directory"
This reverts commit cebb44800ee81f0a71dc594a3f542df892134c0a.
2015-02-22 23:08:32 +06:00
Zeex
cebb44800e Fix freeze when include file is a directory
Fixes #41.
2015-02-22 22:49:14 +06:00
Zeex
e2bbe8e9c2 Add #emit line numbers to debug info
If you consider the following code:

1 #include <a_samp>
2
3 main() {
4 	new x;
5 	#emit halt 1
6 	#emit halt 2
7 	#emit halt 3
8 	return 1;
9 }

This is what pawndisasm would output before:

00000008  proc
1.pwn:3
0000000c  break
1.pwn:4
00000010  break
00000014  stack fffffffc
0000001c  zero.pri
00000020  stor.s.pri fffffffc
00000028  halt 00000001
00000030  halt 00000002
00000038  halt 00000003
1.pwn:8
00000040  break
00000044  const.pri 00000001
0000004c  stack 00000004
00000054  retn

Now it outputs this:

00000008  proc
1.pwn:3
0000000c  break
1.pwn:4
00000010  break
00000014  stack fffffffc
0000001c  zero.pri
00000020  stor.s.pri fffffffc
1.pwn:5
00000028  halt 00000001
1.pwn:6
00000030  halt 00000002
1.pwn:7
00000038  halt 00000003
1.pwn:8
00000040  break
00000044  const.pri 00000001
0000004c  stack 00000004
00000054  retn
2014-09-01 19:05:04 +07:00
Zeex
6aa5ae3b00 Fix conditional compilation not skipping #emit directives
#emit directives inside #if ... #endif blocks were processed by the
compiler regardless of the condition.

--------- test code --------

main() {
	#if 0
		#emit halt 1
	#endif
}

----- end of test code -----
2014-08-31 12:18:37 +07:00
Zeex
7a8ae4b4d7 Fix compile error when have ':' in stringize string
--------- test code --------

static const stock s[]="string"#:x;

native print(const s[]);
native printf(const s[], ...);

main() {
	print(s);
	new x = 1;
	printf("%s", x ? "y" : "n");
}

----- end of test code -----

Fixes #33.
2014-08-09 22:36:34 +07:00
Zeex
e04192699c Fix #file directive not adding files to debug info 2014-08-05 00:03:59 +07:00
Zeex
e35f9c9a21 Fix find_symbol() returning wrong symbol
Stop find_symbol() from exiting too early when have multiple matching
symbols (static and non-static). Ignore non-static symbols (those with
fnumber == -1) unless found nothing else.

Fixes #20.
2014-04-27 00:07:57 +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
49642cb2cf Revert "Fix assert failure due to signed/unsigned char mismatch"
This reverts commit a1d0fe39d488f2376b76b6b2d0a81f29b1b61dcc.

It's a total mess! I can't understand their logic on choosing signed vs.
unsigned char. I guess I'd better off not touching this at all.
2014-04-06 14:05:48 +07:00
Zeex
a1d0fe39d4 Fix assert failure due to signed/unsigned char mismatch 2014-04-06 13:57:43 +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
ed8175dab5 Revert "Don't generate automatic include guards"
This reverts commit 05e34102d4949a7992f836db13085a85dea7c82c.

Conflicts:
	source/compiler/sc2.c
2014-03-29 17:41:24 +07:00
oscar-broman
fceb1d7a75 Fix SYSREQ id always being reserved
Fixes #11.
2014-01-31 19:23:20 +07:00
Zeex
2e215418fc Fix lots of compile warnings 2014-01-26 00:20:27 +07:00
Zeex
a9e1af66b1 Fix typo 2014-01-12 13:51:21 +07:00
Zeex
07802f741a Revert "Add .pwn to the list of #include file extensions"
This reverts commit bf847442e90b0e61e1a396647f3fc432f133fe74.
2014-01-10 12:55:51 +07:00
Zeex
1bd6be93e0 Add #warning directive
This fixes #7.

Example:

 #warning blah blah

Result:

warning.pwn(1) : warning 237: user warning: blah blah

Pawn compiler 3.2.3664.samp	 	 	Copyright (c) 1997-2006, ITB CompuPhase

1 Warning.
2014-01-10 02:10:53 +07:00
Zeex
05e34102d4 Don't generate automatic include guards
They are useful most of the time but also a pain in the ass if you have
multiple files with the same name but in different directories (e.g. YSI).

Even worse, they didn't work with non-native directory separators in
#include directives, but that actually turned out to be useful and helped
defeat the first bug!

See issue #6.
2014-01-07 02:03:42 +07:00
Zeex
8324d8aba6 Revert "Add '/' as a portable path separator for #include"
This reverts commit b9050b452a7ec7ca27be8bc55e00594e279e3fa4.
2014-01-07 00:10:47 +07:00
Zeex
b9050b452a Add '/' as a portable path separator for #include
This fixes a bug where if you use '/' in an #include directive on Windows
the _inc_XXX symbol will contain not only the file name but also its path
as the compiler didn't count '/' as a path separator.
2014-01-07 00:04:59 +07:00
Zeex
bf847442e9 Add .pwn to the list of #include file extensions 2014-01-06 22:06:22 +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
1989a6dd37 Allow multiple warnings in #pragma warning enable/disable
Make it possible to specify multiple warning numbers in #pragma warning
enable/disable. The values must be separated with commas (possibly with
whitespace in between).
2014-01-05 16:35:47 +07:00
Zeex
634f40953b Introduce #pragma warning
This pragma lets you to enable or disable a specific warning by its
unique number (same as in error messages).

Syntax: #pragma warning (push|pop|enable XXX|disable XXX)

#pragma warning push - save current warnings
#pragma warning pop - restore warnings
#pragma warning enable XXX - enable warning XXX
#pragma warning disable XXX - disable warning XXX
2014-01-05 02:58:42 +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
eba8474294 Fix generation of function addresses in #emit code
This fixes a bug where the compiler generated incorrect addresses for
functions in #emit code if they were defined after the point of use.

For example, you couldn't reliably get the address of a function with
"#emit CONST.pri XXX" unless you make sure that XXX is defined before
the function in which you have you are referencing it.

Now the resolution of the function's address is deferred until assembling
phase (as with CALL), and the assembler is guaranteed to see all symbols
with their final addresses. To distinguish between functions and numeric
operands I added a '.' (period) in front of function names for both #emit
and normal calls.

See also 5) here: http://forum.sa-mp.com/showthread.php?t=355877

--------- test code --------

#include <a_samp> // DO NOT REMOVE THIS

main() {
	#emit const.pri foo
}

stock foo() {
	printf("Hello, World!");
}

----- end of test code -----
2014-01-03 09:14:06 +07:00
Zeex
0fa621f5e8 Generalize the native index fix to all instructions
It is possible to use natives in any instructions and their name should
evaluate to a native table index. But the patch in the previous commit
(bb4163ea456fab54385f7310b4e20949cda0aaa6) affected only SYSREQ.C
instructions, thus using natives with other instructions (for example,
with CONST.pri) would still result in an incorrect index.
2014-01-03 04:37:32 +07:00
Zeex
bb4163ea45 Fix #emit SYSREQ.C generating wrong native index for unused natives
This commit fixes a bug where the compiler generated incorrect native
index in assembly code for natives invoked via #emit sysreq.c and not
called elsewhere with the normal syntax.

See 4) here: http://forum.sa-mp.com/showthread.php?t=355877

--------- test code --------

native print(const s[]);
native printf(const format[], ...);

main() {
	new string[] = "hi there!";
	printf(string);
	#emit push.adr string
	#emit push.c 4
	#emit sysreq.c print
	#emit sysreq.c printf
	#emit stack 8
}

----- end of test code -----
2014-01-02 17:36:28 +07:00
Zeex
8d238c4830 Fix compile crash when using CALL in #emit
This fixes a crash when calling a function with the CALL instruction in #emit.

Instead of merely writing a symbol's address to the .asm file we check
if we are in a CALL instruction, and if so we output the function's name
rather than its address.

See 7) here: http://forum.sa-mp.com/showthread.php?t=355877

--------- test code --------

foo() {}

main() {
	#emit call foo
}

----- end of test code -----
2014-01-02 17:13:14 +07:00
Zeex
0c8f23453e Fix compile error with string literals in ternary operator
The ':' symbol was not recognized as a separator in stringize mode
so you always got a weird compile error with a code like this:

(condition) ? "yes : "no"

error 001: expected token: "-string end-", but found "-identifier-"

See 2) here: http://forum.sa-mp.com/showthread.php?t=355877

Test code:

native print(const s[]);

main() {
	new a = 5;
	print((a == 5) ? "is five" : !"is not five");
	print((a != 5) ? !"is not five" : "is five");
}
2014-01-01 03:49:30 +07:00
Zeex
4831cb76a3 Different fix for arrays of unpacked strings
Do it the same way as it's done for packed strings, for consistency.
2013-12-31 01:38:45 +07:00
Zeex
d9999d4da8 Fix compile error with arrays of packed strings
This fixes the "possibly non-terminated string" error when declaring an
array of packed strings (unpacked strings worked OK).

Test code:

new x[][] = {
	!"hello",
	!"world"
};

main() {
	printf("%s", x[0]);
}
2013-12-27 02:41:37 +07:00
Zeex
766b96bcf3 Lower case directory names 2013-09-19 13:06:46 +07:00