Commit graph

103 commits

Author SHA1 Message Date
Sei Lisa
30a07db4fb Mark a couple bugs found to not lose track, and add a regression test. 2016-06-28 03:47:48 +02:00
Sei Lisa
0c3ad9b938 Change skippreproc -> processpre, add #pragma option processing.
Usage:

Options are case insensitive.
2016-06-28 03:20:21 +02:00
Sei Lisa
a13b1cb77e Expand warning text 2016-06-27 22:38:19 +02:00
Sei Lisa
5ad68906e9 Name the groups of keywords.
This is in preparation for having pragmas/defines to select compliation options on the fly within the code.
2016-06-27 20:33:47 +02:00
Sei Lisa
8488254d53 Generate labels sequentially rather than randomly. 2016-06-27 20:32:59 +02:00
Sei Lisa
79dff25769 Update copyright years of some files; add legalese to seftable.txt 2016-06-27 20:06:41 +02:00
Sei Lisa
8fc4240142 Ignore preprocessor commands while scanning for globals.
The pragma warnings were duplicated, one during globals scan, another during actual parsing. This should fix it.

This is somewhat potentially dangerous, as some directives (pragmas, notably) could in future affect the global scan phase by changing the language.
2016-06-27 19:07:20 +02:00
Sei Lisa
633c31df6c The RE wasn't correct, since we want to isolate the directive.
Also check for pragma and emit a warning.
2016-06-27 18:38:40 +02:00
Sei Lisa
fb83279706 Add infrastructure to process preprocessor directives.
Also check that they appear at the beginning of the line.
2016-06-27 16:50:09 +02:00
Sei Lisa
ee091c63a6 Someone's been misusing Python's re.match... O:) 2016-06-26 22:33:10 +02:00
Sei Lisa
893bcf177b Remove dead code.
Commit b73805e introduced lazy lists in assignments only. Commit 890e960 generalized it, allowing any identifier to be followed by brackets, removing the need for assignment-specific treatment. However, we forgot to remove the assignment-specific code parsing, so do it now.
2016-06-26 17:21:52 +02:00
Sei Lisa
28a8f0757c Check the scope as well as the label name, for academic correctness' sake. 2016-05-08 04:14:32 +02:00
Sei Lisa
91ad438bb7 Be a bit smarter when optimizing out default labels.
(Was a TODO item). Also cosmetic changes.
2016-05-08 03:55:55 +02:00
Sei Lisa
3669bbb06e Only add a label and a jump for default and break when necessary.
Well, within reasonable limits.

For break, it's explained in the code. If the block is empty of actual code (code that generates output), then the break position is eliminated.

For default, if the default label is at the top of the block, the jump and the label are both eliminated. This check doesn't include verifying that there are other non-code-generating statements in between, so there's room for improvement (added corresponding TODO item).

This way, we're on par with FS, in case someone (ab)used the FS brokeness when the 'default' label was absent. All one has to do now is add the default label at the top, and the generated code will be the same as it was in FS when abusing that bug, with no extra burden.

Example: In FS, the code at the top acted as default and there was no jump for it:

  default { timer() {
    switch(1)
    {
      0;
     case 1:
      1;
    }
  }}

This generated roughly:
  default { timer() {
    {
      if (1 == 1) jump CASE_1;
      0;
      @CASE_1;
      1;
    }
  }}

In this system, it would trigger an error by default. To obtain the FS behaviour, the scripter can do instead:
  default { timer() {
    switch(1)
    {
     default:
      0;
     case 1:
      1;
    }
  }}

