From a417b0e70dfc96dc6a20823df174c759c06f66fa Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Sun, 11 Apr 2010 20:26:11 -0700
Subject: [PATCH 1/6] vm: speed up nano-count primitive on Mac OS X

---
 vm/os-genunix.cpp |  3 +--
 vm/os-macosx.mm   | 19 +++++++++++++------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/vm/os-genunix.cpp b/vm/os-genunix.cpp
index c7449e867b..fb5ecf9f50 100644
--- a/vm/os-genunix.cpp
+++ b/vm/os-genunix.cpp
@@ -38,8 +38,7 @@ const char *default_image_path()
 u64 nano_count()
 {
 	struct timespec t;
-	int ret;
-	ret = clock_gettime(CLOCK_MONOTONIC,&t);
+	int ret = clock_gettime(CLOCK_MONOTONIC,&t);
 	if(ret != 0)
 		fatal_error("clock_gettime failed", 0);
 	return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
diff --git a/vm/os-macosx.mm b/vm/os-macosx.mm
index 4a6a3cb2b4..05a9aef5c8 100644
--- a/vm/os-macosx.mm
+++ b/vm/os-macosx.mm
@@ -87,12 +87,19 @@ Protocol *objc_getProtocol(char *name)
 
 u64 nano_count()
 {
-	u64 t = mach_absolute_time();
-	mach_timebase_info_data_t info;
-	kern_return_t ret = mach_timebase_info(&info);
-	if(ret != 0)
-		fatal_error("mach_timebase_info failed",ret);
-	return t * (info.numer/info.denom);
+	u64 time = mach_absolute_time();
+
+	static u64 scaling_factor = 0;
+	if(!scaling_factor)
+	{
+		mach_timebase_info_data_t info;
+		kern_return_t ret = mach_timebase_info(&info);
+		if(ret != 0)
+			fatal_error("mach_timebase_info failed",ret);
+		scaling_factor = info.numer/info.denom;
+	}
+
+	return time * scaling_factor;
 }
 
 }

From eaccd0b56ae2426eeea9a07f0df18a1f8b5cea12 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@factorcode.org>
Date: Sun, 11 Apr 2010 22:27:49 -0500
Subject: [PATCH 2/6] vm: speed up nano-count primitive on Windows

---
 vm/os-windows-nt.cpp | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp
index 4fea294a12..97cd2146af 100755
--- a/vm/os-windows-nt.cpp
+++ b/vm/os-windows-nt.cpp
@@ -18,17 +18,24 @@ u64 system_micros()
 
 u64 nano_count()
 {
-	LARGE_INTEGER count;
-	LARGE_INTEGER frequency;
+	static double scale_factor;
+
 	static u32 hi = 0;
 	static u32 lo = 0;
-	BOOL ret;
-	ret = QueryPerformanceCounter(&count);
+
+	LARGE_INTEGER count;
+	BOOL ret = QueryPerformanceCounter(&count);
 	if(ret == 0)
 		fatal_error("QueryPerformanceCounter", 0);
-	ret = QueryPerformanceFrequency(&frequency);
-	if(ret == 0)
-		fatal_error("QueryPerformanceFrequency", 0);
+
+	if(scale_factor == 0.0)
+	{
+		LARGE_INTEGER frequency;
+		BOOL ret = QueryPerformanceFrequency(&frequency);
+		if(ret == 0)
+			fatal_error("QueryPerformanceFrequency", 0);
+		scale_factor = (1000000000.0 / frequency.QuadPart);
+	}
 
 #ifdef FACTOR_64
 	hi = count.HighPart;
@@ -40,7 +47,7 @@ u64 nano_count()
 #endif
 	lo = count.LowPart;
 
-	return (u64)((((u64)hi << 32) | (u64)lo)*(1000000000.0/frequency.QuadPart));
+	return (u64)((((u64)hi << 32) | (u64)lo) * scale_factor);
 }
 
 void sleep_nanos(u64 nsec)

From 5478913e195bb0a0569c9c74c3eafc9838e4b547 Mon Sep 17 00:00:00 2001
From: Erik Charlebois <erikcharlebois@gmail.com>
Date: Sun, 11 Apr 2010 23:51:50 -0700
Subject: [PATCH 3/6] Remove unix.types dependency from macho

---
 extra/macho/macho.factor | 442 +++++++++++++++++++--------------------
 1 file changed, 221 insertions(+), 221 deletions(-)

diff --git a/extra/macho/macho.factor b/extra/macho/macho.factor
index 57424cd243..e3765260bb 100644
--- a/extra/macho/macho.factor
+++ b/extra/macho/macho.factor
@@ -1,6 +1,6 @@
 ! Copyright (C) 2010 Erik Charlebois.
 ! See http:// factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax classes.struct kernel literals math unix.types ;
+USING: alien.c-types alien.syntax classes.struct kernel literals math ;
 IN: macho
 
 TYPEDEF: int       integer_t
@@ -21,26 +21,26 @@ CONSTANT: VM_PROT_WANTS_COPY  HEX: 10
 
 ! loader.h
 STRUCT: mach_header
-    { magic         uint32_t      }
+    { magic         uint          }
     { cputype       cpu_type_t    }
     { cpusubtype    cpu_subtype_t }
-    { filetype      uint32_t      }
-    { ncmds         uint32_t      }
-    { sizeofcmds    uint32_t      }
-    { flags         uint32_t      } ;
+    { filetype      uint          }
+    { ncmds         uint          }
+    { sizeofcmds    uint          }
+    { flags         uint          } ;
 
 CONSTANT: MH_MAGIC    HEX: feedface
 CONSTANT: MH_CIGAM    HEX: cefaedfe
 
 STRUCT: mach_header_64
-    { magic         uint32_t      }
+    { magic         uint          }
     { cputype       cpu_type_t    }
     { cpusubtype    cpu_subtype_t }
-    { filetype      uint32_t      }
-    { ncmds         uint32_t      }
-    { sizeofcmds    uint32_t      }
-    { flags         uint32_t      }
-    { reserved      uint32_t      } ;
+    { filetype      uint          }
+    { ncmds         uint          }
+    { sizeofcmds    uint          }
+    { flags         uint          }
+    { reserved      uint          } ;
 
 CONSTANT: MH_MAGIC_64 HEX: feedfacf
 CONSTANT: MH_CIGAM_64 HEX: cffaedfe
@@ -82,8 +82,8 @@ CONSTANT: MH_NO_REEXPORTED_DYLIBS    HEX: 100000
 CONSTANT: MH_PIE                     HEX: 200000
 
 STRUCT: load_command
-    { cmd     uint32_t }
-    { cmdsize uint32_t } ;
+    { cmd     uint }
+    { cmdsize uint } ;
 
 CONSTANT: LC_REQ_DYLD HEX: 80000000
 
@@ -124,35 +124,35 @@ CONSTANT: LC_DYLD_INFO          HEX: 22
 CONSTANT: LC_DYLD_INFO_ONLY     HEX: 80000022
 
 UNION-STRUCT: lc_str
-    { offset    uint32_t }
+    { offset    uint     }
     { ptr       char*    } ;
 
 STRUCT: segment_command
-    { cmd            uint32_t  }
-    { cmdsize        uint32_t  }
+    { cmd            uint      }
+    { cmdsize        uint      }
     { segname        char[16]  }
-    { vmaddr         uint32_t  }
-    { vmsize         uint32_t  }
-    { fileoff        uint32_t  }
-    { filesize       uint32_t  }
+    { vmaddr         uint      }
+    { vmsize         uint      }
+    { fileoff        uint      }
+    { filesize       uint      }
     { maxprot        vm_prot_t }
     { initprot       vm_prot_t }
-    { nsects         uint32_t  }
-    { flags          uint32_t  } ;
+    { nsects         uint      }
+    { flags          uint      } ;
 
 STRUCT: segment_command_64
-    { cmd            uint32_t  }
-    { cmdsize        uint32_t  }
-    { segname        char[16]  }
-    { vmaddr         uint64_t  }
-    { vmsize         uint64_t  }
-    { fileoff        uint64_t  }
-    { filesize       uint64_t  }
-    { maxprot        vm_prot_t }
-    { initprot       vm_prot_t }
-    { nsects         uint32_t  }
-    { flags          uint32_t  } ;
-
+    { cmd            uint       }
+    { cmdsize        uint       }
+    { segname        char[16]   }
+    { vmaddr         ulonglong  }
+    { vmsize         ulonglong  }
+    { fileoff        ulonglong  }
+    { filesize       ulonglong  }
+    { maxprot        vm_prot_t  }
+    { initprot       vm_prot_t  }
+    { nsects         uint       }
+    { flags          uint       } ;
+    
 CONSTANT: SG_HIGHVM               HEX: 1
 CONSTANT: SG_FVMLIB               HEX: 2
 CONSTANT: SG_NORELOC              HEX: 4
