Commit graph

21 commits

Author SHA1 Message Date
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
Kevin Eady
2d0b675754
Fix super-scoped function resolution; Fix SourceLocation for scoped function calls (#730)
* Fix super-scoped function resolution

* Fix SourceLocation for scoped function calls
2024-10-25 11:20:41 +02:00
Kevin Eady
c7a06fe907 Support handling parent-scoped static function calls (#704) 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
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
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
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
f47ce97d26
Add compiler support for expressions as function callee (#670)
* initial support for function calls with expression callee

* Add support for identifier-named callees

* add compilation failure test; better code docs

* Add core-changes

* Address compiler warnings
- conversion from 'size_t' to 'unsigned int', possible loss of data

* Update grammar

* implementation

* tests

* update core-changes

* Address CI warnings
- declaration of 'method' hides previous local declaration
2024-07-28 20:21:23 +02: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
Kevin Eady
3bd1fdd32a
Throw compile error on function name conflict (#408)
Fixes: #407
2021-08-11 23:01:14 +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
89d663ca00
Use new compiler (when configured) for compile_inc (#303) 2020-09-13 00:41:45 -07:00
Eric Swanson
45a2e53351
Add support for exported functions (#284) 2020-09-07 12:35:17 -07: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
cf42b03e3c
New compiler: Add AST nodes for function calls. Can compile hello world. (#240)
Adds:
- ast/Argument: AST node for an argument passed to a function.
- ast/FunctionCall: AST node for a function call.
- codegen/ModuleDeclarationRegistrar: The code generator registers module function declarations with this in order to determine module indexes and function indexes for instructions.
- model/FunctionLink: this is a reference either:
  - from: a FunctionCall or a FunctionReference
  - to: a ModuleFunctionDeclaration or a UserFunction
- optimizer/ReferencedFunctionGatherer: a visitor that determines which module functions and user functions are referenced, by looking at function calls and function references.

Also:
- CodeGenerator registers module functions
- InstructionGenerator generates code for function calls
- InstructionEmitter generates TOK_FUNC instructions
- StoredTokenDecoder decodes TOK_FUNC instructions

After all of this, the compiler can compile print("hello, world");
2020-08-24 01:47:38 -07:00
Eric Swanson
86c0efbc21
Build AST nodes for module function declarations (#239)
Adds enough to build the AST nodes for the module function declarations in a .em file.

Adds:

- Function: base class for module function declarations and user functions
- FunctionParameterDeclaration: declaration for a function parameter, as well as its default value if any
- FunctionParameterList: just a holder for function parameter declarations
- ModuleFunctionDeclaration: for function declarations in .em files
- FunctionResolver: hooks up function calls to module functions or user functions
- ModuleProcessor: a visitor for processing const declarations and module function declarations (const declarations are yet to come from the main branch)
2020-08-23 15:01:39 -07:00