GithubHelp home page GithubHelp logo

usefulmove / comp Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 8.45 MB

a clean, stack-based interpreter

Home Page: https://github.com/usefulmove/comp

License: MIT License

Rust 99.81% Shell 0.19%
cli interpreter language rpn rpn-calculator rust stack-based

comp's Introduction

comp's People

Contributors

gers2017 avatar usefulmove avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gers2017

comp's Issues

Store commands result in panic error with no value on stack

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

Swap on stack with less than 2 elements results in panic error

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

Vim syntax file is out of date

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
)

Drop on empty stack causes panic

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

Allow additional operations from command line with file option

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

dup still performs a type check

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.

unhandled error: use of unknown symbol causes panic error without presenting information about cause to user

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

Better identify top element on the stack

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

Type-independent command generator helpers ( ? )

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.

Command response function code reuse

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 ).

Unit test setup is cumbersome

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.

Core stack implementation should be improved

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.

panic error when file path is not specified with --file flag

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.

Suggestion to improve argument parsing

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.