Commit graph

146 commits

Author SHA1 Message Date
Eric Swanson
f3202547fb
New compiler: Add support for case statements (#272)
Adds:
- ast/CaseDispatchDefaultSelector: AST node for a "default:" selector
- ast/CaseDispatchGroup: AST node for a collection of selectors and the code to execute
- ast/CaseDispatchGroups: AST node holding all groups in a case statement
- ast/CaseDispatchSelectors: AST node holding all selectors for one group
- ast/CaseStatement: AST node for a whole case statement
- codegen/CaseDispatchGroupVisitor: knows what to put in a case jump dispatch table
- codegen/CaseJumpDataBlock: knows how to build the entries in the data block

Also, detect multiple case selectors with the same value (or default).  This is different from the OG compiler, which only detected duplicate `default:` selectors.
2020-09-05 20:41:58 -07:00
Eric Swanson
a1a15f708d
OG compiler: set module to Mod_Basic when a token is an identifier (#257)
The OG compiler looks up function ids for most tokens, even when it doesn't need to. When this happens, it assigns the module id as the module of the function.

When the token is later found not to be a function call, the parser changes the id to TOK_IDENT and the type to TYP_OPERAND, but leaves the module id.

We can see this in the included script, which adds members, which have names that match module function names, to a struct.

This doesn't cause problems during execution because the executor ignores the type for the emitted instructions.

It does cause problems when comparing .ecl output for parity between the old compiler and the new compiler, because the new compiler does not look up every identifier to see if it's a function.

This change assigns module = Mod_Basic along with id and type for tokens that are identifiers.
2020-08-30 01:47:24 -07:00
Eric Swanson
64503c2866
var statements in program blocks (#256)
Adds:
- analyzer/LocalVariableScope: tracks local variables created within a given scope.
  - Instantiated on the stack during semantic analysis, this registers itself with LocalVariableScopes during construction and deregisters itself during destruction.
  - Detects unused variables during deregistration
- analyzer/LocalVariableScopes: this is what LocalVariableScope registers with.
  - keeps track of the stack of local scopes.
  - can provide the current local scope, for var statements.

Other notes:

"Shadowed" variables: this is when a variable in one scope hides a variable in another, like so:
    var a := 2;
    if (a)
        var a := 3;
        a := 4;
    endif
    print(a); // still 2
"debug_variables": We'll use these later when writing debug files.
2020-08-30 01:32:38 -07:00
Eric Swanson
303665bcd8
Add error listener, and convert lexer symbols to lowercase (#216)
Add file/ConformingCharStream - converts symbols to lowercase to match grammar

Add file/ErrorListener
2020-08-14 03:28:37 -07:00
Eric Swanson
1d82aa5f8e
Add compiler2/ tests (#214) 2020-08-13 15:26:09 +02:00
turleypol
dee75b0a12
Scripttest inside pol (#210)
* python script to generate cpp file with BareDistro content
poltool cmd to generate the files

* updated baredistro, fixed compilation

* fix warning, ignore autogenerated file in stylechecker

* test for pol?
uoconvert got a new argument outdir for the cfg file output
single thread decay has now a upper limit of sleeptime
fixed that the exit_code can only get worse

basic files for core testing in testsuite
added a not really nice way to set it up via ctest
integrated in CI with upload of log output

* testenv

* update poltool filegeneration to c++17

* first real tests

* first npc test

* equip a backpack and test a bit aos props

* fixed early returns
2020-08-12 23:15:40 +02:00
Eric Swanson
e42892fe7b Compiler v1 error messages in *.err1 files 2020-08-01 17:20:20 -07:00
Eric Swanson
cc1b0c6ee3 fix optimizer bug: can stop optimizing prematurely if pre- or post-decrement operators are present
optimize_token() is meant to return true only if it performs an optimization.

By returning true when it did not, it makes the optimizer stop trying.

A script like this can trigger the condition:

var i := 3;
var ii;

ii := 1 - (--i);
print(i);
print(ii);

Notice that line 4 does not optimize to an 'assign-consume' and therefore does not optimize to 'assign global`

Listfile before (see instructions 6-12):

/vagrant/testsuite/escript/opt/opt005-stopped-optimizing-early.src, Line 1
var i := 3;
0: decl global #0
1: 3L
2: :=
3: #
var ii;
4: decl global #1
5: #
ii := 1 - (--i);
6: global #1
7: 1L
8: global #0
9: unary --
10: -
11: :=
12: #
print(i);
13: global #0
14: Func(1,0): Print
15: #
print(ii);
16: global #1
17: Func(1,0): Print
18: #
19: progend

Listfile after (see instructions 6-10):

/vagrant/testsuite/escript/opt/opt005-stopped-optimizing-early.src, Line 1
var i := 3;
0: decl global #0
1: 3L
2: :=
3: #
var ii;
4: decl global #1
5: #
ii := 1 - (--i);
6: 1L
7: global #0
8: unary --
9: -
10: global1 :=
print(i);
11: global #0
12: Func(1,0): Print
13: #
print(ii);
14: global #1
15: Func(1,0): Print
16: #
17: progend
2020-07-29 20:42:07 -07:00
Eric Swanson
13ba4ad940 Fix a bug in the legacy compiler .ecl output
The RSV_LOCAL offset should be the the local variable, not of the local variable within the block

Notice though, that the executor doesn't even use it.

There is more detail in the attached script.

listfile before:
/vagrant/testsuite/escript/bug/bug013-local-variable-index.src, Line 7
program foo()
var a;             // should be 0
0: decl local #0
1: #
if ( a )
2: local #0
3: if false goto 17
var b;         // should be 1    actually emitted 0
4: decl local #0
5: #
var c;         // should be 2    actually emitted 1
6: decl local #1
7: #
if ( b )
8: local #1
9: if false goto 16
var d;     // should be 3    actually emitted 0
10: decl local #0
11: #
print(d);
12: local #3
13: Func(1,0): Print
14: #
15: leave block(1)
16: leave block(2)
17: leave block(1)
18: progend

listfile after:
/vagrant/testsuite/escript/bug/bug013-local-variable-index.src, Line 7
program foo()
var a;             // should be 0
0: decl local #0
1: #
if ( a )
2: local #0
3: if false goto 17
var b;         // should be 1    actually emitted 0
4: decl local #1
5: #
var c;         // should be 2    actually emitted 1
6: decl local #2
7: #
if ( b )
8: local #1
9: if false goto 16
var d;     // should be 3    actually emitted 0
10: decl local #3
11: #
print(d);
12: local #3
13: Func(1,0): Print
14: #
15: leave block(1)
16: leave block(2)
17: leave block(1)
18: progend
2020-07-29 00:05:52 -07:00
turleypol
07f324040f
Merge pull request #149 from polserver/syz-fix-em-param-name-clash
Fix compiler bug with user function names that match module function argument names
2020-06-16 21:29:03 +02:00
Eric Swanson
e7733ccf19 Fix compiler bug: user functions should be able to have the same name as module function parameter names 2020-06-15 22:27:57 -07:00
Eric Swanson
fd6b722eaf Fix optimization error: will sometimes patch an offset of the wrong instruction when
rolling back an if statement branch.
2020-06-14 03:31:03 -07:00
Eric Swanson
252a4947ce Add bug010 - optimizer bug with if statements 2020-06-13 19:10:33 -07:00
Eric Swanson
9b764d6d0c Remove performtests.py - instead, just run Usage
ctest [options] from the bin-build directory
2020-06-10 23:22:14 -07:00
Eric Swanson
debcb2baf1 remove extra newline 2020-06-10 23:17:05 -07:00
Eric Swanson
11bb3fc07e Just include a subset of the error 2020-06-10 23:08:39 -07:00
Eric Swanson
5fd0e4a10d Allow tests with error output that includes the current directory. Replace /Users/ericswanson/poldev/polserver/testsuite/escript with {{WORKDIR}}. 2020-06-10 22:55:48 -07:00
Eric Swanson
b9e1afbe25 fix syntax - two test scripts 2020-06-10 22:39:04 -07:00
Eric Swanson
51129732d1 Make it a compilation error to hit EOF while expecting an expression terminator (usually semicolon). 2020-06-10 22:14:31 -07:00
Eric Swanson
714e6a5b6a Fix docs format
add a structure test
Add more details (including a real example) to docs
2020-04-29 12:03:30 -07:00
Eric Swanson
36d8603666 Add elvis operator:
a ?: b

Evaluates to a if a is true (not: false, 0, undefined, etc)
Otherwise evaluates to b

Short-circuit evaluation
2020-04-29 02:50:11 -07:00
turleypol
5f7c1cf3f5 maybe now the testdata is correct 2020-01-04 17:07:03 +01:00
turleypol
682eb1ec25 corrected testcase 2020-01-04 14:06:44 +01:00
turleypol
5b9ddb20b0 testcase for invalid chars 2020-01-04 12:59:47 +01:00
turleypol
7db59e0ab8 Support for github actions
with artefacts for all platforms
fixed VS2019 build for format lib
2019-12-26 21:43:41 +01:00
turleypol
59c816cab1 added ecompile.cfg and cmdline flag to trigger error when include
directives use the wrong capitalization. The existing warning will now
lead to an error when warnings get treated as errors.
2019-10-07 21:01:26 +02:00
turleypol
da4ef6d950 added test for ++ member_id 2019-10-04 16:47:24 +02:00
turleypol
6486c969e5 added tests for structs 2019-09-23 20:38:45 +02:00
turleypol
1cf738f499 added tests for --i and i-- 2019-09-22 18:21:34 +02:00
turleypol
f61e656c1c added next funny syntax test 2019-09-22 15:25:40 +02:00
turleypol
84e65b270c more funny syntax tests 2019-09-22 11:50:29 +02:00
turleypol
169c1ec4e3 added i--, corrected that no warning appears when using i++. Extended
tests
2019-09-22 11:04:57 +02:00
turleypol
57c7d97b8c more i++ tests and fixed syntax checks 2019-09-22 09:37:51 +02:00
turleypol
b2a3e1b792 starting to support i++ 2019-09-22 00:34:14 +02:00
turleypol
b89b7b399b some fail tests and non number object 2019-09-21 16:35:54 +02:00
turleypol
23bc135c71 added test for const variables 2019-09-21 16:19:19 +02:00
turleypol
902c9cbfde first version of ++i and --i unary operator 2019-09-21 14:56:06 +02:00
turleypol
be86e2d64a added special test 2019-09-07 17:15:10 +02:00
turleypol
0829c6d379 addee explicit unicode base64 test 2019-09-07 16:51:12 +02:00
turleypol
8b085e86ef dont assume a tainted string by default
cfgfiles (which includes savefiles, datafiles) get sanizized on read,
filemod::readfile, xml module, sql handled
old ascii speech packets handled
2019-01-12 17:14:05 +01:00
turleypol
0989654152 added more tests 2019-01-12 14:01:10 +01:00
turleypol
1898b1687c Merge remote-tracking branch 'origin/master' into utf8
* origin/master:
  fixed leak in compiler and xml filemod ecompile/runecl no longer try to log to pol logs activated xml unittest print stderr on testfailure

Conflicts:
	testsuite/escript/config/fileaccess.cfg
	testsuite/escript/filemod/xml.ins
2018-12-23 14:28:37 +01:00
turleypol
ea0c533364 fixed leak in compiler and xml filemod
ecompile/runecl no longer try to log to pol logs
activated xml unittest
print stderr on testfailure
2018-12-23 13:55:47 +01:00
turleypol
8d9de3918a Merge remote-tracking branch 'origin/master' into utf8
* origin/master: (58 commits)
  fixed style
  fixed namespaces of moved files
  moved polfile/uofile files into plib to cleanup atleast a bit the compile dependencies
  fixed cpu usage of usesinglethreadlogin
  fixed warning
  PolCore().internal(6, scriptname) logs name and memoryusage of variables for given script into log/scriptmemory.log. Globals, locals and all current call stacks. scriptname has to be the relative path from root with ecl ending. Precondition is an existing .dbg file for the given script, this will be created by compiling the script with -x
  added PolCore().internal(5) logs memoryusage in bytes of each script instance into log/memoryusagescripts.log
  updated flyweight memory report (used for memory saving of strings) enable via ENABLE_FLYWEIGHT_REPORT cmake option
  Turns out that Windows has the same wrong format specifier
  Fix wrong format specifier for pointers (fmtlib)
  Mentioned the ENTEREDAREA and LEFTAREA events for items in the docs
  Changed core-changes.txt so that there was only one date entry for my additions.
  Fixed more documentation errors for the ListObjectsInBoxOfClass and ListItemsInBoxOfObjType functions.
  Fixed prototype in XML docs for ListObjectsInBoxOfClass and ListObjectsInBoxOfObjType
  ** Fix docs for ListObjectsInBoxOfClass and remove commented debug code.
  **** Commit for 2018-11-25 **** Added ListObjectsInBox to uo.em.
  **** Commit for 2018-11-25 **** Added ListItemsInBoxOfObjType( objtype, x1, y1, z1, x2, y2, z2, realm := _DEFAULT_REALM) to uo.em Updated core-changes.txt with the ListItemsInBoxOfObjType info. Updated uo.em docs with the ListItemsInBoxOfObjType info.
  silence old core-changes.txt format warnings
  Update web server docs.
  More gitignore
  ...
2018-12-22 10:43:32 +01:00
turleypol
e6f59a69a9 removed instructions testscript files they are not used
removed appveyor xml testresult (I'm to dumb)
2018-10-31 12:09:31 +01:00
turleypol
8de143f6af EScript Tests are now implemented completly in cmake
use ctest or target "test"
2018-10-30 21:23:40 +01:00
turleypol
9124241c11 dear travis and appveyor is the testdata difference only 32bit vs 64bit? 2018-10-30 20:32:21 +01:00
turleypol
366f7e7122 Merge remote-tracking branch 'upstream/master'
* upstream/master: (45 commits)
  renamed mobile syshook to character used unique_ptr for all syshooks
  added docs
  code simplification, deprecate warning for uoclient.cfg MethodScript entry
  party and guild ref support docs and testing left?
  custom methods for client and account references
  fixed line length
  syshooks for npc/mobiles
  first round for scripted object class methods
  Fixed formatting error.
  Added new return option to consume ammunition hook which allows the hook to make the core continue with the usual ammunition checks.
  Fix critical bug in FindObjtypeInContainer()
  fixed compiler warning
  fixed linesize
  windows fixes
  Added cmake option to run clang-tidy used everywhere nullptr
  Changed classes to be final if possible, removed override macro
  Added additional documentation.
  next..
  clang 7 is currently untrusted... next try 6 ;)
  fixed new clang warnings, new compiler version on travis (lets see how many commits are needed till it works)
  ...

Conflicts:
	.travis.yml
	pol-core/bscript/impstr.h
	pol-core/clib/cfgfile.cpp
	pol-core/pol/module/npcmod.cpp
2018-10-14 14:00:33 +02:00
turleypol
0aea78c405 added array.sorted_insert to insert into an already sorted array.
Added a few finals and defaults
2018-10-07 21:05:02 +02:00
DevGIB
124d3fdd66 missed trailing line in output files for test suite 2018-07-20 20:56:11 +08:00