Thanks to this optimization, the code will be the same as in FS. Without it, an extra default label and corresponding jump would be present.
2016-05-07 04:40:37 +02:00
Sei Lisa
697e80cb16 Rather than reproduce the broken behaviour, throw an error on missing default.
Changed my mind. This looks saner. Now, if the 'default:' label is missing, an error will be thrown by default. It has to be explicitly disabled if normal C-like behaviour is desired (namely to jump to the 'break' label if no condition is met).
2016-05-07 02:38:54 +02:00
Sei Lisa
b1b84a123e Add broken FS switch behaviour for compatibility.
In the absence of a 'default' label within a switch, FS falls through to the first CASE label (or to the code before the first CASE if there's any).

This commit adds an option, active by default for FS compatibility, that mimics this broken behaviour, as well as a warning in case the 'default' label is absent, which also triggers another warning when the option is active.
2016-05-06 20:15:46 +02:00
Sei Lisa
41149a17aa Report a type mismatch in globals in a more meaningful position.
For example, this script reported the type mismatch in default:

key k=0;
default{timer(){}}

Now it's reported at the semicolon, which is as early as it can be identified and much more meaningful.
2016-04-04 13:58:25 +02:00
Sei Lisa
881a33a427 Remove unnecessary line 2016-01-03 01:30:22 +01:00
Sei Lisa
cfb9dee941 Parse_unary_postfix_expression shouldn't accept the token (i.e. advance to the next) if it's not processed. This caused a mismatch between the reported syntax error and the position where it should have been detected. Fixed.
Added corresponding regression test.
2016-01-03 01:29:57 +01:00
Sei Lisa
ceb442e931 Improve error reporting, by printing the errored line and a caret (^), taking care to display the beginning of the token the error is at. 2016-01-02 03:39:47 +01:00
Sei Lisa
0122d6ed70 On second thought, disable explicitcast for list+nonlist and nonlist+list entirely, as they are not the same as list+(list)nonlist and (list)nonlist+list anyway. 2015-09-05 03:09:46 +02:00
Sei Lisa
d8649deebd nonlist + list was returning the type of the nonlist element. Fixed and added a
regression test.

Funnily enough, it was correct if explicit cast was active. Removed from explicit cast now that it's active for all.
2015-09-04 05:56:05 +02:00
Sei Lisa
1a67db64dc Get rid of builtins.txt.dat by adding a parameter to the parser ctor. 2015-07-09 20:35:14 +02:00
Sei Lisa
1160fea8cf Fix extendedtypecast problem with negative constants after typecasts. 2015-06-23 06:54:04 +02:00
Sei Lisa
52ebe20a67 Refine a comment 2015-06-17 02:31:58 +02:00
Sei Lisa
bfabcd16db Fix parser bug where list = anytype was accepted. Fix also the test suite. 2015-06-16 04:16:59 +02:00
Sei Lisa
faf296fa74 Fix bug with scripts that have UTF-8 characters.
The parser expects bytes, not unicode.
2015-05-03 05:19:14 +02:00
Sei Lisa
4fbbda60a7 Elaborate on the TODO. 2015-03-28 23:34:07 +01:00
Sei Lisa
b8a7e88f1a Add TODO item 2015-03-28 23:31:11 +01:00
Sei Lisa
edbc240408 Remove 'Local' from symbol table; add note about an unimplemented feature; improve symbol table documentation; rename a helper variable. 2015-03-27 02:12:32 +01:00
Sei Lisa
921955f321 Implement function overriding syntax extension, fixing a bug on the way.
The funcoverride option allows defining multiple functions with the same name, each overriding the former. That's for compatibility with Firestorm, whose optimizer does that.

While on it, fix a bug where defining a function whose name matches a library function was not reporting an error, and rename self.functions to self.funclibrary for clarity. It also brings consistency with other parts of the code and with the code documentation.
2015-03-27 00:35:37 +01:00
Sei Lisa
3839863a21 EInternal is no longer reused. 2015-03-26 23:26:36 +01:00
Sei Lisa
e21173170e Simplify the builtins.txt parser REs by checking the types in the code.
Gives us more granularity reporting errors.
2015-03-26 23:08:54 +01:00
Sei Lisa
c8bec32242 Add a comment to prevent mistakes. 2015-03-15 19:49:52 +01:00
Sei Lisa
56f40a9c76 Ensure the script is Unicode before parsing. 2015-03-15 19:19:57 +01:00
Sei Lisa
b8f73bb5e1 Don't open the script in binary mode, open it in text mode.
Not too sure about this change, but it eliminates CRs before LFs.
2015-03-15 02:18:01 +01:00
Sei Lisa
3d965f13e0 Fix bug with the scope of function calls.
Makes this script work, as it should:

`default { timer() { string llSay; llSay(0, llSay); } }`
2015-03-13 16:43:35 +01:00
Sei Lisa
890e960b57 Implement Lazy List reading. Update docs according to last changes (in FS too).
Adds a new tree node type, SUBIDX, which hopefully should never appear in actual output. If it does, it's prefixed with the string (MISSING TYPE) as a cue to the programmer.
2015-03-13 06:38:35 +01:00
Sei Lisa
535dc8434c Allow a code block instead of a ':' as terminator for 'case' and 'default'.
For Firestorm compatibility.
2015-03-13 05:16:22 +01:00
Sei Lisa
39b6036671 Remove 'Scope' from functions in symbol table. Function scope is always 0. 2015-03-13 05:12:09 +01:00
Sei Lisa
4f8d2979aa Fix typo in EParseFunctionMismatch. 2015-03-13 03:28:51 +01:00
Sei Lisa
63e3021a6d Comment tweaking. 2015-03-09 13:20:37 +01:00
Sei Lisa
9c926b6fec Fix obsolete comment.
There was a time where I decided that the tree would be stored inside the symbol table, as values for the global symbols. I changed my mind later and separated them, but that comment remained.
2015-03-09 01:07:55 +01:00
Sei Lisa
6a0eebf157 Implement a couple subtleties of the lexer in the handling of strings.
First, a string does not have its own context, it's a regular expression, therefore if there isn't a matching closing quote until EOF, it's not an unterminated string. It plainly *isn't* a string.

Second, the string lexer searches for either the regexp '[^"\\]' (any character except a double quote or a backslash) or the regexp '\\.', that is, a backslash followed by an "any character" meta. But the "any character" meta does NOT match a newline. The consequence is that a '\' followed by a newline cancels the matching, and the whole thing is not considered a string.

Isolated double quotes are then plain ignored as many other characters.

An example illustrating both cases:
```
default
{
    state_entry()
    {
        string msg = "Hello, Avatar!";
        llOwnerSay"(msg); // the opening quote will be ignored
        // the following backslash at EOL cancels the previous double quote: \
        llOwnerSay(llGetKey(")); // Unterminated string; unmatched so ignored.
    }
}
```
2015-03-08 16:53:58 +01:00
Sei Lisa
a292846d28 Fix missing scope table index when generating the call to lazy_list_set. 2015-03-07 14:50:25 +01:00
Sei Lisa
a9179f2779 Read the data files from the same path where the script resides. 2015-03-06 20:29:54 +01:00
Sei Lisa
c68a1f4ad6 Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00
Sei Lisa
33de6c0efc Comment typo, brackets->braces. 2015-03-05 20:18:13 +01:00
Sei Lisa
308ca7c8ff Add support for 'break n;' and 'continue n;'. Also simplify the break/continue stacks handling code and fix some bugs. 2015-03-05 20:12:32 +01:00
Sei Lisa
cbcf60767a Implement break/continue and switch().
While on it, reorganize the help text and enable 'dcr' by default.
2015-03-05 01:37:32 +01:00