Commit graph

17 commits

Author SHA1 Message Date
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
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
6ed593ac81
Add function reference table to EScriptProgram (#686)
* Introduce FunctionReferenceRegistrar
- Track function references created by functors
- Remove ValueStack-held attributes for functors
- Add Function References section to escript program
- Use Function References section in ins_functor
- Update escript version

* Update listfile snapshots
- Remove ValueStack-held attributes created by functors

* Add function reference tracking to function references
- `emit.function_reference` uses funcref registrar + emits that index
- `ins_funcref` uses parameter count + is variadic from prog funcref table
- update listfile snapshots

* Add core-changes
2024-08-06 20:29:02 +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
9c36b977cd
Internal work to remove OGC (#384)
* Remove LegacyFunctionOrder

* Remove compiler.cpp, compiler.h

* Remove parser.cpp/h and wordlist generation

* Update breaking-changes, core-changes
2021-03-06 01:39:26 +01:00
Kevin Eady
0cd9412066
Properly scope the compiler includes to the Bscript folder. (#360) 2021-02-25 16:53:22 +01:00
Eric Swanson
1567241871
New compiler: write debug info (.dbg and .dbg.txt) (#302)
Also: OG compiler debug info for foreach iterator changed to match actual variable name

Adds:
- ast/DebugStatementMarker: for "intrusive debug" (ecompile -i) instructions
- codegen/DebugBlockGuard: pushes and pops debug block #
- format/DebugStoreSerializer: writes .dbg and .dbg.txt files
- representation/DebugBlock: holds parent block # and local variable names for each block
- representation/DebugStore: holds all debug information
2020-09-12 14:26:58 -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
5e57733a68
New compiler: program declarations (#246)
Add:
- FunctionBody
- Program
- ProgramParameterDeclaration
- ProgramParameterList

Build AST for program sections and generate code for it
2020-08-28 22:45:07 -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
3a8ab09a56
Add Expression, Statement, Value AST base classes, and TopLevelStatements (#229)
* Add ast/ Expression, Statement, Value

* Add ast/TopLevelStatements
2020-08-17 22:53:03 -07:00
Eric Swanson
841bc928d3
Normalize include paths (#221) 2020-08-15 08:01:19 +02:00
Eric Swanson
97f669f94a
Add instruction generator, emitter, emit progend (#211)
* Add codegen/InstructionEmitter

* Add codegen/InstructionGenerator

* CodeGenerator: emit progend

Checkpoint: compiler can compile an empty file

* Comment reason for having both emit and emitter.
2020-08-12 10:30:06 +02:00
Eric Swanson
6b3fdcb263
Add CodeGenerator stub (#206)
* Add codegen/CodeGenerator stub

* Destructor is trivial
2020-08-11 09:08:48 +02:00