Commit graph

21 commits

Author SHA1 Message Date
turleypol
1463b76c7c
Includes are now all relative to pol-core basefolder (#906)
* all except pol

* pol and includes under defines

* something weird has happened

* remove own folder from include searchpath

* fixed remaining, adapted include style for external headers

* missing include
2026-07-25 23:01:18 +02:00
turleypol
cec379ae34
removed printOn method these debug strings where only used at a single (#899)
place
use formatter for Token instead of ostream
2026-07-21 08:50:32 +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
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
f45d12665d
Fix various case sensitivity issues in classes (#725) 2024-10-18 06:53:50 +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
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
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
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
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
0cd9412066
Properly scope the compiler includes to the Bscript folder. (#360) 2021-02-25 16:53:22 +01: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
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