@@ -161,29 +161,29 @@ CONSTANT: SG_PROTECTED_VERSION_1  HEX: 8
 STRUCT: section
     { sectname        char[16] }
     { segname         char[16] }
-    { addr            uint32_t }
-    { size            uint32_t }
-    { offset          uint32_t }
-    { align           uint32_t }
-    { reloff          uint32_t }
-    { nreloc          uint32_t }
-    { flags           uint32_t }
-    { reserved1       uint32_t }
-    { reserved2       uint32_t } ;
+    { addr            uint     }
+    { size            uint     }
+    { offset          uint     }
+    { align           uint     }
+    { reloff          uint     }
+    { nreloc          uint     }
+    { flags           uint     }
+    { reserved1       uint     }
+    { reserved2       uint     } ;
 
 STRUCT: section_64
-    { sectname        char[16] }
-    { segname         char[16] }
-    { addr            uint64_t }
-    { size            uint64_t }
-    { offset          uint32_t }
-    { align           uint32_t }
-    { reloff          uint32_t }
-    { nreloc          uint32_t }
-    { flags           uint32_t }
-    { reserved1       uint32_t }
-    { reserved2       uint32_t }
-    { reserved3       uint32_t } ;
+    { sectname        char[16]  }
+    { segname         char[16]  }
+    { addr            ulonglong }
+    { size            ulonglong }
+    { offset          uint      }
+    { align           uint      }
+    { reloff          uint      }
+    { nreloc          uint      }
+    { flags           uint      }
+    { reserved1       uint      }
+    { reserved2       uint      }
+    { reserved3       uint      } ;
 
 CONSTANT: SECTION_TYPE         HEX: 000000ff
 CONSTANT: SECTION_ATTRIBUTES   HEX: ffffff00
@@ -242,205 +242,205 @@ CONSTANT: SEG_IMPORT        "__IMPORT"
 
 STRUCT: fvmlib
     { name             lc_str   }
-    { minor_version    uint32_t }
-    { header_addr      uint32_t } ;
+    { minor_version    uint     }
+    { header_addr      uint     } ;
 
 STRUCT: fvmlib_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
+    { cmd        uint     }
+    { cmdsize    uint     }
     { fvmlib     fvmlib   } ;
 
 STRUCT: dylib
     { name                  lc_str   }
-    { timestamp             uint32_t }
-    { current_version       uint32_t }
-    { compatibility_version uint32_t } ;
+    { timestamp             uint     }
+    { current_version       uint     }
+    { compatibility_version uint     } ;
 
 STRUCT: dylib_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
+    { cmd        uint     }
+    { cmdsize    uint     }
     { dylib      dylib    } ;
 
 STRUCT: sub_framework_command
-    { cmd         uint32_t }
-    { cmdsize     uint32_t }
+    { cmd         uint     }
+    { cmdsize     uint     }
     { umbrella    lc_str   } ;
 
 STRUCT: sub_client_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
+    { cmd        uint     }
+    { cmdsize    uint     }
     { client     lc_str   } ;
 
 STRUCT: sub_umbrella_command
-    { cmd             uint32_t }
-    { cmdsize         uint32_t }
+    { cmd             uint     }
+    { cmdsize         uint     }
     { sub_umbrella    lc_str   } ;
 
 STRUCT: sub_library_command
-    { cmd            uint32_t }
-    { cmdsize        uint32_t }
+    { cmd            uint     }
+    { cmdsize        uint     }
     { sub_library    lc_str   } ;
 
 STRUCT: prebound_dylib_command
-    { cmd               uint32_t }
-    { cmdsize           uint32_t }
+    { cmd               uint     }
+    { cmdsize           uint     }
     { name              lc_str   }
-    { nmodules          uint32_t }
+    { nmodules          uint     }
     { linked_modules    lc_str   } ;
 
 STRUCT: dylinker_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
+    { cmd        uint     }
+    { cmdsize    uint     }
     { name       lc_str   } ;
 
 STRUCT: thread_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t } ;
+    { cmd        uint }
+    { cmdsize    uint } ;
 
 STRUCT: routines_command
-    { cmd             uint32_t }
-    { cmdsize         uint32_t }
-    { init_address    uint32_t }
-    { init_module     uint32_t }
-    { reserved1       uint32_t }
-    { reserved2       uint32_t }
-    { reserved3       uint32_t }
-    { reserved4       uint32_t }
-    { reserved5       uint32_t }
-    { reserved6       uint32_t } ;
+    { cmd             uint }
+    { cmdsize         uint }
+    { init_address    uint }
+    { init_module     uint }
+    { reserved1       uint }
+    { reserved2       uint }
+    { reserved3       uint }
+    { reserved4       uint }
+    { reserved5       uint }
+    { reserved6       uint } ;
 
 STRUCT: routines_command_64
-    { cmd             uint32_t }
-    { cmdsize         uint32_t }
-    { init_address    uint64_t }
-    { init_module     uint64_t }
-    { reserved1       uint64_t }
-    { reserved2       uint64_t }
-    { reserved3       uint64_t }
-    { reserved4       uint64_t }
-    { reserved5       uint64_t }
-    { reserved6       uint64_t } ;
+    { cmd             uint      }
+    { cmdsize         uint      }
+    { init_address    ulonglong }
+    { init_module     ulonglong }
+    { reserved1       ulonglong }
+    { reserved2       ulonglong }
+    { reserved3       ulonglong }
+    { reserved4       ulonglong }
+    { reserved5       ulonglong }
+    { reserved6       ulonglong } ;
 
 STRUCT: symtab_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
-    { symoff     uint32_t }
-    { nsyms      uint32_t }
-    { stroff     uint32_t }
-    { strsize    uint32_t } ;
+    { cmd        uint }
+    { cmdsize    uint }
+    { symoff     uint }
+    { nsyms      uint }
+    { stroff     uint }
+    { strsize    uint } ;
 
 STRUCT: dysymtab_command
-    { cmd            uint32_t }
-    { cmdsize        uint32_t }
-    { ilocalsym      uint32_t }
-    { nlocalsym      uint32_t }
-    { iextdefsym     uint32_t }
-    { nextdefsym     uint32_t }
-    { iundefsym      uint32_t }
-    { nundefsym      uint32_t }
-    { tocoff         uint32_t }
-    { ntoc           uint32_t }
-    { modtaboff      uint32_t }
-    { nmodtab        uint32_t }
-    { extrefsymoff   uint32_t }
-    { nextrefsyms    uint32_t }
-    { indirectsymoff uint32_t }
-    { nindirectsyms  uint32_t }
-    { extreloff      uint32_t }
-    { nextrel        uint32_t }
-    { locreloff      uint32_t }
-    { nlocrel        uint32_t } ;
+    { cmd            uint }
+    { cmdsize        uint }
+    { ilocalsym      uint }
+    { nlocalsym      uint }
+    { iextdefsym     uint }
+    { nextdefsym     uint }
+    { iundefsym      uint }
+    { nundefsym      uint }
+    { tocoff         uint }
+    { ntoc           uint }
+    { modtaboff      uint }
+    { nmodtab        uint }
+    { extrefsymoff   uint }
+    { nextrefsyms    uint }
+    { indirectsymoff uint }
+    { nindirectsyms  uint }
+    { extreloff      uint }
+    { nextrel        uint }
+    { locreloff      uint }
+    { nlocrel        uint } ;
 
 CONSTANT: INDIRECT_SYMBOL_LOCAL HEX: 80000000
 CONSTANT: INDIRECT_SYMBOL_ABS   HEX: 40000000
 
 STRUCT: dylib_table_of_contents
-    { symbol_index uint32_t }
-    { module_index uint32_t } ;
+    { symbol_index uint }
+    { module_index uint } ;
 
 STRUCT: dylib_module
-    { module_name           uint32_t }
-    { iextdefsym            uint32_t }
-    { nextdefsym            uint32_t }
-    { irefsym               uint32_t }
-    { nrefsym               uint32_t }
-    { ilocalsym             uint32_t }
-    { nlocalsym             uint32_t }
-    { iextrel               uint32_t }
-    { nextrel               uint32_t }
-    { iinit_iterm           uint32_t }
-    { ninit_nterm           uint32_t }
-    { objc_module_info_addr uint32_t }
-    { objc_module_info_size uint32_t } ;
+    { module_name           uint }
+    { iextdefsym            uint }
+    { nextdefsym            uint }
+    { irefsym               uint }
+    { nrefsym               uint }
+    { ilocalsym             uint }
+    { nlocalsym             uint }
+    { iextrel               uint }
+    { nextrel               uint }
+    { iinit_iterm           uint }
+    { ninit_nterm           uint }
+    { objc_module_info_addr uint }
+    { objc_module_info_size uint } ;
 
 STRUCT: dylib_module_64
