A Tcl like command language made for the Clinl kernel testing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
  2. #include "catch.hpp"
  3. */
  4. #include "crank.h"
  5. #include <iostream>
  6. #include <string>
  7. kstd::string_view put(kstd::string_view args, crank_context& ctx)
  8. {
  9. args = skip_whitespace(args);
  10. auto key = extract_token(args);
  11. auto value = skip_linearspace(kstd::string_view(args.begin()+key.size(),args.end()));
  12. for(auto c : args)
  13. std::cout<<c;
  14. return ctx.store(key,value);
  15. }
  16. int main()
  17. {
  18. const char* putstext = "puts";
  19. std::string get="";
  20. crank_context ctx;
  21. ctx.add_native(kstd::string_view((char*)putstext,4), put);
  22. std::cout<<"> ";
  23. while((std::getline(std::cin,get)).good())
  24. {
  25. auto ret = ctx.eval(kstd::string_view(get.data(), get.size()));
  26. std::cout<<"&> ";
  27. for(auto c : ret)
  28. std::cout<<c;
  29. std::cout<<std::endl<<"> ";
  30. ctx.collect();
  31. }
  32. }
  33. /*
  34. TEST_CASE("crank")
  35. {
  36. crank_context ctx;
  37. static const char* setter_code = "set sample \"Hello world\"";
  38. kstd::string_view setter_c{(char*)setter_code, 24};
  39. ctx.eval_no_copy(setter_c);
  40. static const char* getter_code = "$sample";
  41. kstd::string_view getter_c{(char*)getter_code, 7};
  42. ctx.eval_no_copy(getter_c);
  43. }*/