Commit graph

30 commits

Author SHA1 Message Date
Kevin Eady
e03ec25b0c
Fix compiler crash on error{} members with no initializer (#618)
* Add crashing test for TDD

* Add fix

* Add core-changes
2024-02-04 15:38:37 +01:00
Kevin Eady
d4850d8049
Tweak parse tree to treat uninit and bools as literals (#616) 2024-02-01 15:21:52 +07:00
Kevin Eady
593cfffb83
Add uninit, true, false keywords to grammar (#596)
* Update grammar

* Update expression handling for uninit

* update existing tests

* Add new tests

* Remove fullpath from escriptgrammar generation comment

* fix tests

* Update eScript guide

* Declare escript version 0x11

* Add core-changes

* Add `true` and `false` to grammar

* true/false implementation

* Fix existing tests

* Add new tests

* Update core changes

* add docs

* Fix BooleanValue::describe_to

* bool optimizations

* optimize uninit

* remove unused var assignments

* Update grammar for case labels for uninit, booleans

* Fix case label handling for uninit, true, false

* Tests

* Fix compiler version display v1.1700000017881393 -> v1.17

* optimize boolean binary operations

* fix unary boolean optimizer

* add boolean, uninit optimizer test

* Use new fmt lib apis

* Fix compiler warning

* really fix warning lol

* Add Executor[Module]::getParam for bools, FindSubstance test
2024-01-20 05:38:25 +01:00
turleypol
cccf84dfc8
Fewer compile warnings (#413)
* added escriptgrammar as external lib where it belongs. Silenced warnings.

* bscript compiler warning fixes

* special include file to get rid of gcc warnings about antlr4

* misc windows warnings

* time specifc warnings

* buildfix + apple warnings

* never trust apple

* windows debug build warnings

* some windows clang warnings

* last warning fix
2021-08-28 22:26:15 +02:00
Kevin Eady
0ca7912fcd
Add support for conditional operator (#387)
* Grammar update

* AST generation

* Emit instructions

* Add initial tests

* Additional tests

* Rename to ConditionalOperator

* Add docs
2021-03-14 23:20:20 +01:00
Kevin Eady
e41f70d72e
Add support for interpolated strings ("interstrings") (#369)
* Update grammar to support interpolated strings

* Struct initializers, case switchs are regular strings

* Initial stub for interpolated string in AST
This splits the previous STRING_LITERAL terminal into a production,
stringLiteral, to handle REGULAR_STRING terminal and interpolatedString
production.

* Change interpolated strings to expressions

* Fix mode handling in grammar

* Grammar fixes
- Fix mode handling in lexer
- Interpolated strings only have one expression

* Can successfully parse, stub compile interstrings
$"He {there + print("hello")}";

* Add formatting string to grammar

* Fix tests, and add test stubs

* Rename curleys to brace; better AST generation

* initial work interstring instruction

* Initial work on formatted string instruction: emit

* Formatted string instruction: execution

* Add simple formatted string test

* Add formatted string test src

* Review changes #1
- Rename `FormattedString` to `FormatExpression`
- Rename overloaded `try_to_format()` to `get_formatted()`

* Review changes part 2
- Rename `InterpolatedString` ast node to `InterpolateString`

* Review changes part 3
- Modify `ins_interpolate_string`

* Review changes part 4
- Remove unused formal parameter

* Add negative tests

* Spruce up positive tests

* Fix braces, escape chars inside interstring

* Fix, add tests for escaped char and double brace

* Address differences for new lines in tests

* Update Escript version

* Make empty expression an error

* Add documentation for interpolated strings

* Quick touchup on docs
2021-03-11 22:48:16 +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
c2e6722ed5
Clean up warnings: size_t/unsigned mixing, unused private variables (#352) 2020-12-01 02:23:03 -08:00
Eric Swanson
3609d7e9d2
Move more specialized expression types from optimizer to AST builder (#334)
* Move more specialized expression types from optimizer to AST builder

VarStatement now handles its own value consumption

* Move assign-multisubscript-consume logic to the instruction generator
2020-09-30 08:19:05 -07:00
Eric Swanson
72ae01414c
AST nodes are nouns. (#333)
Renamed:
  - GetMember to MemberAccess
  - SetMember to MemberAssignment
  - SetMemberByOperator to MemberAssignmentByOperator
  - AssignVariableConsume to VariableAssignmentStatement
2020-09-28 08:11:10 -07:00
Eric Swanson
b508dd24aa
Build ElementAssignment and SetMember in the AST builder rather than the optimizer (#332) 2020-09-28 06:21:42 -07:00
Eric Swanson
5469e0d30f
remove dead code; call method instead of inline equivalent (#331) 2020-09-27 13:08:09 -07:00
Eric Swanson
3eb030090c
refactor: move membership operator handling into binary_operator (#329) 2020-09-27 12:08:52 -07:00
Eric Swanson
58a04c3097
refactor: ExpressionBuilder token id lookup for binary operators (#328) 2020-09-27 11:43:00 -07:00
Eric Swanson
e8c621136c
New compiler: add elvis operator (#293)
Adds:
- ast/ElvisOperator
2020-09-09 23:11:51 -07:00
Eric Swanson
f2a8c9e480
New compiler: add support for function references (#289)
Adds:
- ast/FunctionReference
2020-09-08 23:20:32 -07:00
Eric Swanson
4f32d4df71
New compiler: method calls (#286)
Adds:
- ast/MethodCall: AST node for an object method call
- ast/MethodCallArgumentList: AST node for arguments passed to a method
2020-09-08 01:24:57 -07:00
Eric Swanson
023f45aecd
New compiler: handle membership operators .+ .- .? (#285) 2020-09-08 00:48:17 -07:00
Eric Swanson
90957a66c6
New compiler: add error initializers (#281)
Adds:
- ast/ErrorInitializer: AST node to create a new error object
2020-09-07 00:58:31 -07:00
Eric Swanson
431978d81a
New compiler: get and set object members (. operator) (#280)
Adds:
- ast/GetMember: AST node for dot-operator access
- ast/SetMember: AST node for optimized assignment operator + dot-operator
2020-09-07 00:00:26 -07:00
Eric Swanson
e7b5c09f35
Add struct initialization. (#279)
Adds:
- ast/StructInitializer: AST node for the overall struct
- ast/StructMemberInitializer: AST node for initialization of a single field
2020-09-06 23:24:53 -07:00
Eric Swanson
ebb186a357
Add support for set and get by index (arrays and dictionaries) (#278)
Adds:
- ast/ElementAccess: AST node for x[a] or x[a,b,...] (may be get or set)
- ast/ElementAssignment: AST node for x[a] := b;
- ast/ElementIndexes: AST node to hold all indexes for element lookup
- optimizer/AssignmentOptimizer: optimizes := in different circumstances
2020-09-06 14:03:02 -07:00
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
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
2b1e8a14ca
Add binary operators (#265) 2020-09-01 22:49:48 -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
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
81331b7200
Add FloatValue (#233) 2020-08-19 19:43:08 +02: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