Commit graph

650 commits

Author SHA1 Message Date
turleypol
7ff9d877a8
Funcrefs do not detect pid change (#889)
* test for sending a function to the same program

* store executor pid inside funcrefs and classes

* docs
2026-05-31 11:45:35 +02:00
turleypol
552248917b
Fixed leak when a class/funcref is a global (#887)
* store globals as weakptr in class/funcs to prevent memleak when stored
as global WIP

* let it crash if globals are no longer valid?

* typo

* removed debug prints

* let only the current executor crash

* fixed logic

* added and corrected tests

* cleanup

* use emplace_back

* classes also need to switch to weakptr

* docs
2026-05-27 08:02:19 +02:00
turleypol
4dd34a9442
using fmt instead of ostringstream (#873)
* using fmt instead of ostringstream

misc cleanup

* missing external libs for clang tidy check

* added test for cprops ignore while stacking
door descriptor

* use contains instead of count, removed disabled ancient code

* pack/packonto simplification/speedup

instead of using ostream and convert to string, use format and directly
a string
2026-04-06 16:21:50 +02:00
turleypol
5bd71ae8ee
Non blocking gump cmd (#871)
* refactor gump pkt creation

* testclient returns buttonid 1 pressed when 'button' is contained in the
commands

* extended test

* cleanup destructor mess a bit

* store gumps as pair to decide if the executor needs to be revived
more refactoring

* disallow copy, if used creates nasty bugs

* helper method to convert imp to character

* gumpevent

* new non-blocking dialog function, sends event instead

* test closegump

* test if serialnumber gets correctly converted and invalid entries get
skipped

* removed unused BApplicPtr class
added BApplicObjBase to impptrIf convert function

* use impptrIf

* CloseGump accepts now also an array of characters
extended tests

* moved deleted copy constructor to the public part

* by default clang tidy will check .inc files, removed this filter

* the last tidy run with modernize-loop wasnt added to the PR check

* keep vector with chr and gumpid per uomod
to prevent growing dont add to the cache if same chr with same id
already exists.

* docs

* core-changes
2026-03-16 08:11:43 +01:00
turleypol
be23b47c86
use unique_ptr to store BSpecialUserFuncJump to be able to delete instance before leftover imps are displayed. (#867)
its not an actual problem aka leak, but confusing since it gets reported
2026-02-20 12:17:55 +01:00
turleypol
24c8c8b92f
Tidy modernize for loops (#862)
* trigger loop convert

* Automated clang-tidy change: modernize-loop-convert

* fixed refactor

* Automated clang-tidy change: modernize-loop-convert

* compile

* first look through

* fixes and start to use a few ranges

* revert autogenerated file

* compilation fix

* second pass

* renamed loop variable

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-31 09:14:02 +01:00
turleypol
da2943acb8
Tidy copy initialization (#859)
* trigger tidy

* copy&move BApplicPtr obj
always commit tidy changes

* move PolObject

* fix house add_component

* Automated clang-tidy change: performance-unnecessary-copy-initialization,performance-unnecessary-value-param

* Revert "Automated clang-tidy change: performance-unnecessary-copy-initialization,performance-unnecessary-value-param"

This reverts commit bb6aab13dbdfa4aaf420cdaafaf22940f241fc5b.

* performance-unnecessary-value-param gives some weird suggestions

* Automated clang-tidy change: performance-unnecessary-copy-initialization

* minor performance improvements

* added used tidy check

* missing dependency

* renamed build so its no longer requires?

* better add docs for the sneaky fix

* silence pr check, not all headers can be compiled seperatly

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-19 08:17:28 +01:00
turleypol
bce1154d7a
ClangTidy readability-else-after-return (#857)
* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-18 09:35:52 +01:00
Lukáš Novotný
cf0346780b
do not include full program in funcref memory estimate (#856) 2026-01-17 18:44:02 +01:00
turleypol
21577d8e5b
Clang Tidy concat namespaces (#855)
* tidy

* Automated clang-tidy change: modernize-concat-nested-namespaces

* compile test

* fix namespace

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-17 10:30:21 +01:00
turleypol
6cc0d1698b
Clang Tidy replace typedefs with more readable using (#854)
* trigger tidy

* Automated clang-tidy change: modernize-use-using

* compile test

* unnamed struct fix?

* more unnamed structs

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-16 18:45:47 +01:00
turleypol
c882c42a31
misc clang-tidy (#853)
* trigger tidy

* Automated clang-tidy change: modernize-use-equals-delete,modernize-make-shared,modernize-make-unique,modernize-use-constraints,readability-container-size-empty,modernize-redundant-void-arg,modernize-use-emplace

* removed non needed macros

* missed to disable tidy build

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-16 12:22:43 +00:00
turleypol
bc9064c338
Clang Tidy default constructor (#852)
* trigger clang tidy

* Automated clang-tidy change: modernize-use-equals-default

* compile test

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-15 22:31:14 +01:00
turleypol
9dbdc7e91b
ClangTidy "modernize-use-override" (#851)
* let clang-tidy do its thing

* Automated clang-tidy change: modernize-use-override

* compile test

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-14 21:35:59 +01:00
turleypol
15409a3469
Class call_method refactor (#850)
* refactored call_method for classes

* cleanParams have to be called after func result is set

* added special bobjectimp to skip valuestack modifications
(Todo: name and comments)

* cleanup
2026-01-14 19:12:19 +01:00
turleypol
0259f11475
Class method if it's a method_id call now works if parameters are given (#849)
* modifed test to trigger the failure

* getParams modifies the ValueStack and thus cannot be called twice.

* docs
2026-01-10 18:12:09 +01:00
turleypol
37bbf0acd2
Fixed method_id call for class methods (#840)
* method-id calls on classes need to be redirected to non-id instruction

* added corechanges

* fixed compiler warning
2026-01-10 10:18:58 +00:00
turleypol
bf4ec1951d
Write filenames and lines into ecompile .lst files (again) (#846)
* ListingWriter prints filepath, filelineno and source line
the old compiler did it, now again in the new compiler
since shortcircuit the original sourcelines are available during compilation

* remove listfile.inc function from test result

* prefix output

* custom formatting

* docs
2026-01-07 22:19:25 +01:00
turleypol
58a6db75be
Integer overflow when using GetConfigInt (#844)
* impptr_if now accepts also const BObjectImp*

* cfg::GetConfigInt returns error if the value would produce an overflow
code cleanup of cfgmod
added tests

* increase test coverage

* added comment why the exception should be catched without reaction
fixed member_id test

* added corechanges
its 2026
removed else
2026-01-04 13:22:11 +01:00
turleypol
6ff48974cc
Code cleanup (structs and container add) (#842)
* BStruct cleanup

* container::add method has now a parameter for the position. reduces the
ambigous setposition calls.
And makes it clearer where the item is created.
removed in the touched headers the non needed virtual.

* removed exception when accessing a struct via an integer, no need to
crash the shard

* fixed test

* missed one virtual
2026-01-03 23:02:53 +01:00
turleypol
ed1b61aab9
Optimize comparison helper class for containers (#826)
* use transparent comparator to optimize away temporary string creation

* missing headers
should be case sensitive compare not insensitive

* flyweightstring support
made it insensitive again
next missing header

* more missing includes :(

* simplified via small wrapper

* allow also char[], removed on caller side some temp object creation which are no longer
needed

* it still only accepts string like objects.. fixed

* switched to strnicmp added comments

* missing header

* fixed comparison

* added unittest
2026-01-02 15:04:19 +01:00
turleypol
1699d413f0
More cmake options and fixed build of more esoteric platforms (#834)
* fixed compiler warning
removed ancient libc check

* extended gitignore

* cmake option to change binary output dir and external lib download dir
updated Efsw
fixed linking under android

* readded missing add_library

* c&p error

* updated Efsw to latest version
2026-01-02 14:29:52 +01:00
Kevin Eady
7bc59bb2fa
Pass OfflineCharacterRef for equip, unequip scripts character parameters (#827)
* use offline char ref for equip, unequip scripts

* add Character script member logged_in; docs; tests

* update core-changes for Character script member logged_in

* Add breaking-changes note
2025-11-19 14:22:39 +01:00
Kevin Eady
5cf6949ea7
Add support for regular expressions (#818)
* implementation

* tests

* maybe fix windows compilation?

* undo change of match_flag_type

* switch to boost regex

* move flags to BRegExp object

* fix tests due to cmake 4 update

* update grammar

* update prettifier

* move flag parsing to BRegExp ctor

* add AST nodes, update instr generation and execution

* copy tests but use regular expression literals

* fix grammar for handling division correctly

* modify return values a bit, update tests
- string.match: make groups hold structs of matched, offset
- string.match: add offset
- string.replace: use a groups array like string.match vs individual arguments

* bundle of changes

- standardize error messages
- add more tests for coverage
- move BRegExp creation to static method:  previous implementation had
  ctor throwing, which was no good inside executor since it didn't have
  a try/catch

* more tests; add OT_REGEXP to basic.em

* move string regex stuff to bregexp and support regex/wregex via std::visit

* maybe fix compilation errors?

* add unicode escape sequence handling

* really maybe fix compilation error?

* fix compiler warnings

* refactor a bit to remove duplicate code

* address discord comments
- just return wstring, no need for vector<wchar_t> method

* Add string.split by string and regexp

* Use Max_Split instead of Limit
This makes it match basic::SplitWords

* add support for empty string delim in SplitWords

* remove duplicate code across string.split and mf_SplitWords

* Squashed commit of the following:

commit b3148e069f
Author: turleypol <turley@polserver.com>
Date:   Sat Sep 27 17:02:22 2025 +0200

    memorylocation of input string is not allowed to changed, switched back
    to uniqueptr

commit 5a4d1c8fcb
Author: turleypol <turley@polserver.com>
Date:   Sat Sep 27 10:18:01 2025 +0200

    no need to use ptr for input

commit 90fa0edc66
Author: turleypol <turley@polserver.com>
Date:   Sat Sep 27 09:56:29 2025 +0200

    fixed typo

commit bed4ff3ac9
Author: turleypol <turley@polserver.com>
Date:   Sat Sep 27 09:47:36 2025 +0200

    make Callback for BContinuation move only

* use uninit when group isn't matched

* fix multiline flag handling; add test

* add docs and doc example tests

* some cleanup

* address review comments
- allow move assignment

* add core-changes
2025-11-17 18:02:45 +01:00
turleypol
4bd1e9c3d8
use git diff to compare testresult of escript tests (#822)
* use git diff to compare testresult of escript tests

* fixed return type of "is" for non classes
2025-10-01 12:27:17 +02:00
Kevin Eady
59046fdc7c
Normalize TypeOf and TypeOfInt return value for ClassInstanceRef (#821)
* implementation

* tests

* docs and core changes

* fix tests due to cmake 4 update
2025-09-29 08:55:48 +02:00
Kevin Eady
c292058283
Skip internal errors for unlinked inherited base classes (#815)
The SemanticAnalyzer was incorrectly reporting internal errors when a
class parent inherited from an unlinked class. The error will already
have been reported, when visiting the class parent.
2025-09-06 19:03:35 +02:00
Kevin Eady
c286b49858
Fix handling of byref, rest, and default parameters in uninitialized functions (#814)
* Update grammar

* update prettifier

* Update semantic analysis
- Move checks for 'super' and non-static to semantic analyzer
- Add checks for byref and default

* Add, update tests

* update escript guide, add tests for examples in guide

* update core-changes

* Address Discord comments
- Update core-changes to explicitly talk about default parameters
2025-09-06 17:26:06 +02:00
Kevin Eady
ddc1b5d26b
Add Escript support for uninitialized class functions (#808)
* update grammar

* AST nodes and test

* Address self-review comments
- Replace `super` comment with something more explanatory
- Rename `make_user_function`

* add class analysis for uninit functions

* fix ast test after disallowing static uninit funcs

* use std::ranges::find_if

* add tests

* use SUPER constant; add test

* Remove unreachable code leftover from #809

Since #809, the super function is only generated for a class when
registering a parent class, and therefore it will always have a body. A
"No base class defines a constructor" will only occur if super was never
generated, and is handled in the "No function linked through
FunctionResolver" section of semantic analyzer.

* Address review comments
- use std::ranges::move instead of move iterators
- use std::is_same_v<> vs std::is_same<>::value
- use switch vs chained ternary conditionals

* update escript guide, create tests that are in escript guide

* add core-changes

* Error on uninit and defined constructor

* Move methods' FunctionLink construction to builder

This allows the error message for the uninit function to have a "See
Also" that point to the defined function.

* Move error checks for uninit and defined functions

These semantic checks should be in the ... SemanticAnalyzer.

* fix typo in core-changes
2025-09-05 23:23:59 +02:00
Kevin Eady
e26f356678
Fix generated function (constructor, super) registration (#809)
* move compiler-generated ctor registration to within class declaration registration; update test error messages

* add more ctor inheritance tests

* skip "Unknown identifier" error for calling undefined ctor

* add test for actual, previously crashing source

* add test for actual, previously crashing source

* move compiler-generator super registration to within class declaration registration

* add super local var test

* make register_available_generated_function private

* remove ClassDeclaration::has_super_ctor

This property was based on if FunctionResolver created the function, so
the logic can be moved to FunctionResolver.

* add core-changes

* use constant for "super" string
2025-09-04 17:37:40 +00:00
Kevin Eady
a6d81bbaec
Fix issue with unresolved base class static methods (#807)
* implementation

* tests

* docs
2025-08-24 21:18:17 +02:00
Kevin Eady
0fcc5060af
Enum class fixes (#805)
* fix enum classes entries without initializer

* docs

* update grammar to support scoped identifiers in case labels

* add support for enum class constants in case statements

* add ScopableName to ConstDeclaration; formatting fixes; tests

* update docs
2025-08-19 09:07:02 +02:00
Kevin Eady
003274de55
Add Escript support for enum class (#804)
* update grammar

* implementation

* tests

* docs and core-changes

* cleanup old .cot files

* add error on duplicate class, enum class definition; tests

* Fix compiler warnings

* add test for unscoped identifier failure
2025-08-18 20:50:18 +02:00
turleypol
ba47821156
further optimize shortcircuits (#800)
* further optimize shortcircuits
combine jumps if possible
dont emit logicalconvert instructions if the next instruction is another shortcircuit jump

* docs
2025-08-12 08:52:50 +02:00
turleypol
5fe8449df8
cleanup of executor (#801)
* cleanup of executor
mostly just minor cleanup
got rid of ESCRIPT_PROFILE define inbetween function/method calls by
moving the logic into a class (which is empty without the define)

* use a macro for profiler so that even in debug builds the class never
gets called without the define
2025-08-08 09:08:12 +02:00
turleypol
fb3faddeae
use c++20 (#799)
* use c++20
* increased used clang version
* compiler report and logfacility use now compile time formatting, which
means that the formatstring gets checked at compile time. (which found 2 errors)
adapted a few places since report only accepts formatting arguments
adapted a few places with logging since char[] is compile time
formatting and string or chr* is runtime formatting
* use std::ranges instead of boost
* disabled pragma_assume vs specific macro (I guess noone cares)
* needed to fix ancient ms exception code
* modernized SpinLock
* removed unused code in ECompile
* replaced std::filesystem::path::u8string with string. It now returns an actual u8string type
* cleanup layers.h added the defines for other layers which where before
  only defined in the pkt
* osmod::OpenConnection and HTTPRequest cleanup: early outs, dont check for pChild which is
  only needed for startscript and placed suspend at the very last
  position

* fix warning

* rebuild cache with new compiler version

* define c++ standard for external libs where possible

* added fixme
2025-08-01 21:40:10 +02:00
turleypol
7090c64840
Short Circuit Optimizer (#797)
* first working short curcuit for && and or
creates jumps after each expressions to skip the following

* fixed valuestack when short circuit jmp does not jump

* use specialized instructions for short circuit && and ||

1: lhs
2: logical jump if false/true goto 4 <- if jmp do logical convert
3: rhs
4: logical convert
5: rest

logical convert is needed since "normal" && || operations convert isTrue
to BLong

added BObjectRef BObjectImp set specialization to remove noise

* fixed converted objimp when jump on false values

* first version of short circuit warning
should be moved to analyzer
added whitelist of module functions which have no sideeffect to reduce
the number of warnings

* moved warning visitor to analyzer and added it as extra compile step
fixed sourceline print and cache the content

* missing include, unused member

* included the correct header

* ecompile.cfg to activate and warn
ecompile cmdline arg to activate it
run all tests also with it active
fixed that only the most right side statement was checked

* ecompile cmdline

* increase ecompile version
cleanup

* compilation error

* missing header

* allow -S- to deactivate shortcircuit like the other params do

* extended whitelist functions

* revert fileformat version increase
fixed escript test cmake

* use the correct arg

* escript testoutput can now be different if shortcircuit is active

* docs

* additional test

* addressed comments
2025-07-28 21:48:34 +02:00
Kevin Eady
87e0c534f4
Add ecompile flag -Z to print AST (#796)
* Add -Z option to print string tree

* Simple test to print an AST

* Make CompiledScript owner of the tree

* some refactoring
- rename ecompile.cfg option
- rename AST generator class

* core-changes, docs

* fix warnings
2025-07-23 23:00:34 +02:00
turleypol
c0bfd2f820
Escript Optimizer more types and operator (#794)
* compile time optimization:
int with doubles and strings
doubles with ints and strings
strings with ints and doubles

* bool with other types, more unary ops, float branch optimizer

* more tests
fixed bool to dbl compare

* output cleanup
more tests

* optimize string values in if statements, optimize ternary operator

* optimize elvis, addes missing files, code cleanup

* use array to keep unoptimized if branch in funcexpr tests

* missing include

* better readable testdata

* removed file

* optimize while and dowhile loops if predicate is a compile time known
value

* cleaner variant of loop optimization?

* added ConstantPredicateLoop Node used by the optimizer for constant loop
predicates
optimize repeat until loop
change tests to run the loops more then once to be sure they work
correctly

* test break/continue with label for constant-loop

* docs
2025-07-10 22:32:29 +02:00
turleypol
21819aacee
Download more external libs from official GitHub repos (#787)
* download Curl, Kaitai, PicoJson, Utf8, ZLib from github
updated versions

* typo

* updated curl cache
2025-06-25 19:55:42 +02:00
turleypol
3bf1af9892
Updated fmt lib to latest release, fixed unreachable code warnings (#786)
* updated fmt to 11.2.0
compile on windows with utf8 activated
added missing include

* fixed unreachable code warnings
mostly constexpr if statements

* removed forloop since it triggers unreachable code warning when it
breaks always after first iteration.

* delay debugger testscript end

* removed fmt lib from repo and download from github
2025-06-24 19:53:21 +02:00
Kevin Eady
9a19423b0e
Add Packet script method assign( Packet other ) (#784)
* implementation

* tests

* docs

* remove improper check for is_variable_length in SetInt8
`SetSize` returns false for non-varlength packets

* address Discord comments
- use std::max for packet `newsize`
- use vector assignment operator for copying
2025-06-23 21:21:11 +02:00
Kevin Eady
000b7f100b
Fix Array method findIndex changing array content (#780)
* fix implementation

* add tests

* add core-changes
2025-05-24 17:21:24 +02:00
turleypol
4f0e6ac548
Modulus operations with doubles (#769)
* implemented modulus operator % and %= for doubles
int%dbl=dbl
dbl%int=dbl
dbl%dbl=dbl
...

* added missing test for ins_set_member_id_consume_divideequal

* more tests
docs
2025-02-23 16:06:52 +01:00
Kevin Eady
d0bbf0a886
Fix warnings introduced in binding PR (#766)
* fix problem matcher

* Fix warnings introduced in binding PR
2025-02-20 06:50:30 +01:00
Kevin Eady
6c7a2b0a30
Add support for spread operator in dictionary and struct initializers; FormatterEllipsisSpacing formatter option (#763)
* update grammar

* implementation

* formatting

* executor implementation, tests

* docs, core-changes

* fix warning introduced in #760

* add format option FormatterEllipsisSpacing

* update core-changes
2025-02-19 18:33:56 +01:00
Kevin Eady
ec344a395d
Add support for sequence and index bindings (#760)
* update grammar

* add ast nodes; ast building

* Rename to unpacking

* semantic analysis

* executor work part 1, unpacking indices

* renamings; implement index binding

* small cleanup

* use multi_index; more tests

* use multi_index only for rest, otherwise list

* initial formatting

* add missing token decoding

* address self-review comments

* formatting tweaks

* add test for var binding in classes

* add StringIterator

* fix spread tests

* add cfgfile iterator; add cfgelem opersubscript; tests

* add iterator for SQLResultSet and SQLRow; tests

* Copy value in take global/local

* Allow any iterable can index rest unpacking
Always use dictionary as rest object in index unpacking

* add docs, core-changes, doc tests

* formatting changes...

* address self-review comments

* update formatter, format all binding test srcs

* address review comments
- unset var scope

* add cfgfile/cfgelem docs

* reformat objref svg
2025-02-17 21:59:42 +01:00
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