Coder Social home page Coder Social logo

alice's Introduction

Build Status Build Status Documentation Status License: MIT

alice

alice is a C++-14 command shell library that supports automatic Python bindings. It offers a simple yet feature-rich embedded DSL to create shell interfaces with user-defined commands that access and manipulate arbitrary user-defined data types. Here is a small example for a shell to manipulate `string` objects.

Read the full documentation.

#include <alice/alice.hpp>

#include <algorithm>
#include <iostream>
#include <string>

namespace alice
{

ALICE_ADD_STORE(std::string, "str", "s", "String", "Strings")

ALICE_PRINT_STORE(std::string, os, element)
{
  os << element << std::endl;
}

ALICE_COMMAND(hello, "Generation", "adds a welcome string to the store")
{
  auto& strings = store<std::string>();
  strings.extend() = "hello world";
}

ALICE_COMMAND(upper, "Manipulation", "changes string to upper bound")
{
  auto& str = store<std::string>().current();
  std::transform( str.begin(), str.end(), str.begin(), ::toupper );
}

}

ALICE_MAIN(demo)

After compiling we obtain a shell program with commands that allow us to do the following:

demo> hello
demo> print -s
hello world
demo> hello
demo> upper
demo> print -s
HELLO WORLD
demo> current -s 0
demo> print -s
hello world
demo> quit

We can use the very same code to compile it into a Python library instead of an executable, allowing us to call the commands as Python methods. For example:

import demo

demo.hello()
demo.upper()
demo.print(str = True)

EPFL logic sythesis libraries

alice is part of the EPFL logic synthesis libraries. The other libraries and several examples on how to use and integrate the libraries can be found in the logic synthesis tool showcase.

alice's People

Contributors

bitfis avatar hriener avatar marcelwa avatar msoeken avatar ruanformigoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alice's Issues

Incorrect plural variable name in the docs

Hi, I'm using alice in my project, ropper.

I found a small issue in the docs. The example in the docs shows the following snippet:

namespace alice {

template<>
struct store_info<graph>
{
  static constexpr const char* key = "graph";
  static constexpr const char* option = "graph";
  static constexpr const char* mnemonic = "g";
  static constexpr const char* name = "graph";
  static constexpr const char* name = "graphs";
};

}

But the last variable should be name_plural as follows:

namespace alice {

template<>
struct store_info<graph>
{
  static constexpr const char* key = "graph";
  static constexpr const char* option = "graph";
  static constexpr const char* mnemonic = "g";
  static constexpr const char* name = "graph";
  static constexpr const char* name_plural = "graphs";
};

}

Memory leak issue while running with `-c`

Hey, great project.

While doing some tests and enabling ASAN (-fsanitize=address) I get quite a big dump of issues. This only seems to happen
while trying to run a command directly.

Command: ./shell -c help

Cut ASAN output:

...
hird_party/alice/repo/include/alice/api.hpp:436
    #23 0x55c0cadff99b in alice::insert_commands<alice::cli<>, std::tuple<alice::send_coap_command, alice::start_command, alice::discover_command, alice::read_command>, 4ul>::insert_commands(alice::cli<>&) /home/nimda/test/knx-iot/third_party/alice/repo/include/alice/api.hpp:436
    #24 0x55c0cade740d in main /home/nimda/test/knx-iot/example/shell/knx_shell.cpp:101
    #25 0x7f149b20b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f149b8aa947 in operator new(unsigned long) (/lib/x86_64-linux-gnu/libasan.so.5+0x10f947)
    #1 0x55c0cae615ba in __gnu_cxx::new_allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > >::allocate(unsigned long, void const*) /usr/include/c++/9/ext/new_allocator.h:114
    #2 0x55c0cae4c3de in std::allocator_traits<std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > > >::allocate(std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > >&, unsigned long) /usr/include/c++/9/bits/alloc_traits.h:444
    #3 0x55c0cae2bad7 in std::_Vector_base<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >, std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > > >::_M_allocate(unsigned long) /usr/include/c++/9/bits/stl_vector.h:343
    #4 0x55c0cae0b540 in void std::vector<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >, std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > > >::_M_realloc_insert<>(__gnu_cxx::__normal_iterator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >*, std::vector<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >, std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > > > >) /usr/include/c++/9/bits/vector.tcc:440
    #5 0x55c0cadf1178 in std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >& std::vector<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> >, std::allocator<std::unique_ptr<CLI::Option, std::default_delete<CLI::Option> > > >::emplace_back<>() /usr/include/c++/9/bits/vector.tcc:121
    #6 0x55c0cadca2f4 in CLI::App::add_option(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::function<bool (std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool) /home/nimda/test/knx-iot/third_party/alice/repo/lib/cli11/CLI11.hpp:1694
    #7 0x55c0cadcae04 in CLI::App::add_flag(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) /home/nimda/test/knx-iot/third_party/alice/repo/lib/cli11/CLI11.hpp:1806
    #8 0x55c0cadcaa32 in CLI::App::set_help_flag(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) /home/nimda/test/knx-iot/third_party/alice/repo/lib/cli11/CLI11.hpp:1795
    #9 0x55c0cadc9ba0 in CLI::App::App(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) /home/nimda/test/knx-iot/third_party/alice/repo/lib/cli11/CLI11.hpp:1624
    #10 0x55c0cadde328 in alice::command::command(std::shared_ptr<alice::environment> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/nimda/test/knx-iot/third_party/alice/repo/include/alice/command.hpp:291
    #11 0x55c0cade42b0 in alice::quit_command::quit_command(std::shared_ptr<alice::environment> const&) /home/nimda/test/knx-iot/third_party/alice/repo/include/alice/commands/quit.hpp:55
    #12 0x55c0caecb23a in void __gnu_cxx::new_allocator<alice::quit_command>::construct<alice::quit_command, std::shared_ptr<alice::environment>&>(alice::quit_command*, std::shared_ptr<alice::environment>&) /usr/include/c++/9/ext/new_allocator.h:147
    #13 0x55c0caeb3007 in void std::allocator_traits<std::allocator<alice::quit_command> >::construct<alice::quit_command, std::shared_ptr<alice::environment>&>(std::allocator<alice::quit_command>&, alice::quit_command*, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/alloc_traits.h:484
    #14 0x55c0cae9e545 in std::_Sp_counted_ptr_inplace<alice::quit_command, std::allocator<alice::quit_command>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<alice::environment>&>(std::allocator<alice::quit_command>, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr_base.h:548
    #15 0x55c0cae8a480 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<alice::quit_command, std::allocator<alice::quit_command>, std::shared_ptr<alice::environment>&>(alice::quit_command*&, std::_Sp_alloc_shared_tag<std::allocator<alice::quit_command> >, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr_base.h:679
    #16 0x55c0cae7997d in std::__shared_ptr<alice::quit_command, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<alice::quit_command>, std::shared_ptr<alice::environment>&>(std::_Sp_alloc_shared_tag<std::allocator<alice::quit_command> >, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr_base.h:1344
    #17 0x55c0cae5b7e8 in std::shared_ptr<alice::quit_command>::shared_ptr<std::allocator<alice::quit_command>, std::shared_ptr<alice::environment>&>(std::_Sp_alloc_shared_tag<std::allocator<alice::quit_command> >, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr.h:359
    #18 0x55c0cae4595e in std::shared_ptr<alice::quit_command> std::allocate_shared<alice::quit_command, std::allocator<alice::quit_command>, std::shared_ptr<alice::environment>&>(std::allocator<alice::quit_command> const&, std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr.h:702
    #19 0x55c0cae1e9ab in std::shared_ptr<alice::quit_command> std::make_shared<alice::quit_command, std::shared_ptr<alice::environment>&>(std::shared_ptr<alice::environment>&) /usr/include/c++/9/bits/shared_ptr.h:718
    #20 0x55c0cadfe00b in alice::cli<>::cli(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/nimda/test/knx-iot/third_party/alice/repo/include/alice/cli.hpp:97
    #21 0x55c0cade733d in main /home/nimda/test/knx-iot/example/shell/knx_shell.cpp:101
    #22 0x7f149b20b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: 15445 byte(s) leaked in 103 allocation(s). 

Cheers

Pass arguments while running with `-c`

Hey, short question,

How can I pass arguments while using -c, --command or the -f, --filename option,
aka, is following possible:

shell -c set --var hello --value Value

If not, I would create a pull request if there is any interest.

Thanks and regards

Access variables list within command / list command

Hello dear alice team

I would like to propose a small extension. It currently seems to be not possible to access the variables list or print the variables list. For this I suggest to create a function like env.aliases() -> env.variables(). I think it could be beneficial to allow for better extensibility.

Thanks for the library, it is really helpful ❤️

C++ reserved keyword 'requires'

Greetings,

The code in lib/cli11/CLI11.hpp does not compile when the C++20 standard is enabled, in supported compilers. This is due to the usage of a novel reserved keyword requires as a function name. Consider the replacement suggested in PR #19 or similar.

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.