Commit graph

8 commits

Author SHA1 Message Date
Eric Swanson
9bbc0518f8
Compiler rewrite: add global variables (#241)
Adds support for var statements at the global level.

Adds:
- analyzer/Variables: keeps track of the variables in scope (either local or global).
- ast/Identifier: AST node for an identifier.
  - The optimizer will replace constant identifiers with their constant value (in a later commit).
  - The semantic analyzer will set the variable field for local or global variable identifiers.
- ast/VarStatement: AST node for a var statement.
  - A single var statement will generate one VarStatement per variable declared.
- model/Variable: Describes a variable, including its index within its scope.
2020-08-25 00:57:03 -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
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
2df8e74ab1
Add file/SourceFile (#220) 2020-08-14 22:54:20 +02:00
Eric Swanson
6b3fdcb263
Add CodeGenerator stub (#206)
* Add codegen/CodeGenerator stub

* Destructor is trivial
2020-08-11 09:08:48 +02:00
Eric Swanson
435db9dc07
bscript/compiler: use c++17 nested namespace definitions (#202) 2020-08-10 12:20:29 +02:00
Eric Swanson
2e1870028b
Add model/CompilerWorkspace, astbuilder/BuilderWorkspace, astbuilder/CompilerWorkspaceBuilder (#200)
Add astbuilder/BuilderWorkspace:
  - Temporary workspace used while building the AST (which goes in the CompilerWorkspace)

Add astbuilder/CompilerWorkspaceBuilder:
  - Builds a CompilerWorkspace for a script

Add model/CompilerWorkspace:
  - Holds AST
  - Holds some intermediate data used by semantic analyzer, optimizer, code generator
2020-08-10 09:42:37 +02:00