Commit graph

603 commits

Author SHA1 Message Date
turleypol
0513b10864
moved remaining eprog2/3 methods to eprog (#752)
simplified Token
2025-01-24 20:20:21 +01:00
turleypol
12eabd789f
more dead code from old compiler (#751) 2025-01-23 21:39:16 +01:00
turleypol
4782dc9757
removed unused code from old compiler out of EProgram (#750)
increased testcoverage for math module to almost 100%
2025-01-23 19:53:11 +01:00
Kevin Eady
0527692a78
Add Script object script method stacktrace (#739)
* Initial implementation, tests

* Enhance tests

* Add quiet to read_dbg_file

* Add pc to array format

* Add docs, core-changes

* fix bad PCs

* touchup on corechanges
2025-01-05 17:22:55 +01:00
turleypol
22b01b3b81
added multi prop/itemdesc items_decay (#735)
* added multi prop/itemdesc items_decay
added region cfg entry NoDecay
misc cleanup eg chr->equip sets position instead of calling side

* docs

* added future pos refactoring comment

* changed region NoDecay to ItemsDecay so it matches the other props
2024-11-14 06:58:18 +01:00
Jonathan Morland-Barrett
8df2f6515e
Added dynaprops for min and max attack range increase. (#511)
* Initial commit of min and max range increase dynaprops.

* Fixed documentation and reported style issues.

* More style check fixes.

* Update missing uobject and script objects for new props.

* Rectify missing code from uoscrobj which prevented assignment on mobiles.
Changed range logic from weapons to include some sanity checks.

* Add a simple test

---------

Co-authored-by: Jonathan Morland-Barrett <jonathan@veridiandynamics.com.au>
Co-authored-by: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
2024-11-02 15:46:50 +01:00
turleypol
300a9ca47d
added ssopt AllowVisualRangeModification (#726)
* added ssopt AllowVisualRangeModification which allows clients to modiy
their LOS via pkt 0xC8

* added ssopt MinimumVisualRange and MaximumVisualRange to limit the range
a client can define.
added r/w script member client.visual_range
if set via script the updaterange can no longer be modified by the
client

* fixed typo

* missing include

* if via script the visual_range is set to 0 use the client given range
remove/add objects when the visual range changes
added test
fixed testclient 0xbf sub clienttype packet

* extra logic to send/remove objects only if they are now/no longer
visible due to range change
script can by pass the VisualRange limit
added docs

* core changes
2024-11-01 19:07:43 +01:00
Kevin Eady
2d0b675754
Fix super-scoped function resolution; Fix SourceLocation for scoped function calls (#730)
* Fix super-scoped function resolution

* Fix SourceLocation for scoped function calls
2024-10-25 11:20:41 +02:00
Lukáš Novotný
d56a6df251
Add moved_at and position_changed_at members to characters (#729)
* add moved_at and position_changed_at members to characters

* add core changes, docs

# Conflicts:
#	docs/docs.polserver.com/pol100/corechanges.xml
#	pol-core/doc/core-changes.txt

* fix docs
2024-10-23 20:27:56 +02:00
Kevin Eady
150d7982fb
Fix too-early fail on calling scoped variable as function (#728) 2024-10-20 17:42:07 +02:00
Kevin Eady
f45d12665d
Fix various case sensitivity issues in classes (#725) 2024-10-18 06:53:50 +02:00
turleypol
2320a5dd35
Socket::has_incoming_data closes socket on error (#721)
* Socket::has_incomming_data closes socket on error
eg auxclient via OpenConnection had the problem that a closed connection
by the other side wasnt detected.
cleanup timeout params uses now milliseconds
removed old unused pollingwithselect
renamed pol.cfg entry for SingleThreadLoginServer socket timeout

* changed the default for the loginserver to single thread
Formatter defaults when no cfg can be loaded match the cfg case now.
added docs
2024-10-17 06:55:06 +02:00
Kevin Eady
92d7cc6237 Updates after rebase
- Update formatter for classes support
- Update expected error message in escript test case
2024-10-10 18:06:04 +02:00
Kevin Eady
8b41711a6d Fix funcref.new(); Correctly error on accessing class name as identifier (#716)
* Fix funcref.new on non-ctors

* Properly error on accessing class name as identifier
2024-10-10 18:06:04 +02:00
Kevin Eady
1c190f7d3e Fix is operator to work across executors (#711)
* Update funcref table
- Add ctor funcref index
- Switch ctor list to be type tag offsets instead of funcref indexes

* Add pol tests for is, set-member across scripts

* Address GitHub CI annotations
- unused variable ‘uf’

* return longs instead of bools
2024-10-10 18:06:04 +02:00
Kevin Eady
a953a37fa7 Support function reference calls with default parameters (#710)
* Support default args in funcref calls
- Simplify BFunctionRef by using funcref index
- Emit default args when visiting function reference

* Move default args gen to second-pass visit

* Better error message on param count errors

* Check for constructor in MTH_NEW

* Address self-review comments
- Update code comments

* Introduce ResourceManager to pol testsuite
- Create a new class-based resource manager for deleting resources
(item NPCs, multis) after each test.
- Migrate house_set_multiid test to use new ResourceManager.

* Move resource cleanup
2024-10-10 18:06:04 +02:00
Kevin Eady
ffbb5a8674 Add BClassInstanceRef; better error messages on bad method calls (#709)
* Add BClassInstanceRef

* Better error messages on bad method calls
2024-10-10 18:06:04 +02:00
Kevin Eady
c449f8eae0 Add semantic error on exported class functions (#707) 2024-10-10 18:06:04 +02:00
Kevin Eady
6a7968c20b Address final implementation TODOs (#706)
* Address code TODOs

* Update Escript version!
2024-10-10 18:06:04 +02:00
Kevin Eady
b22022be1c Add semantic error on cyclic inheritance (#705) 2024-10-10 18:06:04 +02:00
Kevin Eady
c7a06fe907 Support handling parent-scoped static function calls (#704) 2024-10-10 18:06:04 +02:00
Kevin Eady
82cf03ba2a Generate constructors for child classes (#703)
* Make constructor_link nullable; WIP generated function builder changes

* saving work

* saving work, need to resolve double call

* hopefully finish up super inherited constructors

* Error if no base class has ctor

* Fix AddressSanitizer error...?

* Revert unnecessary edit

* Remove duplicate code

* Update pol-core/bscript/compiler/astbuilder/GeneratedFunctionBuilder.cpp
2024-10-10 18:06:04 +02:00
Kevin Eady
d7cdcff383 Add classinst.function member; Add is binary operator; Add funcref MTH_NEW (#701)
* Update grammar

* Implement selfIs in BObjectImp

* Add tests

* Update grammar

* Support obj.function as a MemberAccess [1/2]
- AST generation changes

* Support obj.function as a MemberAccess [2/2]
- add funcref index to eprog class table ctor entry
- allow check_mro on non-class inst (skip ctor calls)

* Move address of funcref into funcref table

* Add funcref.new()
- Add class index to funcref table entry
- Add MTH_NEW

* Fix formatting

* Address self-review comments

* Some more tests

* Address self-review comments

* Update grammar

* Remove ObjMember read_only, hidden
No need to special-handle MBR_FUNCTION

* Addres GitHub CI annotations
- '=': conversion from 'size_t' to 'unsigned int', possible loss of data
2024-10-10 18:06:04 +02:00
Kevin Eady
67aa0c25b0 Initial support for class instances in Executor (#699)
* Associate class descriptor with class instance

* Skeleton of BClassInstance, update tests

* Correctly handle methods on class instances

* Support calling members as methods

* Update super-multiple test

* Track called ctors; Introduce ins_check_mro

* Move class method funcref class to Executor

* Address GitHub CI annotations
- 'argument': conversion from 'size_t' to 'unsigned int'

* Update pol-core/bscript/bclassinstance.cpp

* Introduce BConstObject for class instances

* Fix unnecessary include in uotool

* Removed fixedalloc from BConstObject

* Additional test case

* Address Discord comments
- Reintroduce deleted copy assignment
2024-10-10 18:06:04 +02:00
Kevin Eady
08a5fc54c6 Fix varargs in constructors with super; Remove restriction that base-classes must be constructable (#698)
* Fix super() calls with var args

* Small fixup
- Incorrect calling-scope in  FunctionCall inside super() generated function

* Allow base classes that do not have constructors

* Fix defaults for super()
- Make SimpleValueCloner return an Expression
- Clone parameter's default value in GeneratedFunctionBuilder
2024-10-10 18:06:04 +02:00
Kevin Eady
37a6179971 Add reading, writing of function table to ecl program (#697)
* Make ClassDeclaration only track class methods

* Keep methods, constructors in compiler workspace
- Fix UserFunctionBuilder to force reference to methods, constructors
- Fix Optimizer to include methods, constructors in referenced functions

* WIP for ClassDeclarationRegistrar
- Stub implementation of ClassDeclaration and its Registration
- Create "function table entry" via debug statements

* Use function links in methods

* Finish up ClassDescriptor
- Introduce MethodDescriptor for encapsulation
- ClassDeclarationRegistrar can register and take descriptors

* Handle read and write class table in eprog

* Pass Report to code generator for debug statements

* Fix implementation
- It _is_ possible for the constructor to be empty, ie. static classes

* Update DebugStoreSerializer
Print class table to dbg txt file

* Add missing method_names insertion

* Address GitHub CI Annotations
- unused variable 'uf'
- '=': conversion from 'size_t' to 'unsigned int'
2024-10-10 18:06:04 +02:00
Kevin Eady
e94bc86bda Support linking functions in super scope; explicit super:: scope calls (#695)
* Add support for checking base-class scopes in unscoped function calls

* Add support for `super::` call scope

* Address CI annotations; Discord discussions
- Shadowing
- Change itr post-inc to pre-inc
- Rename `to_link` to `to_check` to better describe its use.

* Address review comments

- Remove unnecessary to_check_itr assignment
2024-10-10 18:06:04 +02:00
Kevin Eady
6838c74cb4 Add super() function call for constructors (#694)
* Grammar updates
- Make class parameters required

* Add ClassLink; wip with `super()` calls in ctors

* More AST nodes as ScopableNames
- (function call) Argument
- FunctionParameterDeclaration

* Add support for ambiguity handling

* Add few more tests

* Handle returns in constructors
- Semantic analysis to error on returning a value
- Introduce specific emitter method for returning from constructor
- Various tests

* Refactor super building to pre-semantic analysis

* Adding several tests, some are TODO
- found an issue with function resolver and funcrefs, fix later

* Address self-review comments

* Fix funcref global func references, tests
2024-10-10 18:06:04 +02:00
Kevin Eady
1842953c31 Changes to default construction and base-class semantic analysis (#693)
* Remove DefaultConstructorFunction

* Modify class parameters; update semantic analysis
- Use ClassDeclarationParameter for class decls vs Identifiers
- Update ScopableName to have equality for constructors and unscoped
  function calls
- Update SemanticAnalyzer (self referencing base class, no ctor)
- Update, add tests

* Semantic updates; debug messaging updates
- Ensure base class is constructable
- Various fmt implementations for debugging

* Address self-review comments
2024-10-10 18:06:04 +02:00
Kevin Eady
0fc285696e Delayed AST building of class variable statements (#692)
* Delay class variable visiting; func resolver fixes; tests

* Maybe fix clib headers?
2024-10-10 18:06:04 +02:00
Kevin Eady
e3512d001b Add scope handling for functions and variables (#690)
* Add Report.debug

* Implement function call scoping

* Implement variable scoping
- Rename `Identifier::scope` to `calling_scope`, and concatenate the identifier scope into `name` if necessary.
- Track current scope in SemanticAnalyzer, similar to UserFunctionVisitor.
- Use current scope in SemanticAnalyzer when visiting identifiers.

* Update grammar for `::identifier` global scoping

* Introduce ScopableName for function resolution

* Address review comments
- Check for display_debugs missing

* Add ScopableName for identifier resolution

* Some cleanup
- Remove `Identifier::calling_scope`, as it is tracked in the semantic
  analyzer
- Refactor `ScopeName::exists` to `global` for better clarification of
  its use
- Removed `X::maybe_scoped_string/name`

* Address self-review comments

* Rename `Function::module_name` to `scope`
2024-10-10 18:06:04 +02:00
Kevin Eady
4ae9519343 Update grammar, parser, semantic analyzer for classes; skeleton codegen and executor (#688)
* Update grammar

* WIP with tracking classes
- Refactor AvailableUserFunction to AvailableParseTree
- Track ClassDeclarationContexts similarly to user functions

* Skeleton AST + tracking

* Finish up AST building

* Implement AST building
- TODO decide better name for UserFunctionBuilder/Visitor,
since it does both user functions and classes

* Update Prettifier

* Crude, first-round semantic analysis + codegen
- Currently, no real difference from regular functions

* Move class var statements to top level statements

* Add semantic analysis for base class existence

* Introduce ClassInstance AST node for generating `this` parameter

* Skeleton create class instance instruction

* Default ctor; 'this' byref; Error if multiple same baseclass

* Update grammar for scoped funcrefs and scoped identifiers

* Update prettifier, builders for scoped funcref, identifiers

* Fix CI issues
- Styling
- Shadowing

* Add grammar tests for scope; Remove scope from switch label

* Final draft todos
- Rename `VarStatement::class_name` to `scope`
- Comment why identifiers dont have scopes in enum declarations
- Remove code comment
2024-10-10 18:06:04 +02:00
turleypol
145eb8185b
fixed missing space when packing funcrefs (#714)
* fixed missing space when packing funcrefs
pack functioncall during group formatting without forcing a newline

* error if resulting format string is empty

* core changes

* do not start a newline when next part is a closing parenthesis during
groupformatting

* pkg loading is again quiet
2024-10-03 15:10:21 +02:00
turleypol
ba9ad6d1d5
more formatting improvements (#696)
* more formatting improvements:

replace inside of comments tabs with spaces if UseTabs is false
do not strip whitespaces at the beginning of linecomments
better handling of long lines eg string additions
"binpack":
  if an array fits equally into up to 3 lines use this instead of having each element in a newline
  struct/dicts get only packed if they fit into a single line, or half of the room for two lines
align comments in statements

* fixed linecomment forcing newline in simple splits
formatting of functionexpressions
```
@(blubb) {
  blah;
};
```

* fixed windows lineendings
fixed extra newline before long comment in certain situations
added option FormatterFormatInsideComments to deactivate trimming and
replacing of tabs

* fixed typo..
ecompile cfg is now FormatterIndentLevel

* FormatterBracketAttachToType: array{} vs array {}
FormatterAllowSingleLines: allow single line case/functionrefs

* align case label expressions
comments at the end still make the expression packable
other bugs

* better detection of case labels, by buffering the text. fixed more
problems with comments while packing lines

* do not allow more then 3 lines to be packed to a single one

* fixed hopefully last bug with comments and packing

removed FormatterAllowSingleLines
added
 FormatterAlignTrailingComments
 FormatterAlignConsecutiveShortCaseStatements
 FormatterAllowShortCaseLabelsOnASingleLine
 FormatterAllowShortFuncRefsOnASingleLine

* better linesplits when prefferedBreak is used (functions with params)

* fixed unalign lines with comments in arrays

* simplified ecompile code, use callback for compilation during iteration
through the directories.
use for pkgs recursive_directory_iterator

* core-changes

* onlinedocs

* onlinedocs-typo

* corrected cfg

* do not touch comments at all when disabled
detect aligned */

* fixed group formatting in var statements in more complicated situations

* when packing finishes right before the last element check if this
element also fit into the last line

* remaining ); or similar parts dont start a new line during group
formatting

* fixed edge cases of preferredBreak tactic with paranthesis alignment

* changed defaults, updated docs
2024-09-13 06:49:00 +02:00
Kevin Eady
ad4882821c
Use SLL parsing with ANTLR (#708)
* use SLL parsing

* Move listeners, fix error catching

* Move error listeners back

* fix warning

* docs
2024-08-31 09:16:14 +02:00
turleypol
50a6658883
Formatter variable declaration, align open parentheses (#691)
* Formatter: variable declaration list gets aligned with "var" breaked at
the comma.
if a linebreak happens while a paranthesis is open align next line with it

* added corechanges
2024-08-11 22:09:30 +02:00
Kevin Eady
88b4f9923d
Allow function reference calls across executors (#687)
* Allow function reference calls across executors

* Update core-changes

* Address review todos

* Change Globals2 to reference

* Revert "Change Globals2 to reference"

This reverts commit 37e37506be.

* Change Globals2 to shared pointer

* Address review comments
- Remove handled TODO comment
- Move arguments passed by value
2024-08-10 17:43:21 +02:00
turleypol
17911b23aa
impptr_if method/impptrIf function to test and return Imp derived classes (#685)
* impptr_if method/impptrIf function to test and return Imp derived
classes.
Simplified a few spots

* more usage of impptr

* fix makeDouble

* fix warnings

* more warnings

* more warnings..

* replaced new/remaining casts

* non owning imp* needs to be protected

* silly me
2024-08-07 22:14:52 +02:00
Kevin Eady
a780712ec7
Add spread operator for array initializers, function calls, and method calls (#684)
* Update grammar

* Update parser and AST generator

* Update semantic analysis, tests

* Handle instruction generation

* Executor implementation
- Instruction `ins_storestackcount`
- Instruction `ins_spread`
- Update listfile tests for new `storestackcount`` instruction

* Add tests targetting resource tracker

* Revert "Executor implementation"

This reverts commit f0caede24179cb11b6d98c8cd1fecd91ce546148.

* New instruction implementation
- Introduce `BSpread` object to manage spreading an object at runtime.

* More tests

* Fix memory leak

* Add test spreading non-arrays

* Add failure reason to bfunc method call
Better than getting uninit

* Core changes; docs + accompanying tests for docs

* Resolve CI annotation warnings
- this statement may fall through

* Fix listfile snapshots due to base rebase, whoops
2024-08-06 23:34:24 +02:00
Kevin Eady
6ed593ac81
Add function reference table to EScriptProgram (#686)
* Introduce FunctionReferenceRegistrar
- Track function references created by functors
- Remove ValueStack-held attributes for functors
- Add Function References section to escript program
- Use Function References section in ins_functor
- Update escript version

* Update listfile snapshots
- Remove ValueStack-held attributes created by functors

* Add function reference tracking to function references
- `emit.function_reference` uses funcref registrar + emits that index
- `ins_funcref` uses parameter count + is variadic from prog funcref table
- update listfile snapshots

* Add core-changes
2024-08-06 20:29:02 +02:00
Kevin Eady
93645f0770
Add variable arguments to user functions (#679)
* Update grammar

* Update parser and AST generator

* Update semantic analysis

* Executor implementation
- Move Executor stack modification logic to BFunctionRef
- Handle user function calls
- Handle expression function calls

* Tests

* Update existing listfile snapshots
- Adds variadic boolean to instruction stack
- Changes instruction counts and offsets

* Fix test issue

* Better implementation of calling user functions

* Add var-args-captures test

* Refactor continuation handling + handle variadic args
- Move stack modifications from make/withContinuation into the executor's handling of the continuation
- Only trim args in continuation call if function is not variadic

* Add var-args-continuation test (via array.filter)

* update escriptguide + formatting, docs

* Fix CI annotations
- '=': conversion from 'size_t' to 'unsigned int', possible loss of data
- declaration of 'continuation' hides previous local declaration
2024-08-04 17:13:30 +02:00
turleypol
f9bd3de71b
destroy modules already in the UOExecutor deconstructor (#681) 2024-08-04 15:13:00 +02:00
Kevin Eady
cfd241bb93
Add support to change House multi id via house.set_multiid() (#677)
* Some changes
- add house `MTH_SET_MULTIID`
- `UMutli::multiid` protected, rename to `multiid_`
- Make setting `multi.graphic` a no-op

* implementation

* initial test

* add walkon, collision tests

* Address review comments
- Add nullptr check

* Add ability to pass string name; tests;

* Add docs

* update objref.xml datemodified
2024-08-03 15:08:43 +02:00
turleypol
cf0c730181
switched impptr to template with default type (#680) 2024-08-03 12:35:01 +02:00
Kevin Eady
d1a1bd3afe
Additional escript array functional methods (#674)
* Implementation change for continuation handling

* Implement array methods find, findIndex, map, reduce

* Add tests

* update filter test for coverage

* update docs

* change implementation to not copy

* update tests; add tests for "polyfill" comparison

* update escript guide
2024-08-02 20:39:32 +02:00
Kevin Eady
060814ec67
Fix function expression assignment to locals and captures (#676)
* implementation

* tests

* docs
2024-08-01 20:22:21 +02:00
Kevin Eady
e43cc86c19
Fix function expression captures to be byref (#675)
* implementation

* tests

* docs
2024-08-01 12:26:49 +02:00
turleypol
d2450b0508
improved escript formatter when formatting if's/function parameters (#673)
* improved escript formatter when formatting if's/function parameters

logical operators get now a preferred break style same for commas in
function/program parameters. split based on this flag the line

* when logical "and/or" and commas from function parameters are in one
line only split based on logical ones

* core changes
2024-08-01 08:00:35 +02:00
turleypol
9e9f8a9656
further simplyifications for memorysize calculation (#672) 2024-07-30 07:58:46 +02:00
Kevin Eady
f381f46dc3
Add compiler support for function expressions (#671)
* initial poc of function expressions
- update grammar
- mock AST builder to return BBoolean(true) for a func expr
- update prettifier for skeleton implementation

* more skeleton work
create AST class FunctionExpression mimicking boolean value

* create ast UserFunction, add to workspace from functexpr

* can generate instructions

* reorg tests; add test for instructions

* can track FunctionDepth in Variable

* can get captures for funcexprs inside funcs.. tbd if this way of nesting works

* Implement create-functor instruction
- Move function depth from Variable to Variables
- Introduce stacking of `Variables` for function expresions via `FunctionVariableScope`
- Add `TOK_FUNCTOR` instruction for 'create-functor'
- Handle emitting a `FunctionExpression` AST node
- Update `emit.declare_variable` and `emit.access_variable` to account for function captures
- Remove `in_function` from instruction generator, as it is tracked via `UserFunction` stack
- Update tests

* Address Discord comments
- Swap pop param order

* Bubble up captured variables through nested functions

* Improve testing infrastructure; add some test cases

* Fix compilation error

* prepend captures to function parameters in funcref mth_call

* update tests

* move from function{} to @{}

* implementation fix

* some more tests

* update docs

* Some cleanup

* fix CI annotation warning
- 'argument': conversion from 'size_t' to 'VariableIndex', possible loss of data

* Address review comments
- Add `passert_always`
- Use better example in docs

* Some cleanup
- Remove unused functions
2024-07-29 22:30:52 +02:00