Commit graph

50 commits

Author SHA1 Message Date
Eric Swanson
002ea6fbba
Add support for dictionary creation (#277)
Adds:
- ast/DictionaryEntry: AST node for a key -> value pair in a dictionary initializdr
- ast/DictionaryInitializer: AST node for creating a new dictionary
- ast/UninitializedValue: AST node for an uninit object
2020-09-06 04:02:37 -07:00
Eric Swanson
5033aefcdc
Add do-while statement (#276)
Adds:
- ast/DoWhileLoop
2020-09-06 02:26:41 -07:00
Eric Swanson
966b3acf5a
Add foreach loops (#275)
Adds:
- ast/ForeachLoop: AST node
2020-09-06 01:22:47 -07:00
Eric Swanson
103c27a9af
New compiler: array initialization (#274)
* Add array initialization

Adds:
- ast/ArrayInitializer: AST node for an expression that creates an array
2020-09-06 00:13:49 -07:00
Eric Swanson
f3202547fb
New compiler: Add support for case statements (#272)
Adds:
- ast/CaseDispatchDefaultSelector: AST node for a "default:" selector
- ast/CaseDispatchGroup: AST node for a collection of selectors and the code to execute
- ast/CaseDispatchGroups: AST node holding all groups in a case statement
- ast/CaseDispatchSelectors: AST node holding all selectors for one group
- ast/CaseStatement: AST node for a whole case statement
- codegen/CaseDispatchGroupVisitor: knows what to put in a case jump dispatch table
- codegen/CaseJumpDataBlock: knows how to build the entries in the data block

Also, detect multiple case selectors with the same value (or default).  This is different from the OG compiler, which only detected duplicate `default:` selectors.
2020-09-05 20:41:58 -07:00
Eric Swanson
92ba5be8cf
Add break and continue statements. (#270)
Adds:
- ast/JumpStatement: AST node for break and continue statements
2020-09-04 18:21:08 -07:00
Eric Swanson
805cc2f314
New compiler: assignment to local and global variables. (#269)
Adds:
- ast/AssignVariableConsume: AST node for assignment to a variable, while consuming the result
- optimizer/ValueConsumerOptimizer: Optimizes expressions where the resulting value will be consumed
2020-09-04 00:10:38 -07:00
Eric Swanson
1a3619b231
Add support for while loops (#268)
Adds:
- analyzer/FlowControlScope: Registers a break/continue scope
- analyzer/FlowControlScopes: Registry for break/continue scopes
- ast/LabelableStatement: Base class for AST nodes that can be labelled (loops and case)
- ast/LoopStatement: Base class for AST nodes for loops (have a break and continue label)
- ast/WhileLoop: AST node for a while loop
2020-09-03 19:46:27 -07:00
Eric Swanson
447e8d4e2e
Optimizations: binary operators (#266)
Adds:
- optimizer/BinaryOperatorOptimizer: optimizes expressions with a binary operator
  - assignments will be handled by optimizer/AssignmentOptimizer
- optimizer/BinaryOperatorWithFloatOptimizer: optimizes binary operator expressions with a FloatValue left-hand side
- optimizer/BinaryOperatorWithIntegerOptimizer: optimizes binary operator expressions with an IntegerValue left-hand side
- optimizer/BinaryOperatorWithStringOptimizer: optimizes binary operator expressions with a StringValue left-hand side
2020-09-02 00:27:09 -07:00
Eric Swanson
2b1e8a14ca
Add binary operators (#265) 2020-09-01 22:49:48 -07:00
Eric Swanson
6ce9c38de3
Add support for const declarations (#264)
Adds:
- analyzer/Constants: holds constant name -> value for lookup
- ast/ConstDeclaration: AST node for a const declaration
- optimizer/ConstValidator: validates that an optimized expression is valid to use as a constant.

the Optimizer converts Identifiers that refer to a constant to the optimized constant value.
2020-09-01 00:54:24 -07:00
Eric Swanson
6d163918c5
Handle default parameter values, pass-by-name, and return statements in functions. (#263)
Process function call parameters to account for:
- default parameter values
- passing parameters by name

Also handle return within a function (I left this out of the previous PR)

Adds:
- astbuilder/SimpleValueCloner: clones values that are valid as constants and parameter default values.
2020-08-31 23:16:30 -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
98e74bd7dc
New compiler: add return and exit statements (#261)
Add:
- ast/ExitStatement: AST node for the exit statement.
- ast/ReturnStatement: AST node for the return statement.
  - only handles top-level returns and returns inside program declarations, which do the same thing: progend.
2020-08-30 22:55:30 -07:00
Eric Swanson
95e604e417
Add support for if-then-else statements (#259)
Adds:
- ast/Block: a block scope that allows declaring local variables
- ast/IfThenElseStatement: AST node for if..elseif..else..endif statements
- model/FlowControlLabel: provides an anchor for jumps or calls.
  - Function calls, break statements, continue statements, and loops will all use these.
2020-08-30 17:03:26 -07:00
Eric Swanson
64503c2866
var statements in program blocks (#256)
Adds:
- analyzer/LocalVariableScope: tracks local variables created within a given scope.
  - Instantiated on the stack during semantic analysis, this registers itself with LocalVariableScopes during construction and deregisters itself during destruction.
  - Detects unused variables during deregistration
- analyzer/LocalVariableScopes: this is what LocalVariableScope registers with.
  - keeps track of the stack of local scopes.
  - can provide the current local scope, for var statements.

Other notes:

"Shadowed" variables: this is when a variable in one scope hides a variable in another, like so:
    var a := 2;
    if (a)
        var a := 3;
        a := 4;
    endif
    print(a); // still 2
"debug_variables": We'll use these later when writing debug files.
2020-08-30 01:32:38 -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
a77ddd028e
New compiler: Add optimized unary expressions (#244)
Adds:
- UnaryOperator: AST node for unary operators -, ++, --, and so forth
- UnaryOperatorOptimizer: optimizes a unary operator with its operand
  - now integer and float negation, and integer inversion
  - later x[y]++ to a single instruction

Also:
- automatically include basic.em, which includes some parameter defaults like -1.

This allows the compiler to generate output for a hello, world script with the exact same .ecl output as the legacy compiler.
2020-08-26 19:24:47 -07:00
Eric Swanson
5e85fcc9e4
New compiler: Add IntegerValue (#243) 2020-08-25 23:27:24 -07:00
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
47aeb634d6
New compiler: Add StringValue (#235)
* Add StringValue
2020-08-20 10:27:35 +02:00
Eric Swanson
81331b7200
Add FloatValue (#233) 2020-08-19 19:43:08 +02:00
Eric Swanson
f93573ae51
Add SourceFileProcessor, ValueConsumer (#232)
* Add astbuilder/ SourceFileProcessor

* Add ast/ ValueConsumer

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-18 23:32:57 -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
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
11abe52f3e
Add ast/Node (#227) 2020-08-17 08:03:33 +02:00
Eric Swanson
50e42719b8
Add file/SourceFileCache (#222)
* Add file/SourceFileCache

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-16 17:22:16 -07:00
Eric Swanson
2df8e74ab1
Add file/SourceFile (#220) 2020-08-14 22:54:20 +02:00
Eric Swanson
303665bcd8
Add error listener, and convert lexer symbols to lowercase (#216)
Add file/ConformingCharStream - converts symbols to lowercase to match grammar

Add file/ErrorListener
2020-08-14 03:28:37 -07: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
d22a9af254
Add code emitter and data emitter (#209)
* Add codegen/ DataEmitter

* Add codegen/ CodeEmitter
2020-08-11 20:50:16 +02:00
Eric Swanson
978b9ff6ec
Add StoredTokenDecoder and ListingWriter stubs; write listfile (#208) 2020-08-11 12:49:18 +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
72bd179051
Add analyzer/Disambiguator stub (#205)
The Disambiguator will correct the AST based on context.

At present, it needs to handle ambiguities in the grammar between
case group selectors and named break/continue labels.
2020-08-11 08:21:34 +02:00
Eric Swanson
d184dda473
Add Optimizer stub (#203) 2020-08-10 13:54:59 +02:00
Eric Swanson
eb6594b4c6
Add ast/NodeVisitor, analyzer/SemanticAnalyzer stubs (#201) 2020-08-10 10:37:07 +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
Eric Swanson
63326cd44c
Add format/ CompiledScriptSerializer (#198)
* Add format/ CompiledScriptSerializer

* Add CompiledScript output, write with CompiledScriptSerializer
2020-08-10 09:00:47 +02:00
Eric Swanson
a5f22fe583
Add types that define compiler output: (#195)
representation/
    CompiledScript
    ExportedFunction
    ModuleDescriptor
    ModuleFunctionDescriptor
2020-08-09 09:31:18 +02:00
Eric Swanson
cc28f4f4f2
Add compiler/ Profile and Report (#193)
* Add compiler/Profile

* Add compiler/Report

* From CR notes: add newline on caught exception.
Also added comments that messages should have a newline at the end.
2020-08-08 16:31:55 +02:00
Eric Swanson
ef8012cfbc
Add SourceFileIdentifier, SourceLocation, formatfwd (#189)
* Add SourceFileIdentifier, SourceLocation, formatfwd

* Add formatfwd.h to clib make sources

* Note to not keep a SourceFileLocation after the lifetime of the SourceFileIdentifiers.
2020-08-06 08:43:00 +02:00
Eric Swanson
49ec52beae
Add ecompile mode: compare old and new compiler output (#187)
* Add -G / CompareCompilerOutput ecompile mode that runs old and new compiler and compares output.
Add LegacyFunctionOrder because parity needs to know how the old compiler ordered functions.

* Fix class/struct mixup, add to cmake sources
2020-08-05 09:01:07 +02:00
Eric Swanson
6e8c7ad074
Add stub for new compiler, with -g and UseCompiler2020 options to select. (#184) 2020-08-05 07:42:46 +02:00
Eric Swanson
ed033fc6e4 bscript uses antlr library, and compiles the lexer and parser
Ignore ANTLR grammar plugin (idea) generated files
2020-08-03 19:39:29 -07:00
Eric Swanson
4609818753 Move StoredToken to its own cpp/h 2020-07-31 16:19:38 -07:00
Eric Swanson
df5c3ced7b Move Expression class to expression.cpp/h 2020-04-24 13:37:26 -07:00
turleypol
c102b58135 curl is somehow able to build via cmake on win.
Added CMakeSources to sources to be shown up in IDE
2018-02-11 21:57:38 +01:00
turleypol
0d04d5e19b Current FunctionRef status. Mixed with a few more cmake stuff 2018-02-03 19:05:22 +01:00