Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

Sample of generated code

By: eudoxia on Jan 6th, 2012  |  syntax: C++  |  size: 2.35 KB  |  hits: 58  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <string>
  2. #include <iostream>
  3.  
  4. //include the ffcall lib
  5. #include </usr/include/avcall.h>
  6.  
  7. #define FUNCTION_EXTERNAL 0
  8. //... other machine functions
  9. #define TABLE_1 1
  10. #define TABLE_2 2
  11. //... other tables
  12. #define FUNCTION_1 1
  13. #define FUNCTION_2 2
  14. //... other C functions
  15. #define STORE 1
  16. #define NOSTORE 0
  17. //Types:
  18. #define TYPE_INT 0
  19. //... other primitive types
  20.  
  21. //type codes: 0 int, 1 bool
  22.  
  23. int integer_storage;
  24.  
  25. int add(int a, int b)
  26. {
  27.   std::cout << a + b << std::endl;
  28. }
  29.  
  30. template<typename Arg, typename... Args>
  31. void table1_findLookupFunction(const Arg& functionCode, int store, Args... args)
  32. {
  33.   switch(functionCode)
  34.     {
  35.       case 1:
  36.         std::cout << "Table 1. Function code: " << functionCode << std::endl;
  37.         std::cout << "Function: Add" << std::endl;
  38.         if(store)
  39.         {
  40.           integer_storage = add(args...);
  41.         }
  42.         else
  43.         {
  44.           //call function
  45.           add(args...);
  46.         }
  47.         break;
  48.       default:
  49.         std::cout << "Couldn't find function :(" << std::endl;
  50.     }
  51. }
  52.  
  53. template <typename ... Arg>
  54. void table2_findLookupFunction(int functionCode, Arg... args)
  55. {
  56.   std::cout << "Table 2. Function code: " << functionCode << std::endl;
  57. }
  58.  
  59. template <typename ... Arg>
  60. void findLookupTable(int tableCode, int functionCode, int store, Arg... args)
  61. {
  62.   switch(tableCode)
  63.     {
  64.       case 1:
  65.         std::cout << "Table: " << tableCode << std::endl;
  66.         table1_findLookupFunction(functionCode, store, args...);
  67.         break;
  68.       case 2:
  69.         std::cout << "Table: " << tableCode << std::endl;
  70.         table2_findLookupFunction(functionCode, store, args...);
  71.         break;
  72.       default:
  73.         std::cout << "Couldn't find lookup table :(" << std::endl;
  74.     }
  75. }
  76.  
  77.  
  78. int main()
  79. {
  80.   //interpreter goes here
  81.   int command[] = {FUNCTION_EXTERNAL, TABLE_1, FUNCTION_1, STORE, 2, TYPE_INT, 2, TYPE_INT, 2};
  82.   //loop over the commands, then...
  83.   if(command[0] = FUNCTION_EXTERNAL)
  84.   {
  85.     av_alist L;
  86.     av_start_void(L,&findLookupTable);
  87.     av_int(L,command[1]); //push table ID
  88.     av_int(L,command[2]); //push function ID
  89.     av_int(L,command[3]); //push store pseudo-boolean
  90.     for(int argIndex = 5;argIndex <= command[6];argIndex++)
  91.     {
  92.       std::cout << "Command: " << command[argIndex] << std::endl;
  93.     }
  94.     //av_int(L,10);
  95.     //av_double(L,3.14);
  96.     av_call(L);
  97.   }
  98.   //continue the loop
  99.   return 0;
  100. }
  101.  
  102. //compile with g++ sample.cpp -I/usr/include -lavcall