Subversion Repositories Kolibri OS

Rev

Rev 7565 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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