greg
ad994c38ae
Test simplification
2017-09-19 22:10:58 -07:00
greg
48343d3fad
Tightened tokenization tests
2017-09-19 22:10:58 -07:00
greg
4f8ff35d0f
fixed bug with ends_identifier
2017-09-19 22:10:58 -07:00
greg
7311d0311f
Simplify pattern a little bit
2017-09-19 22:10:58 -07:00
greg
1b59c264b4
Use itertools peeking_take_while
...
Cuts down on lines in the tokenizer
2017-09-19 22:10:58 -07:00
greg
b2e453a9de
Rewrite of tokenizer
2017-09-19 22:10:58 -07:00
greg
59226eb731
Ran rustfmt on parser.rs
2017-09-19 22:10:58 -07:00
greg
297003c0b0
Operator only needs to be a tuple struct
2017-09-19 22:10:58 -07:00
greg
e5ee072b00
Convert tokenizer to large match statement
...
In the hopes of making it shorter
2017-09-19 22:10:58 -07:00
greg
9b62efc830
Fix conditional parsing
...
Needed to account for semicolons/newlines. Maybe need to generalize
delimiter-separated list of things
2017-09-19 22:10:58 -07:00
greg
f626ca1427
Add test for conditional parsing
2017-09-19 22:10:57 -07:00
greg
82c52ede48
Finish evaluating conditionals
2017-09-19 22:10:57 -07:00
greg
7f52b20d97
Conditional eval partway implemented
...
Need to change the AST representation to support compound statements I
think
2017-09-19 22:10:57 -07:00
greg
12fee6158c
Vector'd expressions don't need to be boxed
2017-09-19 22:10:57 -07:00
greg
2d21de7cc3
Added support for conditionals to parser
...
Not to eval yet
2017-09-19 22:10:57 -07:00
greg
9cc9c5977d
Fixed evaluation of function calls
...
This bit still isn't quite small-step but maybe that's okay for
functions
2017-09-19 22:10:57 -07:00
greg
ed9d1312d1
Change representation of variables
2017-09-19 22:10:57 -07:00
greg
29d9e50311
All environment changes represented explicitly
...
Start the work of rewriting the evluator to be a true small-step
evaluator - that is, all state changes are represented explicitly as
SideEffect types, and not as methods called on the evaluator, except at
the very top of the evaluation loop
2017-09-19 22:10:57 -07:00
greg
e84550f3ec
Kill two compilation warnings
2017-09-19 22:10:57 -07:00
greg
3063de1242
Run rustfmt on the rest of them
2017-09-19 22:10:57 -07:00
greg
e1d07b4e66
Rustfmt on llvm_wrap
2017-09-19 22:10:57 -07:00
greg
af45004afa
Run rustfmt on some files
2017-09-19 22:10:57 -07:00
greg
d4d61ce5ad
Use process::exit in main
2017-09-19 22:10:57 -07:00
greg
743311d18a
Convert Tokenize to Result
2017-09-19 22:10:57 -07:00
greg
17f9846bb9
Make tests pass w/ new match syntax
2017-09-19 22:10:57 -07:00
greg
fe8418edbe
Kill some extraneous spaces
2017-09-19 22:10:57 -07:00
greg
1d8102b9fa
Make compilation controllable
2017-09-19 22:10:57 -07:00
greg
aac3ca40fe
Add getopts
2017-09-19 22:10:57 -07:00
greg
c389b44bf8
Compile statements with variables
2017-09-19 22:10:57 -07:00
greg
db52f9b716
Package compilation context into one struct
2017-09-19 22:10:57 -07:00
greg
d3a743442b
= should have high precedence
2017-09-19 22:10:57 -07:00
greg
e46d840d96
Move more code to llvm_wrap
...
And silence a few compiler warnings
2017-09-19 22:10:57 -07:00
greg
3d406f1dd2
Move llmv wrapper into separate file
2017-09-19 22:10:57 -07:00
greg
fca307d3ab
Package more functions in LLVMWrapper
2017-09-19 22:10:57 -07:00
greg
a65544356c
Fix bug in delete routine
2017-09-19 22:10:57 -07:00
greg
10d51cc29c
Compile binexps
2017-09-19 22:10:57 -07:00
greg
95b773de7f
Compilation sequence
...
-move all steps of the llvm IR compilation process into the binary
2017-09-19 22:10:57 -07:00
greg
c032da712f
Successfully compiling a main function
2017-09-19 22:10:57 -07:00
greg
cfb93d9dea
Compilation that returns an output code works
2017-09-19 22:10:57 -07:00
greg
08798fb690
Move all LLVM functions into LLVMWrap
...
so I can kill the global unsafe
2017-09-19 22:10:57 -07:00
greg
e0eef5e58f
More moving functions around
2017-09-19 22:10:57 -07:00
greg
2107e6344e
More function wrapping
2017-09-19 22:10:57 -07:00
greg
2ad65a1c5d
Some in-progress work
2017-09-19 22:10:57 -07:00
greg
a01b6c874e
Small-step function arg evaluation
2017-09-19 22:10:57 -07:00
greg
907af38f44
Evaluate printing
2017-09-19 22:10:57 -07:00
greg
923566c4e9
Get rid of println's for token/ast debugging
...
Instead just explicitly stick them into the returned string.
This is necessary 'cause I'm gonna convert simplerepl to use ncurses
soon, so I can't have any side effects
2017-09-19 22:10:57 -07:00
greg
96c51a9b88
Move some more unsafe code into block
2017-09-19 22:10:57 -07:00
greg
8528c912bd
Added side effect framework
2017-09-19 22:10:57 -07:00
greg
47f4c25020
Doing some wrapping
2017-09-19 22:10:56 -07:00
greg
c18c1a639a
compilation does something usefl
...
Following along with:
http://blog.ulysse.io/2016/07/03/llvm-getting-started.html
2017-09-19 22:10:56 -07:00
greg
d3f6bbabaa
Starting to add actual LLVM generating code
2017-09-19 22:10:56 -07:00
greg
ee12e10ac6
Fix slice syntax
2017-09-19 22:10:56 -07:00
greg
6a0b50f278
Kill hashmap import for now
2017-09-19 22:10:56 -07:00
greg
6c44d295db
Framework for compilation
2017-09-19 22:10:56 -07:00
greg
cd69ebaa9d
Split main() into subfunctions
2017-09-19 22:10:56 -07:00
greg
3fe9ec95d5
Fix repl error message
2017-09-19 22:10:56 -07:00
greg
8b5d1ecd15
Kill compilation for now
...
Don't wanna deal with this right this second
2017-09-19 22:10:56 -07:00
greg
272fa92052
More fleshing out
2017-09-19 22:10:56 -07:00
greg
0c717c721e
Import Function type
2017-09-19 22:10:56 -07:00
greg
64d560a1fc
Still more work
2017-09-19 22:10:56 -07:00
greg
8a92d5ffa8
Partial LLVM work
2017-09-19 22:10:56 -07:00
greg
5ed0ed727b
Starting to add LLVM code
2017-09-19 22:10:56 -07:00
greg
5428810d2c
Add llvm dependencies
2017-09-19 22:10:56 -07:00
greg
b48c007bca
Get rid of old evaluator file
...
No longer need it
2017-09-19 22:10:56 -07:00
greg
5aa4c404a5
Added conditionals to grammar
2017-09-19 22:10:56 -07:00
greg
0e3aaa8b08
Add conditional expression support
2017-09-19 22:10:56 -07:00
greg
f33cfdadfe
Fix variable lookup order
...
Evaluator uses frames as a stack, so to find the most-recent variable
binding we have to iterate through it the reverse way. This fixes a bug
manifested by:
fn a(x)
x + 20
end
fn b(x)
a(x) + 20
end
2017-09-19 22:10:56 -07:00
greg
231de69084
Added infrastructure for reading files
2017-09-19 22:10:56 -07:00
greg
f014c1a9d9
Kill compiler warnings
2017-09-19 22:10:56 -07:00
greg
c36bc3377e
Fix lookup_binding in function call case
2017-09-19 22:10:56 -07:00
greg
5eba222679
Variable binding in fucntion call work
2017-09-19 22:10:56 -07:00
greg
dcf89aa429
Move lookup_function back onto Evaluator
...
THe problem was that we were borrowing the output of the inner HashMap,
if we clone it we don't borrow anything
2017-09-19 22:10:56 -07:00
greg
1ffbeb6472
Return last value out of function
2017-09-19 22:10:56 -07:00
greg
f8a521fc9b
Start making function calls work
...
This commit isn't fully done yet
2017-09-19 22:10:56 -07:00
greg
77f72806be
Add support for multiple frames
2017-09-19 22:10:56 -07:00
greg
dcde5d6018
Start function call reduction
...
Move the varmap and funcmap functions to the Evaluator, to mkae it
easier to facilitate separate frames
2017-09-19 22:10:56 -07:00
greg
6bb227d052
Rename methods
...
make reduce() the entry point to evaluation
2017-09-19 22:10:56 -07:00
greg
29d4cb53a4
Add infrastructure to do function evaluation
...
Right now you can successfully evaluate a function definition (returning
Null), but cannot call a function
2017-09-19 22:10:56 -07:00
greg
3915c1f035
Remove println from reduction
2017-09-19 22:10:56 -07:00
greg
b400796e4d
Get rid of test variable input
2017-09-19 22:10:56 -07:00
greg
96e6a87f64
Add string concat
2017-09-19 22:10:56 -07:00
greg
b1f9e5cefc
Fix variable lookup
2017-09-19 22:10:56 -07:00
greg
be36d4697d
Pretty-print evaluated AST nodes
2017-09-19 22:10:56 -07:00
greg
ce8c511929
Evaluate additional operators
2017-09-19 22:10:55 -07:00
greg
a8cafa8c64
Move Evaluator state into interpreter state
2017-09-19 22:10:55 -07:00
greg
229e6ae733
More expression parsing work
2017-09-19 22:10:55 -07:00
greg
e9dd0d9ae8
Add concept of Null expression
...
Finally, the null-only behavior is starting to manifest itself!
2017-09-19 22:10:55 -07:00
greg
15d4317191
Add null expression
2017-09-19 22:10:55 -07:00
greg
7114e446a4
Adding, subtracting works
2017-09-19 22:10:55 -07:00
greg
044f534ac5
Start implementing variable lookup
2017-09-19 22:10:55 -07:00
greg
d3207ad890
Move evaluation logic back into methods
...
They need to be able to access the environment which is stored in the
Evalator struct
2017-09-19 22:10:55 -07:00
greg
19fffd5063
Variable binding infrastructure
2017-09-19 22:10:55 -07:00
greg
785c916ece
Start reducing ASTs
...
Start writing code to reduce AST nodes
q
2017-09-19 22:10:55 -07:00
greg
5a9ebb188d
Make Evaluable trait
2017-09-19 22:10:55 -07:00
greg
16e8d969be
Add basic evaluation
2017-09-19 22:10:55 -07:00
greg
70bf68d9bd
More concision in parser
2017-09-19 22:10:55 -07:00
greg
f53c14535b
Made error! macro more programtic
...
TODO implement Display on Token so we're not just displaying the debug
name of the token enum variants
2017-09-19 22:10:55 -07:00
greg
4f96abd7d9
Changes to make the code more concise
2017-09-19 22:10:55 -07:00
greg
fdaf4c302c
Fix all compiler warnings
2017-09-19 22:10:55 -07:00
greg
8ce53d7c72
Fix bind error
2017-09-19 22:10:55 -07:00
greg
428d560e2a
Add tests for call expr parsing
2017-09-19 22:10:55 -07:00
greg
80bc7ec089
Proper call expression parsing
2017-09-19 22:10:55 -07:00
greg
e6591b80d9
Add paren test
2017-09-19 22:10:55 -07:00
greg
e099f713ad
Add binop parsing test
2017-09-19 22:10:55 -07:00
greg
9b54256521
Import types for breivty
...
and rename function to be explicit
2017-09-19 22:10:55 -07:00
greg
087402ece6
Add more tests
...
Need to use box patterns
2017-09-19 22:10:55 -07:00
greg
252b6e8bd9
Okay, this strategy makes the test work
2017-09-19 22:10:55 -07:00
greg
b1163e2ae4
Operator-precedence parsing + tests
...
The tests are crippled now, because it's hard to write a test macro that
can also match on Strings
2017-09-19 22:10:55 -07:00
greg
032d01c9f5
Fix tokenization bug
2017-09-19 22:10:55 -07:00
greg
c4ab1ed105
Fix tokenizer tests
2017-09-19 22:10:55 -07:00
greg
9a257f08d7
Introduce Op type
...
For operator parsing
2017-09-19 22:10:55 -07:00
greg
47d56a7b44
fix operator parsing
2017-09-19 22:10:55 -07:00
greg
1f7ae2e30f
Paren expression
2017-09-19 22:10:55 -07:00
greg
e3c8753a4d
Expression parsing
2017-09-19 22:10:55 -07:00
greg
e1aa7ecb17
Finish tokenizing Op separately
2017-09-19 22:10:55 -07:00
greg
f09a6e14ba
Tokenizer work to support operators
...
work in progress but committing to transfer
2017-09-19 22:10:55 -07:00
greg
31da25a66e
Expression parsing work
2017-09-19 22:10:55 -07:00
greg
fff9cb7d25
Fix functin parsing
2017-09-19 22:10:55 -07:00
greg
db1e188fdb
Move grammar to top of file
2017-09-19 22:10:55 -07:00
greg
935185ed92
more parsing
2017-09-19 22:10:55 -07:00
greg
0999cbe28e
More parsing work
2017-09-19 22:10:55 -07:00
greg
674f70a428
Convert parsing to method-based
2017-09-19 22:10:54 -07:00
greg
b1b6672399
Implement function parsing
...
With a lot of dummy code, especially around expression parsing
2017-09-19 22:10:54 -07:00
greg
bd1c455dc8
Basic infrastructure parses
...
Also got rid of EOF, don't need it
2017-09-19 22:10:54 -07:00
greg
b62ef43f07
Add basic BNF grammar
2017-09-19 22:10:54 -07:00
greg
09b67dc3f7
Change error message
2017-09-19 22:10:54 -07:00
greg
a613fa73e5
Basic parsing framework
2017-09-19 22:10:54 -07:00
greg
8c473c554e
Fix bug
2017-09-19 22:10:54 -07:00
greg
3e04cbfa29
Add comma tokenization
2017-09-19 22:10:54 -07:00
greg
570650cbfa
Finish keyword tokenization
2017-09-19 22:10:54 -07:00
greg
49be163181
Add test to ignore
...
For better handing of user-defined operators, which I will do in the
future
2017-09-19 22:10:54 -07:00
greg
b4f93acbd8
Couple more tests
2017-09-19 22:10:54 -07:00
greg
8c65ae3214
Macro-ize token tests
2017-09-19 22:10:54 -07:00
greg
e436533638
Passing test
2017-09-19 22:10:54 -07:00
greg
4601a56867
Start working on tokenization tests
2017-09-19 22:10:54 -07:00
greg
2f7a1850db
Finish tokenizing
2017-09-19 22:10:54 -07:00
greg
71aef379d3
Tokenize number literals
...
TODO: expand this bit of code to handle 0x12, etc. syntax
2017-09-19 22:10:54 -07:00
greg
8662a3ba0e
Make tokenize error-able
2017-09-19 22:10:54 -07:00
greg
5ca98c7d77
Print tokeniziation
2017-09-19 22:10:54 -07:00
greg
13cde3106c
Start making tokenizer changes
...
Hopefully this time iron out all the bugs from the last implementation
2017-09-19 22:10:54 -07:00
greg
09d524c74a
Changing how parsing works again
...
Someone wrote a port of the LLVM kaleidoscope tutorial to rust, namely
https://github.com/jauhien/iron-kaleidoscope
I'm just gonna follow this along
2017-09-19 22:10:54 -07:00
greg
61c36c4def
Fix assign parsing
...
= is a keyword not an identifier
2017-09-19 22:10:54 -07:00
greg
bc4fbe4276
Start implementing definition
...
WIP, doesn't work
2017-09-19 22:10:54 -07:00
greg
fc11ee753d
Add block parsing
...
Right now evaluating a block reduces it to just the last AST in it, will
fix later with environments
2017-09-19 22:10:54 -07:00
greg
dd2b4893a4
Get rid of Separator token
...
Have separate newline and semicolon tokens
2017-09-19 22:10:54 -07:00
greg
51745fd800
Make convenience macro for parse errors
2017-09-19 22:10:54 -07:00
greg
8c0ac19fa8
Add full test
...
Test evaluate, tokenize, parser all at once
2017-09-19 22:10:54 -07:00
greg
971ab9ba21
Implement paren expressions
2017-09-19 22:10:54 -07:00
greg
819fb3f58f
Basic evaluator functionality
...
Interpreter now works for simple arithmetic expressions
2017-09-19 22:10:54 -07:00
greg
1c23329656
Add boilerplate for evaluation
...
Just wires everything up, doesn't actually evaluate yet
2017-09-19 22:10:54 -07:00
greg
6da20cbfaf
Address compiler warnings
2017-09-19 22:10:54 -07:00
greg
f48451125e
Parsing arithmetic expressions works
...
At the expense of an unnecessary move in lookahead()
2017-09-19 22:10:54 -07:00
greg
06c3999430
Add expect_identifier function
...
For utility
2017-09-19 22:10:54 -07:00
greg
1af1589550
Make Parser class internally use IntoIterator
...
And wrap the next() and peek() methods
2017-09-19 22:10:54 -07:00
greg
32a90b8103
write expect
...
and also make the ParseResult type more general so it can be used for
more things.
2017-09-19 22:10:54 -07:00
greg
186c900920
Implement expect macro
...
Seems like there's no way around passing in self manually
2017-09-19 22:10:54 -07:00
greg
509ab80b9c
I can now parse one thing
2017-09-19 22:10:54 -07:00
greg
247638c4db
Get parsing REPL working
2017-09-19 22:10:54 -07:00
greg
be98f8387e
Add another test
2017-09-19 22:10:54 -07:00
greg
841b38d5b1
Add tokenization test
2017-09-19 22:10:53 -07:00
greg
16dfbb27d5
Use state features from simplerepl
2017-09-19 22:10:53 -07:00
greg
3af7e6a409
Refactoring Schala
...
Gonna work on Schala in earnest now! Using the simplerepl crate instead
of a build-in REPL, temporarily dropping parsing and evaluation code.
2017-09-19 22:10:53 -07:00
greg
123f388711
Rename language to "Schala"
2017-09-19 22:10:53 -07:00
greg
bb349cda5f
Fix newline tokenizing bug
...
Still need to fix <statements> parsing because of the final newline
2017-09-19 22:10:53 -07:00
greg
caa331ecdc
Read from file as well as repl
2017-09-19 22:10:53 -07:00
greg
ae3a030ad8
Use iterative semantics for reduction
...
Becuase if you try to make reduce() recursive you blow out the stack.
Incidentally, "let a = 0; while a < 999999; let a = a + 1 end" is a neat
thing to try at this stage of the game
2017-09-19 22:10:53 -07:00
greg
ddb09b453d
Implement booleans
2017-09-19 22:10:53 -07:00
greg
9a4760d44f
Implement while-reduction
2017-09-19 22:10:53 -07:00
greg
eb5ce2ef9e
Don't print newline for empty REPL result
2017-09-19 22:10:53 -07:00
greg
b080ea7c81
Add if-statement evaluation
2017-09-19 22:10:53 -07:00
greg
dffab8ae94
Fixed arg list parsing
2017-09-19 22:10:53 -07:00
greg
48ee6c9a75
Add function name to parse
2017-09-19 22:10:53 -07:00
greg
58d399dace
More function parsing
2017-09-19 22:10:53 -07:00
greg
57ea1bae30
Preliminary addition of function blocks
2017-09-19 22:10:53 -07:00
greg
e870d8172a
Make = a keyword
2017-09-19 22:10:53 -07:00
greg
72b26755a7
Make ParseResult just a normal Result type
...
No reason for it to be different
2017-09-19 22:10:53 -07:00
greg
1416c9d444
Parse null as simple_expression
2017-09-19 22:10:53 -07:00
greg
5c79563e53
Reduce binop args before reducing full expr
2017-09-19 22:10:53 -07:00
greg
c27c900e7f
Add operators % and **
...
semantics for these are hard with floats handle later
2017-09-19 22:10:53 -07:00
greg
50c5dbe96d
Evaluate simple binops
...
Woo this is kind of a neat milestone! I can now compute with this
language!
2017-09-19 22:10:53 -07:00
greg
be8c8b3343
Add paren test
2017-09-19 22:10:53 -07:00
greg
b856023072
Fixed paren parsing
...
also made error reporting a bit nicer
2017-09-19 22:10:53 -07:00
greg
868373f409
use match syntax in simple_parse
2017-09-19 22:10:53 -07:00
greg
582a7fd6dc
Make parse and tokens optional
2017-09-19 22:10:53 -07:00
greg
a947ec3cb2
Add simple parsing test
2017-09-19 22:10:53 -07:00
greg
79619025ea
Add directive to print precedence chart
2017-09-19 22:10:53 -07:00
greg
56b338a6a8
Move to global precedence table
2017-09-19 22:10:53 -07:00
greg
7d6f946e22
Fill out a few more precedences
2017-09-19 22:10:53 -07:00
greg
0da7f7e3a1
Fully fixed binop parsing
2017-09-19 22:10:53 -07:00
greg
19a344fa77
Fixed precedent-less binop parsing
2017-09-19 22:10:53 -07:00
greg
626a7f3861
Working on binop parsing
2017-09-19 22:10:53 -07:00
greg
8e3a571d67
.env dirctive to display environment
2017-09-19 22:10:53 -07:00
greg
f88f115567
Environment persistent across repl loop
2017-09-19 22:10:53 -07:00
greg
08f1092b69
Variable lookup works
...
Note this introduces a panic - if the AST node inserted into the
environment is not reduced, it throws an error when trying to look it up
2017-09-19 22:10:53 -07:00
greg
6ddea790c0
Beginning of variable lookup
...
everything is null
2017-09-19 22:10:53 -07:00
greg
6897eb1283
Implemented variable binding
2017-09-19 22:10:53 -07:00
greg
34fdf2be00
Add machinery for evaluation environments
2017-09-19 22:10:53 -07:00
greg
4ef93fafb5
Cause tokenize error for unclosed strings
2017-09-19 22:10:53 -07:00
greg
d2108f0f97
First pass at evaluation
...
Very incomplete
2017-09-19 22:10:52 -07:00
greg
2989ac338c
Implemented binop parsing
...
Uses Operator-precedence parsing algorithm, which I don't fully
understand.
2017-09-19 22:10:52 -07:00