hello. i'm duane.
- experience ( resume )
- contact me ( dedmonds.co )
- coren one ( site , repo )
- othello ( emacs lisp functional programming library )
- comp ( interpreter )
- enc ( emacs encryption )
- leetcode
- language-oriented programming ( blog post )
a clean, stack-based interpreter
Home Page: https://github.com/usefulmove/comp
License: MIT License
hello. i'm duane.
The store commands (sa
, .a
, sb
, ...) cause panic errors when the stack is empty. The panic description does not sufficiently describe the cause of the error to the end user.
% comp sa
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/comp.rs:300:35
Issuing a swap command when the stack has less than 2 elements results in a panic error with a poor description of the cause of the error for the end user.
% comp 1 swap
thread 'main' panicked at 'index out of bounds: the len is 1 but the indes is 18446744073709551615', src/comp.rs:284:16
The Vim syntax highlighting file (support/comp.vim) is out of date and is not consistent with the latest version of comp (0.23.5).
{ fold tests }
(
count
0 [ drop 1 + ] fold
)
Add if..else
functionality to user-defined functions.
It may be useful to have an option to maintain the stack across different sessions. This would allow more complex operations.
% comp 8 io
1
2
3
4
5
6
7
8
% comp prod
40320
The help
, version
, and other command line options have not been implemented.
Passing the drop
operation when the stack is empty results in a panic error with no description of the problem to the end user.
% comp drop
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/comp.rs:274:22
If command line operations are passed after a file is specified using the file option, they are ignored. If this behavior is changed to accept additional operations, it will be possible to define functions in the file that is processed and use the user-defined functions in the following operations.
% comp -f temp.cmp 212 FtoC
100
The maintainability of the pop_stack
family of functions can be improved (e.g., better code reuse) by passing behavior as functions and-or generic functions.
The dup
command still requires that the value on the stack be parsable to a float. This is legacy code from before the stack was changed, and is limiting. Duplication should be independent of the value type. Type checks should now happen at the time of command execution.
It could be cleaner and would be more idiomatic to implement the Interpreter::is_user_function()
method using the Option
return type from the std::option
module.
The restore stored memory instructions (a
, b
, c
) interfere with the operation of the recently-added hexadecimal conversion commands. Example below...
% comp c0 h_d
192
%comp c h_d (this should return 12)
0
%comp 0c h_d
12
The use of an unknown symbol (native operation, user-defined function, or value) in the element list passed to the interpreter causes an unhandled error that results in a panic error being presented to the user with no indication of what caused the error.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }', src/comp.rs:208:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
It may be useful to implement a rot
command that rotates the stack the opposite direction than the current roll
command as is available in the Forth language.
It would be helpful to be able to quickly identify the last element on the top of the stack when there are more than one element on stack.
% comp 1 2 3 4
1
2
3
4
Add log2
and/or logn
commands.
It should be possible to construct the command generator helper function family (commandgen()
, pop_stack...()
, value parsing, etc.) to be type-independent [T]. This could significantly improve code structure and enhance maintainability.
Add TOML support to allow the use of a comp.toml (or similar) configuration file.
The factorial (!) command function does not work correctly for large input values.
There is a significant amount of code duplication in the command response functions (c_...
). It may be possible to simplify the code in meaningful ways ( poss. using function composition ).
The manual unit tests in functions.cm, map.cm, fold.cm, and scan.cm were broken with the merge with the persistence
branch.
The current unit test structure is cumbersome and more difficult to maintain than is ideal. It makes sense to revisit this structure at some point.
Add hexadecimal and binary conversion commands
Tab completion of file path on command line doesn't work.
Edit: Completion appears to work in the Bash shell but not in Zsh (on both macOS and Linux).
Implement parenthetical Lisp syntax for user-defined functions ( change from current fn-end syntax or allow choice )
( fn sum_squares
dup x
swap
dup x +
)
Changing the core stack implementation from a vector of doubles should open additional behaviors (such as hexadecimal to decimal conversion, etc.) that cannot be implemented with the current stack implementation. The current implementation limits future development.
Add a command to multiply an RGB color a scalar value and return the resulting (bounded, etc.) color. The interface should be consistent with the rgb
and rgbh
commands.
The file option has not been implemented as of version 0.15.1.
A panic error occurs when the file path is not specified with the --file
option. The error message does not indicate what caused the error to the user.
% comp --file
thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', src/comp.rs:87:28
stack backtrace:
0: rust_begin_unwind
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
2: core::panicking::panic_bounds_check
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:84:5
3: <usize as core::slice::index::SliceIndex<[T]>>::index
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/slice/index.rs:241:10
4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/slice/index.rs:18:9
5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/vec/mod.rs:2533:9
6: comp::main
at ./src/comp.rs:87:28
7: core::ops::function::FnOnce::call_once
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
There is a bug in the handling of negative values on the stack with the the max_
command.
% comp -1 -5 -10 max_
0
Hi @usefulmove I noticed that you're parsing the arguments by yourself.
I'm referring to src/comp.rs
let mut args: Vec<String> = env::args().collect();
// ...
if args.len() <= 1 {
args.push("help".to_string());
}
// ...
As a suggestion please take a look at this crate, which takes care of argument parsing, (lightweight in comparison to clap)
This is only a suggestion, you're free to dismiss it ๐. Hopefully this will help you with future projects!
Implement comment functionality
The output of the proot
principal root command is incorrect for cases where the discriminant is negative.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.