-    { module_name           uint32_t }
-    { iextdefsym            uint32_t }
-    { nextdefsym            uint32_t }
-    { irefsym               uint32_t }
-    { nrefsym               uint32_t }
-    { ilocalsym             uint32_t }
-    { nlocalsym             uint32_t }
-    { iextrel               uint32_t }
-    { nextrel               uint32_t }
-    { iinit_iterm           uint32_t }
-    { ninit_nterm           uint32_t }
-    { objc_module_info_size uint32_t }
-    { objc_module_info_addr uint64_t } ;
+    { module_name           uint      }
+    { iextdefsym            uint      }
+    { nextdefsym            uint      }
+    { irefsym               uint      }
+    { nrefsym               uint      }
+    { ilocalsym             uint      }
+    { nlocalsym             uint      }
+    { iextrel               uint      }
+    { nextrel               uint      }
+    { iinit_iterm           uint      }
+    { ninit_nterm           uint      }
+    { objc_module_info_size uint      }
+    { objc_module_info_addr ulonglong } ;
 
 STRUCT: dylib_reference
-    { isym_flags uint32_t } ;
+    { isym_flags uint } ;
 
 STRUCT: twolevel_hints_command
-    { cmd     uint32_t }
-    { cmdsize uint32_t }
-    { offset  uint32_t }
-    { nhints  uint32_t } ;
+    { cmd     uint }
+    { cmdsize uint }
+    { offset  uint }
+    { nhints  uint } ;
 
 STRUCT: twolevel_hint
-    { isub_image_itoc uint32_t } ;
+    { isub_image_itoc uint } ;
 
 STRUCT: prebind_cksum_command
-    { cmd     uint32_t }
-    { cmdsize uint32_t }
-    { cksum   uint32_t } ;
+    { cmd     uint }
+    { cmdsize uint }
+    { cksum   uint } ;
 
 STRUCT: uuid_command
-    { cmd        uint32_t    }
-    { cmdsize    uint32_t    }
-    { uuid       uint8_t[16] } ;
+    { cmd        uint        }
+    { cmdsize    uint        }
+    { uuid       uchar[16]   } ;
 
 STRUCT: rpath_command
-    { cmd         uint32_t }
-    { cmdsize     uint32_t }
+    { cmd         uint     }
+    { cmdsize     uint     }
     { path        lc_str   } ;
 
 STRUCT: linkedit_data_command
-    { cmd         uint32_t }
-    { cmdsize     uint32_t }
-    { dataoff     uint32_t }
-    { datasize    uint32_t } ;
+    { cmd         uint }
+    { cmdsize     uint }
+    { dataoff     uint }
+    { datasize    uint } ;
 
 STRUCT: encryption_info_command
-    { cmd       uint32_t }
-    { cmdsize   uint32_t }
-    { cryptoff  uint32_t }
-    { cryptsize uint32_t }
-    { cryptid   uint32_t } ;
+    { cmd       uint }
+    { cmdsize   uint }
+    { cryptoff  uint }
+    { cryptsize uint }
+    { cryptid   uint } ;
 
 STRUCT: dyld_info_command
-    { cmd              uint32_t }
-    { cmdsize          uint32_t }
-    { rebase_off       uint32_t }
-    { rebase_size      uint32_t }
-    { bind_off         uint32_t }
-    { bind_size        uint32_t }
-    { weak_bind_off    uint32_t }
-    { weak_bind_size   uint32_t }
-    { lazy_bind_off    uint32_t }
-    { lazy_bind_size   uint32_t }
-    { export_off       uint32_t }
-    { export_size      uint32_t } ;
+    { cmd              uint }
+    { cmdsize          uint }
+    { rebase_off       uint }
+    { rebase_size      uint }
+    { bind_off         uint }
+    { bind_size        uint }
+    { weak_bind_off    uint }
+    { weak_bind_size   uint }
+    { lazy_bind_off    uint }
+    { lazy_bind_size   uint }
+    { export_off       uint }
+    { export_size      uint } ;
 
 CONSTANT: REBASE_TYPE_POINTER                     1
 CONSTANT: REBASE_TYPE_TEXT_ABSOLUTE32             2
@@ -493,20 +493,20 @@ CONSTANT: EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION         HEX: 08
 CONSTANT: EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS         HEX: 10
 
 STRUCT: symseg_command
-    { cmd        uint32_t }
-    { cmdsize    uint32_t }
-    { offset     uint32_t }
-    { size       uint32_t } ;
+    { cmd        uint }
+    { cmdsize    uint }
+    { offset     uint }
+    { size       uint } ;
 
 STRUCT: ident_command
-    { cmd     uint32_t }
-    { cmdsize uint32_t } ;
+    { cmd     uint }
+    { cmdsize uint } ;
 
 STRUCT: fvmfile_command
-    { cmd            uint32_t }
-    { cmdsize        uint32_t }
+    { cmd            uint     }
+    { cmdsize        uint     }
     { name           lc_str   }
-    { header_addr    uint32_t } ;
+    { header_addr    uint     } ;
 
 ! machine.h
 CONSTANT: CPU_STATE_MAX       4
@@ -670,30 +670,30 @@ CONSTANT: FAT_MAGIC HEX: cafebabe
 CONSTANT: FAT_CIGAM HEX: bebafeca
 
 STRUCT: fat_header
-    { magic        uint32_t }
-    { nfat_arch    uint32_t } ;
+    { magic        uint }
+    { nfat_arch    uint } ;
 
 STRUCT: fat_arch
     { cputype      cpu_type_t    }
     { cpusubtype   cpu_subtype_t }
-    { offset       uint32_t      }
-    { size         uint32_t      }
-    { align        uint32_t      } ;
+    { offset       uint          }
+    { size         uint          }
+    { align        uint          } ;
 
 ! nlist.h
 STRUCT: nlist
-    { n_strx  int32_t  }
-    { n_type  uint8_t  }
-    { n_sect  uint8_t  }
-    { n_desc  int16_t  }
-    { n_value uint32_t } ;
+    { n_strx  int      }
+    { n_type  uchar    }
+    { n_sect  uchar    }
+    { n_desc  short    }
+    { n_value uint     } ;
 
 STRUCT: nlist_64
-    { n_strx  uint32_t }
-    { n_type  uint8_t  }
-    { n_sect  uint8_t  }
-    { n_desc  uint16_t }
-    { n_value uint64_t } ;
+    { n_strx  uint      }
+    { n_type  uchar     }
+    { n_sect  uchar     }
+    { n_desc  ushort    }
+    { n_value ulonglong } ;
 
 CONSTANT: N_STAB  HEX: e0
 CONSTANT: N_PEXT  HEX: 10
@@ -750,24 +750,24 @@ CONSTANT: SYMDEF        "__.SYMDEF"
 CONSTANT: SYMDEF_SORTED "__.SYMDEF SORTED"
 
 STRUCT: ranlib
-    { ran_strx uint32_t }
-    { ran_off  uint32_t } ;
+    { ran_strx uint }
+    { ran_off  uint } ;
 
 ! reloc.h
 STRUCT: relocation_info
-    { r_address                            int32_t  }
-    { r_symbolnum_pcrel_length_extern_type uint32_t } ;
+    { r_address                            int  }
+    { r_symbolnum_pcrel_length_extern_type uint } ;
 
 CONSTANT: R_ABS   0
 CONSTANT: R_SCATTERED HEX: 80000000
 
 STRUCT: scattered_relocation_info_big_endian
-    { r_scattered_pcrel_length_type_address  uint32_t }
-    { r_value                                int32_t  } ;
+    { r_scattered_pcrel_length_type_address  uint }
+    { r_value                                int  } ;
 
 STRUCT: scattered_relocation_info_little_endian
-    { r_address_type_length_pcrel_scattered uint32_t }
-    { r_value                               int32_t  } ;
+    { r_address_type_length_pcrel_scattered uint }
+    { r_value                               int  } ;
 
 C-ENUM: reloc_type_generic
     GENERIC_RELOC_VANILLA

From 3d4dadffe2728c8de93cc1c0af4e4e9246434246 Mon Sep 17 00:00:00 2001
From: Erik Charlebois <erikcharlebois@gmail.com>
Date: Mon, 12 Apr 2010 00:49:16 -0700
Subject: [PATCH 4/6] Image encoding/decoding of PBM format

