Commit graph

3748 commits

Author SHA1 Message Date
turleypol
7c77157d2e fixed smooth boat pkt (7.x clients) 2020-09-08 18:45:19 +02:00
turleypol
bccccb525a fixed compilation
ugly hack to keep uotool compiling
2020-09-06 21:01:42 +02:00
turleypol
6a2bd7c705 Merge remote-tracking branch 'origin/master' into vector_classes
* origin/master: (93 commits)
  Add support for dictionary creation (#277)
  Add do-while statement (#276)
  Add foreach loops (#275)
  New compiler: array initialization (#274)
  Disambiguator: figure out if label is a case statement dispatch selector, or should apply to a statement within the case dispatch group's block. (#273)
  New compiler: Add support for case statements (#272)
  Change "logical" to "bitwise". (#258)
  Fix divide-by-zero errors, and mask FormatError if it were thrown in a destructor. (#271)
  Add break and continue statements. (#270)
  New compiler: assignment to local and global variables. (#269)
  Add support for while loops (#268)
  Optimize if statements, and emit module functions in legacy order (#267)
  Optimizations: binary operators (#266)
  Add binary operators (#265)
  Add support for const declarations (#264)
  Handle default parameter values, pass-by-name, and return statements in functions. (#263)
  Add limited support for user functions (#262)
  New compiler: add return and exit statements (#261)
  Add support for if-then-else statements (#259)
  OG compiler: set module to Mod_Basic when a token is an identifier (#257)
  ...
2020-09-06 20:14:26 +02:00
turleypol
a3eda8818e fixed crash while creating house components
fixed moveitem
2020-09-06 19:47:27 +02:00
turleypol
aa5ec519e5 fixed z coord compare in ListItemsInBox, fixed move from storage 2020-09-06 16:22:57 +02:00
Eric Swanson
002ea6fbba
Add support for dictionary creation (#277)
Adds:
- ast/DictionaryEntry: AST node for a key -> value pair in a dictionary initializdr
- ast/DictionaryInitializer: AST node for creating a new dictionary
- ast/UninitializedValue: AST node for an uninit object
2020-09-06 04:02:37 -07:00
Eric Swanson
5033aefcdc
Add do-while statement (#276)
Adds:
- ast/DoWhileLoop
2020-09-06 02:26:41 -07:00
Eric Swanson
966b3acf5a
Add foreach loops (#275)
Adds:
- ast/ForeachLoop: AST node
2020-09-06 01:22:47 -07:00
Eric Swanson
103c27a9af
New compiler: array initialization (#274)
* Add array initialization

Adds:
- ast/ArrayInitializer: AST node for an expression that creates an array
2020-09-06 00:13:49 -07:00
Eric Swanson
4a033340bf
Disambiguator: figure out if label is a case statement dispatch selector, or should apply to a statement within the case dispatch group's block. (#273) 2020-09-05 21:52:56 -07:00
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
Admin-Yukiko
2fe96de2fd
Change "logical" to "bitwise". (#258)
* Change name of "logical" operators AND, OR and XOR to "bitwise".

Co-authored-by: Admin-Yukiko <hopelivesproject@gmail.com>
Co-authored-by: Eric Swanson <eric.the.unicorn@gmail.com>
2020-09-05 10:58:53 +02:00
Eric Swanson
775ef51d91
Fix divide-by-zero errors, and mask FormatError if it were thrown in a destructor. (#271) 2020-09-05 01:19:12 -07:00
Eric Swanson
92ba5be8cf
Add break and continue statements. (#270)
Adds:
- ast/JumpStatement: AST node for break and continue statements
2020-09-04 18:21:08 -07:00
Eric Swanson
805cc2f314
New compiler: assignment to local and global variables. (#269)
Adds:
- ast/AssignVariableConsume: AST node for assignment to a variable, while consuming the result
- optimizer/ValueConsumerOptimizer: Optimizes expressions where the resulting value will be consumed
2020-09-04 00:10:38 -07:00
Eric Swanson
1a3619b231
Add support for while loops (#268)
Adds:
- analyzer/FlowControlScope: Registers a break/continue scope
- analyzer/FlowControlScopes: Registry for break/continue scopes
- ast/LabelableStatement: Base class for AST nodes that can be labelled (loops and case)
- ast/LoopStatement: Base class for AST nodes for loops (have a break and continue label)
- ast/WhileLoop: AST node for a while loop
2020-09-03 19:46:27 -07:00
Eric Swanson
25654c358f
Optimize if statements, and emit module functions in legacy order (#267)
1. Optimize if statements (parity with OG compiler):
- discard empty 'alternative' blocks
- optimize to the consequent if the predicate is a nonzero integer
- optimize to the alternative, or an empty block if there is none, if the predicate is a zero integer.

2. In comparison mode, emit module functions in the same order as the OG compiler.
This is because the OG compiler can emit declarations for module functions that it doesn't actually call, and in a different order than calls to actual module functions.
2020-09-02 23:29:22 -07:00
Eric Swanson
447e8d4e2e
Optimizations: binary operators (#266)
Adds:
- optimizer/BinaryOperatorOptimizer: optimizes expressions with a binary operator
  - assignments will be handled by optimizer/AssignmentOptimizer
- optimizer/BinaryOperatorWithFloatOptimizer: optimizes binary operator expressions with a FloatValue left-hand side
- optimizer/BinaryOperatorWithIntegerOptimizer: optimizes binary operator expressions with an IntegerValue left-hand side
- optimizer/BinaryOperatorWithStringOptimizer: optimizes binary operator expressions with a StringValue left-hand side
2020-09-02 00:27:09 -07:00
Eric Swanson
2b1e8a14ca
Add binary operators (#265) 2020-09-01 22:49:48 -07:00
Eric Swanson
6ce9c38de3
Add support for const declarations (#264)
Adds:
- analyzer/Constants: holds constant name -> value for lookup
- ast/ConstDeclaration: AST node for a const declaration
- optimizer/ConstValidator: validates that an optimized expression is valid to use as a constant.

the Optimizer converts Identifiers that refer to a constant to the optimized constant value.
2020-09-01 00:54:24 -07:00
Eric Swanson
6d163918c5
Handle default parameter values, pass-by-name, and return statements in functions. (#263)
Process function call parameters to account for:
- default parameter values
- passing parameters by name

Also handle return within a function (I left this out of the previous PR)

Adds:
- astbuilder/SimpleValueCloner: clones values that are valid as constants and parameter default values.
2020-08-31 23:16:30 -07:00
Eric Swanson
b3bd302785
Add limited support for user functions (#262)
Adds:
- ast/UserFunction AST node for user-defined functions.
- astbuilder/AvailableUserFunction: reference to a parse tree for a user function.
  - The AST builder only generates ASTs for user functions that are actually referenced.
- astbuilder/UserFunctionVisitor: visits (builds an AST for) a parse tree for a user function.
  - This happens after the .src or .inc file has been otherwise processed, so this class serves to hook up the correct SourceFileIdentifier to the AST.
2020-08-31 18:46:27 -07:00
Eric Swanson
98e74bd7dc
New compiler: add return and exit statements (#261)
Add:
- ast/ExitStatement: AST node for the exit statement.
- ast/ReturnStatement: AST node for the return statement.
  - only handles top-level returns and returns inside program declarations, which do the same thing: progend.
2020-08-30 22:55:30 -07:00
Eric Swanson
95e604e417
Add support for if-then-else statements (#259)
Adds:
- ast/Block: a block scope that allows declaring local variables
- ast/IfThenElseStatement: AST node for if..elseif..else..endif statements
- model/FlowControlLabel: provides an anchor for jumps or calls.
  - Function calls, break statements, continue statements, and loops will all use these.
2020-08-30 17:03:26 -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
turleypol
26511144dc
fixed typo and codepoint in unicode sanitize, fixed compiler warning (#254) 2020-08-29 13:46:11 +02:00
turleypol
f1736e3b2f
fixed pessimistic move and signed/unsigned compare (#255) 2020-08-29 13:45:45 +02:00
Eric Swanson
92098e3784
grammar: report trailing commas in dictionary, struct, array initializer lists (#252) 2020-08-29 02:52:40 -07:00
Fernando Rozenblit
cbadd96b49
General cleanup of module includes (#253)
1) Made all module methods [[nodiscard]]. Glad to report no leaks were found. We should add the same to BObjects.

2) Protected members of NPCExecutorModule (were public before).
3) Added NPCExecutorModule::controlled_npc() so that osmod can access the npc's name and position.

4) Removed declarations for undefined functions:
- attributemod.h: mf_SetAttributeIntrinsicMod()
- osmod.h: mf_System_RPM()
- vitalmod.h: mf_SetVitalMaximumValue() and mf_SetVitalRegenRate()
2020-08-29 11:35:13 +02:00
Fernando Rozenblit
4f3da669aa
Refactor suspicious activity warnings and suppress B1 overflow warnings (#249)
* Refactored the reporting of suspicious activities
* Only show warnings about B1 packet overflow if ShowWarningGump is enabled
2020-08-29 09:39:18 +02:00
Eric Swanson
5e57733a68
New compiler: program declarations (#246)
Add:
- FunctionBody
- Program
- ProgramParameterDeclaration
- ProgramParameterList

Build AST for program sections and generate code for it
2020-08-28 22:45:07 -07:00
Eric Swanson
a10481130f
Make OSExecutorModule module functions public, to cope with MSVC compiler problems (#250) 2020-08-29 07:17:19 +02:00
Eric Swanson
41efd3ea80 Make NPCExecutorModule module functions public (like those of other modules) 2020-08-28 18:15:40 -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