Subversion Repositories Kolibri OS

Rev

Rev 7566 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /* Lisp functions */
  3. :dword std_exit()
  4. {
  5.         con_exit stdcall (1);
  6.         ExitProcess();
  7. }
  8.  
  9. :dword std_set(dword count, args)
  10. {
  11.         dword name = 0;
  12.         dword value = 0;
  13.         WHILE(count > 0)
  14.         {
  15.                 name = DSDWORD[args];
  16.                 args += 4;
  17.                 value = DSDWORD[args];
  18.                 args += 4;
  19.                 variables.set(name, value);
  20.                 count -= 2;
  21.         }
  22. }
  23.  
  24. :dword std_get(dword count, args)
  25. {
  26.         IF(!count) RETURN 0;
  27.         RETURN variables.get(DSDWORD[args]);
  28. }
  29.  
  30. :dword std_str(dword count, args)
  31. {
  32.         dword tmp = 0;
  33.         IF(!count) RETURN "";
  34.         tmp = malloc(15);
  35.         itoa_(tmp,DSDWORD[args]);
  36.         RETURN tmp;
  37. }
  38.  
  39. /* Math functions */
  40. :dword std_add(dword count, args)
  41. {
  42.         dword ret = 0;
  43.         WHILE(count)
  44.         {
  45.                 ret += DSDWORD[args];
  46.                 args+=4;
  47.                 count--;
  48.         }
  49.         RETURN ret;
  50. }
  51.  
  52. :dword std_sub(dword count, args)
  53. {
  54.         dword ret = 0;
  55.         IF(count)
  56.         {
  57.                 ret = DSDWORD[args];
  58.                 count--;
  59.                 args+=4;
  60.         }
  61.         WHILE(count)
  62.         {
  63.                 ret -= DSDWORD[args];
  64.                 args += 4;
  65.                 count--;
  66.         }
  67.         RETURN ret;
  68. }
  69.  
  70. /* Console functions */
  71. :dword std_print(dword count, args)
  72. {
  73.         dword ret = 0;
  74.         consoleInit();
  75.         WHILE(count)
  76.         {
  77.                 IF(!DSDWORD[args]) con_printf stdcall ("nil");
  78.                 ELSE con_printf stdcall (DSDWORD[args]);
  79.                 args+=4;
  80.                 count--;
  81.         }
  82.         RETURN ret;
  83. }
  84.  
  85. :dword std_input(dword count, args)
  86. {
  87.         dword buf = 0;
  88.         consoleInit();
  89.         buf = malloc(100);
  90.         WHILE(count)
  91.         {
  92.                 con_printf stdcall (DSDWORD[args]);
  93.                 args+=4;
  94.                 count--;
  95.         }
  96.         con_gets stdcall(buf, 100);
  97.         RETURN EAX;
  98. }
  99.  
  100. void Init()
  101. {
  102.         functions.init(100);
  103.        
  104.         /* Console functions */
  105.         functions.set("print", #std_print);
  106.         functions.set("input", #std_input);
  107.        
  108.         /* String functions */
  109.         functions.set("str", #std_str);
  110.        
  111.         /* System functions */
  112.         functions.set("exit", #std_exit);
  113.        
  114.         /* Math functions */
  115.         functions.set("+", #std_add);
  116.         functions.set("-", #std_sub);
  117.        
  118.         /* Lisp functions */
  119.         functions.set("set", #std_set);
  120.         functions.set("get", #std_get);
  121.        
  122.         variables.init(100);
  123. }
  124.  
  125. dword StdCall(dword count, name, args)
  126. {
  127.         functions.get(name);
  128.         IF(EAX) RETURN EAX(count, args);
  129.         RETURN 0;
  130. }
  131.  
  132.