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.

46 line
1.1 KiB

6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
  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. }
  31. }
  32. /*
  33. TEST_CASE("crank")
  34. {
  35. crank_context ctx;
  36. static const char* setter_code = "set sample \"Hello world\"";
  37. kstd::string_view setter_c{(char*)setter_code, 24};
  38. ctx.eval_no_copy(setter_c);
  39. static const char* getter_code = "$sample";
  40. kstd::string_view getter_c{(char*)getter_code, 7};
  41. ctx.eval_no_copy(getter_c);
  42. }*/