Commit graph

3620 commits

Author SHA1 Message Date
Eric Swanson
e67c468744 collapse namespaces 2020-08-26 21:45:01 -07:00
Eric Swanson
91bca2cc48 Attempt to fix 'cannot access protected member declared in class' errors, by specifying Pol::Module namespace explicitly rather than 'using namespace' 2020-08-26 21:33:50 -07:00
Eric Swanson
a77ddd028e
New compiler: Add optimized unary expressions (#244)
Adds:
- UnaryOperator: AST node for unary operators -, ++, --, and so forth
- UnaryOperatorOptimizer: optimizes a unary operator with its operand
  - now integer and float negation, and integer inversion
  - later x[y]++ to a single instruction

Also:
- automatically include basic.em, which includes some parameter defaults like -1.

This allows the compiler to generate output for a hello, world script with the exact same .ecl output as the legacy compiler.
2020-08-26 19:24:47 -07:00
Eric Swanson
5e85fcc9e4
New compiler: Add IntegerValue (#243) 2020-08-25 23:27:24 -07:00
Eric Swanson
9bbc0518f8
Compiler rewrite: add global variables (#241)
Adds support for var statements at the global level.

Adds:
- analyzer/Variables: keeps track of the variables in scope (either local or global).
- ast/Identifier: AST node for an identifier.
  - The optimizer will replace constant identifiers with their constant value (in a later commit).
  - The semantic analyzer will set the variable field for local or global variable identifiers.
- ast/VarStatement: AST node for a var statement.
  - A single var statement will generate one VarStatement per variable declared.
- model/Variable: Describes a variable, including its index within its scope.
2020-08-25 00:57:03 -07:00
Eric Swanson
cf42b03e3c
New compiler: Add AST nodes for function calls. Can compile hello world. (#240)
Adds:
- ast/Argument: AST node for an argument passed to a function.
- ast/FunctionCall: AST node for a function call.
- codegen/ModuleDeclarationRegistrar: The code generator registers module function declarations with this in order to determine module indexes and function indexes for instructions.
- model/FunctionLink: this is a reference either:
  - from: a FunctionCall or a FunctionReference
  - to: a ModuleFunctionDeclaration or a UserFunction
- optimizer/ReferencedFunctionGatherer: a visitor that determines which module functions and user functions are referenced, by looking at function calls and function references.

Also:
- CodeGenerator registers module functions
- InstructionGenerator generates code for function calls
- InstructionEmitter generates TOK_FUNC instructions
- StoredTokenDecoder decodes TOK_FUNC instructions

After all of this, the compiler can compile print("hello, world");
2020-08-24 01:47:38 -07:00
Eric Swanson
86c0efbc21
Build AST nodes for module function declarations (#239)
Adds enough to build the AST nodes for the module function declarations in a .em file.

Adds:

- Function: base class for module function declarations and user functions
- FunctionParameterDeclaration: declaration for a function parameter, as well as its default value if any
- FunctionParameterList: just a holder for function parameter declarations
- ModuleFunctionDeclaration: for function declarations in .em files
- FunctionResolver: hooks up function calls to module functions or user functions
- ModuleProcessor: a visitor for processing const declarations and module function declarations (const declarations are yet to come from the main branch)
2020-08-23 15:01:39 -07:00
Eric Swanson
d456cc98eb
Update compiler grammar (#238)
* Update grammar
  - add '=' to grammar so that we can report appropriate errors
  - add elvis ?: operator
  - add foreachIterableExpression to match old compiler (which only allows certain expressions)
  - allow both byref and unused on the same function parameter
  - rename methodCall -> functionCall
  - rename memberCall -> methodCall
  - add named parser rule for functionReference
  - move everything that isn't expression(s) with operators into primary
    - expression is now just the left-recursive rules and prefix operators
  - add named parser rules for struct, dictionary, error, array initialization
  - remove special-case for named parameters with := from function call argument, because it is ambiguous with assignment
  - Moved array access, object member access, and object method calls to navigationSuffix

* Regen grammar
2020-08-21 01:53:42 -07:00
Eric Swanson
47aeb634d6
New compiler: Add StringValue (#235)
* Add StringValue
2020-08-20 10:27:35 +02:00
Eric Swanson
05afc9b851
Upgrade Vagrant setup to Ubuntu 20.04 (focal64) (#236)
* Upgrade Vagrant setup to Ubuntu 20.04 (focal64)

* Add clang and clang-format.

Now build_tools.sh -c works too

* Update comment: refer to git repo, not SVN
2020-08-20 09:47:21 +02:00
Eric Swanson
81331b7200
Add FloatValue (#233) 2020-08-19 19:43:08 +02:00
turleypol
3b9051271e
Option to disable Reuse of clib pch (#234)
* by default on windows the clib pch shouldnt be reused and instead rebuild
* activate reuse_pch for windows ci build
* changed pch header from public to private
2020-08-19 14:55:09 +02:00
Eric Swanson
f93573ae51
Add SourceFileProcessor, ValueConsumer (#232)
* Add astbuilder/ SourceFileProcessor

* Add ast/ ValueConsumer

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-18 23:32:57 -07:00
Fernando Rozenblit
70b9c1305c
Add maximum cmdlevel to polsys::ListTextCommands() (#231)
The default, -1, will return all commands as before. No need for a version bump because the method checks the number of arguments.
2020-08-19 07:19:30 +02:00
Eric Swanson
ed218a967f
Add AST builder stubs (#230)
* Add astbuilder/TreeBuilder

* Add astbuilder/ValueBuilder

* Add astbuilder/ExpressionBuilder

* Add astbuilder/ SimpleStatementBuilder

* Add astbuilder/CompoundStatementBuilder

* Add ModuleDeclarationBuilder

* Add ProgramBuilder

* Add UserFunctionBuilder
2020-08-18 12:07:51 +02:00
Eric Swanson
3a8ab09a56
Add Expression, Statement, Value AST base classes, and TopLevelStatements (#229)
* Add ast/ Expression, Statement, Value

* Add ast/TopLevelStatements
2020-08-17 22:53:03 -07:00
Fernando Rozenblit
c49f5b4abb
Reorganize regions and realms (#228)
* Moved realms.h and realms.cpp to realms/..

* Moved regions into their own folder
2020-08-17 22:29:07 +02:00
Eric Swanson
11abe52f3e
Add ast/Node (#227) 2020-08-17 08:03:33 +02:00
Eric Swanson
f0f4fc6f9f
Improve SourceFileCache::keep_some() (#226)
* Log cache prune time

* pair, nth_element, no shared ptr, no string copy
2020-08-16 22:59:13 -07:00
Eric Swanson
50e42719b8
Add file/SourceFileCache (#222)
* Add file/SourceFileCache

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-16 17:22:16 -07:00
turleypol
5a09130a29
Coverity build fix (#224)
* build antlr before compiling with coverity
* missing uuid-dev
2020-08-15 18:51:00 +02:00
Fernando Rozenblit
26b12acc98
Use @v1 for vsdevenv action instead of @master (#223)
* Use @v1 for vsdevenv action instead of @master

* Second place where it uses @master instead of @v1
2020-08-15 10:39:32 +02:00
Eric Swanson
841bc928d3
Normalize include paths (#221) 2020-08-15 08:01:19 +02:00
Eric Swanson
2df8e74ab1
Add file/SourceFile (#220) 2020-08-14 22:54:20 +02:00
Fernando Rozenblit
815bb6f856
Cmake and zlib cleanup (#219)
* Added explicit path to the lib/ folder.

* Added use_zlib() function to the cmake files. Changed the remaining cmake files to use POL_EXT_LIB_DIR.

* Removed relative path to zlib. It seems we were always using our zlib header (even when linking to the system zlib on linux!).
2020-08-14 22:16:02 +02:00
Fernando Rozenblit
f3c3dbd0cf
Remove unused library and header (#218) 2020-08-14 21:38:02 +02:00
Fernando Rozenblit
4b96f9b663
Add pol-core to include path (#217)
* Add pol-core to include path

* Change a few example files to use an include path relative to pol-core or the project
2020-08-14 20:40:14 +02: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
ad3644de23
Antlr and Curl build step fix (#213)
* force antlr to always build in release node also for multiconfigs
set the correct c++ runtime flag for clang on windows
fixed lib path for antlr
in CI also test msbuild and different modes then release

* cache antlr in nopch and force recompile in pch build

* force release mode also for curl
2020-08-13 15:16:36 +02:00
Fernando Rozenblit
266bff30c2
item.hitscript and item.onhitscript will now return the full spec for the script. Added breaking-changes.txt. (#215)
* Return the full spec for item.hitscript and item.onhitscript. The relative name wasn't very helpful.

* Added breaking changes.txt. We can add more breaking changes later.

* Added ScriptDef::qualifiedname(). Returns the full spec necessary to call the script ("::scriptname" or ":pkgname:scriptname"). Returns an empty string if there is no script.
2020-08-13 11:29:07 +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
97f669f94a
Add instruction generator, emitter, emit progend (#211)
* Add codegen/InstructionEmitter

* Add codegen/InstructionGenerator

* CodeGenerator: emit progend

Checkpoint: compiler can compile an empty file

* Comment reason for having both emit and emitter.
2020-08-12 10:30:06 +02:00
Eric Swanson
d22a9af254
Add code emitter and data emitter (#209)
* Add codegen/ DataEmitter

* Add codegen/ CodeEmitter
2020-08-11 20:50:16 +02:00
Eric Swanson
978b9ff6ec
Add StoredTokenDecoder and ListingWriter stubs; write listfile (#208) 2020-08-11 12:49:18 +02:00
Eric Swanson
c0229ce872
Cleanup: vector byte, default dtor (#207)
* [[]] vector<uint8_t> -> vector<byte>

* Remove unnecessary explicit default destructor
2020-08-11 10:46:35 +02:00
Eric Swanson
6b3fdcb263
Add CodeGenerator stub (#206)
* Add codegen/CodeGenerator stub

* Destructor is trivial
2020-08-11 09:08:48 +02:00
Eric Swanson
72bd179051
Add analyzer/Disambiguator stub (#205)
The Disambiguator will correct the AST based on context.

At present, it needs to handle ambiguities in the grammar between
case group selectors and named break/continue labels.
2020-08-11 08:21:34 +02:00
turleypol
62fa91ec8e
Antlr external project (#204)
Build antlr as external project inside of lib/antlr.
Cache in Ci the antlr folder to speed up compilation times.

* replace ERROR with ANTLR_ERROR, fix clang build
* added missing define needed to link on windows
* different lib name with clang on windows
2020-08-10 14:53:29 -07:00
Eric Swanson
d184dda473
Add Optimizer stub (#203) 2020-08-10 13:54:59 +02:00
Eric Swanson
435db9dc07
bscript/compiler: use c++17 nested namespace definitions (#202) 2020-08-10 12:20:29 +02:00
Eric Swanson
eb6594b4c6
Add ast/NodeVisitor, analyzer/SemanticAnalyzer stubs (#201) 2020-08-10 10:37:07 +02:00
turleypol
35e1712f3c
C++17 (#197)
* move to c++17

* update readme with new compiler requirements

* use c++17 filesystem in testfiles creation

* use gcc9

* Vagrant support for c++17: use gcc9 and llvm 7 (#199)

Co-authored-by: Eric Swanson <eric.the.unicorn@gmail.com>
2020-08-10 10:04:03 +02:00
Eric Swanson
2e1870028b
Add model/CompilerWorkspace, astbuilder/BuilderWorkspace, astbuilder/CompilerWorkspaceBuilder (#200)
Add astbuilder/BuilderWorkspace:
  - Temporary workspace used while building the AST (which goes in the CompilerWorkspace)

Add astbuilder/CompilerWorkspaceBuilder:
  - Builds a CompilerWorkspace for a script

Add model/CompilerWorkspace:
  - Holds AST
  - Holds some intermediate data used by semantic analyzer, optimizer, code generator
2020-08-10 09:42:37 +02:00
Eric Swanson
63326cd44c
Add format/ CompiledScriptSerializer (#198)
* Add format/ CompiledScriptSerializer

* Add CompiledScript output, write with CompiledScriptSerializer
2020-08-10 09:00:47 +02:00
turleypol
fe301c82ea
Misc test preparation improvements and fixes (#196)
* uodir parameter for uoconvert tiles/landtiles/multis
limit decay sleeptime to 500ms
exit_code cannot be "fixed" with a later call
2020-08-09 15:10:52 +02:00
Eric Swanson
a5f22fe583
Add types that define compiler output: (#195)
representation/
    CompiledScript
    ExportedFunction
    ModuleDescriptor
    ModuleFunctionDescriptor
2020-08-09 09:31:18 +02:00
Eric Swanson
cc28f4f4f2
Add compiler/ Profile and Report (#193)
* Add compiler/Profile

* Add compiler/Report

* From CR notes: add newline on caught exception.
Also added comments that messages should have a newline at the end.
2020-08-08 16:31:55 +02:00
turleypol
2484998469
poltool is now able to generate clientdata (#191)
added simple test for uoconvert
fixed poltool mapdump argument handling
2020-08-08 09:34:40 +02:00
Eric Swanson
4d4b03d252
Fix unsigned short/size_t conversion warnings (#190) 2020-08-06 10:43:55 +02:00