---
 basis/images/pbm/authors.txt             |   1 +
 basis/images/pbm/pbm-tests.factor        |   7 +
 basis/images/pbm/pbm.factor              |  85 ++++++
 basis/images/pbm/summary.txt             |   1 +
 extra/images/testing/pbm/test.ascii.fig  | Bin 0 -> 25659 bytes
 extra/images/testing/pbm/test.ascii.pbm  | 369 +++++++++++++++++++++++
 extra/images/testing/pbm/test.binary.fig | Bin 0 -> 25659 bytes
 extra/images/testing/pbm/test.binary.pbm | Bin 0 -> 3250 bytes
 8 files changed, 463 insertions(+)
 create mode 100644 basis/images/pbm/authors.txt
 create mode 100644 basis/images/pbm/pbm-tests.factor
 create mode 100644 basis/images/pbm/pbm.factor
 create mode 100644 basis/images/pbm/summary.txt
 create mode 100644 extra/images/testing/pbm/test.ascii.fig
 create mode 100644 extra/images/testing/pbm/test.ascii.pbm
 create mode 100644 extra/images/testing/pbm/test.binary.fig
 create mode 100644 extra/images/testing/pbm/test.binary.pbm

diff --git a/basis/images/pbm/authors.txt b/basis/images/pbm/authors.txt
new file mode 100644
index 0000000000..6f03a12101
--- /dev/null
+++ b/basis/images/pbm/authors.txt
@@ -0,0 +1 @@
+Erik Charlebois
diff --git a/basis/images/pbm/pbm-tests.factor b/basis/images/pbm/pbm-tests.factor
new file mode 100644
index 0000000000..73558cc144
--- /dev/null
+++ b/basis/images/pbm/pbm-tests.factor
@@ -0,0 +1,7 @@
+! Copyright (C) 2010 Erik Charlebois.
+! See http://factorcode.org/license.txt for BSD license.
+USING: images.testing ;
+IN: images.pbm.tests
+
+"vocab:images/testing/pbm/test.binary.pbm" decode-test
+"vocab:images/testing/pbm/test.ascii.pbm" decode-test
diff --git a/basis/images/pbm/pbm.factor b/basis/images/pbm/pbm.factor
new file mode 100644
index 0000000000..ba27c545cf
--- /dev/null
+++ b/basis/images/pbm/pbm.factor
@@ -0,0 +1,85 @@
+! Copyright (C) 2010 Erik Charlebois.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types arrays ascii bit-arrays byte-arrays
+combinators continuations grouping images images.loader io
+io.encodings.ascii io.encodings.string kernel locals make math
+math.functions math.parser sequences specialized-arrays ;
+SPECIALIZED-ARRAY: ushort
+IN: images.pbm
+
+SINGLETON: pbm-image
+"pbm" pbm-image register-image-class
+
+<PRIVATE
+: read-token ( -- token )
+    [ read1 dup blank?
+      [ t ]
+      [ dup CHAR: # =
+        [ "\n" read-until 2drop t ]
+        [ f ] if
+      ] if
+    ] [ drop ] while
+    " \n\r\t" read-until drop swap
+    prefix ascii decode ;
+
+: read-number ( -- number )
+    read-token string>number ;
+
+: read-ascii-bits ( -- )
+    read1 {
+        { CHAR: 1 [ 0 , read-ascii-bits ] }
+        { CHAR: 0 [ 255 , read-ascii-bits ] }
+        { f [ ] }
+        [ drop read-ascii-bits ]
+    } case ;
+
+:: read-binary-bits ( width height -- )
+    width 8 align 8 / height * read
+    width 8 align 8 / <groups> [| row |
+        width iota [| n |
+            n 8 / floor row nth
+            n 8 mod 7 swap - bit?
+            [ 0 ] [ 255 ] if ,
+        ] each
+    ] each ;
+
+:: write-binary-bits ( bitmap width -- )
+    bitmap width <groups> [
+        width 8 align 255 pad-tail
+        8 <groups> [
+            [ 255 = [ f ] [ t ] if ] { } map-as
+            >bit-array reverse bit-array>integer
+            1array >byte-array write
+        ] each
+    ] each ;
+
+:: read-pbm ( -- image )
+    read-token     :> type
+    read-number    :> width
+    read-number    :> height
+    width height * :> npixels
+    width 8 mod    :> leftover
+    
+    type {
+        { "P1" [ [ [ read-ascii-bits ] ignore-errors ] B{ } make ] }
+        { "P4" [ [ width height read-binary-bits ] B{ } make ] }
+    } case :> data
+                     
+    image new
+    L                >>component-order
+    { width height } >>dim
+    f                >>upside-down?
+    data             >>bitmap
+    ubyte-components >>component-type ;
+PRIVATE>
+
+M: pbm-image stream>image
+    drop [ read-pbm ] with-input-stream ;
+
+M: pbm-image image>stream
+    drop {
+        [ drop "P4\n" ascii encode write ]
+        [ dim>> first number>string " " append ascii encode write ]
+        [ dim>> second number>string "\n" append ascii encode write ]
+        [ [ bitmap>> ] [ dim>> first ] bi write-binary-bits ]
+    } cleave ;
diff --git a/basis/images/pbm/summary.txt b/basis/images/pbm/summary.txt
new file mode 100644
index 0000000000..4f484f91a8
--- /dev/null
+++ b/basis/images/pbm/summary.txt
@@ -0,0 +1 @@
+Image loading for PBM image files.
diff --git a/extra/images/testing/pbm/test.ascii.fig b/extra/images/testing/pbm/test.ascii.fig
new file mode 100644
index 0000000000000000000000000000000000000000..aee805ec6985a325ad215ee428ef13f16dc889c4
GIT binary patch
literal 25659
zcmeHO%WmaF5DokfAHkj_KM){7EG8K#gCdqe8rFOQ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P@e#4AEn<3o$w^>Cnl7hgGD7=oKuNh#X15L<w=7m)fOi;qGwwjj;QXm
ziPu`@-F@m`omH?gQZ2YKtJ&t%@+(%`Z$MhX4Kc*RGYPqN;9>iJq>03Rkvwkg8x(pT
xxbvqtjT6^aFKFI8tqvguNF@7h1EdwWEeKpwknz{)AdA7$s=da1N2yA$e*tvWh=KqB

literal 0
HcmV?d00001

diff --git a/extra/images/testing/pbm/test.ascii.pbm b/extra/images/testing/pbm/test.ascii.pbm
new file mode 100644
index 0000000000..2cf2555793
--- /dev/null
+++ b/extra/images/testing/pbm/test.ascii.pbm
@@ -0,0 +1,369 @@
+P1
+# CREATOR: GIMP PNM Filter Version 1.1
+160 160
+1111111100000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000111111111111111100000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000011111111111111111000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000111111111111111111
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0111111111111111111000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000111111111111111110000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000001111111111111111100000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000011111111
+1111111110000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000111111101111110000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000001011111001010000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000101000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000001111
+1111111111111111111111010000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000011111111111111111111111111111111000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000001111111111111111111111111111111111100
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000111111111111111111
+1111111111111111111000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0111111111111111111111111111111111111111000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000001111111111111111111111111111111111111110000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000011111111111111111111111111111
+1111111111000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001111111111
+1111111111111111111111111111110000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000111111111111111111111111111111111111111100000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000011111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000111111111111111111111
+1111111111111111111100000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000001
+1111111111111111111111111111111111111111000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000111111111111000000000000000001111111111110000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000001111111111110000000000000000011
+1111111111000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000011111111111
+1000000000000000001111111111110000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000001111111111110000000000000000011111111111100000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000011111111111100000000000000000111111111111
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000111111111111000000000
+0000000011111111111100000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000001
+1111111111100000000000000000111111111111000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000111111111111000000000000000001111111111110000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000001111111111110000000000000000011
+1111111111000000000000000000000000000000000000000000000000000000000000
+0000000000011110100000000000000000000000000000000000000000011111111111
+1000000000000000001111111111110000000000000000000000000000000000000000
+0000000000000000000000000000111111111110000000000000000000000000000000
+0000000001111111111110000000000000000011111111111100000000000000000000
+0000000000000000000000000000000000000000000000111111111111110000000000
+0000000000000000000000000000011111111111100000000000000000111111111111
+0000000000000000000000000000000000000000000000000000000000000001111111
+1111111111100000000000000000000000000000000000000111111111111000000000
+0000000111111111111100000000000000000000000000000000000000000000000000
+0000000000111111111111111111111100000000000000000000000000000000000001
+1111111111100000000000000001111111111110000000000000000000000000000000
+0000000000000000000000000000011111111111111111111111000000000000000000
+0000000000000000001111111111111000000000000000011111111111100000000000
+0000000000000000000000000000000000000000000000011111111111111111111111
+1110000000000000000000000000000000000001111111111100000000000000000111
+1111111110000000000000000000000000000000000000000000000000000000001111
+1111111111111111111111100000000000000000000000000000000000111111111111
+0000000000000000011111111111100000000000000000000000000000000000000000
+0000000000000011111111111111111111111111111000000000000000000000000000
+0000000011111111111100000000000000000111111111110000000000000000000000
+0000000000000000000000000000000011111111111111111111111111111110000000
+0000000000000000000000000000111111111111000000000000000011111111111100
+0000000000000000000000000000000000000000000000000001111111111111111111
+1111111111111000000000000000000000000000000000001111111111110000000000
+0000001111111111110000000000000000000000000000000000000000000000000000
+1111111111111111111111111111111110000000000000000000000000000000000011
+1111111111000000000000000011111111111100000000000000000000000000000000
+0000000000000000000111111111111111111111111111111111110000000000000000
+0000000000000000001111111111110000000000000000111111111111000000000000
+0000000000000000000000000000000000000001111111111111111111111011111111
+1111000000000000000000000000000000000111111111111100000000000000001111
+1111111100000000000000000000000000000000000000000000000000011111111111
+1111110000001111111111110000000000000000000000000000000011111111111110
+0000000000000000111111111111000000000000000000000000000000000000000000
+0000000011111111111111111000000011111111111110000000000000000000000000
+0000011111111111111000000000000000001111111111110000000000000000000000
+0000000000000000000000000000111111111111111000000000011111111111000000
+0000000000000000000000000111111111111110000000000000000011111111111100
+0000000000000000000000000000000000000000000000001111111111111100000000
+0001111111111110000000000000000000000000000011111111111111000000000000
+0000001111111111110000000000000000000000000000000000000000000000000011
+1111111111000000000000011111111111100000000000000000000000000011111111
+1111111100000000000000000011111111111100000000000000000000000000000000
+0000000000000000001111111111100000000000000111111111111000000000000000
+0000000000001111111111111110000000000000000000111111111111000000000000
+0000000000000000000000000000000000000111111111111000000000000001111111
+1111100000000000000000000000000111111111111111000000000000000000001111
+1111111100000000000000000000000000000000000000000000000001111111111110
+0000000000000111111111111000000000000000000000000011111111111111110000
+0000000000000000111111111111000000000000000000000000000000000000000000
+0000000111111111111000000000000001111111111110000000000000000000000001
+1111111111111110000000000000000000001111111111110000000000000000000000
+0000000000000000000000000001111111111110000000000000011111111111110000
+0000000000000000000111111111111111000000000000000000000011111111111100
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000111111111111000000000000000000000111111111111111100000000000000000
+0000001111111111110000000000000000000000000000000000000000000000000111
+1111111110000000000000001111111111110000000000000000000011111111111111
+1100000000000000000000000011111111111100000000000000000000000000000000
+0000000000000000011111111111100000000000000011111111111110000000000000
+0000011111111111111110000000000000000000000000111111111111000000000000
+0000000000000000000000000000000000000111111111111000000000000000011111
+1111111000000000000000000111111111111111100000000000000000000000001111
+1111111100000000000000000000000000000000000000000000000001111111111110
+0000000000000001111111111110000000000000000111111111111111100000000000
+0000000000000000111111111110000000000000000000000000000000000000000000
+0000000111111111111000000000000000011111111111100000000000000001111111
+1111111110000000000000000000000000011111111111110000000000000000000000
+0000000000000000000000000001111111111110000000000000000111111111111000
+0000000000001111111111111111000000000000000000000000000111111111111000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000011111111111110000000000000111111111111111100000000000000000000000
+0000011111111111100000000000000000000000000000000000000000000000000111
+1111111110000000000000000011111111111100000000000011111111111111110000
+0000000000000000000000000111111111111000000000000000000000000000000000
+0000000000000000011111111111100000000000000000111111111111000000000001
+1111111111111100000000000000000000000000000001111111111110000000000000
+0000000000000000000000000000000000000111111111111000000000000000001111
+1111111110000000001111111111111111000000000000000000000000000000011111
+1111111000000000000000000000000000000000000000000000000001111111111110
+0000000000000000011111111111100000000111111111111111100000000000000000
+0000000000000001111111111110000000000000000000000000000000000000000000
+0000000111111111111000000000000000000111111111111000000111111111111111
+1100000000000000000000000000000000011111111111100000000000000000000000
+0000000000000000000000000001111111111110000000000000000001111111111110
+0000011111111111111110000000000000000000000000000000000111111111111000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000000111111111111000011111111111111111000000000000000000000000000000
+0000011111111111100000000000000000000000000000000000000000000000000111
+1111111110000000000000000000111111111111001111111111111111110000000000
+0000000000000000000000000111111111111000000000000000000000000000000000
+0000000000000000011111111111100000000000000000001111111111110111111111
+1111111100000000000000000000000000000000000001111111111110000000000000
+0000000000000000000000000000000000000111111111111000000000000000000011
+1111111111111111111111111111000000000000000000000000000000000000011111
+1111111000000000000000000000000000000000000000000000000001111111111110
+0000000000000000001111111111111111111111111111000000000000000000000000
+0000000000000001111111111110000000000000000000000000000000000000000000
+0000000111111111111000000000000000000001111111111111111111111111100000
+0000000000000000000000000000000000011111111111100000000000000000000000
+0000000000000000000000000001111111111110000000000000000000011111111111
+1111111111111100000000000000000000000000000000000000001111111111110000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000000001111111111111111111111110000000000000000000000000000000000000
+0000111111111111000000000000000000000000000000000000000000000000000111
+1111111110000000000000000000011111111111111111111111000000000000000000
+0000000000000000000000001111111111110000000000000000000000000000000000
+0000000000000000011111111111100000000000000000000111111111111111111111
+0000000000000000000000000000000000000000000011111111111100000000000000
+0000000000000000000000000000000000000111111111111000000000000000000001
+1111111111111111111000000000000000000000000000000000000000000000111111
+1111110000000000000000000000000000000000000000000000000001111111111110
+0000000000000000000111111111111111111100000000000000000000000000000000
+0000000000000011111111111100000000000000000000000000000000000000000000
+0000000111111111111000000000000000000000111111111111111110000000000000
+0000000000000000000000000000000000111111111111000000000000000000000000
+0000000000000000000000000001111111111110000000000000000000001111111111
+1111111000000000000000000000000000000000000000000000001111111111110000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000000000111111111111111000000000000000000000000000000000000000000000
+0000111111111111000000000000000000000000000000000000000000000000000111
+1111111110000000000000000000001111111111111000000000000000000000000000
+0000000000000000000000001111111111110000000000000000000000000000000000
+0000000000000000011111111111100000000000000000000001111111111110000000
+0000000000000000000000000000000000000000000011111111111100000000000000
+0000000000000000000000000000000000000111111111111000000000000000000000
+0011111111110000000000000000000000000000000000000000000000000000111111
+1111110000000000000000000000000000000000000000000000000001111111111110
+0000000000000000000000011111110000001011111111111110100000000000000000
+0000000000000011111111111100000000000000000000000000000000000000000000
+0000000111111111111000000000000000000000000000101010111111111111111111
+1111111111000000000000000000000000111111111111000000000000000000000000
+0000000000000000000000000001111111111110000000000000000000000000001111
+1111111111111111111111111111111100000000000000000000001111111111110000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000000101111111111111111111111111111111111111111111100000000000000000
+0000111111111111000000000000000000000000000000000000000000000000000111
+1111111110000000000000101111111111111111111111111111111111111111111111
+1110000000000000000000001111111111110000000000000000000000000000000000
+0000000000000000011111111111100000101111111111111111111111111111111111
+1111111111111111111111110000000000000000000011111111111100000000000000
+0000000000000000000000000000000000000111111111111000111111111111111111
+1111111111111111111111111111111111111111111100000000000000000000111111
+1111110000000000000000000000000000000000000000000000000001111111111110
+0011111111111111111111111111111111111111111111111111111111111111000000
+0000000000000011111111111100000000000000000000000000000000000000000000
+0000000111111111111111111111111111111111111111111111111111111111111111
+1111111111111100000000000000000000111111111111000000000000000000000000
+0000000000000000000000000001111111111111111111111111111111111111111111
+1111111111111111111111111111111110000000000000000000011111111111110000
+0000000000000000000000000000000000000000000000011111111111111111111111
+1111111111111111111111111111111111111111111111111111100000000000000000
+0001111111111110000000000000000000000000000000000000000000000000000111
+1111111111111111111111111111111111111111111111111111111111111111111111
+1100000000000000000000011111111111100000000000000000000000000000000000
+0000000000000000011111111111111111111111111111111111111111111111111111
+1111111111111111111100000000000000000000000111111111111000000000000000
+0000000000000000000000000000000000000111111111111111111111111111111111
+1111111111111111111111111111111111111000000000000000000000000011111111
+1111100000000000000000000000000000000000000000000000000001111111111111
+1111111111111111111111111111111111111111111111111111110000000000000000
+0000000000011111111111110000000000000000000000000000000000000000000000
+0000000111111111111111111111111111110100000000111111111111111111111111
+1100000000000000000000000000000111111111111100000000000000000000000000
+0000000000000000000000000001111111111111111111111111010000000000011111
+1111111111111111111000000000000000000000000000000111111111111111000000
+0000000000000000000000000000000000000000000000111111111111111111111000
+0000000000000111111111111111111111111000000000000000000000000000000001
+1111111111111000000000000000000000000000000000000000000000000000001111
+1111111111111110000000000000000111111111111111111111111000000000000000
+0000000000000000011111111111111110000000000000000000000000000000000000
+0000000000000000111111111111111100000000000000000111111111111111111111
+1111000000000000000000000000000000011111111111111111000000000000000000
+0000000000000000000000000000000000001111111111111110000000000000000011
+1111111111111111111110000000000000000000000000000000001111111111111111
+1000000000000000000000000000000000000000000000000000000001111111111110
+0000000000000000001111111111111111111101000000000000000000000000000000
+0001111111111111111110000000000000000000000000000000000000000000000000
+0000000111111111110000000000000000000111111111111111111110000000000000
+0000000000000000000001111111111111111111000000000000000000000000000000
+0000000000000000000000000000111111111000000000000000000011111111111111
+1111110000000000000000000000000000000000011111111111111111100000000000
+0000000000000000000000000000000000000000000000000111111100000000000000
+0000001111111111111111100000000000000000000000000000000000011111111111
+1111111100000000000000000000000000000000000000000000000000000000000000
+0010100000000000000000000011111111111111110000000000000000000000000000
+0000000011111111111111111110000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000111111111111111000000000
+0000000000000000000000000011111111111111111110000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000001111
+1111111110000000000000000000000000000000000000111111111111111111100000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000111111111111000000000000000000000000000000000000011111
+1111111111110000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000001111111111110000000000000000000000
+0000000000000011111111111111111000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000011111111111100
+0000000000000000000000000000000001111111111111111100000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000001111111111110000000000000000000000000000000000111111111111111111
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000001111111111100000000000000000000000000000000
+1111111111111111110000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000011111111111100000000000
+0000000000000000000111111111111111111000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000111
+1111111110000000000000000000000000000111111111111111111100000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000011111111111110000000000000000000000000011111111111111
+1111000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000011111111111100000000000000000000
+0000111111111111111111110000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000111111111111
+1000000000000000000000011111111111111111110000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000011111111111110000000000000000000011111111111111111111000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000011111111111110000000000000000000111111111
+1111111111100000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000111111111111100000000
+0000000001111111111111111111100000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+1111111111110000000000000000111111111111111111110000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000011111111111110000000000000011111111111111111110000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000011111111111100000000000001111
+1111111111111110000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000111111111
+1111000000000001111111111111111110000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000011111111111110000000000111111111111111111000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000011111111111110000000011111111111111111
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000111111111111110000
+0011111111111111111100000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0001111111111111000011111111111111111100000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000001111111111111100111111111111111110000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000011111111111111111111111111
+1111100000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000011111
+1111111111111111111111110000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000001111111111111111111111111111100000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000001111111111111111111111111110000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000011111111111111
+1111111111110000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+0000000111111111111111111111110000000000000000000000000000000000000000
+0000000000000000000000000101000000101000000000000000000000000000000000
+0000000000000000000000000000111111111111111111111000000000000000000000
+0000000000000000000000000000000000000000000011111100111111000000000000
+0000000000000000000000000000000000000000000000000111111111111111111110
+0000000000000000000000000000000000000000000000000000000000000001111111
+1111111110000000000000000000000000000000000000000000000000000000000000
+1111111111111111100000000000000000000000000000000000000000000000000000
+0000000000001111111111111111110000000000000000000000000000000000000000
+0000000000000000000001111111111111111000000000000000000000000000000000
+0000000000000000000000000000000011111111111111111100000000000000000000
+0000000000000000000000000000000000000000011111111111111000000000000000
+0000000000000000000000000000000000000000000000000001111111111111111111
+1000000000000000000000000000000000000000000000000000000000000001111111
+1111000000000000000000000000000000000000000000000000000000000000000000
+0111111111111111111100000000000000000000000000000000000000000000000000
+0000000000000001111101000000000000000000000000000000000000000000000000
+0000000000000000000000111111111111111111000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000011111111
\ No newline at end of file
diff --git a/extra/images/testing/pbm/test.binary.fig b/extra/images/testing/pbm/test.binary.fig
new file mode 100644
index 0000000000000000000000000000000000000000..aee805ec6985a325ad215ee428ef13f16dc889c4
GIT binary patch
literal 25659
zcmeHO%WmaF5DokfAHkj_KM){7EG8K#gCdqe8rFOQe;T@NclW7hm+jlOK{p`XQ*|D7
zu9Hk=M)2d?>(}2tJ^uRi`q%vO`1SG6&)@u${(XCW|Ka8R?e*{9fBNIg(|13=eER(I
z{Pg_g_2vEf`)_}FC?6kJ`zXcA>&5z&TJ`nn{T?n=us*g5E>-X2qxLG`-fz_tD37ha
zu5uqBUWzTB=mQR}Jn=9$OJ9lUpG$sRw%8?~*1gpI3EZE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a/extra/images/testing/pbm/test.binary.pbm b/extra/images/testing/pbm/test.binary.pbm
new file mode 100644
index 0000000000000000000000000000000000000000..3a49dd760304edab6e9a9bc0e3cfefb76e6929cd
GIT binary patch
literal 3250
zcmdUxzit#U5XODlVx>#5O=`Rn4Wd9qLKHL(LVzd&QG{qyr9eU;1!}yH!lUe?Y)MCo
z6jxkgzHj_zZSP7%RAA|J_RpWk<C(GVPM>V=_b<*~K7ar2>{<W%&B<wh`u3!M_3_iU
zi_8AQ#pTzJUq1IokB+uSPapUAY@J#(>xKn$t8A=wn|0k??Jafod%cBH=MR?baEbmi
zVw}6KU3O>{Lxi0hOW2T2C2Ps9{*HAkYuA`w(cPKdDpmWZ|5<i#U?fZbe8daZ_!AXO
zyIokjN#}KLpV-8nQpl??bBpdINFj%a2=?9240#Y{GG=l%`n5<+)HR`ASUNRh>C{Y0
zhgPshTnqL~O3~(Q-wDGBqpowij!(s=U{gz7$;OsCMr>Y-6N7a*yNzs0IvtqCx#HT$
z%nIXsR_I2hEF8)hyBh|gVvR#m3O2zXBs618*BaAIW5WZX!9VJRwILsY(PbDIDD%22
zxQAiJcva*nDA|VYmAaj{Trj&6_bR5P8gqMgC+<}`E8gZhvv*5&<6o*mhuY$qDkf!~
zGwm4BQU@lFmoG3SR}XBWu43Z~BdT;#<rNcG3WoY!tX*f*if&l2c+TACMxs*sx7i=K
zpIDvi)I$UiQ7D)JgWEYf2V(7J?0~3b9x)@c&WP-fET{@yWY|}S^XQ!UaAPhs_>6j&
zmKe^qU<00=O2;hW*-2}UjW3RjUE{{^%J>TbrNQCx-q8}D9ccy~yki{s3xN(VAN*mh
zX<u<<13q#gjjuRN!jf?}v||&4Pgcxfr;$^LEv$QUV1ppl!nz+|caN0%LB>HRPDbnp
z^mJ~1P%(Op-N#uLeooW2G9zb#E1Ase@bKr%(q1ReNy3&+=)x5x%*IH0spKI=z%zr`
zV2ja@0z(Y52naM_x`+VB>&(Y`w#Yj6vCi2rCnI3oLAWx^BJ}VEx7D^}RRnm3Db+<Z
zfZr@rMu0_jRh<@Uhlg^AtHQVQMOjePZYb{=uQ3#5UKb(;lTw&hGI%NQhubiL{|!Uv
r8WTG0%xs)(=BOkq^2_MgWGuRZcu&EgR1y1G4)k%DM6SlzP2cV}gDx8X

literal 0
HcmV?d00001


From 0448c867e2cfba16b7108eecbc6fd73b3e42bdae Mon Sep 17 00:00:00 2001
From: Erik Charlebois <erikcharlebois@gmail.com>
Date: Mon, 12 Apr 2010 01:15:49 -0700
Subject: [PATCH 5/6] Fix indentation in read-token

---
 basis/images/pbm/pbm.factor | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/basis/images/pbm/pbm.factor b/basis/images/pbm/pbm.factor
index ba27c545cf..7db7ccedc6 100644
--- a/basis/images/pbm/pbm.factor
+++ b/basis/images/pbm/pbm.factor
@@ -1,10 +1,9 @@
 ! Copyright (C) 2010 Erik Charlebois.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays ascii bit-arrays byte-arrays
-combinators continuations grouping images images.loader io
-io.encodings.ascii io.encodings.string kernel locals make math
-math.functions math.parser sequences specialized-arrays ;
-SPECIALIZED-ARRAY: ushort
+USING: accessors arrays ascii bit-arrays byte-arrays combinators
+continuations grouping images images.loader io io.encodings.ascii
+io.encodings.string kernel locals make math math.functions math.parser
+sequences ;
 IN: images.pbm
 
 SINGLETON: pbm-image
@@ -12,12 +11,14 @@ SINGLETON: pbm-image
 
 <PRIVATE
 : read-token ( -- token )
-    [ read1 dup blank?
-      [ t ]
-      [ dup CHAR: # =
-        [ "\n" read-until 2drop t ]
-        [ f ] if
-      ] if
+    [
+        read1 dup blank?
+        [ t ]
+        [
+            dup CHAR: # =
+            [ "\n" read-until 2drop t ]
+            [ f ] if
+        ] if
     ] [ drop ] while
     " \n\r\t" read-until drop swap
     prefix ascii decode ;
@@ -59,12 +60,12 @@ SINGLETON: pbm-image
     read-number    :> height
     width height * :> npixels
     width 8 mod    :> leftover
-    
+
     type {
         { "P1" [ [ [ read-ascii-bits ] ignore-errors ] B{ } make ] }
         { "P4" [ [ width height read-binary-bits ] B{ } make ] }
     } case :> data
-                     
+
     image new
     L                >>component-order
     { width height } >>dim

From 1434a305c876680e05d5c6045ac3686a65a51235 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Mon, 12 Apr 2010 14:22:41 -0700
Subject: [PATCH 6/6] vm: add a new rc-absolute-1 relocation class to allow
 storing values in 8-bit operands, and optimized code sequences for inline
 caches using this

---
 basis/compiler/constants/constants.factor | 61 +++++++++++++----------
 basis/cpu/ppc/bootstrap.factor            | 24 +++++----
 basis/cpu/x86/32/bootstrap.factor         |  4 ++
 basis/cpu/x86/64/bootstrap.factor         |  5 ++
 basis/cpu/x86/bootstrap.factor            | 52 +++++++++----------
 vm/dispatch.cpp                           |  4 +-
 vm/inline_cache.cpp                       |  3 +-
 vm/instruction_operands.cpp               |  5 ++
 vm/instruction_operands.hpp               | 12 +++--
 vm/jit.cpp                                |  6 ---
 vm/jit.hpp                                |  2 -
 11 files changed, 97 insertions(+), 81 deletions(-)

diff --git a/basis/compiler/constants/constants.factor b/basis/compiler/constants/constants.factor
index ac0fcff0ff..2fec5ca190 100644
--- a/basis/compiler/constants/constants.factor
+++ b/basis/compiler/constants/constants.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math kernel layouts system strings words quotations byte-arrays
-alien arrays literals sequences ;
+alien alien.syntax arrays literals sequences ;
 IN: compiler.constants
 
 ! These constants must match vm/memory.h
@@ -40,32 +40,41 @@ CONSTANT: deck-bits 18
 : segment-end-offset ( -- n ) 2 bootstrap-cells ; inline
 
 ! Relocation classes
-CONSTANT: rc-absolute-cell 0
-CONSTANT: rc-absolute 1
-CONSTANT: rc-relative 2
-CONSTANT: rc-absolute-ppc-2/2 3
-CONSTANT: rc-absolute-ppc-2 4
-CONSTANT: rc-relative-ppc-2 5
-CONSTANT: rc-relative-ppc-3 6
-CONSTANT: rc-relative-arm-3 7
-CONSTANT: rc-indirect-arm 8
-CONSTANT: rc-indirect-arm-pc 9
-CONSTANT: rc-absolute-2 10
+C-ENUM: f
+    rc-absolute-cell
+    rc-absolute
+    rc-relative
+    rc-absolute-ppc-2/2
+    rc-absolute-ppc-2
+    rc-relative-ppc-2
+    rc-relative-ppc-3
+    rc-relative-arm-3
+    rc-indirect-arm
+    rc-indirect-arm-pc
+    rc-absolute-2
+    rc-absolute-1 ;
 
 ! Relocation types
-CONSTANT: rt-dlsym 0
-CONSTANT: rt-entry-point 1
-CONSTANT: rt-entry-point-pic 2
-CONSTANT: rt-entry-point-pic-tail 3
-CONSTANT: rt-here 4
-CONSTANT: rt-this 5
-CONSTANT: rt-literal 6
-CONSTANT: rt-untagged 7
-CONSTANT: rt-megamorphic-cache-hits 8
-CONSTANT: rt-vm 9
-CONSTANT: rt-cards-offset 10
-CONSTANT: rt-decks-offset 11
-CONSTANT: rt-exception-handler 12
+C-ENUM: f
+    rt-dlsym
+    rt-entry-point
+    rt-entry-point-pic
+    rt-entry-point-pic-tail
+    rt-here
+    rt-this
+    rt-literal
+    rt-untagged
+    rt-megamorphic-cache-hits
+    rt-vm
+    rt-cards-offset
+    rt-decks-offset
+    rt-exception-handler ;
 
 : rc-absolute? ( n -- ? )
-    ${ rc-absolute-ppc-2/2 rc-absolute-cell rc-absolute } member? ;
+    ${
+        rc-absolute-ppc-2/2
+        rc-absolute-cell
+        rc-absolute
+        rc-absolute-2
+        rc-absolute-1
+    } member? ;
diff --git a/basis/cpu/ppc/bootstrap.factor b/basis/cpu/ppc/bootstrap.factor
index f7a1917d0e..4df7a487d4 100644
--- a/basis/cpu/ppc/bootstrap.factor
+++ b/basis/cpu/ppc/bootstrap.factor
@@ -286,25 +286,19 @@ CONSTANT: nv-reg 17
     4 ds-reg 0 LWZ rc-absolute-ppc-2 rt-untagged jit-rel
 ] pic-load jit-define
 
-! Tag
-: load-tag ( -- )
-    4 4 tag-mask get ANDI
-    4 4 tag-bits get SLWI ;
+[ 4 4 tag-mask get ANDI ] pic-tag jit-define
 
-[ load-tag ] pic-tag jit-define
-
-! Tuple
 [
     3 4 MR
-    load-tag
-    0 4 tuple type-number tag-fixnum CMPI
+    4 4 tag-mask get ANDI
+    0 4 tuple type-number CMPI
     [ BNE ]
-    [ 4 3 tuple type-number neg 4 + LWZ ]
+    [ 4 3 tuple-class-offset LWZ ]
     jit-conditional*
 ] pic-tuple jit-define
 
 [
-    0 4 0 CMPI rc-absolute-ppc-2 rt-literal jit-rel
+    0 4 0 CMPI rc-absolute-ppc-2 rt-untagged jit-rel
 ] pic-check-tag jit-define
 
 [
@@ -342,6 +336,14 @@ CONSTANT: nv-reg 17
 ! ! ! Megamorphic caches
 
 [
+    ! class = ...
+    3 4 MR
+    4 4 tag-mask get ANDI
+    4 4 tag-bits get SLWI
+    0 4 tuple type-number tag-fixnum CMPI
+    [ BNE ]
+    [ 4 3 tuple-class-offset LWZ ]
+    jit-conditional*
     ! cache = ...
     0 3 LOAD32 rc-absolute-ppc-2/2 rt-literal jit-rel
     ! key = hashcode(class)
diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor
index 4eb8335b67..a52a3390ac 100644
--- a/basis/cpu/x86/32/bootstrap.factor
+++ b/basis/cpu/x86/32/bootstrap.factor
@@ -176,6 +176,10 @@ IN: bootstrap.x86
 [ jit-jump-quot ]
 \ lazy-jit-compile define-combinator-primitive
 
+[
+    temp1 HEX: ffffffff CMP rc-absolute-cell rt-literal jit-rel
+] pic-check-tuple jit-define
+
 ! Inline cache miss entry points
 : jit-load-return-address ( -- )
     pic-tail-reg ESP stack-frame-size bootstrap-cell - [+] MOV ;
diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor
index 39046bce6a..393d1c9b8b 100644
--- a/basis/cpu/x86/64/bootstrap.factor
+++ b/basis/cpu/x86/64/bootstrap.factor
@@ -160,6 +160,11 @@ IN: bootstrap.x86
 [ jit-jump-quot ]
 \ lazy-jit-compile define-combinator-primitive
 
+[
+    temp2 HEX: ffffffff MOV rc-absolute-cell rt-literal jit-rel
+    temp1 temp2 CMP
+] pic-check-tuple jit-define
+
 ! Inline cache miss entry points
 : jit-load-return-address ( -- )
     RBX RSP stack-frame-size bootstrap-cell - [+] MOV ;
diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor
index 7accc4b1cb..969c02c910 100644
--- a/basis/cpu/x86/bootstrap.factor
+++ b/basis/cpu/x86/bootstrap.factor
@@ -206,43 +206,37 @@ big-endian off
 
 ! Load a value from a stack position
 [
-    temp1 ds-reg HEX: ffffffff [+] MOV rc-absolute rt-untagged jit-rel
+    temp1 ds-reg HEX: 7f [+] MOV rc-absolute-1 rt-untagged jit-rel
 ] pic-load jit-define
 
-! Tag
-: load-tag ( -- )
-    temp1 tag-mask get AND
-    temp1 tag-bits get SHL ;
+[ temp1 tag-mask get AND ] pic-tag jit-define
 
-[ load-tag ] pic-tag jit-define
-
-! The 'make' trick lets us compute the jump distance for the
-! conditional branches there
-
-! Tuple
 [
     temp0 temp1 MOV
-    load-tag
-    temp1 tuple type-number tag-fixnum CMP
+    temp1 tag-mask get AND
+    temp1 tuple type-number CMP
     [ JNE ]
-    [ temp1 temp0 tuple type-number neg bootstrap-cell + [+] MOV ]
+    [ temp1 temp0 tuple-class-offset [+] MOV ]
     jit-conditional
 ] pic-tuple jit-define
 
 [
-    temp1 HEX: ffffffff CMP rc-absolute rt-literal jit-rel
+    temp1 HEX: 7f CMP rc-absolute-1 rt-untagged jit-rel
 ] pic-check-tag jit-define
 
-[
-    temp2 HEX: ffffffff MOV rc-absolute-cell rt-literal jit-rel
-    temp1 temp2 CMP
-] pic-check-tuple jit-define
-
 [ 0 JE rc-relative rt-entry-point jit-rel ] pic-hit jit-define
 
 ! ! ! Megamorphic caches
 
 [
+    ! class = ...
+    temp0 temp1 MOV
+    temp1 tag-mask get AND
+    temp1 tag-bits get SHL
+    temp1 tuple type-number tag-fixnum CMP
+    [ JNE ]
+    [ temp1 temp0 tuple-class-offset [+] MOV ]
+    jit-conditional
     ! cache = ...
     temp0 0 MOV rc-absolute-cell rt-literal jit-rel
     ! key = hashcode(class)
@@ -256,14 +250,16 @@ big-endian off
     temp0 temp2 ADD
     ! if(get(cache) == class)
     temp0 [] temp1 CMP
-    bootstrap-cell 4 = 14 22 ? JNE ! Yuck!
-    ! megamorphic_cache_hits++
-    temp1 0 MOV rc-absolute-cell rt-megamorphic-cache-hits jit-rel
-    temp1 [] 1 ADD
-    ! goto get(cache + bootstrap-cell)
-    temp0 temp0 bootstrap-cell [+] MOV
-    temp0 word-entry-point-offset [+] JMP
-    ! fall-through on miss
+    [ JNE ]
+    [
+        ! megamorphic_cache_hits++
+        temp1 0 MOV rc-absolute-cell rt-megamorphic-cache-hits jit-rel
+        temp1 [] 1 ADD
+        ! goto get(cache + bootstrap-cell)
+        temp0 temp0 bootstrap-cell [+] MOV
+        temp0 word-entry-point-offset [+] JMP
+        ! fall-through on miss
+    ] jit-conditional
 ] mega-lookup jit-define
 
 ! ! ! Sub-primitives
diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp
index b0f9159da7..480da1fd03 100755
--- a/vm/dispatch.cpp
+++ b/vm/dispatch.cpp
@@ -148,8 +148,8 @@ void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cac
 	data_root<array> methods(methods_,parent);
 	data_root<array> cache(cache_,parent);
 
-	/* Generate machine code to determine the object's class. */
-	emit_class_lookup(index,PIC_TUPLE);
+	/* Load the object from the datastack. */
+	emit_with_literal(parent->special_objects[PIC_LOAD],tag_fixnum(-index * sizeof(cell)));
 
 	/* Do a cache lookup. */
 	emit_with_literal(parent->special_objects[MEGA_LOOKUP],cache.value());
diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp
index c8a1b22879..b7cd7630ac 100755
--- a/vm/inline_cache.cpp
+++ b/vm/inline_cache.cpp
@@ -89,7 +89,8 @@ void inline_cache_jit::compile_inline_cache(fixnum index,
 	parent->update_pic_count(inline_cache_type);
 
 	/* Generate machine code to determine the object's class. */
-	emit_class_lookup(index,inline_cache_type);
+	emit_with_literal(parent->special_objects[PIC_LOAD],tag_fixnum(-index * sizeof(cell)));
+	emit(parent->special_objects[inline_cache_type]);
 
 	/* Generate machine code to check, in turn, if the class is one of the cached entries. */
 	cell i;
diff --git a/vm/instruction_operands.cpp b/vm/instruction_operands.cpp
index 59dbf1ef8e..b11db279a5 100644
--- a/vm/instruction_operands.cpp
+++ b/vm/instruction_operands.cpp
@@ -49,6 +49,8 @@ fixnum instruction_operand::load_value(cell relative_to)
 		return load_value_masked(rel_indirect_arm_mask,20,0) + relative_to + sizeof(cell);
 	case RC_ABSOLUTE_2:
 		return *(u16 *)(pointer - sizeof(u16));
+	case RC_ABSOLUTE_1:
+		return *(u8 *)(pointer - sizeof(u8));
 	default:
 		critical_error("Bad rel class",rel.rel_class());
 		return 0;
@@ -124,6 +126,9 @@ void instruction_operand::store_value(fixnum absolute_value)
 	case RC_ABSOLUTE_2:
 		*(u16 *)(pointer - sizeof(u16)) = (u16)absolute_value;
 		break;
+	case RC_ABSOLUTE_1:
+		*(u8 *)(pointer - sizeof(u8)) = (u8)absolute_value;
+		break;
 	default:
 		critical_error("Bad rel class",rel.rel_class());
 		break;
diff --git a/vm/instruction_operands.hpp b/vm/instruction_operands.hpp
index 66ffddc24e..5dda411c8b 100644
--- a/vm/instruction_operands.hpp
+++ b/vm/instruction_operands.hpp
@@ -33,11 +33,11 @@ enum relocation_type {
 };
 
 enum relocation_class {
-	/* absolute address in a 64-bit location */
+	/* absolute address in a pointer-width location */
 	RC_ABSOLUTE_CELL,
-	/* absolute address in a 32-bit location */
+	/* absolute address in a 4 byte location */
 	RC_ABSOLUTE,
-	/* relative address in a 32-bit location */
+	/* relative address in a 4 byte location */
 	RC_RELATIVE,
 	/* absolute address in a PowerPC LIS/ORI sequence */
 	RC_ABSOLUTE_PPC_2_2,
@@ -53,8 +53,10 @@ enum relocation_class {
 	RC_INDIRECT_ARM,
 	/* pointer to address in an ARM LDR/STR instruction offset by 8 bytes */
 	RC_INDIRECT_ARM_PC,
-	/* absolute address in a 16-bit location */
-	RC_ABSOLUTE_2
+	/* absolute address in a 2 byte location */
+	RC_ABSOLUTE_2,
+	/* absolute address in a 1 byte location */
+	RC_ABSOLUTE_1,
 };
 
 static const cell rel_absolute_ppc_2_mask = 0xffff;
diff --git a/vm/jit.cpp b/vm/jit.cpp
index 8d2f5abb9a..3324cfb366 100644
--- a/vm/jit.cpp
+++ b/vm/jit.cpp
@@ -103,12 +103,6 @@ bool jit::emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p)
 	return false;
 }
 	
-void jit::emit_class_lookup(fixnum index, cell type)
-{
-	emit_with_literal(parent->special_objects[PIC_LOAD],tag_fixnum(-index * sizeof(cell)));
-	emit(parent->special_objects[type]);
-}
-
 /* Facility to convert compiled code offsets to quotation offsets.
 Call jit_compute_offset() with the compiled code offset, then emit
 code, and at the end jit->position is the quotation position. */
diff --git a/vm/jit.hpp b/vm/jit.hpp
index a9716cab79..963115d6ab 100644
--- a/vm/jit.hpp
+++ b/vm/jit.hpp
@@ -47,8 +47,6 @@ struct jit {
 
 	bool emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p);
 
-	void emit_class_lookup(fixnum index, cell type);
-
 	fixnum get_position()
 	{
 		if(computing_offset_p)