Ejemplo n.º 1
0
        /* Utility Methods */

        /** apply_setup
         * Unpacks arguments to Procedure in Result from list
         * Pre: Result contains Procedure; register k1 a list;
         *      register k2 the length of that list (fixnum)
         * Returns number of arguments
         * Called by inlined IL of apply
         */
        public static int applySetup(int k1, int k2)
        {
#if HAS_PERFORMANCE_COUNTERS
            if (applySetupCounter != null)
            {
                applySetupCounter.Increment();
            }
#endif
            int n = ((SFixnum)Reg.getRegister(k2)).value;
            if (n < Reg.NREGS - 1)
            {
                // Load registers 1 through n with elts of list in k1
                Reg.spreadRegister(k1, n);
//                SObject p = Reg.getRegister(k1);
//                for (int i = 1; i <= n; ++i) {
//                    SPair pp = (SPair) p;
//                    Reg.setRegister(i, pp.getFirst());
//                    p = pp.getRest();
//                }
            }
            else
            {
                // Load registers 1 to NREGS-2 with first NREGS-2 elts of
                // list in k1 and put remaining tail in register NREG-1
                SPair p = (SPair)Reg.getRegister(k1);

                for (int i = 1; i <= Reg.NREGS - 2; ++i)
                {
                    Reg.setRegister(i, p.getFirst());
                    p = (SPair)p.getRest();
                }
                Reg.setRegister(Reg.NREGS - 1, p);
            }
            return(n);
        }
Ejemplo n.º 2
0
 // ============
 //   Lists
 // ============
 public static SObject copyList(SObject list)
 {
     if (list == Factory.Null)
     {
         return(list);
     }
     else
     {
         SPair copyhead    = new SPair(null, null);
         SPair copyIntoCdr = copyhead;
         SPair listPair    = list as SPair;
         while (listPair != null)
         {
             SPair newpair = new SPair(listPair.first, null);
             copyIntoCdr.rest = newpair;
             copyIntoCdr      = newpair;
             list             = listPair.rest;
             listPair         = list as SPair;
         }
         copyIntoCdr.rest = list;
         return(copyhead.rest);
     }
 }
Ejemplo n.º 3
0
  public static SPair globalCell (string identifier)
  {
    SPair cell = globals[identifier] as SPair;
    if (cell == null) {
	cell = new SPair(Factory.Undefined,
			 Factory.internSymbol (identifier));
	globals[identifier] = cell;
        }
    return cell;
  }
Ejemplo n.º 4
0
 /// <summary>
 /// 把 list 送入非托管空间,返回其指针
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 public static IntPtr slist2_ptr(SPair[] list)
 {
     if (list == null || list.Length == 0)
         return IntPtr.Zero;
     int sz = Marshal.SizeOf(typeof(NativePcsSList2));
     IntPtr lstPtr = Marshal.AllocHGlobal(sz * list.Length);
     IntPtr p = lstPtr;
     byte[] bytes;
     NativePcsSList2 item;
     for (int i = 0; i < list.Length; i++)
     {
         item = new NativePcsSList2();
         item.str1 = utf8_str_ptr(list[i].str1);
         item.str2 = utf8_str_ptr(list[i].str2);
         if (i < list.Length - 1) /*不是最后一个*/
             item.next = IntPtrAdd(p, Marshal.SizeOf(typeof(NativePcsSList2)));
         else
             item.next = IntPtr.Zero;
         bytes = StructToBytes(item);
         Marshal.Copy(bytes, 0, p, bytes.Length);
         p = item.next;
     }
     return lstPtr;
 }
Ejemplo n.º 5
0
        // ============
        //   Lists
        // ============
        public static SObject copyList(SObject list) {
	  if (list == Factory.Null) {
	      return list;
	      }
	  else {
	      SPair copyhead = new SPair(null, null);
	      SPair copyIntoCdr = copyhead;
	      SPair listPair = list as SPair;
	      while (listPair != null) {
		  SPair newpair = new SPair(listPair.first, null);
		  copyIntoCdr.rest = newpair;
		  copyIntoCdr = newpair;
		  list = listPair.rest;
		  listPair = list as SPair;
		  }
	      copyIntoCdr.rest = list;
	      return copyhead.rest;
	      }
        }