Commit graph

97 commits

Author SHA1 Message Date
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
Kevin Eady
21fc580e66
Add filter method to escript arrays (#667)
* POC of calling user functions from core

* rename to BContinuation

* fix annotation warnings

* fix annotation warnings 2

* some cleanup, comments

* add more params to filter

* add more tests

* fix stack issues, wip determine what to do with printStack helper testing function

* print stack only for debug; increase OTContinuation to 100

* docs

* remove debugging leftovers
2024-07-28 22:51:04 +02:00
turleypol
c046da4d5a
Moved target/menu members from char to ClientGameData, simplified memory size estimation (#668)
* moved more members from Character to ClientGameData
reordered a few members to reduce padding
added memsize functions for std containers to simplify code

* few more comments
2024-07-28 10:42:47 +02:00
Kevin Eady
271722af13
Send Print() messages to attached debugger (#663)
* Implementation

* Tests

* Update core-changes

* Implementation fixup
- do not copy message from executor
2024-07-16 12:41:55 +02:00
Kevin Eady
e80d5a8074
fix locals state after initforeach instruction (#657) 2024-07-10 20:01:59 +02:00
Kevin Eady
686090d950
Introduce DAP Debugger (#608)
* Add cppdap debugger library and simple server (#508)

* Add cppdap library

* Add cppdap server

* fixup cmake scripts for windows

* Enable caching of cppdap on GitHub actions

* Fix CMake for cppdap target

* Wait 1s for session close before thread ends

* Address review comments
- Remove unnecessary use of wait_for
- Fix wait_for method

* Do not use SocketClientThread for cppdap clients

* Address review comments
- Cleanup object ownership

* Add authorization and event handling (#510)

* Add authorization and event handling [WIP]

* Use std::weak_ptr; Only allow one debugger conn

* Only attach debugger if dbg file exists

* Cleanup weak_ptr; Fix listeners; Add handler stubs

* Address review comments
- PolLock on uoexec and weakptr access
- Use make_shared when creating client thread

* Add ExecutorDebugListener on_destroy callback

* Use cppdap sockets instead of clib sockets

* Update cppdap repository to 2703cf4

* Implement server address binding

* Update cppdap repository to eeca5ce

* Fix warnings

* Use weak_from_this

* Fix stalled executors on disconnect

* Fix stalled executors on re-attach

* Clear uoexec weakptr on all debugger detaches

* Move server to gamestate

* move DapDebugServer into Network namespace

* move DapDebugServer into GameState for storage

* Move DapDebugServer into NetworkManager

* Fix missing memory include

* Add more events (#513)

* Add more events

* Implement dbg_step_out

* Fix breakpoint clearing

* Add even more events (#515)

* add launch request

* Add custom `processes` command

* fixup loop

* Refactoring to move handlers to member functions

* Add VariablesRequest and ScopesRequest

* use std::varaint for Handles

* add pollocks

* refactor Handles to new file

* move custom messages to proto.h

* move clientthread

* some formatting / cleanup

* Add missing PolLock

* move dap variables creation to Handles

* appobj members

* rename ClientThread to DebugClientThread

* rename LaunchRequest args to arg

* Fix compiler error on size_t

* Add support for EvaluateRequest and SetVariableRequest (#519)

* Update grammar for evaluateUnit

* Cleanup various compiler code

* Add support for EvaluateRequest
Only supports values, variables, element access, member access

* Add report clearing to reinitialize state

* Add support for SetVariableRequest

* Fix CI build errors

* Move ExpressionEvaluator to Bscript

* Fix formatting

* Fix include

* Refactor global and frame variable references

* Encapsulate Executor debugging environment; Fix step over (#524)

* Fix step over

* Some cleanup of executor
- Remove unused debug states
- Rename members for consistency

* move debugging environment to new class

* Move instruction inspection to class

* Cleanup slashes on Windows; Add Executor state to processes response (#527)

* Fix backspaces in script names on Windows

* Fix compilation warnings with data loss

* Use boost::icontains for string comparison

* Add Executor state to processes response

* Updates for libfmt

* Fix tests; Fix cppdap build for Mac universal binary (#607)

* fix tests

* fix cppdap build for mac universal binary

* Update cppdap to 2a4c7cf

* Add tests; Modify launch behavior to not stop at entry (redo) (#609)

* Remove unused setExceptionBreakpoints handler

* Add debugger tests

* Launching a script should not set attaching state

* Add launch tests

* Do not check for connection in debugger tests

* Rename `program` to `script` in protocol structs

* Fix launch stopAtEntry; quote string var values

* Fix compilation error on Windows

* Add configfiles doc entry

* Various fixes for finishing touches; Add core-changes (#610)

* switch cmake projects

* simple docs

* cmake move make_directory

* Fix launch request with relative, absolute, package paths

* make relative paths as absolute in source request

* Add true, false, uninit to ExpressionEvaluator

* Re-add setExceptionBreakpoints to avoid unhandled message errors

* Better debug thread logging with instance numbers

* launched scripts should terminate on disconnect (according to DAP spec)

* Properly handle exited event in client thread

* Add core-changes

* Address Discord comments
- Mention vscode-escript in core-changes
- Re-add "cppdap already built" in cmake

* change cmake escriptgrammarlib visibility to public
2024-01-28 09:49:55 +01:00
Kevin Eady
593cfffb83
Add uninit, true, false keywords to grammar (#596)
* Update grammar

* Update expression handling for uninit

* update existing tests

* Add new tests

* Remove fullpath from escriptgrammar generation comment

* fix tests

* Update eScript guide

* Declare escript version 0x11

* Add core-changes

* Add `true` and `false` to grammar

* true/false implementation

* Fix existing tests

* Add new tests

* Update core changes

* add docs

* Fix BooleanValue::describe_to

* bool optimizations

* optimize uninit

* remove unused var assignments

* Update grammar for case labels for uninit, booleans

* Fix case label handling for uninit, true, false

* Tests

* Fix compiler version display v1.1700000017881393 -> v1.17

* optimize boolean binary operations

* fix unary boolean optimizer

* add boolean, uninit optimizer test

* Use new fmt lib apis

* Fix compiler warning

* really fix warning lol

* Add Executor[Module]::getParam for bools, FindSubstance test
2024-01-20 05:38:25 +01:00
turleypol
d848deae18
POLLOG* macros use the new formatting (#598)
* POLLOG* macros use the new formatting
removed all old logging functions

* removed old fmt lib from everything except StreamWriter
removed unneeded functions

* fixed review comments
2024-01-16 17:55:42 +01:00
turleypol
154a68a9fd
LEAKLOG, DEBUGLOG, SCRIPTLOG, FLEXLOG changed to new logging (#597)
* LEAKLOG, DEBUGLOG, SCRIPTLOG changed to new logging

* updated FLEXLOG
2024-01-13 17:08:33 +01:00
turleypol
0e675c516a
use new formatter for ERROR_PRINT, added ERROR_PRINTLN (#595)
* use new formatter for ERROR_PRINT, added ERROR_PRINTLN

* remove old log define

* fix comments
2024-01-12 06:51:44 +01:00
turleypol
43b776b94d
New format lib version (#592)
* renamed include guard to be able to use both format lib versions in
parallel

* build Fmt lib and link it into clib

* use std::string instead of format Writer for logging
added variant "2" for logging with new fmt lib

* use new logging variant for two logs

* always add \n to flush log, lets see if the assumption holds

* use new lib for tostring

* replaced all INFO_PRINTS in clib

* formatter for Token, BObject and BObjectImp

* started with bsccript

* use function instead of actual object for logging

* remaining bscript, started plib

* logvariant without newline added, more template magic

* format support for base types, added test for format padding
new version for fdump

* chanhed ecompile/runecl fixed compilation with ESCRIPT_PROFILE

* rewrite INFO_PRINT in plib,poltool/uoconvert/uotool

* replaced remaining INFO_PRINTS, renamed macros INFO_PRINT for logging
without newline, INFO_PRINTLN for newline addition.
Replaced also INFO_PRINT_TRACE and renamed it to INFO_PRINTLN_TRACE

* gitignore for fmt lib

* cleanup vim leftovers
2024-01-10 18:29:10 +01:00
turleypol
37c2fb0299
Method function crash (#477)
* Crash reproducer with methods

* potential crash fix

* removed ASan build, added core changes

* do not store valuestack reference before calling method to fix potential
dangling reference

* Take into account that the ValueStack can grow due to method calls.
2022-10-16 19:39:25 +02:00
turleypol
95783a3226
removed ufacing move_delta, added getPos*Param (#424)
* removed ufacing move_delta, added getPos*Param

* renamed move_self to move_to
2021-09-12 14:39:06 +02:00
Fernando Rozenblit
ab96d4ce60
Add more details to "Return without GOSUB" error. Also fix printing of INS_CALL_METHOD_ID in the .lst (#395)
For INS_CALL_METHOD_ID, the number of parameters 'type' is u8 and was being printed as char.
2021-08-31 08:06:20 +02:00
Kevin Eady
e41f70d72e
Add support for interpolated strings ("interstrings") (#369)
* Update grammar to support interpolated strings

* Struct initializers, case switchs are regular strings

* Initial stub for interpolated string in AST
This splits the previous STRING_LITERAL terminal into a production,
stringLiteral, to handle REGULAR_STRING terminal and interpolatedString
production.

* Change interpolated strings to expressions

* Fix mode handling in grammar

* Grammar fixes
- Fix mode handling in lexer
- Interpolated strings only have one expression

* Can successfully parse, stub compile interstrings
$"He {there + print("hello")}";

* Add formatting string to grammar

* Fix tests, and add test stubs

* Rename curleys to brace; better AST generation

* initial work interstring instruction

* Initial work on formatted string instruction: emit

* Formatted string instruction: execution

* Add simple formatted string test

* Add formatted string test src

* Review changes #1
- Rename `FormattedString` to `FormatExpression`
- Rename overloaded `try_to_format()` to `get_formatted()`

* Review changes part 2
- Rename `InterpolatedString` ast node to `InterpolateString`

* Review changes part 3
- Modify `ins_interpolate_string`

* Review changes part 4
- Remove unused formal parameter

* Add negative tests

* Spruce up positive tests

* Fix braces, escape chars inside interstring

* Fix, add tests for escaped char and double brace

* Address differences for new lines in tests

* Update Escript version

* Make empty expression an error

* Add documentation for interpolated strings

* Quick touchup on docs
2021-03-11 22:48:16 +01:00
Eric Swanson
464a3643c1 Remove unused Executor.makeObj() 2020-06-17 00:23:42 -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
13c66d7b82 fixed memleak when oldstyle unicode arrays are used 2020-01-03 19:29:40 +01:00
turleypol
da4ef6d950 added test for ++ member_id 2019-10-04 16:47:24 +02:00
turleypol
8f0da8b9e9 fixed refptr::set when given pointer is equal owned one.
Removed workaround in executor to temporary increase refcount of
BObjectImp
2019-09-26 21:50:23 +02:00
turleypol
fc523320d9 added support of ++/-- for object members. 2019-09-26 07:06:45 +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
b2a3e1b792 starting to support i++ 2019-09-22 00:34:14 +02:00
turleypol
902c9cbfde first version of ++i and --i unary operator 2019-09-21 14:56:06 +02:00
turleypol
f5310f48f4 Merge remote-tracking branch 'origin/master' into utf8
* origin/master:
  Style...
  Getting rid of a warning
  Fixed wrong return type
  style issues :p
  Fixed the check for max line length and some other minor issues
  Added SocketLineReader class, which is responsible for reading lines from a socket in a more efficient way. Modified Aux, Debug and WWW to use the new class.
  removed some ancient macros from clib.h
  Added error for if NaN sent as PID
  Update docs to use different wording to prevent confusion.
  Updated Docs.
  Fix for GetProcess() not actually loading the parent PID.
  Update docs to use different wording to prevent confusion.
  updated travis build clang and ninja
  Updated Docs.
  Fix for GetProcess() not actually loading the parent PID.
  Improved network code used by http and aux servers

Conflicts:
	pol-core/doc/core-changes.txt
2019-09-02 18:55:07 +02:00
turleypol
691d330c07 removed some ancient macros from clib.h 2019-08-25 09:05:15 +02:00
turleypol
ebe884c2fe Merge remote-tracking branch 'origin/master' into utf8
* origin/master: (70 commits)
  Fix to items randomly loading with AOS props due to incorrect initalization of props on load of server.
  Rectify core not clearing mobiles from client during shadow realm shift.
  SendQuestArrow() fix for HSA clients (#91)
  Hotfix/start skill script (#90)
  Noninvasive dynaprops (#89)
  Update objref.xml
  Some network error conditions were missing...
  Final adjustments to core-changes
  Added Turley's missing core-changes :P
  Improved connection handling:  - Linux isn't limited to 1024 connections anymore  - Windows may have some slight performance boost
  removed senseless gitignore files
  use generator unspecific clean cmd in build_tools.sh always generate compile_commands.json force color diagnostic (to work with ninja)
  Curl building uses now the same compiler as pol
  fixed target_link_directories system header declaration
  check if container is orphan when adding items as content. for now it crashes the shard to have the backtrace. (would crash anyway later)
  add corechanges for doc changes
  new build target "clang_format" runs clang-format on current modified or new files in pol-core dir.
  Formatting
  Fix xml indentation
  fix indentation
  ...

Conflicts:
	pol-core/bscript/execmodl.cpp
	pol-core/doc/core-changes.txt
	pol-core/pol/getmsg.cpp
	pol-core/pol/module/unimod.cpp
2019-08-16 19:02:53 +02:00
turleypol
395083a31c memoryestimation did not add the module cost per executor
added EstimateSize util.em function returns estimated memorysize in
bytes of given argument. (docs to be done)
2019-02-01 23:18:43 +01:00
turleypol
ab89708107 completly converted all uses of convertArrayToUC, so all
functions/methods now accept arrays and strings
2018-12-31 16:25:34 +01:00
turleypol
3973851383 added getUnicodeStringParam needed for all the unicode em functions
which now accept only unicode arrays and should then also accept
strings
(arrays then only for backward compatibility)
2018-12-31 11:59:47 +01:00
turleypol
4f40aa7997 removed Clib::decint and used Clib::tostring, changed Clib::hexint to
template function for all integers
2018-10-28 09:31:58 +01:00
turleypol
892005f2b0 code simplification, deprecate warning for uoclient.cfg MethodScript
entry
2018-10-13 21:46:41 +02:00
turleypol
a5e6206164 Added cmake option to run clang-tidy
used everywhere nullptr
2018-10-09 16:36:35 +02:00
turleypol
0a39af15a1 Changed classes to be final if possible, removed override macro 2018-10-09 09:47:27 +02:00
turleypol
fd1dcb6512 switch tests where never executed :(
fixed unaligned load for switch statements
2018-06-03 21:54:16 +02:00
Gabriele Tozzi
72fc9d1ae4 Breaking long lines 2018-04-03 04:24:00 +02:00
turleypol
3afc41241b
CMake on windows (#48)
CMake can now also be used for windows
2018-02-24 22:34:55 +01:00
turleypol
2ba436bd56 protected functionref to be executed in a different script
added testscripts
2018-02-04 16:08:03 +01:00
turleypol
9d3cd4ffd5 fixed unittests, removed remaining debug prints 2018-02-04 12:56:08 +01:00
turleypol
d7fbb4ac8e cleanup debug prints
fixed funcref implementation
2018-02-04 11:58:26 +01:00
turleypol
0d04d5e19b Current FunctionRef status. Mixed with a few more cmake stuff 2018-02-03 19:05:22 +01:00
turleypol
dbb25bdb62
Include and buildsystem cleanup (#45)
Include cleanup
Reworked buildsystem (Linux only)
Removed dynamic libs, Linux now again uses static linking (like windows)
2018-01-29 21:55:48 +01:00
turleypol
798eda5b63 Cleanup of header includes. 2018-01-01 21:52:14 +01:00
turleypol
00ac2f834b Found the next easy bottleneck during method call. 2017-12-20 22:21:49 +01:00
Fernando Rozenblit
81ef24d781 UOExecutor now tells if the script could be suspended
Scripts which are running to completion outside the ScriptScheduler
can't be suspended. This will now be tested by the UOExecutor (as
os_module->suspend() doesn't care).
2017-07-30 20:10:19 +02:00
turley
a8a3dce207 removed pol.cfg entry to disable assertions, only hides the real
reason. Now all codepathes should complain about wrong version of em
files.
2017-05-28 14:15:26 +02:00
turley
f9c3db9e41 Modules share the same (helper) template base class
Optimize function name search for all modules not only uo by using an additional map, replaced c array with vector for functionsdef.
Simplified pragma pack order. (MSVC version is supported in all
compilers)
Removed compilerassert.h (asserteql,..) replaced with static_assert
Removed some old #ifs
2016-12-20 23:53:32 +01:00
turley
189cad3479 Formating everything
Authors are not forced to use the clang-format setting, but should
atleast be inspired by the style.
The only thing which is now not allowed are tabs for ident/alignment!
2016-02-19 19:26:35 +01:00
Gabriele Tozzi
ff64e3b2b4 Minor: forcing SpinLock to be used only via SpinLockGuard 2016-02-03 06:08:26 +01:00
Gabriele Tozzi
d1ac902926 Documentation: reformatted headers for DoxyGen 2016-01-28 14:52:40 +01:00