Commit graph

164 commits

Author SHA1 Message Date
Kevin Eady
68bad65741
move sqlitemod from runecl to pol 2024-07-19 23:21:14 +02:00
Kevin Eady
8e66a6600f
add sqlitecpp test 2024-07-19 11:27:58 +02:00
Kevin Eady
2de1995c19
Fix compiler for escaping } correctly in interpolated strings (#620)
* Update grammar; add tests
String literals inside an interpolated string cannot start with `}`, as it must be a DOUBLE_RBRACE `}}`

* Fix interpolate string token reading

* Update core-changes
2024-02-06 10:44:26 +01:00
Kevin Eady
e03ec25b0c
Fix compiler crash on error{} members with no initializer (#618)
* Add crashing test for TDD

* Add fix

* Add core-changes
2024-02-04 15:38:37 +01: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
cb6750405c
Double to string precision (#580)
* use std::to_chars for doubles

* fixed cmake errors when an escript error occurs

* macos 13 with clang15

* CI: macos new cache version

* guessing game

* guess no2

* test shipped clang with deloytarget env

* adapted testdata, lets see if all platforms behave the same

* explicit test if high precision double can get packed+unpacked

* log testclient receive buffer on error

* added docs
2023-12-20 22:13:39 +01:00
turleypol
a538d812a0
Unpack of bigger double values on windows (#576)
* added test for pack/unpack double which has exponent representation. Bug
in vs 2022 17.8..
removed unneeded minimum versions of cmake, root cmake file has a higher
minimum version

* switch back to vs2019

* force rebuild external libs

* docs
2023-12-10 20:30:17 +00:00
turleypol
31780b070e
extended print and syslog with color support (#544)
* extended print and syslog with color support
needs linux or atleast windows11

* added pol.cfg setting to disable colored output

* added docs
2023-10-18 15:18:06 +02:00
Kevin Eady
4aa02252fb
Fix int overflow in GetConfigString (#525) 2023-05-19 09:10:19 +02:00
Kevin Eady
469a454446
Add prettify argument to PackJSON() (#520)
* Add prettify argument to PackJson()

* simplify test
2023-04-28 09:44:22 +02:00
turleypol
737db933ac
OpenXMLFile return value for not existing files or parsing errors (#463)
* OpenXMLFile: return error if file does not exist instead of xmlobject in
error state

* added docs

* translate every xml open/parsing error to BError

* updated core changes entry, to reflect the latest changes
2022-06-21 21:07:41 +02:00
Kevin Eady
3bd1fdd32a
Throw compile error on function name conflict (#408)
Fixes: #407
2021-08-11 23:01:14 +02:00
Kevin Eady
c6301c0c52
Fix constant declaration production (#399)
* Fix constant delcaration production

* Add tests
2021-04-19 21:58:36 +02:00
Kevin Eady
0ca7912fcd
Add support for conditional operator (#387)
* Grammar update

* AST generation

* Emit instructions

* Add initial tests

* Additional tests

* Rename to ConditionalOperator

* Add docs
2021-03-14 23:20:20 +01: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
Kevin Eady
ae96ecbf77
Remove OGC from EcompileMain, testsuites (#383)
* Remove OGC from escript testsuite

* Remove compiler options

* Remove Facility::Compiler

* Update docs and options in ecompile help usage

* Update core-changes, breaking-changes
2021-03-04 17:39:14 +01:00
Kevin Eady
44c864b917
Remove erroneous lexing productions (#371)
* Remove erroneous lexing productions

* Fix hex float literals

* Address review comments.
2021-02-27 23:54:07 +01:00
Kevin Eady
c29c4ebfab
Undo breakage caused by multiline strings (#375)
* Undo breakage caused by multiline strings

* Use different newline string test
2021-02-26 22:59:55 +01:00
Kevin Eady
b1e8d2b36a
Fix escape sequences, double-slash in strings (#368) 2021-02-22 21:20:55 +01:00
turleypol
28556ecaf5
Appendcfgelem error (#358)
* added error check if file could not be opened for AppendCfgElem.

* added docs
2020-12-17 22:06:05 +01:00
turleypol
8ba2639669
Strftime (#345)
* updated strformattime to allow c++11 specifiers, removed 100 chr
limitation

* ambiguous std::max on windows

* fixed utc dependent testdata

* print output file on runecl error

* vs2019 seems to not support E and 0 formats

* use vector of chars as buffer to avoid potential UB

* resize vector, extended test
2020-11-06 21:57:50 +01:00
Eric Swanson
78243c208e
Disallow multiline string literals (#341) 2020-10-20 22:39:56 -07:00
Eric Swanson
2cae8137f3
Enable building on OSX (clion) (#318)
* Build on OSX

* Add macos-latest to build matrix

* Fix case sensitivity checks/tests

* On osx builds, cope with unpacking a double that might be followed by either an exponent or an error (as part of an array).

Also, remove static unpack(const char*) forms that were never called.

Co-authored-by: turleypol <turley@polserver.com>
2020-09-26 06:57:10 -07:00
Eric Swanson
cbd2f97c5b
Add an error message about known reserved words (#322) 2020-09-22 03:11:25 -07:00
Eric Swanson
d74146a2f9
Report location of integer values that are out of range (#319) 2020-09-20 11:04:37 -07:00
Eric Swanson
591eb37d04
New compiler: No longer reserved words: null, declare (#313)
* These are not reserved words:
  - null
  - declare

Fixes https://github.com/polserver/polserver/issues/309
2020-09-15 00:16:31 -07:00
Eric Swanson
0d191e01bc
Fixed incorrect error message when passing too many arguments to a function. (#312)
* Fixed: if too many parameters were passed in a function call, an incorrect error message was displayed, and the compiler could even crash.

Also updated all of the error messages related to function call parameters to include the function name.
2020-09-14 22:05:08 -07:00
turleypol
1bdbd5150b
fixed crash in str.format when invalid param index is given (#307) 2020-09-13 11:38:17 +02:00
Eric Swanson
d8ad58f64f
Update test suite for new compiler (#299)
* Update test suite:
- run test suite with both OG compiler and new compiler
- run compiler parity test against testsuite/escript
2020-09-11 01:38:39 -07:00
Eric Swanson
e6d9f78f2a
Disallow var names that match an unreferenced function. (#300)
Remember known user function names when they are declared, rather than when they are referenced.
2020-09-11 01:16:24 -07:00
Eric Swanson
7598c9486f
Disallow function names as variable, argument, and const names (#298) 2020-09-11 00:16:20 -07:00
Eric Swanson
3ffb02397f
New compiler: Disallow 0-parameter system calls as parameter defaults (#297)
There is one part that differs from const declarations: 0-parameter function calls are allowed (by accident) as const values, but not for default parameter values.
2020-09-10 01:39:57 -07:00
Eric Swanson
de171c1cdd
Allow empty array, dictionary, error, struct as constants. (#296)
Checkpoint: parity for ClassicDistro
2020-09-10 00:35:40 -07:00
Eric Swanson
0cf61caa5a
New compiler: alter test: postfix operators are now highest precedence (#295) 2020-09-10 00:09:34 -07:00
Eric Swanson
ee9ad368de
Add for loops (basic and c-style) (#287)
Adds:
- ast/BasicForLoop
- ast/CstyleForLoop
2020-09-08 01:56:30 -07:00
Eric Swanson
45a2e53351
Add support for exported functions (#284) 2020-09-07 12:35:17 -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
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
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
Eric Swanson
e42892fe7b Compiler v1 error messages in *.err1 files 2020-08-01 17:20:20 -07:00
Eric Swanson
cc1b0c6ee3 fix optimizer bug: can stop optimizing prematurely if pre- or post-decrement operators are present
optimize_token() is meant to return true only if it performs an optimization.

By returning true when it did not, it makes the optimizer stop trying.

A script like this can trigger the condition:

var i := 3;
var ii;

ii := 1 - (--i);
print(i);
print(ii);

Notice that line 4 does not optimize to an 'assign-consume' and therefore does not optimize to 'assign global`

Listfile before (see instructions 6-12):

/vagrant/testsuite/escript/opt/opt005-stopped-optimizing-early.src, Line 1
var i := 3;
0: decl global #0
1: 3L
2: :=
3: #
var ii;
4: decl global #1
5: #
ii := 1 - (--i);
6: global #1
7: 1L
8: global #0
9: unary --
10: -
11: :=
12: #
print(i);
13: global #0
14: Func(1,0): Print
15: #
print(ii);
16: global #1
17: Func(1,0): Print
18: #
19: progend

Listfile after (see instructions 6-10):

/vagrant/testsuite/escript/opt/opt005-stopped-optimizing-early.src, Line 1
var i := 3;
0: decl global #0
1: 3L
2: :=
3: #
var ii;
4: decl global #1
5: #
ii := 1 - (--i);
6: 1L
7: global #0
8: unary --
9: -
10: global1 :=
print(i);
11: global #0
12: Func(1,0): Print
13: #
print(ii);
14: global #1
15: Func(1,0): Print
16: #
17: progend
2020-07-29 20:42:07 -07:00
Eric Swanson
13ba4ad940 Fix a bug in the legacy compiler .ecl output
The RSV_LOCAL offset should be the the local variable, not of the local variable within the block

Notice though, that the executor doesn't even use it.

There is more detail in the attached script.

listfile before:
/vagrant/testsuite/escript/bug/bug013-local-variable-index.src, Line 7
program foo()
var a;             // should be 0
0: decl local #0
1: #
if ( a )
2: local #0
3: if false goto 17
var b;         // should be 1    actually emitted 0
4: decl local #0
5: #
var c;         // should be 2    actually emitted 1
6: decl local #1
7: #
if ( b )
8: local #1
9: if false goto 16
var d;     // should be 3    actually emitted 0
10: decl local #0
11: #
print(d);
12: local #3
13: Func(1,0): Print
14: #
15: leave block(1)
16: leave block(2)
17: leave block(1)
18: progend

listfile after:
/vagrant/testsuite/escript/bug/bug013-local-variable-index.src, Line 7
program foo()
var a;             // should be 0
0: decl local #0
1: #
if ( a )
2: local #0
3: if false goto 17
var b;         // should be 1    actually emitted 0
4: decl local #1
5: #
var c;         // should be 2    actually emitted 1
6: decl local #2
7: #
if ( b )
8: local #1
9: if false goto 16
var d;     // should be 3    actually emitted 0
10: decl local #3
11: #
print(d);
12: local #3
13: Func(1,0): Print
14: #
15: leave block(1)
16: leave block(2)
17: leave block(1)
18: progend
2020-07-29 00:05:52 -07:00
turleypol
07f324040f
Merge pull request #149 from polserver/syz-fix-em-param-name-clash
Fix compiler bug with user function names that match module function argument names
2020-06-16 21:29:03 +02:00
Eric Swanson
e7733ccf19 Fix compiler bug: user functions should be able to have the same name as module function parameter names 2020-06-15 22:27:57 -07:00
Eric Swanson
fd6b722eaf Fix optimization error: will sometimes patch an offset of the wrong instruction when
rolling back an if statement branch.
2020-06-14 03:31:03 -07:00
Eric Swanson
252a4947ce Add bug010 - optimizer bug with if statements 2020-06-13 19:10:33 -07:00
Eric Swanson
9b764d6d0c Remove performtests.py - instead, just run Usage
ctest [options] from the bin-build directory
2020-06-10 23:22:14 -07:00