292 Commits

Author SHA1 Message Date
Zeex
77bde2ea54 More optimal array growth factor
http://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array
2014-01-25 20:07:09 +07:00
Zeex
200abb1d75 Fix grow_stgbuffer() not updating buffer size
The grow_stgbuffer() function, which grows the staging buffer, was
not updating the buffer size after reallocating the buffer itself.
This caused lots of reallocations because stgwrite() calls this
function for every character (!).

This also decreases compile times by ~20% (from 10s down to 8s in
my setup).
2014-01-25 20:06:58 +07:00
Zeex
fba30db927 Optimize stringlist functions
The get_string() function becomes a major bottleneck (around 80% of
the time) when debug info is on because it uses a linked list for
storage and it's mostly called in for loops iterating over the whole
list by index. That's a quadratic complexity.

This patch rewrites all stringlist functions to use an array instead
of a linked list. It decreased my test script's compile time from 84s
to 10s, or by 730%(!). The script is just 100,000 lines of print()
statements. If debug info is turned off the times are the same for both
implementations.
2014-01-25 14:40:32 +07:00
Zeex
e8bfcefdb1 Normalize line endings 2014-01-13 01:51:20 +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
a9e1af66b1 Fix typo 2014-01-12 13:51:21 +07:00
Zeex
5ecee7c582 Normalize line endings 2014-01-12 13:50:41 +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
fb96f7e44e Regenerate .scp files 2014-01-10 01:58:25 +07:00
Zeex
3e85c5bf3e Add .gitignore 2014-01-10 01:49:29 +07:00
Zeex
8fefb73592 Add .gitattributes 2014-01-10 01:47:26 +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
6943995219 Fix missing newline in error message 2014-01-04 16:01:31 +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
6b0809a99e Append ".samp" to the version string 2014-01-04 14:35:07 +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
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
23a4b5a18a Don't strip symbols in debug build 2014-01-01 19:23:14 +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
c20d9cb33b Fix compile crash when calling a function at global scope
This fixes a crash that occurs if a global variable is initialized
with the result of a function call.

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

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

native use(...);

f() {
	return 0;
}

new x = f();

main() {
	use(x);
}

----- end of test code -----
2014-01-01 16:49:55 +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
c316b6d3be Fix CMake warnings 2013-12-27 18:52:21 +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
99df013361 Add pawn-lang.pdf 2013-10-07 23:09:17 +07:00
Zeex
be9842f5a2 Add pawn-imp.pdf 2013-10-07 22:47:41 +07:00
Zeex
79f2031cab Revert breaking changes
It looks like I accidentally applied not_samp_compatible patches before
uploading the code.
2013-09-22 22:06:20 +07:00
Zeex
766b96bcf3 Lower case directory names 2013-09-19 13:06:46 +07:00
Zeex
00f21e67d5 Pawn 3.2.3664 code with samp_compatible patches applied 2013-05-09 01:32:43 +07:00