Subversion Repositories Kolibri OS

Rev

Rev 7564 | 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.         WHILE(count)
  69.         {
  70.                 con_printf stdcall (DSDWORD[args]);
  71.                 args+=4;
  72.                 count--;
  73.         }
  74.         RETURN ret;
  75. }
  76.  
  77. :dword std_input(dword count, args)
  78. {
  79.         dword buf = 0;
  80.         buf = malloc(100);
  81.         WHILE(count)
  82.         {
  83.                 con_printf stdcall (DSDWORD[args]);
  84.                 args+=4;
  85.                 count--;
  86.         }
  87.         con_gets stdcall(buf, 100);
  88.         RETURN EAX;
  89. }
  90.  
  91. void Init()
  92. {
  93.         functions.init(100);
  94.        
  95.         /* Console functions */
  96.         functions.set("print", #std_print);
  97.         functions.set("input", #std_input);
  98.        
  99.         /* String functions */
  100.         functions.set("str", #std_str);
  101.        
  102.         /* System functions */
  103.         functions.set("exit", #ExitProcess);
  104.        
  105.         /* Math functions */
  106.         functions.set("+", #std_add);
  107.         functions.set("-", #std_sub);
  108.        
  109.         /* Lisp functions */
  110.         functions.set("set", #std_set);
  111.         functions.set("get", #std_get);
  112.        
  113.         variables.init(100);
  114. }
  115.  
  116. dword StdCall(dword count, name, args)
  117. {
  118.         functions.get(name);
  119.         IF(EAX) RETURN EAX(count, args);
  120.         RETURN 0;
  121. }
  122.  
  123.