Commit Graph

74 Commits

Author SHA1 Message Date
88e9964d9a Recursion finally works
Switched from Box to Rc (Yeah, I peeked at solution but I understood Rc
and RefCell just now) to allow multiple references to env data

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-08-06 18:26:08 +02:00
81cfe11092 Not really like this fix either
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-27 16:57:29 +02:00
24a42d5628 Implemented fn* special form
- Don't really like how it is behaving: turning expressions into a list
of expression and evaluating them separately

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-27 16:50:45 +02:00
fc7328167a Added do form
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-26 18:33:30 +02:00
67a9c6d0ae Implementing conditional and integer comparators
- added `init` function, will be used later to implement functions
- moved `car_cdr` to `types.rs`
- improved some error messages
- implemented `do` and `if` special forms
- implemented comparison between numeric values (integers)
- improved comment

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-24 23:31:42 +02:00
6f28ca5df6 Fixed panic with let*
Previously panic occured on a `let*` with an empty body, due to how
`let_star` and `eval` functions interacted:

 - (let* (a 1)) resulted in an index-out-of-bound panic on trying to
 evaluate the empty body of the statement, a simple guard has been
 inserted, I probably can write it a bit better

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-08 12:49:34 +02:00
148196dae5 Change code syntax to make it a bit better
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-07-08 12:48:53 +02:00
cf68e7094d Cleaning some match statements in eval.rs
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-21 13:47:24 +02:00
d7173c393c Implemented let* special function
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-21 12:17:31 +02:00
3456a62879 Implemented def!
Implemented `def!` to define new symbols into the current
environment, still need to implement `let*`

Added some helper functon for the eval phase

Defined a macro for more readable environment initialization

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-18 01:00:00 +02:00
c8e83ee7a8 Moving to (hopefully) proper references 2023-06-14 00:45:51 +02:00
fe92bbcaa1 Preparing to implement multiple environments
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-13 23:59:39 +02:00
d1c56b02bb Added pointer for outer environment
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-12 00:54:15 +02:00
58cf35a039 Went back to fixed iterative Int eval
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-11 16:30:39 +02:00
f5b324d8f1 Fixed integer operations evaluation recursively
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-11 16:06:54 +02:00
d03f43a94c Added environment with basic math functions
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-11 03:03:25 +02:00
fe6fbf061c Eval cycle implemented
Yet to be implement:
- Environment
- Function calls

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-10 23:19:29 +02:00
7be624e032 Cleaning repl
Cleaning repl, removing multi-statement repl, further implementation as
separated code from the rest

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-10 03:10:47 +02:00
ce21d3b728 Multi-expr repl improved
Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-07 18:50:31 +02:00
54d196582f Oneline multi expression
Multiple expressions can be evaluated on a single line

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-07 14:41:12 +02:00
9d35d24cd4 Error handling and small editor
- Error handling to signal what is preventing evaluation instead of
  program crash
- Small editor feature (allow edit new
line of code to complete the previous ones instead of destroying the
input, if an empty line inserted return the error preventing evaluation
- Auto indentation on multiline input based on depth

Still does not parse multi-statement code
- This is a problem when dealing with macros: does not allow
  expressions like `'()` since the atomic `'` hides the list ().
  Need to chose between:
  - Replace `'...` with `(quote ... )` during tokenization (may be
    hard to implement macros later)
  - Allows multi-statement code (this also allows to execute multiple
    statements when reading a file)

Will probably delete auto-indentation since it breaks code's uniformity
too much
2023-06-07 00:50:06 +02:00
703b6888b5 Implementing new types
- nil symbols
- Bool
- Vectors
- Maps
2023-06-06 16:33:01 +02:00
13790d0864 Step 1: Create an AST
This step consists of creating the AST to represent the input
expression, the only evaluation done for now is the recognition of three
MalTypes for the nodes of the AST:
- Symbols: atomic isolated groups of characters
- Integers: Symbols that can be parsed as number and are treated as so
- Lists: recognizable by the presence of parentheses (only "()" for now,
  "[]" and "{}" later), these can contain any number of MalTypes

The second half of this step (much easier) is to reconstruct the
original syntax (with clean whitespaces) to check the correctness of the
process

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-05 23:04:51 +02:00
b30c7dd6fc Project start: writing step step0_repl
Step 0 alone only act as an echo for the input, define the sructure of
the interpreter

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-01 23:33:27 +02:00