Commit graph

10 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
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
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
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
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
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