vm-engine.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422
  1. /* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013,
  2. * 2014, 2015 Free Software Foundation, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public License
  6. * as published by the Free Software Foundation; either version 3 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301 USA
  18. */
  19. /* This file is included in vm.c multiple times. */
  20. #define UNPACK_8_8_8(op,a,b,c) \
  21. do \
  22. { \
  23. a = (op >> 8) & 0xff; \
  24. b = (op >> 16) & 0xff; \
  25. c = op >> 24; \
  26. } \
  27. while (0)
  28. #define UNPACK_8_16(op,a,b) \
  29. do \
  30. { \
  31. a = (op >> 8) & 0xff; \
  32. b = op >> 16; \
  33. } \
  34. while (0)
  35. #define UNPACK_16_8(op,a,b) \
  36. do \
  37. { \
  38. a = (op >> 8) & 0xffff; \
  39. b = op >> 24; \
  40. } \
  41. while (0)
  42. #define UNPACK_12_12(op,a,b) \
  43. do \
  44. { \
  45. a = (op >> 8) & 0xfff; \
  46. b = op >> 20; \
  47. } \
  48. while (0)
  49. #define UNPACK_24(op,a) \
  50. do \
  51. { \
  52. a = op >> 8; \
  53. } \
  54. while (0)
  55. /* Assign some registers by hand. There used to be a bigger list here,
  56. but it was never tested, and in the case of x86-32, was a source of
  57. compilation failures. It can be revived if it's useful, but my naive
  58. hope is that simply annotating the locals with "register" will be a
  59. sufficient hint to the compiler. */
  60. #ifdef __GNUC__
  61. # if defined __x86_64__
  62. /* GCC 4.6 chooses %rbp for IP_REG and %rbx for SP_REG, which works
  63. well. Tell it to keep the jump table in a r12, which is
  64. callee-saved. */
  65. # define JT_REG asm ("r12")
  66. # endif
  67. #endif
  68. #ifndef IP_REG
  69. # define IP_REG
  70. #endif
  71. #ifndef FP_REG
  72. # define FP_REG
  73. #endif
  74. #ifndef JT_REG
  75. # define JT_REG
  76. #endif
  77. #define VM_ASSERT(condition, handler) \
  78. do { \
  79. if (SCM_UNLIKELY (!(condition))) \
  80. { \
  81. SYNC_IP(); \
  82. handler; \
  83. } \
  84. } while (0)
  85. #ifdef VM_ENABLE_ASSERTIONS
  86. # define ASSERT(condition) VM_ASSERT (condition, abort())
  87. #else
  88. # define ASSERT(condition)
  89. #endif
  90. #if VM_USE_HOOKS
  91. #define RUN_HOOK(exp) \
  92. do { \
  93. if (SCM_UNLIKELY (vp->trace_level > 0)) \
  94. { \
  95. SYNC_IP (); \
  96. exp; \
  97. CACHE_SP (); \
  98. } \
  99. } while (0)
  100. #else
  101. #define RUN_HOOK(exp)
  102. #endif
  103. #define RUN_HOOK0(h) RUN_HOOK (vm_dispatch_##h##_hook (vp))
  104. #define RUN_HOOK1(h, arg) RUN_HOOK (vm_dispatch_##h##_hook (vp, arg))
  105. #define APPLY_HOOK() \
  106. RUN_HOOK0 (apply)
  107. #define PUSH_CONTINUATION_HOOK() \
  108. RUN_HOOK0 (push_continuation)
  109. #define POP_CONTINUATION_HOOK(old_fp) \
  110. RUN_HOOK1 (pop_continuation, old_fp)
  111. #define NEXT_HOOK() \
  112. RUN_HOOK0 (next)
  113. #define ABORT_CONTINUATION_HOOK() \
  114. RUN_HOOK0 (abort)
  115. #define VM_HANDLE_INTERRUPTS \
  116. SCM_ASYNC_TICK_WITH_GUARD_CODE (thread, SYNC_IP (), CACHE_SP ())
  117. /* Virtual Machine
  118. The VM has three state bits: the instruction pointer (IP), the frame
  119. pointer (FP), and the stack pointer (SP). We cache the IP in a
  120. machine register, local to the VM, because it is used extensively by
  121. the VM. We do the same for SP. The FP is used more by code outside
  122. the VM than by the VM itself, we don't bother caching it locally.
  123. Keeping vp->ip in sync with the local IP would be a big lose, as it
  124. is updated so often. Instead of updating vp->ip all the time, we
  125. call SYNC_IP whenever we would need to know the IP of the top frame.
  126. In practice, we need to SYNC_IP whenever we call out of the VM to a
  127. function that would like to walk the stack, perhaps as the result of
  128. an exception. On the other hand, we do always keep vp->sp in sync
  129. with the local SP.
  130. One more thing. We allow the stack to move, when it expands.
  131. Therefore if you call out to a C procedure that could call Scheme
  132. code, or otherwise push anything on the stack, you will need to
  133. CACHE_SP afterwards to restore the possibly-changed stack pointer. */
  134. #define SYNC_IP() vp->ip = (ip)
  135. #define CACHE_SP() sp = vp->sp
  136. #define CACHE_REGISTER() \
  137. do { \
  138. ip = vp->ip; \
  139. CACHE_SP (); \
  140. } while (0)
  141. /* Reserve stack space for a frame. Will check that there is sufficient
  142. stack space for N locals, including the procedure. Invoke after
  143. preparing the new frame and setting the fp and ip.
  144. If there is not enough space for this frame, we try to expand the
  145. stack, possibly relocating it somewhere else in the address space.
  146. Because of the possible relocation, no pointer into the stack besides
  147. FP is valid across an ALLOC_FRAME call. Be careful! */
  148. #define ALLOC_FRAME(n) \
  149. do { \
  150. sp = vp->fp - (n); \
  151. if (sp < vp->sp_min_since_gc) \
  152. { \
  153. if (SCM_UNLIKELY (sp < vp->stack_limit)) \
  154. { \
  155. SYNC_IP (); \
  156. vm_expand_stack (vp, sp); \
  157. CACHE_SP (); \
  158. } \
  159. else \
  160. vp->sp_min_since_gc = vp->sp = sp; \
  161. } \
  162. else \
  163. vp->sp = sp; \
  164. } while (0)
  165. /* Reset the current frame to hold N locals. Used when we know that no
  166. stack expansion is needed. */
  167. #define RESET_FRAME(n) \
  168. do { \
  169. vp->sp = sp = vp->fp - (n); \
  170. if (sp < vp->sp_min_since_gc) \
  171. vp->sp_min_since_gc = sp; \
  172. } while (0)
  173. /* Compute the number of locals in the frame. At a call, this is equal
  174. to the number of actual arguments when a function is first called,
  175. plus one for the function. */
  176. #define FRAME_LOCALS_COUNT() (vp->fp - sp)
  177. #define FRAME_LOCALS_COUNT_FROM(slot) (FRAME_LOCALS_COUNT () - slot)
  178. /* Restore registers after returning from a frame. */
  179. #define RESTORE_FRAME() \
  180. do { \
  181. } while (0)
  182. #ifdef HAVE_LABELS_AS_VALUES
  183. # define BEGIN_DISPATCH_SWITCH /* */
  184. # define END_DISPATCH_SWITCH /* */
  185. # define NEXT(n) \
  186. do \
  187. { \
  188. ip += n; \
  189. NEXT_HOOK (); \
  190. op = *ip; \
  191. goto *jump_table[op & 0xff]; \
  192. } \
  193. while (0)
  194. # define VM_DEFINE_OP(opcode, tag, name, meta) \
  195. op_##tag:
  196. #else
  197. # define BEGIN_DISPATCH_SWITCH \
  198. vm_start: \
  199. NEXT_HOOK (); \
  200. op = *ip; \
  201. switch (op & 0xff) \
  202. {
  203. # define END_DISPATCH_SWITCH \
  204. }
  205. # define NEXT(n) \
  206. do \
  207. { \
  208. ip += n; \
  209. goto vm_start; \
  210. } \
  211. while (0)
  212. # define VM_DEFINE_OP(opcode, tag, name, meta) \
  213. op_##tag: \
  214. case opcode:
  215. #endif
  216. #define FP_SLOT(i) SCM_FRAME_SLOT (vp->fp, i)
  217. #define FP_REF(i) SCM_FRAME_LOCAL (vp->fp, i)
  218. #define FP_SET(i,o) SCM_FRAME_LOCAL (vp->fp, i) = o
  219. #define SP_REF(i) (sp[i].as_scm)
  220. #define SP_SET(i,o) (sp[i].as_scm = o)
  221. #define VARIABLE_REF(v) SCM_VARIABLE_REF (v)
  222. #define VARIABLE_SET(v,o) SCM_VARIABLE_SET (v, o)
  223. #define VARIABLE_BOUNDP(v) (!scm_is_eq (VARIABLE_REF (v), SCM_UNDEFINED))
  224. #define RETURN_ONE_VALUE(ret) \
  225. do { \
  226. SCM val = ret; \
  227. union scm_vm_stack_element *old_fp; \
  228. VM_HANDLE_INTERRUPTS; \
  229. ALLOC_FRAME (2); \
  230. old_fp = vp->fp; \
  231. ip = SCM_FRAME_RETURN_ADDRESS (old_fp); \
  232. vp->fp = SCM_FRAME_DYNAMIC_LINK (old_fp); \
  233. /* Clear frame. */ \
  234. old_fp[0].as_scm = SCM_BOOL_F; \
  235. old_fp[1].as_scm = SCM_BOOL_F; \
  236. /* Leave proc. */ \
  237. SP_SET (0, val); \
  238. POP_CONTINUATION_HOOK (old_fp); \
  239. NEXT (0); \
  240. } while (0)
  241. /* While we could generate the list-unrolling code here, it's fine for
  242. now to just tail-call (apply values vals). */
  243. #define RETURN_VALUE_LIST(vals_) \
  244. do { \
  245. SCM vals = vals_; \
  246. VM_HANDLE_INTERRUPTS; \
  247. ALLOC_FRAME (3); \
  248. SP_SET (2, vm_builtin_apply); \
  249. SP_SET (1, vm_builtin_values); \
  250. SP_SET (0, vals); \
  251. ip = (scm_t_uint32 *) vm_builtin_apply_code; \
  252. goto op_tail_apply; \
  253. } while (0)
  254. #define BR_NARGS(rel) \
  255. scm_t_uint32 expected; \
  256. UNPACK_24 (op, expected); \
  257. if (FRAME_LOCALS_COUNT() rel expected) \
  258. { \
  259. scm_t_int32 offset = ip[1]; \
  260. offset >>= 8; /* Sign-extending shift. */ \
  261. NEXT (offset); \
  262. } \
  263. NEXT (2)
  264. #define BR_UNARY(x, exp) \
  265. scm_t_uint32 test; \
  266. SCM x; \
  267. UNPACK_24 (op, test); \
  268. x = SP_REF (test); \
  269. if ((ip[1] & 0x1) ? !(exp) : (exp)) \
  270. { \
  271. scm_t_int32 offset = ip[1]; \
  272. offset >>= 8; /* Sign-extending shift. */ \
  273. if (offset <= 0) \
  274. VM_HANDLE_INTERRUPTS; \
  275. NEXT (offset); \
  276. } \
  277. NEXT (2)
  278. #define BR_BINARY(x, y, exp) \
  279. scm_t_uint32 a, b; \
  280. SCM x, y; \
  281. UNPACK_24 (op, a); \
  282. UNPACK_24 (ip[1], b); \
  283. x = SP_REF (a); \
  284. y = SP_REF (b); \
  285. if ((ip[2] & 0x1) ? !(exp) : (exp)) \
  286. { \
  287. scm_t_int32 offset = ip[2]; \
  288. offset >>= 8; /* Sign-extending shift. */ \
  289. if (offset <= 0) \
  290. VM_HANDLE_INTERRUPTS; \
  291. NEXT (offset); \
  292. } \
  293. NEXT (3)
  294. #define BR_ARITHMETIC(crel,srel) \
  295. { \
  296. scm_t_uint32 a, b; \
  297. SCM x, y; \
  298. UNPACK_24 (op, a); \
  299. UNPACK_24 (ip[1], b); \
  300. x = SP_REF (a); \
  301. y = SP_REF (b); \
  302. if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
  303. { \
  304. scm_t_signed_bits x_bits = SCM_UNPACK (x); \
  305. scm_t_signed_bits y_bits = SCM_UNPACK (y); \
  306. if ((ip[2] & 0x1) ? !(x_bits crel y_bits) : (x_bits crel y_bits)) \
  307. { \
  308. scm_t_int32 offset = ip[2]; \
  309. offset >>= 8; /* Sign-extending shift. */ \
  310. if (offset <= 0) \
  311. VM_HANDLE_INTERRUPTS; \
  312. NEXT (offset); \
  313. } \
  314. NEXT (3); \
  315. } \
  316. else \
  317. { \
  318. SCM res; \
  319. SYNC_IP (); \
  320. res = srel (x, y); \
  321. CACHE_SP (); \
  322. if ((ip[2] & 0x1) ? scm_is_false (res) : scm_is_true (res)) \
  323. { \
  324. scm_t_int32 offset = ip[2]; \
  325. offset >>= 8; /* Sign-extending shift. */ \
  326. if (offset <= 0) \
  327. VM_HANDLE_INTERRUPTS; \
  328. NEXT (offset); \
  329. } \
  330. NEXT (3); \
  331. } \
  332. }
  333. #define ARGS1(a1) \
  334. scm_t_uint16 dst, src; \
  335. SCM a1; \
  336. UNPACK_12_12 (op, dst, src); \
  337. a1 = SP_REF (src)
  338. #define ARGS2(a1, a2) \
  339. scm_t_uint8 dst, src1, src2; \
  340. SCM a1, a2; \
  341. UNPACK_8_8_8 (op, dst, src1, src2); \
  342. a1 = SP_REF (src1); \
  343. a2 = SP_REF (src2)
  344. #define RETURN(x) \
  345. do { SP_SET (dst, x); NEXT (1); } while (0)
  346. #define RETURN_EXP(exp) \
  347. do { SCM __x; SYNC_IP (); __x = exp; CACHE_SP (); RETURN (__x); } while (0)
  348. /* The maximum/minimum tagged integers. */
  349. #define INUM_MAX \
  350. ((scm_t_signed_bits) SCM_UNPACK (SCM_I_MAKINUM (SCM_MOST_POSITIVE_FIXNUM)))
  351. #define INUM_MIN \
  352. ((scm_t_signed_bits) SCM_UNPACK (SCM_I_MAKINUM (SCM_MOST_NEGATIVE_FIXNUM)))
  353. #define INUM_STEP \
  354. ((scm_t_signed_bits) SCM_UNPACK (SCM_INUM1) \
  355. - (scm_t_signed_bits) SCM_UNPACK (SCM_INUM0))
  356. #define BINARY_INTEGER_OP(CFUNC,SFUNC) \
  357. { \
  358. ARGS2 (x, y); \
  359. if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
  360. { \
  361. scm_t_int64 n = SCM_I_INUM (x) CFUNC SCM_I_INUM (y); \
  362. if (SCM_FIXABLE (n)) \
  363. RETURN (SCM_I_MAKINUM (n)); \
  364. } \
  365. RETURN_EXP (SFUNC (x, y)); \
  366. }
  367. #define VM_VALIDATE_PAIR(x, proc) \
  368. VM_ASSERT (scm_is_pair (x), vm_error_not_a_pair (proc, x))
  369. #define VM_VALIDATE_STRUCT(obj, proc) \
  370. VM_ASSERT (SCM_STRUCTP (obj), vm_error_not_a_pair (proc, obj))
  371. #define VM_VALIDATE_BYTEVECTOR(x, proc) \
  372. VM_ASSERT (SCM_BYTEVECTOR_P (x), vm_error_not_a_bytevector (proc, x))
  373. /* Return true (non-zero) if PTR has suitable alignment for TYPE. */
  374. #define ALIGNED_P(ptr, type) \
  375. ((scm_t_uintptr) (ptr) % alignof_type (type) == 0)
  376. static SCM
  377. VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
  378. scm_i_jmp_buf *registers, int resume)
  379. {
  380. /* Instruction pointer: A pointer to the opcode that is currently
  381. running. */
  382. register scm_t_uint32 *ip IP_REG;
  383. /* Stack pointer: A pointer to the hot end of the stack, off of which
  384. we index arguments and local variables. Pushed at function calls,
  385. popped on returns. */
  386. register union scm_vm_stack_element *sp FP_REG;
  387. /* Current opcode: A cache of *ip. */
  388. register scm_t_uint32 op;
  389. #ifdef HAVE_LABELS_AS_VALUES
  390. static const void *jump_table_[256] = {
  391. #define LABEL_ADDR(opcode, tag, name, meta) &&op_##tag,
  392. FOR_EACH_VM_OPERATION(LABEL_ADDR)
  393. #undef LABEL_ADDR
  394. };
  395. register const void **jump_table JT_REG;
  396. /* Attempt to keep JUMP_TABLE_POINTER in a register. This saves one
  397. load instruction at each instruction dispatch. */
  398. jump_table = jump_table_;
  399. #endif
  400. /* Load VM registers. */
  401. CACHE_REGISTER ();
  402. VM_HANDLE_INTERRUPTS;
  403. /* Usually a call to the VM happens on application, with the boot
  404. continuation on the next frame. Sometimes it happens after a
  405. non-local exit however; in that case the VM state is all set up,
  406. and we have but to jump to the next opcode. */
  407. if (SCM_UNLIKELY (resume))
  408. NEXT (0);
  409. apply:
  410. while (!SCM_PROGRAM_P (FP_REF (0)))
  411. {
  412. SCM proc = FP_REF (0);
  413. if (SCM_STRUCTP (proc) && SCM_STRUCT_APPLICABLE_P (proc))
  414. {
  415. FP_SET (0, SCM_STRUCT_PROCEDURE (proc));
  416. continue;
  417. }
  418. if (SCM_HAS_TYP7 (proc, scm_tc7_smob) && SCM_SMOB_APPLICABLE_P (proc))
  419. {
  420. scm_t_uint32 n = FRAME_LOCALS_COUNT();
  421. /* Shuffle args up. (FIXME: no real need to shuffle; just set
  422. IP and go. ) */
  423. ALLOC_FRAME (n + 1);
  424. while (n--)
  425. FP_SET (n + 1, FP_REF (n));
  426. FP_SET (0, SCM_SMOB_DESCRIPTOR (proc).apply_trampoline);
  427. continue;
  428. }
  429. SYNC_IP();
  430. vm_error_wrong_type_apply (proc);
  431. }
  432. /* Let's go! */
  433. ip = SCM_PROGRAM_CODE (FP_REF (0));
  434. APPLY_HOOK ();
  435. NEXT (0);
  436. BEGIN_DISPATCH_SWITCH;
  437. /*
  438. * Call and return
  439. */
  440. /* halt _:24
  441. *
  442. * Bring the VM to a halt, returning all the values from the stack.
  443. */
  444. VM_DEFINE_OP (0, halt, "halt", OP1 (X32))
  445. {
  446. /* Boot closure in r0, empty frame in r1/r2, proc in r3, values from r4. */
  447. scm_t_uint32 nvals = FRAME_LOCALS_COUNT_FROM (4);
  448. SCM ret;
  449. if (nvals == 1)
  450. ret = FP_REF (4);
  451. else
  452. {
  453. scm_t_uint32 n;
  454. ret = SCM_EOL;
  455. for (n = nvals; n > 0; n--)
  456. ret = scm_inline_cons (thread, FP_REF (4 + n - 1), ret);
  457. ret = scm_values (ret);
  458. }
  459. vp->ip = SCM_FRAME_RETURN_ADDRESS (vp->fp);
  460. vp->sp = SCM_FRAME_PREVIOUS_SP (vp->fp);
  461. vp->fp = SCM_FRAME_DYNAMIC_LINK (vp->fp);
  462. return ret;
  463. }
  464. /* call proc:24 _:8 nlocals:24
  465. *
  466. * Call a procedure. PROC is the local corresponding to a procedure.
  467. * The two values below PROC will be overwritten by the saved call
  468. * frame data. The new frame will have space for NLOCALS locals: one
  469. * for the procedure, and the rest for the arguments which should
  470. * already have been pushed on.
  471. *
  472. * When the call returns, execution proceeds with the next
  473. * instruction. There may be any number of values on the return
  474. * stack; the precise number can be had by subtracting the address of
  475. * PROC from the post-call SP.
  476. */
  477. VM_DEFINE_OP (1, call, "call", OP2 (X8_F24, X8_C24))
  478. {
  479. scm_t_uint32 proc, nlocals;
  480. union scm_vm_stack_element *old_fp;
  481. UNPACK_24 (op, proc);
  482. UNPACK_24 (ip[1], nlocals);
  483. VM_HANDLE_INTERRUPTS;
  484. PUSH_CONTINUATION_HOOK ();
  485. old_fp = vp->fp;
  486. vp->fp = SCM_FRAME_SLOT (old_fp, proc - 1);
  487. SCM_FRAME_SET_DYNAMIC_LINK (vp->fp, old_fp);
  488. SCM_FRAME_SET_RETURN_ADDRESS (vp->fp, ip + 2);
  489. RESET_FRAME (nlocals);
  490. if (SCM_UNLIKELY (!SCM_PROGRAM_P (FP_REF (0))))
  491. goto apply;
  492. ip = SCM_PROGRAM_CODE (FP_REF (0));
  493. APPLY_HOOK ();
  494. NEXT (0);
  495. }
  496. /* call-label proc:24 _:8 nlocals:24 label:32
  497. *
  498. * Call a procedure in the same compilation unit.
  499. *
  500. * This instruction is just like "call", except that instead of
  501. * dereferencing PROC to find the call target, the call target is
  502. * known to be at LABEL, a signed 32-bit offset in 32-bit units from
  503. * the current IP. Since PROC is not dereferenced, it may be some
  504. * other representation of the closure.
  505. */
  506. VM_DEFINE_OP (2, call_label, "call-label", OP3 (X8_F24, X8_C24, L32))
  507. {
  508. scm_t_uint32 proc, nlocals;
  509. scm_t_int32 label;
  510. union scm_vm_stack_element *old_fp;
  511. UNPACK_24 (op, proc);
  512. UNPACK_24 (ip[1], nlocals);
  513. label = ip[2];
  514. VM_HANDLE_INTERRUPTS;
  515. PUSH_CONTINUATION_HOOK ();
  516. old_fp = vp->fp;
  517. vp->fp = SCM_FRAME_SLOT (old_fp, proc - 1);
  518. SCM_FRAME_SET_DYNAMIC_LINK (vp->fp, old_fp);
  519. SCM_FRAME_SET_RETURN_ADDRESS (vp->fp, ip + 3);
  520. RESET_FRAME (nlocals);
  521. ip += label;
  522. APPLY_HOOK ();
  523. NEXT (0);
  524. }
  525. /* tail-call nlocals:24
  526. *
  527. * Tail-call a procedure. Requires that the procedure and all of the
  528. * arguments have already been shuffled into position. Will reset the
  529. * frame to NLOCALS.
  530. */
  531. VM_DEFINE_OP (3, tail_call, "tail-call", OP1 (X8_C24))
  532. {
  533. scm_t_uint32 nlocals;
  534. UNPACK_24 (op, nlocals);
  535. VM_HANDLE_INTERRUPTS;
  536. RESET_FRAME (nlocals);
  537. if (SCM_UNLIKELY (!SCM_PROGRAM_P (FP_REF (0))))
  538. goto apply;
  539. ip = SCM_PROGRAM_CODE (FP_REF (0));
  540. APPLY_HOOK ();
  541. NEXT (0);
  542. }
  543. /* tail-call-label nlocals:24 label:32
  544. *
  545. * Tail-call a known procedure. As call is to call-label, tail-call
  546. * is to tail-call-label.
  547. */
  548. VM_DEFINE_OP (4, tail_call_label, "tail-call-label", OP2 (X8_C24, L32))
  549. {
  550. scm_t_uint32 nlocals;
  551. scm_t_int32 label;
  552. UNPACK_24 (op, nlocals);
  553. label = ip[1];
  554. VM_HANDLE_INTERRUPTS;
  555. RESET_FRAME (nlocals);
  556. ip += label;
  557. APPLY_HOOK ();
  558. NEXT (0);
  559. }
  560. /* tail-call/shuffle from:24
  561. *
  562. * Tail-call a procedure. The procedure should already be set to slot
  563. * 0. The rest of the args are taken from the frame, starting at
  564. * FROM, shuffled down to start at slot 0. This is part of the
  565. * implementation of the call-with-values builtin.
  566. */
  567. VM_DEFINE_OP (5, tail_call_shuffle, "tail-call/shuffle", OP1 (X8_F24))
  568. {
  569. scm_t_uint32 n, from, nlocals;
  570. UNPACK_24 (op, from);
  571. VM_HANDLE_INTERRUPTS;
  572. VM_ASSERT (from > 0, abort ());
  573. nlocals = FRAME_LOCALS_COUNT ();
  574. for (n = 0; from + n < nlocals; n++)
  575. FP_SET (n + 1, FP_REF (from + n));
  576. RESET_FRAME (n + 1);
  577. if (SCM_UNLIKELY (!SCM_PROGRAM_P (FP_REF (0))))
  578. goto apply;
  579. ip = SCM_PROGRAM_CODE (FP_REF (0));
  580. APPLY_HOOK ();
  581. NEXT (0);
  582. }
  583. /* receive dst:12 proc:12 _:8 nlocals:24
  584. *
  585. * Receive a single return value from a call whose procedure was in
  586. * PROC, asserting that the call actually returned at least one
  587. * value. Afterwards, resets the frame to NLOCALS locals.
  588. */
  589. VM_DEFINE_OP (6, receive, "receive", OP2 (X8_F12_F12, X8_C24) | OP_DST)
  590. {
  591. scm_t_uint16 dst, proc;
  592. scm_t_uint32 nlocals;
  593. UNPACK_12_12 (op, dst, proc);
  594. UNPACK_24 (ip[1], nlocals);
  595. VM_ASSERT (FRAME_LOCALS_COUNT () > proc + 1, vm_error_no_values ());
  596. FP_SET (dst, FP_REF (proc + 1));
  597. RESET_FRAME (nlocals);
  598. NEXT (2);
  599. }
  600. /* receive-values proc:24 allow-extra?:1 _:7 nvalues:24
  601. *
  602. * Receive a return of multiple values from a call whose procedure was
  603. * in PROC. If fewer than NVALUES values were returned, signal an
  604. * error. Unless ALLOW-EXTRA? is true, require that the number of
  605. * return values equals NVALUES exactly. After receive-values has
  606. * run, the values can be copied down via `mov'.
  607. */
  608. VM_DEFINE_OP (7, receive_values, "receive-values", OP2 (X8_F24, B1_X7_C24))
  609. {
  610. scm_t_uint32 proc, nvalues;
  611. UNPACK_24 (op, proc);
  612. UNPACK_24 (ip[1], nvalues);
  613. if (ip[1] & 0x1)
  614. VM_ASSERT (FRAME_LOCALS_COUNT () > proc + nvalues,
  615. vm_error_not_enough_values ());
  616. else
  617. VM_ASSERT (FRAME_LOCALS_COUNT () == proc + 1 + nvalues,
  618. vm_error_wrong_number_of_values (nvalues));
  619. NEXT (2);
  620. }
  621. /* return src:24
  622. *
  623. * Return a value.
  624. */
  625. VM_DEFINE_OP (8, return, "return", OP1 (X8_S24))
  626. {
  627. scm_t_uint32 src;
  628. UNPACK_24 (op, src);
  629. RETURN_ONE_VALUE (SP_REF (src));
  630. }
  631. /* return-values _:24
  632. *
  633. * Return a number of values from a call frame. This opcode
  634. * corresponds to an application of `values' in tail position. As
  635. * with tail calls, we expect that the values have already been
  636. * shuffled down to a contiguous array starting at slot 1.
  637. * We also expect the frame has already been reset.
  638. */
  639. VM_DEFINE_OP (9, return_values, "return-values", OP1 (X32))
  640. {
  641. union scm_vm_stack_element *old_fp;
  642. VM_HANDLE_INTERRUPTS;
  643. old_fp = vp->fp;
  644. ip = SCM_FRAME_RETURN_ADDRESS (vp->fp);
  645. vp->fp = SCM_FRAME_DYNAMIC_LINK (vp->fp);
  646. /* Clear stack frame. */
  647. old_fp[0].as_scm = SCM_BOOL_F;
  648. old_fp[1].as_scm = SCM_BOOL_F;
  649. POP_CONTINUATION_HOOK (old_fp);
  650. NEXT (0);
  651. }
  652. /*
  653. * Specialized call stubs
  654. */
  655. /* subr-call _:24
  656. *
  657. * Call a subr, passing all locals in this frame as arguments. Return
  658. * from the calling frame. This instruction is part of the
  659. * trampolines created in gsubr.c, and is not generated by the
  660. * compiler.
  661. */
  662. VM_DEFINE_OP (10, subr_call, "subr-call", OP1 (X32))
  663. {
  664. SCM ret;
  665. SYNC_IP ();
  666. ret = scm_apply_subr (sp, FRAME_LOCALS_COUNT ());
  667. CACHE_SP ();
  668. if (SCM_UNLIKELY (SCM_VALUESP (ret)))
  669. /* multiple values returned to continuation */
  670. RETURN_VALUE_LIST (scm_struct_ref (ret, SCM_INUM0));
  671. else
  672. RETURN_ONE_VALUE (ret);
  673. }
  674. /* foreign-call cif-idx:12 ptr-idx:12
  675. *
  676. * Call a foreign function. Fetch the CIF and foreign pointer from
  677. * CIF-IDX and PTR-IDX, both free variables. Return from the calling
  678. * frame. Arguments are taken from the stack. This instruction is
  679. * part of the trampolines created by the FFI, and is not generated by
  680. * the compiler.
  681. */
  682. VM_DEFINE_OP (11, foreign_call, "foreign-call", OP1 (X8_C12_C12))
  683. {
  684. scm_t_uint16 cif_idx, ptr_idx;
  685. SCM closure, cif, pointer, ret;
  686. UNPACK_12_12 (op, cif_idx, ptr_idx);
  687. closure = FP_REF (0);
  688. cif = SCM_PROGRAM_FREE_VARIABLE_REF (closure, cif_idx);
  689. pointer = SCM_PROGRAM_FREE_VARIABLE_REF (closure, ptr_idx);
  690. SYNC_IP ();
  691. // FIXME: separate args
  692. ret = scm_i_foreign_call (scm_inline_cons (thread, cif, pointer), sp);
  693. CACHE_SP ();
  694. if (SCM_UNLIKELY (SCM_VALUESP (ret)))
  695. /* multiple values returned to continuation */
  696. RETURN_VALUE_LIST (scm_struct_ref (ret, SCM_INUM0));
  697. else
  698. RETURN_ONE_VALUE (ret);
  699. }
  700. /* continuation-call contregs:24
  701. *
  702. * Return to a continuation, nonlocally. The arguments to the
  703. * continuation are taken from the stack. CONTREGS is a free variable
  704. * containing the reified continuation. This instruction is part of
  705. * the implementation of undelimited continuations, and is not
  706. * generated by the compiler.
  707. */
  708. VM_DEFINE_OP (12, continuation_call, "continuation-call", OP1 (X8_C24))
  709. {
  710. SCM contregs;
  711. scm_t_uint32 contregs_idx;
  712. UNPACK_24 (op, contregs_idx);
  713. contregs =
  714. SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), contregs_idx);
  715. SYNC_IP ();
  716. scm_i_check_continuation (contregs);
  717. vm_return_to_continuation (scm_i_contregs_vp (contregs),
  718. scm_i_contregs_vm_cont (contregs),
  719. FRAME_LOCALS_COUNT_FROM (1),
  720. sp);
  721. scm_i_reinstate_continuation (contregs);
  722. /* no NEXT */
  723. abort ();
  724. }
  725. /* compose-continuation cont:24
  726. *
  727. * Compose a partial continuation with the current continuation. The
  728. * arguments to the continuation are taken from the stack. CONT is a
  729. * free variable containing the reified continuation. This
  730. * instruction is part of the implementation of partial continuations,
  731. * and is not generated by the compiler.
  732. */
  733. VM_DEFINE_OP (13, compose_continuation, "compose-continuation", OP1 (X8_C24))
  734. {
  735. SCM vmcont;
  736. scm_t_uint32 cont_idx;
  737. UNPACK_24 (op, cont_idx);
  738. vmcont = SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), cont_idx);
  739. SYNC_IP ();
  740. VM_ASSERT (SCM_VM_CONT_REWINDABLE_P (vmcont),
  741. vm_error_continuation_not_rewindable (vmcont));
  742. vm_reinstate_partial_continuation (vp, vmcont, FRAME_LOCALS_COUNT_FROM (1),
  743. &thread->dynstack, registers);
  744. CACHE_REGISTER ();
  745. NEXT (0);
  746. }
  747. /* tail-apply _:24
  748. *
  749. * Tail-apply the procedure in local slot 0 to the rest of the
  750. * arguments. This instruction is part of the implementation of
  751. * `apply', and is not generated by the compiler.
  752. */
  753. VM_DEFINE_OP (14, tail_apply, "tail-apply", OP1 (X32))
  754. {
  755. int i, list_idx, list_len, nlocals;
  756. SCM list;
  757. VM_HANDLE_INTERRUPTS;
  758. nlocals = FRAME_LOCALS_COUNT ();
  759. // At a minimum, there should be apply, f, and the list.
  760. VM_ASSERT (nlocals >= 3, abort ());
  761. list_idx = nlocals - 1;
  762. list = FP_REF (list_idx);
  763. list_len = scm_ilength (list);
  764. VM_ASSERT (list_len >= 0, vm_error_apply_to_non_list (list));
  765. nlocals = nlocals - 2 + list_len;
  766. ALLOC_FRAME (nlocals);
  767. for (i = 1; i < list_idx; i++)
  768. FP_SET (i - 1, FP_REF (i));
  769. /* Null out these slots, just in case there are less than 2 elements
  770. in the list. */
  771. FP_SET (list_idx - 1, SCM_UNDEFINED);
  772. FP_SET (list_idx, SCM_UNDEFINED);
  773. for (i = 0; i < list_len; i++, list = SCM_CDR (list))
  774. FP_SET (list_idx - 1 + i, SCM_CAR (list));
  775. if (SCM_UNLIKELY (!SCM_PROGRAM_P (FP_REF (0))))
  776. goto apply;
  777. ip = SCM_PROGRAM_CODE (FP_REF (0));
  778. APPLY_HOOK ();
  779. NEXT (0);
  780. }
  781. /* call/cc _:24
  782. *
  783. * Capture the current continuation, and tail-apply the procedure in
  784. * local slot 1 to it. This instruction is part of the implementation
  785. * of `call/cc', and is not generated by the compiler.
  786. */
  787. VM_DEFINE_OP (15, call_cc, "call/cc", OP1 (X32))
  788. {
  789. SCM vm_cont, cont;
  790. scm_t_dynstack *dynstack;
  791. int first;
  792. VM_HANDLE_INTERRUPTS;
  793. SYNC_IP ();
  794. dynstack = scm_dynstack_capture_all (&thread->dynstack);
  795. vm_cont = scm_i_vm_capture_stack (vp->stack_top,
  796. SCM_FRAME_DYNAMIC_LINK (vp->fp),
  797. SCM_FRAME_PREVIOUS_SP (vp->fp),
  798. SCM_FRAME_RETURN_ADDRESS (vp->fp),
  799. dynstack,
  800. 0);
  801. /* FIXME: Seems silly to capture the registers here, when they are
  802. already captured in the registers local, which here we are
  803. copying out to the heap; and likewise, the setjmp(&registers)
  804. code already has the non-local return handler. But oh
  805. well! */
  806. cont = scm_i_make_continuation (&first, vp, vm_cont);
  807. if (first)
  808. {
  809. RESET_FRAME (2);
  810. SP_SET (1, SP_REF (0));
  811. SP_SET (0, cont);
  812. if (SCM_UNLIKELY (!SCM_PROGRAM_P (SP_REF (1))))
  813. goto apply;
  814. ip = SCM_PROGRAM_CODE (SP_REF (1));
  815. APPLY_HOOK ();
  816. NEXT (0);
  817. }
  818. else
  819. {
  820. CACHE_REGISTER ();
  821. ABORT_CONTINUATION_HOOK ();
  822. NEXT (0);
  823. }
  824. }
  825. /* abort _:24
  826. *
  827. * Abort to a prompt handler. The tag is expected in r1, and the rest
  828. * of the values in the frame are returned to the prompt handler.
  829. * This corresponds to a tail application of abort-to-prompt.
  830. */
  831. VM_DEFINE_OP (16, abort, "abort", OP1 (X32))
  832. {
  833. scm_t_uint32 nlocals = FRAME_LOCALS_COUNT ();
  834. ASSERT (nlocals >= 2);
  835. /* FIXME: Really we should capture the caller's registers. Until
  836. then, manually advance the IP so that when the prompt resumes,
  837. it continues with the next instruction. */
  838. ip++;
  839. SYNC_IP ();
  840. vm_abort (vp, FP_REF (1), nlocals - 2, registers);
  841. /* vm_abort should not return */
  842. abort ();
  843. }
  844. /* builtin-ref dst:12 idx:12
  845. *
  846. * Load a builtin stub by index into DST.
  847. */
  848. VM_DEFINE_OP (17, builtin_ref, "builtin-ref", OP1 (X8_S12_C12) | OP_DST)
  849. {
  850. scm_t_uint16 dst, idx;
  851. UNPACK_12_12 (op, dst, idx);
  852. SP_SET (dst, scm_vm_builtin_ref (idx));
  853. NEXT (1);
  854. }
  855. /*
  856. * Function prologues
  857. */
  858. /* br-if-nargs-ne expected:24 _:8 offset:24
  859. * br-if-nargs-lt expected:24 _:8 offset:24
  860. * br-if-nargs-gt expected:24 _:8 offset:24
  861. *
  862. * If the number of actual arguments is not equal, less than, or greater
  863. * than EXPECTED, respectively, add OFFSET, a signed 24-bit number, to
  864. * the current instruction pointer.
  865. */
  866. VM_DEFINE_OP (18, br_if_nargs_ne, "br-if-nargs-ne", OP2 (X8_C24, X8_L24))
  867. {
  868. BR_NARGS (!=);
  869. }
  870. VM_DEFINE_OP (19, br_if_nargs_lt, "br-if-nargs-lt", OP2 (X8_C24, X8_L24))
  871. {
  872. BR_NARGS (<);
  873. }
  874. VM_DEFINE_OP (20, br_if_nargs_gt, "br-if-nargs-gt", OP2 (X8_C24, X8_L24))
  875. {
  876. BR_NARGS (>);
  877. }
  878. /* assert-nargs-ee expected:24
  879. * assert-nargs-ge expected:24
  880. * assert-nargs-le expected:24
  881. *
  882. * If the number of actual arguments is not ==, >=, or <= EXPECTED,
  883. * respectively, signal an error.
  884. */
  885. VM_DEFINE_OP (21, assert_nargs_ee, "assert-nargs-ee", OP1 (X8_C24))
  886. {
  887. scm_t_uint32 expected;
  888. UNPACK_24 (op, expected);
  889. VM_ASSERT (FRAME_LOCALS_COUNT () == expected,
  890. vm_error_wrong_num_args (FP_REF (0)));
  891. NEXT (1);
  892. }
  893. VM_DEFINE_OP (22, assert_nargs_ge, "assert-nargs-ge", OP1 (X8_C24))
  894. {
  895. scm_t_uint32 expected;
  896. UNPACK_24 (op, expected);
  897. VM_ASSERT (FRAME_LOCALS_COUNT () >= expected,
  898. vm_error_wrong_num_args (FP_REF (0)));
  899. NEXT (1);
  900. }
  901. VM_DEFINE_OP (23, assert_nargs_le, "assert-nargs-le", OP1 (X8_C24))
  902. {
  903. scm_t_uint32 expected;
  904. UNPACK_24 (op, expected);
  905. VM_ASSERT (FRAME_LOCALS_COUNT () <= expected,
  906. vm_error_wrong_num_args (FP_REF (0)));
  907. NEXT (1);
  908. }
  909. /* alloc-frame nlocals:24
  910. *
  911. * Ensure that there is space on the stack for NLOCALS local variables,
  912. * setting them all to SCM_UNDEFINED, except those nargs values that
  913. * were passed as arguments and procedure.
  914. */
  915. VM_DEFINE_OP (24, alloc_frame, "alloc-frame", OP1 (X8_C24))
  916. {
  917. scm_t_uint32 nlocals, nargs;
  918. UNPACK_24 (op, nlocals);
  919. nargs = FRAME_LOCALS_COUNT ();
  920. ALLOC_FRAME (nlocals);
  921. while (nlocals-- > nargs)
  922. FP_SET (nlocals, SCM_UNDEFINED);
  923. NEXT (1);
  924. }
  925. /* reset-frame nlocals:24
  926. *
  927. * Like alloc-frame, but doesn't check that the stack is big enough.
  928. * Used to reset the frame size to something less than the size that
  929. * was previously set via alloc-frame.
  930. */
  931. VM_DEFINE_OP (25, reset_frame, "reset-frame", OP1 (X8_C24))
  932. {
  933. scm_t_uint32 nlocals;
  934. UNPACK_24 (op, nlocals);
  935. RESET_FRAME (nlocals);
  936. NEXT (1);
  937. }
  938. /* push src:24
  939. *
  940. * Push SRC onto the stack.
  941. */
  942. VM_DEFINE_OP (26, push, "push", OP1 (X8_S24))
  943. {
  944. scm_t_uint32 src;
  945. SCM val;
  946. UNPACK_24 (op, src);
  947. val = SP_REF (src);
  948. ALLOC_FRAME (FRAME_LOCALS_COUNT () + 1);
  949. SP_SET (0, val);
  950. NEXT (1);
  951. }
  952. /* pop dst:24
  953. *
  954. * Pop the stack, storing to DST.
  955. */
  956. VM_DEFINE_OP (27, pop, "pop", OP1 (X8_S24) | OP_DST)
  957. {
  958. scm_t_uint32 dst;
  959. SCM val;
  960. UNPACK_24 (op, dst);
  961. val = SP_REF (0);
  962. vp->sp = sp = sp + 1;
  963. SP_SET (dst, val);
  964. NEXT (1);
  965. }
  966. /* drop count:24
  967. *
  968. * Drop some number of values from the stack.
  969. */
  970. VM_DEFINE_OP (28, drop, "drop", OP1 (X8_C24))
  971. {
  972. scm_t_uint32 count;
  973. UNPACK_24 (op, count);
  974. vp->sp = sp = sp + count;
  975. NEXT (1);
  976. }
  977. /* assert-nargs-ee/locals expected:12 nlocals:12
  978. *
  979. * Equivalent to a sequence of assert-nargs-ee and reserve-locals. The
  980. * number of locals reserved is EXPECTED + NLOCALS.
  981. */
  982. VM_DEFINE_OP (29, assert_nargs_ee_locals, "assert-nargs-ee/locals", OP1 (X8_C12_C12))
  983. {
  984. scm_t_uint16 expected, nlocals;
  985. UNPACK_12_12 (op, expected, nlocals);
  986. VM_ASSERT (FRAME_LOCALS_COUNT () == expected,
  987. vm_error_wrong_num_args (FP_REF (0)));
  988. ALLOC_FRAME (expected + nlocals);
  989. while (nlocals--)
  990. SP_SET (nlocals, SCM_UNDEFINED);
  991. NEXT (1);
  992. }
  993. /* br-if-npos-gt nreq:24 _:8 npos:24 _:8 offset:24
  994. *
  995. * Find the first positional argument after NREQ. If it is greater
  996. * than NPOS, jump to OFFSET.
  997. *
  998. * This instruction is only emitted for functions with multiple
  999. * clauses, and an earlier clause has keywords and no rest arguments.
  1000. * See "Case-lambda" in the manual, for more on how case-lambda
  1001. * chooses the clause to apply.
  1002. */
  1003. VM_DEFINE_OP (30, br_if_npos_gt, "br-if-npos-gt", OP3 (X8_C24, X8_C24, X8_L24))
  1004. {
  1005. scm_t_uint32 nreq, npos;
  1006. UNPACK_24 (op, nreq);
  1007. UNPACK_24 (ip[1], npos);
  1008. /* We can only have too many positionals if there are more
  1009. arguments than NPOS. */
  1010. if (FRAME_LOCALS_COUNT() > npos)
  1011. {
  1012. scm_t_uint32 n;
  1013. for (n = nreq; n < npos; n++)
  1014. if (scm_is_keyword (FP_REF (n)))
  1015. break;
  1016. if (n == npos && !scm_is_keyword (FP_REF (n)))
  1017. {
  1018. scm_t_int32 offset = ip[2];
  1019. offset >>= 8; /* Sign-extending shift. */
  1020. NEXT (offset);
  1021. }
  1022. }
  1023. NEXT (3);
  1024. }
  1025. /* bind-kwargs nreq:24 flags:8 nreq-and-opt:24 _:8 ntotal:24 kw-offset:32
  1026. *
  1027. * flags := allow-other-keys:1 has-rest:1 _:6
  1028. *
  1029. * Find the last positional argument, and shuffle all the rest above
  1030. * NTOTAL. Initialize the intervening locals to SCM_UNDEFINED. Then
  1031. * load the constant at KW-OFFSET words from the current IP, and use it
  1032. * to bind keyword arguments. If HAS-REST, collect all shuffled
  1033. * arguments into a list, and store it in NREQ-AND-OPT. Finally, clear
  1034. * the arguments that we shuffled up.
  1035. *
  1036. * A macro-mega-instruction.
  1037. */
  1038. VM_DEFINE_OP (31, bind_kwargs, "bind-kwargs", OP4 (X8_C24, C8_C24, X8_C24, N32))
  1039. {
  1040. scm_t_uint32 nreq, nreq_and_opt, ntotal, npositional, nkw, n, nargs;
  1041. scm_t_int32 kw_offset;
  1042. scm_t_bits kw_bits;
  1043. SCM kw;
  1044. char allow_other_keys, has_rest;
  1045. UNPACK_24 (op, nreq);
  1046. allow_other_keys = ip[1] & 0x1;
  1047. has_rest = ip[1] & 0x2;
  1048. UNPACK_24 (ip[1], nreq_and_opt);
  1049. UNPACK_24 (ip[2], ntotal);
  1050. kw_offset = ip[3];
  1051. kw_bits = (scm_t_bits) (ip + kw_offset);
  1052. VM_ASSERT (!(kw_bits & 0x7), abort());
  1053. kw = SCM_PACK (kw_bits);
  1054. nargs = FRAME_LOCALS_COUNT ();
  1055. /* look in optionals for first keyword or last positional */
  1056. /* starting after the last required positional arg */
  1057. npositional = nreq;
  1058. while (/* while we have args */
  1059. npositional < nargs
  1060. /* and we still have positionals to fill */
  1061. && npositional < nreq_and_opt
  1062. /* and we haven't reached a keyword yet */
  1063. && !scm_is_keyword (FP_REF (npositional)))
  1064. /* bind this optional arg (by leaving it in place) */
  1065. npositional++;
  1066. nkw = nargs - npositional;
  1067. /* shuffle non-positional arguments above ntotal */
  1068. ALLOC_FRAME (ntotal + nkw);
  1069. n = nkw;
  1070. while (n--)
  1071. FP_SET (ntotal + n, FP_REF (npositional + n));
  1072. /* and fill optionals & keyword args with SCM_UNDEFINED */
  1073. n = npositional;
  1074. while (n < ntotal)
  1075. FP_SET (n++, SCM_UNDEFINED);
  1076. VM_ASSERT (has_rest || (nkw % 2) == 0,
  1077. vm_error_kwargs_length_not_even (FP_REF (0)));
  1078. /* Now bind keywords, in the order given. */
  1079. for (n = 0; n < nkw; n++)
  1080. if (scm_is_keyword (FP_REF (ntotal + n)))
  1081. {
  1082. SCM walk;
  1083. for (walk = kw; scm_is_pair (walk); walk = SCM_CDR (walk))
  1084. if (scm_is_eq (SCM_CAAR (walk), FP_REF (ntotal + n)))
  1085. {
  1086. SCM si = SCM_CDAR (walk);
  1087. FP_SET (SCM_I_INUMP (si) ? SCM_I_INUM (si) : scm_to_uint32 (si),
  1088. FP_REF (ntotal + n + 1));
  1089. break;
  1090. }
  1091. VM_ASSERT (scm_is_pair (walk) || allow_other_keys,
  1092. vm_error_kwargs_unrecognized_keyword (FP_REF (0),
  1093. FP_REF (ntotal + n)));
  1094. n++;
  1095. }
  1096. else
  1097. VM_ASSERT (has_rest, vm_error_kwargs_invalid_keyword (FP_REF (0),
  1098. FP_REF (ntotal + n)));
  1099. if (has_rest)
  1100. {
  1101. SCM rest = SCM_EOL;
  1102. n = nkw;
  1103. while (n--)
  1104. rest = scm_inline_cons (thread, FP_REF (ntotal + n), rest);
  1105. FP_SET (nreq_and_opt, rest);
  1106. }
  1107. RESET_FRAME (ntotal);
  1108. NEXT (4);
  1109. }
  1110. /* bind-rest dst:24
  1111. *
  1112. * Collect any arguments at or above DST into a list, and store that
  1113. * list at DST.
  1114. */
  1115. VM_DEFINE_OP (32, bind_rest, "bind-rest", OP1 (X8_F24) | OP_DST)
  1116. {
  1117. scm_t_uint32 dst, nargs;
  1118. SCM rest = SCM_EOL;
  1119. UNPACK_24 (op, dst);
  1120. nargs = FRAME_LOCALS_COUNT ();
  1121. if (nargs <= dst)
  1122. {
  1123. ALLOC_FRAME (dst + 1);
  1124. while (nargs < dst)
  1125. FP_SET (nargs++, SCM_UNDEFINED);
  1126. }
  1127. else
  1128. {
  1129. while (nargs-- > dst)
  1130. {
  1131. rest = scm_inline_cons (thread, FP_REF (nargs), rest);
  1132. FP_SET (nargs, SCM_UNDEFINED);
  1133. }
  1134. RESET_FRAME (dst + 1);
  1135. }
  1136. FP_SET (dst, rest);
  1137. NEXT (1);
  1138. }
  1139. /*
  1140. * Branching instructions
  1141. */
  1142. /* br offset:24
  1143. *
  1144. * Add OFFSET, a signed 24-bit number, to the current instruction
  1145. * pointer.
  1146. */
  1147. VM_DEFINE_OP (33, br, "br", OP1 (X8_L24))
  1148. {
  1149. scm_t_int32 offset = op;
  1150. offset >>= 8; /* Sign-extending shift. */
  1151. if (offset <= 0)
  1152. VM_HANDLE_INTERRUPTS;
  1153. NEXT (offset);
  1154. }
  1155. /* br-if-true test:24 invert:1 _:7 offset:24
  1156. *
  1157. * If the value in TEST is true for the purposes of Scheme, add
  1158. * OFFSET, a signed 24-bit number, to the current instruction pointer.
  1159. */
  1160. VM_DEFINE_OP (34, br_if_true, "br-if-true", OP2 (X8_S24, B1_X7_L24))
  1161. {
  1162. BR_UNARY (x, scm_is_true (x));
  1163. }
  1164. /* br-if-null test:24 invert:1 _:7 offset:24
  1165. *
  1166. * If the value in TEST is the end-of-list or Lisp nil, add OFFSET, a
  1167. * signed 24-bit number, to the current instruction pointer.
  1168. */
  1169. VM_DEFINE_OP (35, br_if_null, "br-if-null", OP2 (X8_S24, B1_X7_L24))
  1170. {
  1171. BR_UNARY (x, scm_is_null (x));
  1172. }
  1173. /* br-if-nil test:24 invert:1 _:7 offset:24
  1174. *
  1175. * If the value in TEST is false to Lisp, add OFFSET, a signed 24-bit
  1176. * number, to the current instruction pointer.
  1177. */
  1178. VM_DEFINE_OP (36, br_if_nil, "br-if-nil", OP2 (X8_S24, B1_X7_L24))
  1179. {
  1180. BR_UNARY (x, scm_is_lisp_false (x));
  1181. }
  1182. /* br-if-pair test:24 invert:1 _:7 offset:24
  1183. *
  1184. * If the value in TEST is a pair, add OFFSET, a signed 24-bit number,
  1185. * to the current instruction pointer.
  1186. */
  1187. VM_DEFINE_OP (37, br_if_pair, "br-if-pair", OP2 (X8_S24, B1_X7_L24))
  1188. {
  1189. BR_UNARY (x, scm_is_pair (x));
  1190. }
  1191. /* br-if-struct test:24 invert:1 _:7 offset:24
  1192. *
  1193. * If the value in TEST is a struct, add OFFSET, a signed 24-bit
  1194. * number, to the current instruction pointer.
  1195. */
  1196. VM_DEFINE_OP (38, br_if_struct, "br-if-struct", OP2 (X8_S24, B1_X7_L24))
  1197. {
  1198. BR_UNARY (x, SCM_STRUCTP (x));
  1199. }
  1200. /* br-if-char test:24 invert:1 _:7 offset:24
  1201. *
  1202. * If the value in TEST is a char, add OFFSET, a signed 24-bit number,
  1203. * to the current instruction pointer.
  1204. */
  1205. VM_DEFINE_OP (39, br_if_char, "br-if-char", OP2 (X8_S24, B1_X7_L24))
  1206. {
  1207. BR_UNARY (x, SCM_CHARP (x));
  1208. }
  1209. /* br-if-tc7 test:24 invert:1 tc7:7 offset:24
  1210. *
  1211. * If the value in TEST has the TC7 given in the second word, add
  1212. * OFFSET, a signed 24-bit number, to the current instruction pointer.
  1213. */
  1214. VM_DEFINE_OP (40, br_if_tc7, "br-if-tc7", OP2 (X8_S24, B1_C7_L24))
  1215. {
  1216. BR_UNARY (x, SCM_HAS_TYP7 (x, (ip[1] >> 1) & 0x7f));
  1217. }
  1218. /* br-if-eq a:12 b:12 invert:1 _:7 offset:24
  1219. *
  1220. * If the value in A is eq? to the value in B, add OFFSET, a signed
  1221. * 24-bit number, to the current instruction pointer.
  1222. */
  1223. VM_DEFINE_OP (41, br_if_eq, "br-if-eq", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1224. {
  1225. BR_BINARY (x, y, scm_is_eq (x, y));
  1226. }
  1227. /* br-if-eqv a:12 b:12 invert:1 _:7 offset:24
  1228. *
  1229. * If the value in A is eqv? to the value in B, add OFFSET, a signed
  1230. * 24-bit number, to the current instruction pointer.
  1231. */
  1232. VM_DEFINE_OP (42, br_if_eqv, "br-if-eqv", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1233. {
  1234. BR_BINARY (x, y,
  1235. scm_is_eq (x, y)
  1236. || (SCM_NIMP (x) && SCM_NIMP (y)
  1237. && scm_is_true (scm_eqv_p (x, y))));
  1238. }
  1239. // FIXME: remove, have compiler inline eqv test instead
  1240. /* br-if-equal a:12 b:12 invert:1 _:7 offset:24
  1241. *
  1242. * If the value in A is equal? to the value in B, add OFFSET, a signed
  1243. * 24-bit number, to the current instruction pointer.
  1244. */
  1245. // FIXME: Should sync_ip before calling out and cache_sp before coming
  1246. // back! Another reason to remove this opcode!
  1247. VM_DEFINE_OP (43, br_if_equal, "br-if-equal", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1248. {
  1249. BR_BINARY (x, y,
  1250. scm_is_eq (x, y)
  1251. || (SCM_NIMP (x) && SCM_NIMP (y)
  1252. && scm_is_true (scm_equal_p (x, y))));
  1253. }
  1254. /* br-if-logtest a:24 _:8 b:24 invert:1 _:7 offset:24
  1255. *
  1256. * If the exact integer in A has any bits in common with the exact
  1257. * integer in B, add OFFSET, a signed 24-bit number, to the current
  1258. * instruction pointer.
  1259. */
  1260. VM_DEFINE_OP (44, br_if_logtest, "br-if-logtest", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1261. {
  1262. BR_BINARY (x, y,
  1263. ((SCM_I_INUMP (x) && SCM_I_INUMP (y))
  1264. ? (SCM_UNPACK (x) & SCM_UNPACK (y) & ~scm_tc2_int)
  1265. : scm_is_true (scm_logtest (x, y))));
  1266. }
  1267. /* br-if-= a:12 b:12 invert:1 _:7 offset:24
  1268. *
  1269. * If the value in A is = to the value in B, add OFFSET, a signed
  1270. * 24-bit number, to the current instruction pointer.
  1271. */
  1272. VM_DEFINE_OP (45, br_if_ee, "br-if-=", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1273. {
  1274. BR_ARITHMETIC (==, scm_num_eq_p);
  1275. }
  1276. /* br-if-< a:12 b:12 invert:1 _:7 offset:24
  1277. *
  1278. * If the value in A is < to the value in B, add OFFSET, a signed
  1279. * 24-bit number, to the current instruction pointer.
  1280. */
  1281. VM_DEFINE_OP (46, br_if_lt, "br-if-<", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1282. {
  1283. BR_ARITHMETIC (<, scm_less_p);
  1284. }
  1285. /* br-if-<= a:12 b:12 invert:1 _:7 offset:24
  1286. *
  1287. * If the value in A is <= to the value in B, add OFFSET, a signed
  1288. * 24-bit number, to the current instruction pointer.
  1289. */
  1290. VM_DEFINE_OP (47, br_if_le, "br-if-<=", OP3 (X8_S24, X8_S24, B1_X7_L24))
  1291. {
  1292. BR_ARITHMETIC (<=, scm_leq_p);
  1293. }
  1294. /*
  1295. * Lexical binding instructions
  1296. */
  1297. /* mov dst:12 src:12
  1298. *
  1299. * Copy a value from one local slot to another.
  1300. */
  1301. VM_DEFINE_OP (48, mov, "mov", OP1 (X8_S12_S12) | OP_DST)
  1302. {
  1303. scm_t_uint16 dst;
  1304. scm_t_uint16 src;
  1305. UNPACK_12_12 (op, dst, src);
  1306. SP_SET (dst, SP_REF (src));
  1307. NEXT (1);
  1308. }
  1309. /* long-mov dst:24 _:8 src:24
  1310. *
  1311. * Copy a value from one local slot to another.
  1312. */
  1313. VM_DEFINE_OP (49, long_mov, "long-mov", OP2 (X8_S24, X8_S24) | OP_DST)
  1314. {
  1315. scm_t_uint32 dst;
  1316. scm_t_uint32 src;
  1317. UNPACK_24 (op, dst);
  1318. UNPACK_24 (ip[1], src);
  1319. SP_SET (dst, SP_REF (src));
  1320. NEXT (2);
  1321. }
  1322. /* long-fmov dst:24 _:8 src:24
  1323. *
  1324. * Copy a value from one local slot to another. Slot indexes are
  1325. * relative to the FP.
  1326. */
  1327. VM_DEFINE_OP (50, long_fmov, "long-fmov", OP2 (X8_F24, X8_F24) | OP_DST)
  1328. {
  1329. scm_t_uint32 dst;
  1330. scm_t_uint32 src;
  1331. UNPACK_24 (op, dst);
  1332. UNPACK_24 (ip[1], src);
  1333. FP_SET (dst, FP_REF (src));
  1334. NEXT (2);
  1335. }
  1336. /* box dst:12 src:12
  1337. *
  1338. * Create a new variable holding SRC, and place it in DST.
  1339. */
  1340. VM_DEFINE_OP (51, box, "box", OP1 (X8_S12_S12) | OP_DST)
  1341. {
  1342. scm_t_uint16 dst, src;
  1343. UNPACK_12_12 (op, dst, src);
  1344. SP_SET (dst, scm_inline_cell (thread, scm_tc7_variable,
  1345. SCM_UNPACK (SP_REF (src))));
  1346. NEXT (1);
  1347. }
  1348. /* box-ref dst:12 src:12
  1349. *
  1350. * Unpack the variable at SRC into DST, asserting that the variable is
  1351. * actually bound.
  1352. */
  1353. VM_DEFINE_OP (52, box_ref, "box-ref", OP1 (X8_S12_S12) | OP_DST)
  1354. {
  1355. scm_t_uint16 dst, src;
  1356. SCM var;
  1357. UNPACK_12_12 (op, dst, src);
  1358. var = SP_REF (src);
  1359. VM_ASSERT (SCM_VARIABLEP (var),
  1360. vm_error_not_a_variable ("variable-ref", var));
  1361. VM_ASSERT (VARIABLE_BOUNDP (var), vm_error_unbound (var));
  1362. SP_SET (dst, VARIABLE_REF (var));
  1363. NEXT (1);
  1364. }
  1365. /* box-set! dst:12 src:12
  1366. *
  1367. * Set the contents of the variable at DST to SET.
  1368. */
  1369. VM_DEFINE_OP (53, box_set, "box-set!", OP1 (X8_S12_S12))
  1370. {
  1371. scm_t_uint16 dst, src;
  1372. SCM var;
  1373. UNPACK_12_12 (op, dst, src);
  1374. var = SP_REF (dst);
  1375. VM_ASSERT (SCM_VARIABLEP (var),
  1376. vm_error_not_a_variable ("variable-set!", var));
  1377. VARIABLE_SET (var, SP_REF (src));
  1378. NEXT (1);
  1379. }
  1380. /* make-closure dst:24 offset:32 _:8 nfree:24
  1381. *
  1382. * Make a new closure, and write it to DST. The code for the closure
  1383. * will be found at OFFSET words from the current IP. OFFSET is a
  1384. * signed 32-bit integer. Space for NFREE free variables will be
  1385. * allocated.
  1386. */
  1387. VM_DEFINE_OP (54, make_closure, "make-closure", OP3 (X8_S24, L32, X8_C24) | OP_DST)
  1388. {
  1389. scm_t_uint32 dst, nfree, n;
  1390. scm_t_int32 offset;
  1391. SCM closure;
  1392. UNPACK_24 (op, dst);
  1393. offset = ip[1];
  1394. UNPACK_24 (ip[2], nfree);
  1395. // FIXME: Assert range of nfree?
  1396. closure = scm_inline_words (thread, scm_tc7_program | (nfree << 16),
  1397. nfree + 2);
  1398. SCM_SET_CELL_WORD_1 (closure, ip + offset);
  1399. // FIXME: Elide these initializations?
  1400. for (n = 0; n < nfree; n++)
  1401. SCM_PROGRAM_FREE_VARIABLE_SET (closure, n, SCM_BOOL_F);
  1402. SP_SET (dst, closure);
  1403. NEXT (3);
  1404. }
  1405. /* free-ref dst:12 src:12 _:8 idx:24
  1406. *
  1407. * Load free variable IDX from the closure SRC into local slot DST.
  1408. */
  1409. VM_DEFINE_OP (55, free_ref, "free-ref", OP2 (X8_S12_S12, X8_C24) | OP_DST)
  1410. {
  1411. scm_t_uint16 dst, src;
  1412. scm_t_uint32 idx;
  1413. UNPACK_12_12 (op, dst, src);
  1414. UNPACK_24 (ip[1], idx);
  1415. /* CHECK_FREE_VARIABLE (src); */
  1416. SP_SET (dst, SCM_PROGRAM_FREE_VARIABLE_REF (SP_REF (src), idx));
  1417. NEXT (2);
  1418. }
  1419. /* free-set! dst:12 src:12 _:8 idx:24
  1420. *
  1421. * Set free variable IDX from the closure DST to SRC.
  1422. */
  1423. VM_DEFINE_OP (56, free_set, "free-set!", OP2 (X8_S12_S12, X8_C24))
  1424. {
  1425. scm_t_uint16 dst, src;
  1426. scm_t_uint32 idx;
  1427. UNPACK_12_12 (op, dst, src);
  1428. UNPACK_24 (ip[1], idx);
  1429. /* CHECK_FREE_VARIABLE (src); */
  1430. SCM_PROGRAM_FREE_VARIABLE_SET (SP_REF (dst), idx, SP_REF (src));
  1431. NEXT (2);
  1432. }
  1433. /*
  1434. * Immediates and statically allocated non-immediates
  1435. */
  1436. /* make-short-immediate dst:8 low-bits:16
  1437. *
  1438. * Make an immediate whose low bits are LOW-BITS, and whose top bits are
  1439. * 0.
  1440. */
  1441. VM_DEFINE_OP (57, make_short_immediate, "make-short-immediate", OP1 (X8_S8_I16) | OP_DST)
  1442. {
  1443. scm_t_uint8 dst;
  1444. scm_t_bits val;
  1445. UNPACK_8_16 (op, dst, val);
  1446. SP_SET (dst, SCM_PACK (val));
  1447. NEXT (1);
  1448. }
  1449. /* make-long-immediate dst:24 low-bits:32
  1450. *
  1451. * Make an immediate whose low bits are LOW-BITS, and whose top bits are
  1452. * 0.
  1453. */
  1454. VM_DEFINE_OP (58, make_long_immediate, "make-long-immediate", OP2 (X8_S24, I32) | OP_DST)
  1455. {
  1456. scm_t_uint32 dst;
  1457. scm_t_bits val;
  1458. UNPACK_24 (op, dst);
  1459. val = ip[1];
  1460. SP_SET (dst, SCM_PACK (val));
  1461. NEXT (2);
  1462. }
  1463. /* make-long-long-immediate dst:24 high-bits:32 low-bits:32
  1464. *
  1465. * Make an immediate with HIGH-BITS and LOW-BITS.
  1466. */
  1467. VM_DEFINE_OP (59, make_long_long_immediate, "make-long-long-immediate", OP3 (X8_S24, A32, B32) | OP_DST)
  1468. {
  1469. scm_t_uint32 dst;
  1470. scm_t_bits val;
  1471. UNPACK_24 (op, dst);
  1472. #if SIZEOF_SCM_T_BITS > 4
  1473. val = ip[1];
  1474. val <<= 32;
  1475. val |= ip[2];
  1476. #else
  1477. ASSERT (ip[1] == 0);
  1478. val = ip[2];
  1479. #endif
  1480. SP_SET (dst, SCM_PACK (val));
  1481. NEXT (3);
  1482. }
  1483. /* make-non-immediate dst:24 offset:32
  1484. *
  1485. * Load a pointer to statically allocated memory into DST. The
  1486. * object's memory is will be found OFFSET 32-bit words away from the
  1487. * current instruction pointer. OFFSET is a signed value. The
  1488. * intention here is that the compiler would produce an object file
  1489. * containing the words of a non-immediate object, and this
  1490. * instruction creates a pointer to that memory, effectively
  1491. * resurrecting that object.
  1492. *
  1493. * Whether the object is mutable or immutable depends on where it was
  1494. * allocated by the compiler, and loaded by the loader.
  1495. */
  1496. VM_DEFINE_OP (60, make_non_immediate, "make-non-immediate", OP2 (X8_S24, N32) | OP_DST)
  1497. {
  1498. scm_t_uint32 dst;
  1499. scm_t_int32 offset;
  1500. scm_t_uint32* loc;
  1501. scm_t_bits unpacked;
  1502. UNPACK_24 (op, dst);
  1503. offset = ip[1];
  1504. loc = ip + offset;
  1505. unpacked = (scm_t_bits) loc;
  1506. VM_ASSERT (!(unpacked & 0x7), abort());
  1507. SP_SET (dst, SCM_PACK (unpacked));
  1508. NEXT (2);
  1509. }
  1510. /* static-ref dst:24 offset:32
  1511. *
  1512. * Load a SCM value into DST. The SCM value will be fetched from
  1513. * memory, OFFSET 32-bit words away from the current instruction
  1514. * pointer. OFFSET is a signed value.
  1515. *
  1516. * The intention is for this instruction to be used to load constants
  1517. * that the compiler is unable to statically allocate, like symbols.
  1518. * These values would be initialized when the object file loads.
  1519. */
  1520. VM_DEFINE_OP (61, static_ref, "static-ref", OP2 (X8_S24, R32) | OP_DST)
  1521. {
  1522. scm_t_uint32 dst;
  1523. scm_t_int32 offset;
  1524. scm_t_uint32* loc;
  1525. scm_t_uintptr loc_bits;
  1526. UNPACK_24 (op, dst);
  1527. offset = ip[1];
  1528. loc = ip + offset;
  1529. loc_bits = (scm_t_uintptr) loc;
  1530. VM_ASSERT (ALIGNED_P (loc, SCM), abort());
  1531. SP_SET (dst, *((SCM *) loc_bits));
  1532. NEXT (2);
  1533. }
  1534. /* static-set! src:24 offset:32
  1535. *
  1536. * Store a SCM value into memory, OFFSET 32-bit words away from the
  1537. * current instruction pointer. OFFSET is a signed value.
  1538. */
  1539. VM_DEFINE_OP (62, static_set, "static-set!", OP2 (X8_S24, LO32))
  1540. {
  1541. scm_t_uint32 src;
  1542. scm_t_int32 offset;
  1543. scm_t_uint32* loc;
  1544. UNPACK_24 (op, src);
  1545. offset = ip[1];
  1546. loc = ip + offset;
  1547. VM_ASSERT (ALIGNED_P (loc, SCM), abort());
  1548. *((SCM *) loc) = SP_REF (src);
  1549. NEXT (2);
  1550. }
  1551. /* static-patch! _:24 dst-offset:32 src-offset:32
  1552. *
  1553. * Patch a pointer at DST-OFFSET to point to SRC-OFFSET. Both offsets
  1554. * are signed 32-bit values, indicating a memory address as a number
  1555. * of 32-bit words away from the current instruction pointer.
  1556. */
  1557. VM_DEFINE_OP (63, static_patch, "static-patch!", OP3 (X32, LO32, L32))
  1558. {
  1559. scm_t_int32 dst_offset, src_offset;
  1560. void *src;
  1561. void** dst_loc;
  1562. dst_offset = ip[1];
  1563. src_offset = ip[2];
  1564. dst_loc = (void **) (ip + dst_offset);
  1565. src = ip + src_offset;
  1566. VM_ASSERT (ALIGNED_P (dst_loc, void*), abort());
  1567. *dst_loc = src;
  1568. NEXT (3);
  1569. }
  1570. /*
  1571. * Mutable top-level bindings
  1572. */
  1573. /* There are three slightly different ways to resolve toplevel
  1574. variables.
  1575. 1. A toplevel reference outside of a function. These need to be
  1576. looked up when the expression is evaluated -- no later, and no
  1577. before. They are looked up relative to the module that is
  1578. current when the expression is evaluated. For example:
  1579. (if (foo) a b)
  1580. The "resolve" instruction resolves the variable (box), and then
  1581. access is via box-ref or box-set!.
  1582. 2. A toplevel reference inside a function. These are looked up
  1583. relative to the module that was current when the function was
  1584. defined. Unlike code at the toplevel, which is usually run only
  1585. once, these bindings benefit from memoized lookup, in which the
  1586. variable resulting from the lookup is cached in the function.
  1587. (lambda () (if (foo) a b))
  1588. The toplevel-box instruction is equivalent to "resolve", but
  1589. caches the resulting variable in statically allocated memory.
  1590. 3. A reference to an identifier with respect to a particular
  1591. module. This can happen for primitive references, and
  1592. references residualized by macro expansions. These can always
  1593. be cached. Use module-box for these.
  1594. */
  1595. /* current-module dst:24
  1596. *
  1597. * Store the current module in DST.
  1598. */
  1599. VM_DEFINE_OP (64, current_module, "current-module", OP1 (X8_S24) | OP_DST)
  1600. {
  1601. scm_t_uint32 dst;
  1602. UNPACK_24 (op, dst);
  1603. SYNC_IP ();
  1604. SP_SET (dst, scm_current_module ());
  1605. NEXT (1);
  1606. }
  1607. /* resolve dst:24 bound?:1 _:7 sym:24
  1608. *
  1609. * Resolve SYM in the current module, and place the resulting variable
  1610. * in DST.
  1611. */
  1612. VM_DEFINE_OP (65, resolve, "resolve", OP2 (X8_S24, B1_X7_S24) | OP_DST)
  1613. {
  1614. scm_t_uint32 dst;
  1615. scm_t_uint32 sym;
  1616. SCM var;
  1617. UNPACK_24 (op, dst);
  1618. UNPACK_24 (ip[1], sym);
  1619. SYNC_IP ();
  1620. var = scm_lookup (SP_REF (sym));
  1621. CACHE_SP ();
  1622. if (ip[1] & 0x1)
  1623. VM_ASSERT (VARIABLE_BOUNDP (var), vm_error_unbound (SP_REF (sym)));
  1624. SP_SET (dst, var);
  1625. NEXT (2);
  1626. }
  1627. /* define! sym:12 val:12
  1628. *
  1629. * Look up a binding for SYM in the current module, creating it if
  1630. * necessary. Set its value to VAL.
  1631. */
  1632. VM_DEFINE_OP (66, define, "define!", OP1 (X8_S12_S12))
  1633. {
  1634. scm_t_uint16 sym, val;
  1635. UNPACK_12_12 (op, sym, val);
  1636. SYNC_IP ();
  1637. scm_define (SP_REF (sym), SP_REF (val));
  1638. CACHE_SP ();
  1639. NEXT (1);
  1640. }
  1641. /* toplevel-box dst:24 var-offset:32 mod-offset:32 sym-offset:32 bound?:1 _:31
  1642. *
  1643. * Load a SCM value. The SCM value will be fetched from memory,
  1644. * VAR-OFFSET 32-bit words away from the current instruction pointer.
  1645. * VAR-OFFSET is a signed value. Up to here, toplevel-box is like
  1646. * static-ref.
  1647. *
  1648. * Then, if the loaded value is a variable, it is placed in DST, and control
  1649. * flow continues.
  1650. *
  1651. * Otherwise, we have to resolve the variable. In that case we load
  1652. * the module from MOD-OFFSET, just as we loaded the variable.
  1653. * Usually the module gets set when the closure is created. The name
  1654. * is an offset to a symbol.
  1655. *
  1656. * We use the module and the symbol to resolve the variable, placing it in
  1657. * DST, and caching the resolved variable so that we will hit the cache next
  1658. * time.
  1659. */
  1660. VM_DEFINE_OP (67, toplevel_box, "toplevel-box", OP5 (X8_S24, R32, R32, N32, B1_X31) | OP_DST)
  1661. {
  1662. scm_t_uint32 dst;
  1663. scm_t_int32 var_offset;
  1664. scm_t_uint32* var_loc_u32;
  1665. SCM *var_loc;
  1666. SCM var;
  1667. UNPACK_24 (op, dst);
  1668. var_offset = ip[1];
  1669. var_loc_u32 = ip + var_offset;
  1670. VM_ASSERT (ALIGNED_P (var_loc_u32, SCM), abort());
  1671. var_loc = (SCM *) var_loc_u32;
  1672. var = *var_loc;
  1673. if (SCM_UNLIKELY (!SCM_VARIABLEP (var)))
  1674. {
  1675. SCM mod, sym;
  1676. scm_t_int32 mod_offset = ip[2]; /* signed */
  1677. scm_t_int32 sym_offset = ip[3]; /* signed */
  1678. scm_t_uint32 *mod_loc = ip + mod_offset;
  1679. scm_t_uint32 *sym_loc = ip + sym_offset;
  1680. SYNC_IP ();
  1681. VM_ASSERT (ALIGNED_P (mod_loc, SCM), abort());
  1682. VM_ASSERT (ALIGNED_P (sym_loc, SCM), abort());
  1683. mod = *((SCM *) mod_loc);
  1684. sym = *((SCM *) sym_loc);
  1685. /* If the toplevel scope was captured before modules were
  1686. booted, use the root module. */
  1687. if (scm_is_false (mod))
  1688. mod = scm_the_root_module ();
  1689. var = scm_module_lookup (mod, sym);
  1690. CACHE_SP ();
  1691. if (ip[4] & 0x1)
  1692. VM_ASSERT (VARIABLE_BOUNDP (var), vm_error_unbound (sym));
  1693. *var_loc = var;
  1694. }
  1695. SP_SET (dst, var);
  1696. NEXT (5);
  1697. }
  1698. /* module-box dst:24 var-offset:32 mod-offset:32 sym-offset:32 bound?:1 _:31
  1699. *
  1700. * Like toplevel-box, except MOD-OFFSET points at the name of a module
  1701. * instead of the module itself.
  1702. */
  1703. VM_DEFINE_OP (68, module_box, "module-box", OP5 (X8_S24, R32, N32, N32, B1_X31) | OP_DST)
  1704. {
  1705. scm_t_uint32 dst;
  1706. scm_t_int32 var_offset;
  1707. scm_t_uint32* var_loc_u32;
  1708. SCM *var_loc;
  1709. SCM var;
  1710. UNPACK_24 (op, dst);
  1711. var_offset = ip[1];
  1712. var_loc_u32 = ip + var_offset;
  1713. VM_ASSERT (ALIGNED_P (var_loc_u32, SCM), abort());
  1714. var_loc = (SCM *) var_loc_u32;
  1715. var = *var_loc;
  1716. if (SCM_UNLIKELY (!SCM_VARIABLEP (var)))
  1717. {
  1718. SCM modname, sym;
  1719. scm_t_int32 modname_offset = ip[2]; /* signed */
  1720. scm_t_int32 sym_offset = ip[3]; /* signed */
  1721. scm_t_uint32 *modname_words = ip + modname_offset;
  1722. scm_t_uint32 *sym_loc = ip + sym_offset;
  1723. SYNC_IP ();
  1724. VM_ASSERT (!(((scm_t_uintptr) modname_words) & 0x7), abort());
  1725. VM_ASSERT (ALIGNED_P (sym_loc, SCM), abort());
  1726. modname = SCM_PACK ((scm_t_bits) modname_words);
  1727. sym = *((SCM *) sym_loc);
  1728. if (!scm_module_system_booted_p)
  1729. {
  1730. ASSERT (scm_is_true
  1731. scm_equal_p (modname,
  1732. scm_list_2
  1733. (SCM_BOOL_T,
  1734. scm_from_utf8_symbol ("guile"))));
  1735. var = scm_lookup (sym);
  1736. }
  1737. else if (scm_is_true (SCM_CAR (modname)))
  1738. var = scm_public_lookup (SCM_CDR (modname), sym);
  1739. else
  1740. var = scm_private_lookup (SCM_CDR (modname), sym);
  1741. CACHE_SP ();
  1742. if (ip[4] & 0x1)
  1743. VM_ASSERT (VARIABLE_BOUNDP (var), vm_error_unbound (sym));
  1744. *var_loc = var;
  1745. }
  1746. SP_SET (dst, var);
  1747. NEXT (5);
  1748. }
  1749. /*
  1750. * The dynamic environment
  1751. */
  1752. /* prompt tag:24 escape-only?:1 _:7 proc-slot:24 _:8 handler-offset:24
  1753. *
  1754. * Push a new prompt on the dynamic stack, with a tag from TAG and a
  1755. * handler at HANDLER-OFFSET words from the current IP. The handler
  1756. * will expect a multiple-value return as if from a call with the
  1757. * procedure at PROC-SLOT.
  1758. */
  1759. VM_DEFINE_OP (69, prompt, "prompt", OP3 (X8_S24, B1_X7_F24, X8_L24))
  1760. {
  1761. scm_t_uint32 tag, proc_slot;
  1762. scm_t_int32 offset;
  1763. scm_t_uint8 escape_only_p;
  1764. scm_t_dynstack_prompt_flags flags;
  1765. UNPACK_24 (op, tag);
  1766. escape_only_p = ip[1] & 0x1;
  1767. UNPACK_24 (ip[1], proc_slot);
  1768. offset = ip[2];
  1769. offset >>= 8; /* Sign extension */
  1770. /* Push the prompt onto the dynamic stack. */
  1771. flags = escape_only_p ? SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY : 0;
  1772. scm_dynstack_push_prompt (&thread->dynstack, flags,
  1773. SP_REF (tag),
  1774. vp->stack_top - vp->fp,
  1775. vp->stack_top - FP_SLOT (proc_slot),
  1776. ip + offset,
  1777. registers);
  1778. NEXT (3);
  1779. }
  1780. /* wind winder:12 unwinder:12
  1781. *
  1782. * Push wind and unwind procedures onto the dynamic stack. Note that
  1783. * neither are actually called; the compiler should emit calls to wind
  1784. * and unwind for the normal dynamic-wind control flow. Also note that
  1785. * the compiler should have inserted checks that they wind and unwind
  1786. * procs are thunks, if it could not prove that to be the case.
  1787. */
  1788. VM_DEFINE_OP (70, wind, "wind", OP1 (X8_S12_S12))
  1789. {
  1790. scm_t_uint16 winder, unwinder;
  1791. UNPACK_12_12 (op, winder, unwinder);
  1792. scm_dynstack_push_dynwind (&thread->dynstack,
  1793. SP_REF (winder), SP_REF (unwinder));
  1794. NEXT (1);
  1795. }
  1796. /* unwind _:24
  1797. *
  1798. * A normal exit from the dynamic extent of an expression. Pop the top
  1799. * entry off of the dynamic stack.
  1800. */
  1801. VM_DEFINE_OP (71, unwind, "unwind", OP1 (X32))
  1802. {
  1803. scm_dynstack_pop (&thread->dynstack);
  1804. NEXT (1);
  1805. }
  1806. /* push-fluid fluid:12 value:12
  1807. *
  1808. * Dynamically bind VALUE to FLUID.
  1809. */
  1810. VM_DEFINE_OP (72, push_fluid, "push-fluid", OP1 (X8_S12_S12))
  1811. {
  1812. scm_t_uint32 fluid, value;
  1813. UNPACK_12_12 (op, fluid, value);
  1814. scm_dynstack_push_fluid (&thread->dynstack,
  1815. SP_REF (fluid), SP_REF (value),
  1816. thread->dynamic_state);
  1817. NEXT (1);
  1818. }
  1819. /* pop-fluid _:24
  1820. *
  1821. * Leave the dynamic extent of a with-fluid* expression, restoring the
  1822. * fluid to its previous value.
  1823. */
  1824. VM_DEFINE_OP (73, pop_fluid, "pop-fluid", OP1 (X32))
  1825. {
  1826. /* This function must not allocate. */
  1827. scm_dynstack_unwind_fluid (&thread->dynstack,
  1828. thread->dynamic_state);
  1829. NEXT (1);
  1830. }
  1831. /* fluid-ref dst:12 src:12
  1832. *
  1833. * Reference the fluid in SRC, and place the value in DST.
  1834. */
  1835. VM_DEFINE_OP (74, fluid_ref, "fluid-ref", OP1 (X8_S12_S12) | OP_DST)
  1836. {
  1837. scm_t_uint16 dst, src;
  1838. size_t num;
  1839. SCM fluid, fluids;
  1840. UNPACK_12_12 (op, dst, src);
  1841. fluid = SP_REF (src);
  1842. fluids = SCM_I_DYNAMIC_STATE_FLUIDS (thread->dynamic_state);
  1843. if (SCM_UNLIKELY (!SCM_FLUID_P (fluid))
  1844. || ((num = SCM_I_FLUID_NUM (fluid)) >= SCM_SIMPLE_VECTOR_LENGTH (fluids)))
  1845. {
  1846. /* Punt dynstate expansion and error handling to the C proc. */
  1847. SYNC_IP ();
  1848. SP_SET (dst, scm_fluid_ref (fluid));
  1849. }
  1850. else
  1851. {
  1852. SCM val = SCM_SIMPLE_VECTOR_REF (fluids, num);
  1853. if (scm_is_eq (val, SCM_UNDEFINED))
  1854. val = SCM_I_FLUID_DEFAULT (fluid);
  1855. VM_ASSERT (!scm_is_eq (val, SCM_UNDEFINED),
  1856. vm_error_unbound_fluid (fluid));
  1857. SP_SET (dst, val);
  1858. }
  1859. NEXT (1);
  1860. }
  1861. /* fluid-set fluid:12 val:12
  1862. *
  1863. * Set the value of the fluid in DST to the value in SRC.
  1864. */
  1865. VM_DEFINE_OP (75, fluid_set, "fluid-set", OP1 (X8_S12_S12))
  1866. {
  1867. scm_t_uint16 a, b;
  1868. size_t num;
  1869. SCM fluid, fluids;
  1870. UNPACK_12_12 (op, a, b);
  1871. fluid = SP_REF (a);
  1872. fluids = SCM_I_DYNAMIC_STATE_FLUIDS (thread->dynamic_state);
  1873. if (SCM_UNLIKELY (!SCM_FLUID_P (fluid))
  1874. || ((num = SCM_I_FLUID_NUM (fluid)) >= SCM_SIMPLE_VECTOR_LENGTH (fluids)))
  1875. {
  1876. /* Punt dynstate expansion and error handling to the C proc. */
  1877. SYNC_IP ();
  1878. scm_fluid_set_x (fluid, SP_REF (b));
  1879. }
  1880. else
  1881. SCM_SIMPLE_VECTOR_SET (fluids, num, SP_REF (b));
  1882. NEXT (1);
  1883. }
  1884. /*
  1885. * Strings, symbols, and keywords
  1886. */
  1887. /* string-length dst:12 src:12
  1888. *
  1889. * Store the length of the string in SRC in DST.
  1890. */
  1891. VM_DEFINE_OP (76, string_length, "string-length", OP1 (X8_S12_S12) | OP_DST)
  1892. {
  1893. ARGS1 (str);
  1894. if (SCM_LIKELY (scm_is_string (str)))
  1895. RETURN (SCM_I_MAKINUM (scm_i_string_length (str)));
  1896. else
  1897. {
  1898. SYNC_IP ();
  1899. RETURN (scm_string_length (str));
  1900. }
  1901. }
  1902. /* string-ref dst:8 src:8 idx:8
  1903. *
  1904. * Fetch the character at position IDX in the string in SRC, and store
  1905. * it in DST.
  1906. */
  1907. VM_DEFINE_OP (77, string_ref, "string-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  1908. {
  1909. scm_t_signed_bits i = 0;
  1910. ARGS2 (str, idx);
  1911. if (SCM_LIKELY (scm_is_string (str)
  1912. && SCM_I_INUMP (idx)
  1913. && ((i = SCM_I_INUM (idx)) >= 0)
  1914. && i < scm_i_string_length (str)))
  1915. RETURN (SCM_MAKE_CHAR (scm_i_string_ref (str, i)));
  1916. else
  1917. {
  1918. SYNC_IP ();
  1919. RETURN (scm_string_ref (str, idx));
  1920. }
  1921. }
  1922. /* No string-set! instruction, as there is no good fast path there. */
  1923. /* string->number dst:12 src:12
  1924. *
  1925. * Parse a string in SRC to a number, and store in DST.
  1926. */
  1927. VM_DEFINE_OP (78, string_to_number, "string->number", OP1 (X8_S12_S12) | OP_DST)
  1928. {
  1929. scm_t_uint16 dst, src;
  1930. UNPACK_12_12 (op, dst, src);
  1931. SYNC_IP ();
  1932. SP_SET (dst,
  1933. scm_string_to_number (SP_REF (src),
  1934. SCM_UNDEFINED /* radix = 10 */));
  1935. NEXT (1);
  1936. }
  1937. /* string->symbol dst:12 src:12
  1938. *
  1939. * Parse a string in SRC to a symbol, and store in DST.
  1940. */
  1941. VM_DEFINE_OP (79, string_to_symbol, "string->symbol", OP1 (X8_S12_S12) | OP_DST)
  1942. {
  1943. scm_t_uint16 dst, src;
  1944. UNPACK_12_12 (op, dst, src);
  1945. SYNC_IP ();
  1946. SP_SET (dst, scm_string_to_symbol (SP_REF (src)));
  1947. NEXT (1);
  1948. }
  1949. /* symbol->keyword dst:12 src:12
  1950. *
  1951. * Make a keyword from the symbol in SRC, and store it in DST.
  1952. */
  1953. VM_DEFINE_OP (80, symbol_to_keyword, "symbol->keyword", OP1 (X8_S12_S12) | OP_DST)
  1954. {
  1955. scm_t_uint16 dst, src;
  1956. UNPACK_12_12 (op, dst, src);
  1957. SYNC_IP ();
  1958. SP_SET (dst, scm_symbol_to_keyword (SP_REF (src)));
  1959. NEXT (1);
  1960. }
  1961. /*
  1962. * Pairs
  1963. */
  1964. /* cons dst:8 car:8 cdr:8
  1965. *
  1966. * Cons CAR and CDR, and store the result in DST.
  1967. */
  1968. VM_DEFINE_OP (81, cons, "cons", OP1 (X8_S8_S8_S8) | OP_DST)
  1969. {
  1970. ARGS2 (x, y);
  1971. RETURN (scm_inline_cons (thread, x, y));
  1972. }
  1973. /* car dst:12 src:12
  1974. *
  1975. * Place the car of SRC in DST.
  1976. */
  1977. VM_DEFINE_OP (82, car, "car", OP1 (X8_S12_S12) | OP_DST)
  1978. {
  1979. ARGS1 (x);
  1980. VM_VALIDATE_PAIR (x, "car");
  1981. RETURN (SCM_CAR (x));
  1982. }
  1983. /* cdr dst:12 src:12
  1984. *
  1985. * Place the cdr of SRC in DST.
  1986. */
  1987. VM_DEFINE_OP (83, cdr, "cdr", OP1 (X8_S12_S12) | OP_DST)
  1988. {
  1989. ARGS1 (x);
  1990. VM_VALIDATE_PAIR (x, "cdr");
  1991. RETURN (SCM_CDR (x));
  1992. }
  1993. /* set-car! pair:12 car:12
  1994. *
  1995. * Set the car of DST to SRC.
  1996. */
  1997. VM_DEFINE_OP (84, set_car, "set-car!", OP1 (X8_S12_S12))
  1998. {
  1999. scm_t_uint16 a, b;
  2000. SCM x, y;
  2001. UNPACK_12_12 (op, a, b);
  2002. x = SP_REF (a);
  2003. y = SP_REF (b);
  2004. VM_VALIDATE_PAIR (x, "set-car!");
  2005. SCM_SETCAR (x, y);
  2006. NEXT (1);
  2007. }
  2008. /* set-cdr! pair:12 cdr:12
  2009. *
  2010. * Set the cdr of DST to SRC.
  2011. */
  2012. VM_DEFINE_OP (85, set_cdr, "set-cdr!", OP1 (X8_S12_S12))
  2013. {
  2014. scm_t_uint16 a, b;
  2015. SCM x, y;
  2016. UNPACK_12_12 (op, a, b);
  2017. x = SP_REF (a);
  2018. y = SP_REF (b);
  2019. VM_VALIDATE_PAIR (x, "set-car!");
  2020. SCM_SETCDR (x, y);
  2021. NEXT (1);
  2022. }
  2023. /*
  2024. * Numeric operations
  2025. */
  2026. /* add dst:8 a:8 b:8
  2027. *
  2028. * Add A to B, and place the result in DST.
  2029. */
  2030. VM_DEFINE_OP (86, add, "add", OP1 (X8_S8_S8_S8) | OP_DST)
  2031. {
  2032. BINARY_INTEGER_OP (+, scm_sum);
  2033. }
  2034. /* add1 dst:12 src:12
  2035. *
  2036. * Add 1 to the value in SRC, and place the result in DST.
  2037. */
  2038. VM_DEFINE_OP (87, add1, "add1", OP1 (X8_S12_S12) | OP_DST)
  2039. {
  2040. ARGS1 (x);
  2041. /* Check for overflow. We must avoid overflow in the signed
  2042. addition below, even if X is not an inum. */
  2043. if (SCM_LIKELY ((scm_t_signed_bits) SCM_UNPACK (x) <= INUM_MAX - INUM_STEP))
  2044. {
  2045. SCM result;
  2046. /* Add 1 to the integer without untagging. */
  2047. result = SCM_PACK ((scm_t_signed_bits) SCM_UNPACK (x) + INUM_STEP);
  2048. if (SCM_LIKELY (SCM_I_INUMP (result)))
  2049. RETURN (result);
  2050. }
  2051. RETURN_EXP (scm_sum (x, SCM_I_MAKINUM (1)));
  2052. }
  2053. /* sub dst:8 a:8 b:8
  2054. *
  2055. * Subtract B from A, and place the result in DST.
  2056. */
  2057. VM_DEFINE_OP (88, sub, "sub", OP1 (X8_S8_S8_S8) | OP_DST)
  2058. {
  2059. BINARY_INTEGER_OP (-, scm_difference);
  2060. }
  2061. /* sub1 dst:12 src:12
  2062. *
  2063. * Subtract 1 from SRC, and place the result in DST.
  2064. */
  2065. VM_DEFINE_OP (89, sub1, "sub1", OP1 (X8_S12_S12) | OP_DST)
  2066. {
  2067. ARGS1 (x);
  2068. /* Check for overflow. We must avoid overflow in the signed
  2069. subtraction below, even if X is not an inum. */
  2070. if (SCM_LIKELY ((scm_t_signed_bits) SCM_UNPACK (x) >= INUM_MIN + INUM_STEP))
  2071. {
  2072. SCM result;
  2073. /* Substract 1 from the integer without untagging. */
  2074. result = SCM_PACK ((scm_t_signed_bits) SCM_UNPACK (x) - INUM_STEP);
  2075. if (SCM_LIKELY (SCM_I_INUMP (result)))
  2076. RETURN (result);
  2077. }
  2078. RETURN_EXP (scm_difference (x, SCM_I_MAKINUM (1)));
  2079. }
  2080. /* mul dst:8 a:8 b:8
  2081. *
  2082. * Multiply A and B, and place the result in DST.
  2083. */
  2084. VM_DEFINE_OP (90, mul, "mul", OP1 (X8_S8_S8_S8) | OP_DST)
  2085. {
  2086. ARGS2 (x, y);
  2087. RETURN_EXP (scm_product (x, y));
  2088. }
  2089. /* div dst:8 a:8 b:8
  2090. *
  2091. * Divide A by B, and place the result in DST.
  2092. */
  2093. VM_DEFINE_OP (91, div, "div", OP1 (X8_S8_S8_S8) | OP_DST)
  2094. {
  2095. ARGS2 (x, y);
  2096. RETURN_EXP (scm_divide (x, y));
  2097. }
  2098. /* quo dst:8 a:8 b:8
  2099. *
  2100. * Divide A by B, and place the quotient in DST.
  2101. */
  2102. VM_DEFINE_OP (92, quo, "quo", OP1 (X8_S8_S8_S8) | OP_DST)
  2103. {
  2104. ARGS2 (x, y);
  2105. RETURN_EXP (scm_quotient (x, y));
  2106. }
  2107. /* rem dst:8 a:8 b:8
  2108. *
  2109. * Divide A by B, and place the remainder in DST.
  2110. */
  2111. VM_DEFINE_OP (93, rem, "rem", OP1 (X8_S8_S8_S8) | OP_DST)
  2112. {
  2113. ARGS2 (x, y);
  2114. RETURN_EXP (scm_remainder (x, y));
  2115. }
  2116. /* mod dst:8 a:8 b:8
  2117. *
  2118. * Place the modulo of A by B in DST.
  2119. */
  2120. VM_DEFINE_OP (94, mod, "mod", OP1 (X8_S8_S8_S8) | OP_DST)
  2121. {
  2122. ARGS2 (x, y);
  2123. RETURN_EXP (scm_modulo (x, y));
  2124. }
  2125. /* ash dst:8 a:8 b:8
  2126. *
  2127. * Shift A arithmetically by B bits, and place the result in DST.
  2128. */
  2129. VM_DEFINE_OP (95, ash, "ash", OP1 (X8_S8_S8_S8) | OP_DST)
  2130. {
  2131. ARGS2 (x, y);
  2132. if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
  2133. {
  2134. if (SCM_I_INUM (y) < 0)
  2135. /* Right shift, will be a fixnum. */
  2136. RETURN (SCM_I_MAKINUM
  2137. (SCM_SRS (SCM_I_INUM (x),
  2138. (-SCM_I_INUM (y) <= SCM_I_FIXNUM_BIT-1)
  2139. ? -SCM_I_INUM (y) : SCM_I_FIXNUM_BIT-1)));
  2140. else
  2141. /* Left shift. See comments in scm_ash. */
  2142. {
  2143. scm_t_signed_bits nn, bits_to_shift;
  2144. nn = SCM_I_INUM (x);
  2145. bits_to_shift = SCM_I_INUM (y);
  2146. if (bits_to_shift < SCM_I_FIXNUM_BIT-1
  2147. && ((scm_t_bits)
  2148. (SCM_SRS (nn, (SCM_I_FIXNUM_BIT-1 - bits_to_shift)) + 1)
  2149. <= 1))
  2150. RETURN (SCM_I_MAKINUM (nn < 0
  2151. ? -(-nn << bits_to_shift)
  2152. : (nn << bits_to_shift)));
  2153. /* fall through */
  2154. }
  2155. /* fall through */
  2156. }
  2157. RETURN_EXP (scm_ash (x, y));
  2158. }
  2159. /* logand dst:8 a:8 b:8
  2160. *
  2161. * Place the bitwise AND of A and B into DST.
  2162. */
  2163. VM_DEFINE_OP (96, logand, "logand", OP1 (X8_S8_S8_S8) | OP_DST)
  2164. {
  2165. ARGS2 (x, y);
  2166. if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
  2167. /* Compute bitwise AND without untagging */
  2168. RETURN (SCM_PACK (SCM_UNPACK (x) & SCM_UNPACK (y)));
  2169. RETURN_EXP (scm_logand (x, y));
  2170. }
  2171. /* logior dst:8 a:8 b:8
  2172. *
  2173. * Place the bitwise inclusive OR of A with B in DST.
  2174. */
  2175. VM_DEFINE_OP (97, logior, "logior", OP1 (X8_S8_S8_S8) | OP_DST)
  2176. {
  2177. ARGS2 (x, y);
  2178. if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
  2179. /* Compute bitwise OR without untagging */
  2180. RETURN (SCM_PACK (SCM_UNPACK (x) | SCM_UNPACK (y)));
  2181. RETURN_EXP (scm_logior (x, y));
  2182. }
  2183. /* logxor dst:8 a:8 b:8
  2184. *
  2185. * Place the bitwise exclusive OR of A with B in DST.
  2186. */
  2187. VM_DEFINE_OP (98, logxor, "logxor", OP1 (X8_S8_S8_S8) | OP_DST)
  2188. {
  2189. ARGS2 (x, y);
  2190. if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
  2191. RETURN (SCM_I_MAKINUM (SCM_I_INUM (x) ^ SCM_I_INUM (y)));
  2192. RETURN_EXP (scm_logxor (x, y));
  2193. }
  2194. /* make-vector dst:8 length:8 init:8
  2195. *
  2196. * Make a vector and write it to DST. The vector will have space for
  2197. * LENGTH slots. They will be filled with the value in slot INIT.
  2198. */
  2199. VM_DEFINE_OP (99, make_vector, "make-vector", OP1 (X8_S8_S8_S8) | OP_DST)
  2200. {
  2201. scm_t_uint8 dst, init, length;
  2202. UNPACK_8_8_8 (op, dst, length, init);
  2203. SP_SET (dst, scm_make_vector (SP_REF (length), SP_REF (init)));
  2204. NEXT (1);
  2205. }
  2206. /* make-vector/immediate dst:8 length:8 init:8
  2207. *
  2208. * Make a short vector of known size and write it to DST. The vector
  2209. * will have space for LENGTH slots, an immediate value. They will be
  2210. * filled with the value in slot INIT.
  2211. */
  2212. VM_DEFINE_OP (100, make_vector_immediate, "make-vector/immediate", OP1 (X8_S8_C8_S8) | OP_DST)
  2213. {
  2214. scm_t_uint8 dst, init;
  2215. scm_t_int32 length, n;
  2216. SCM val, vector;
  2217. UNPACK_8_8_8 (op, dst, length, init);
  2218. val = SP_REF (init);
  2219. vector = scm_inline_words (thread, scm_tc7_vector | (length << 8),
  2220. length + 1);
  2221. for (n = 0; n < length; n++)
  2222. SCM_SIMPLE_VECTOR_SET (vector, n, val);
  2223. SP_SET (dst, vector);
  2224. NEXT (1);
  2225. }
  2226. /* vector-length dst:12 src:12
  2227. *
  2228. * Store the length of the vector in SRC in DST.
  2229. */
  2230. VM_DEFINE_OP (101, vector_length, "vector-length", OP1 (X8_S12_S12) | OP_DST)
  2231. {
  2232. ARGS1 (vect);
  2233. VM_ASSERT (SCM_I_IS_VECTOR (vect),
  2234. vm_error_not_a_vector ("vector-ref", vect));
  2235. RETURN (SCM_I_MAKINUM (SCM_I_VECTOR_LENGTH (vect)));
  2236. }
  2237. /* vector-ref dst:8 src:8 idx:8
  2238. *
  2239. * Fetch the item at position IDX in the vector in SRC, and store it
  2240. * in DST.
  2241. */
  2242. VM_DEFINE_OP (102, vector_ref, "vector-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2243. {
  2244. scm_t_signed_bits i = 0;
  2245. ARGS2 (vect, idx);
  2246. VM_ASSERT (SCM_I_IS_VECTOR (vect),
  2247. vm_error_not_a_vector ("vector-ref", vect));
  2248. VM_ASSERT ((SCM_I_INUMP (idx)
  2249. && ((i = SCM_I_INUM (idx)) >= 0)
  2250. && i < SCM_I_VECTOR_LENGTH (vect)),
  2251. vm_error_out_of_range ("vector-ref", idx));
  2252. RETURN (SCM_I_VECTOR_ELTS (vect)[i]);
  2253. }
  2254. /* vector-ref/immediate dst:8 src:8 idx:8
  2255. *
  2256. * Fill DST with the item IDX elements into the vector at SRC. Useful
  2257. * for building data types using vectors.
  2258. */
  2259. VM_DEFINE_OP (103, vector_ref_immediate, "vector-ref/immediate", OP1 (X8_S8_S8_C8) | OP_DST)
  2260. {
  2261. scm_t_uint8 dst, src, idx;
  2262. SCM v;
  2263. UNPACK_8_8_8 (op, dst, src, idx);
  2264. v = SP_REF (src);
  2265. VM_ASSERT (SCM_I_IS_VECTOR (v),
  2266. vm_error_not_a_vector ("vector-ref", v));
  2267. VM_ASSERT (idx < SCM_I_VECTOR_LENGTH (v),
  2268. vm_error_out_of_range ("vector-ref", scm_from_size_t (idx)));
  2269. SP_SET (dst, SCM_I_VECTOR_ELTS (SP_REF (src))[idx]);
  2270. NEXT (1);
  2271. }
  2272. /* vector-set! dst:8 idx:8 src:8
  2273. *
  2274. * Store SRC into the vector DST at index IDX.
  2275. */
  2276. VM_DEFINE_OP (104, vector_set, "vector-set!", OP1 (X8_S8_S8_S8))
  2277. {
  2278. scm_t_uint8 dst, idx_var, src;
  2279. SCM vect, idx, val;
  2280. scm_t_signed_bits i = 0;
  2281. UNPACK_8_8_8 (op, dst, idx_var, src);
  2282. vect = SP_REF (dst);
  2283. idx = SP_REF (idx_var);
  2284. val = SP_REF (src);
  2285. VM_ASSERT (SCM_I_IS_VECTOR (vect),
  2286. vm_error_not_a_vector ("vector-ref", vect));
  2287. VM_ASSERT ((SCM_I_INUMP (idx)
  2288. && ((i = SCM_I_INUM (idx)) >= 0)
  2289. && i < SCM_I_VECTOR_LENGTH (vect)),
  2290. vm_error_out_of_range ("vector-ref", idx));
  2291. SCM_I_VECTOR_WELTS (vect)[i] = val;
  2292. NEXT (1);
  2293. }
  2294. /* vector-set!/immediate dst:8 idx:8 src:8
  2295. *
  2296. * Store SRC into the vector DST at index IDX. Here IDX is an
  2297. * immediate value.
  2298. */
  2299. VM_DEFINE_OP (105, vector_set_immediate, "vector-set!/immediate", OP1 (X8_S8_C8_S8))
  2300. {
  2301. scm_t_uint8 dst, idx, src;
  2302. SCM vect, val;
  2303. UNPACK_8_8_8 (op, dst, idx, src);
  2304. vect = SP_REF (dst);
  2305. val = SP_REF (src);
  2306. VM_ASSERT (SCM_I_IS_VECTOR (vect),
  2307. vm_error_not_a_vector ("vector-ref", vect));
  2308. VM_ASSERT (idx < SCM_I_VECTOR_LENGTH (vect),
  2309. vm_error_out_of_range ("vector-ref", scm_from_size_t (idx)));
  2310. SCM_I_VECTOR_WELTS (vect)[idx] = val;
  2311. NEXT (1);
  2312. }
  2313. /*
  2314. * Structs and GOOPS
  2315. */
  2316. /* struct-vtable dst:12 src:12
  2317. *
  2318. * Store the vtable of SRC into DST.
  2319. */
  2320. VM_DEFINE_OP (106, struct_vtable, "struct-vtable", OP1 (X8_S12_S12) | OP_DST)
  2321. {
  2322. ARGS1 (obj);
  2323. VM_VALIDATE_STRUCT (obj, "struct_vtable");
  2324. RETURN (SCM_STRUCT_VTABLE (obj));
  2325. }
  2326. /* allocate-struct dst:8 vtable:8 nfields:8
  2327. *
  2328. * Allocate a new struct with VTABLE, and place it in DST. The struct
  2329. * will be constructed with space for NFIELDS fields, which should
  2330. * correspond to the field count of the VTABLE.
  2331. */
  2332. VM_DEFINE_OP (107, allocate_struct, "allocate-struct", OP1 (X8_S8_S8_S8) | OP_DST)
  2333. {
  2334. scm_t_uint8 dst, vtable, nfields;
  2335. SCM ret;
  2336. UNPACK_8_8_8 (op, dst, vtable, nfields);
  2337. SYNC_IP ();
  2338. ret = scm_allocate_struct (SP_REF (vtable), SP_REF (nfields));
  2339. SP_SET (dst, ret);
  2340. NEXT (1);
  2341. }
  2342. /* struct-ref dst:8 src:8 idx:8
  2343. *
  2344. * Fetch the item at slot IDX in the struct in SRC, and store it
  2345. * in DST.
  2346. */
  2347. VM_DEFINE_OP (108, struct_ref, "struct-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2348. {
  2349. scm_t_uint8 dst, src, idx;
  2350. SCM obj;
  2351. SCM index;
  2352. UNPACK_8_8_8 (op, dst, src, idx);
  2353. obj = SP_REF (src);
  2354. index = SP_REF (idx);
  2355. if (SCM_LIKELY (SCM_STRUCTP (obj)
  2356. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2357. SCM_VTABLE_FLAG_SIMPLE)
  2358. && SCM_I_INUMP (index)
  2359. && SCM_I_INUM (index) >= 0
  2360. && SCM_I_INUM (index) < (SCM_STRUCT_DATA_REF
  2361. (SCM_STRUCT_VTABLE (obj),
  2362. scm_vtable_index_size))))
  2363. RETURN (SCM_STRUCT_SLOT_REF (obj, SCM_I_INUM (index)));
  2364. SYNC_IP ();
  2365. RETURN (scm_struct_ref (obj, index));
  2366. }
  2367. /* struct-set! dst:8 idx:8 src:8
  2368. *
  2369. * Store SRC into the struct DST at slot IDX.
  2370. */
  2371. VM_DEFINE_OP (109, struct_set, "struct-set!", OP1 (X8_S8_S8_S8))
  2372. {
  2373. scm_t_uint8 dst, idx, src;
  2374. SCM obj, val, index;
  2375. UNPACK_8_8_8 (op, dst, idx, src);
  2376. obj = SP_REF (dst);
  2377. val = SP_REF (src);
  2378. index = SP_REF (idx);
  2379. if (SCM_LIKELY (SCM_STRUCTP (obj)
  2380. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2381. SCM_VTABLE_FLAG_SIMPLE)
  2382. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2383. SCM_VTABLE_FLAG_SIMPLE_RW)
  2384. && SCM_I_INUMP (index)
  2385. && SCM_I_INUM (index) >= 0
  2386. && SCM_I_INUM (index) < (SCM_STRUCT_DATA_REF
  2387. (SCM_STRUCT_VTABLE (obj),
  2388. scm_vtable_index_size))))
  2389. {
  2390. SCM_STRUCT_SLOT_SET (obj, SCM_I_INUM (index), val);
  2391. NEXT (1);
  2392. }
  2393. SYNC_IP ();
  2394. scm_struct_set_x (obj, index, val);
  2395. NEXT (1);
  2396. }
  2397. /* allocate-struct/immediate dst:8 vtable:8 nfields:8
  2398. *
  2399. * Allocate a new struct with VTABLE, and place it in DST. The struct
  2400. * will be constructed with space for NFIELDS fields, which should
  2401. * correspond to the field count of the VTABLE.
  2402. */
  2403. VM_DEFINE_OP (110, allocate_struct_immediate, "allocate-struct/immediate", OP1 (X8_S8_S8_C8) | OP_DST)
  2404. {
  2405. scm_t_uint8 dst, vtable, nfields;
  2406. SCM ret;
  2407. UNPACK_8_8_8 (op, dst, vtable, nfields);
  2408. SYNC_IP ();
  2409. ret = scm_allocate_struct (SP_REF (vtable), SCM_I_MAKINUM (nfields));
  2410. SP_SET (dst, ret);
  2411. NEXT (1);
  2412. }
  2413. /* struct-ref/immediate dst:8 src:8 idx:8
  2414. *
  2415. * Fetch the item at slot IDX in the struct in SRC, and store it
  2416. * in DST. IDX is an immediate unsigned 8-bit value.
  2417. */
  2418. VM_DEFINE_OP (111, struct_ref_immediate, "struct-ref/immediate", OP1 (X8_S8_S8_C8) | OP_DST)
  2419. {
  2420. scm_t_uint8 dst, src, idx;
  2421. SCM obj;
  2422. UNPACK_8_8_8 (op, dst, src, idx);
  2423. obj = SP_REF (src);
  2424. if (SCM_LIKELY (SCM_STRUCTP (obj)
  2425. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2426. SCM_VTABLE_FLAG_SIMPLE)
  2427. && idx < SCM_STRUCT_DATA_REF (SCM_STRUCT_VTABLE (obj),
  2428. scm_vtable_index_size)))
  2429. RETURN (SCM_STRUCT_SLOT_REF (obj, idx));
  2430. SYNC_IP ();
  2431. RETURN (scm_struct_ref (obj, SCM_I_MAKINUM (idx)));
  2432. }
  2433. /* struct-set!/immediate dst:8 idx:8 src:8
  2434. *
  2435. * Store SRC into the struct DST at slot IDX. IDX is an immediate
  2436. * unsigned 8-bit value.
  2437. */
  2438. VM_DEFINE_OP (112, struct_set_immediate, "struct-set!/immediate", OP1 (X8_S8_C8_S8))
  2439. {
  2440. scm_t_uint8 dst, idx, src;
  2441. SCM obj, val;
  2442. UNPACK_8_8_8 (op, dst, idx, src);
  2443. obj = SP_REF (dst);
  2444. val = SP_REF (src);
  2445. if (SCM_LIKELY (SCM_STRUCTP (obj)
  2446. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2447. SCM_VTABLE_FLAG_SIMPLE)
  2448. && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj,
  2449. SCM_VTABLE_FLAG_SIMPLE_RW)
  2450. && idx < SCM_STRUCT_DATA_REF (SCM_STRUCT_VTABLE (obj),
  2451. scm_vtable_index_size)))
  2452. {
  2453. SCM_STRUCT_SLOT_SET (obj, idx, val);
  2454. NEXT (1);
  2455. }
  2456. SYNC_IP ();
  2457. scm_struct_set_x (obj, SCM_I_MAKINUM (idx), val);
  2458. NEXT (1);
  2459. }
  2460. /* class-of dst:12 type:12
  2461. *
  2462. * Store the vtable of SRC into DST.
  2463. */
  2464. VM_DEFINE_OP (113, class_of, "class-of", OP1 (X8_S12_S12) | OP_DST)
  2465. {
  2466. ARGS1 (obj);
  2467. if (SCM_INSTANCEP (obj))
  2468. RETURN (SCM_CLASS_OF (obj));
  2469. SYNC_IP ();
  2470. RETURN (scm_class_of (obj));
  2471. }
  2472. /*
  2473. * Arrays, packed uniform arrays, and bytevectors.
  2474. */
  2475. /* load-typed-array dst:24 _:8 type:24 _:8 shape:24 offset:32 len:32
  2476. *
  2477. * Load the contiguous typed array located at OFFSET 32-bit words away
  2478. * from the instruction pointer, and store into DST. LEN is a byte
  2479. * length. OFFSET is signed.
  2480. */
  2481. VM_DEFINE_OP (114, load_typed_array, "load-typed-array", OP5 (X8_S24, X8_S24, X8_S24, N32, C32) | OP_DST)
  2482. {
  2483. scm_t_uint32 dst, type, shape;
  2484. scm_t_int32 offset;
  2485. scm_t_uint32 len;
  2486. UNPACK_24 (op, dst);
  2487. UNPACK_24 (ip[1], type);
  2488. UNPACK_24 (ip[2], shape);
  2489. offset = ip[3];
  2490. len = ip[4];
  2491. SYNC_IP ();
  2492. SP_SET (dst, scm_from_contiguous_typed_array (SP_REF (type),
  2493. SP_REF (shape),
  2494. ip + offset, len));
  2495. NEXT (5);
  2496. }
  2497. /* make-array dst:24 _:8 type:24 _:8 fill:24 _:8 bounds:24
  2498. *
  2499. * Make a new array with TYPE, FILL, and BOUNDS, storing it in DST.
  2500. */
  2501. VM_DEFINE_OP (115, make_array, "make-array", OP4 (X8_S24, X8_S24, X8_S24, X8_S24) | OP_DST)
  2502. {
  2503. scm_t_uint32 dst, type, fill, bounds;
  2504. UNPACK_24 (op, dst);
  2505. UNPACK_24 (ip[1], type);
  2506. UNPACK_24 (ip[2], fill);
  2507. UNPACK_24 (ip[3], bounds);
  2508. SYNC_IP ();
  2509. SP_SET (dst, scm_make_typed_array (SP_REF (type), SP_REF (fill),
  2510. SP_REF (bounds)));
  2511. NEXT (4);
  2512. }
  2513. /* bv-u8-ref dst:8 src:8 idx:8
  2514. * bv-s8-ref dst:8 src:8 idx:8
  2515. * bv-u16-ref dst:8 src:8 idx:8
  2516. * bv-s16-ref dst:8 src:8 idx:8
  2517. * bv-u32-ref dst:8 src:8 idx:8
  2518. * bv-s32-ref dst:8 src:8 idx:8
  2519. * bv-u64-ref dst:8 src:8 idx:8
  2520. * bv-s64-ref dst:8 src:8 idx:8
  2521. * bv-f32-ref dst:8 src:8 idx:8
  2522. * bv-f64-ref dst:8 src:8 idx:8
  2523. *
  2524. * Fetch the item at byte offset IDX in the bytevector SRC, and store
  2525. * it in DST. All accesses use native endianness.
  2526. */
  2527. #define BV_FIXABLE_INT_REF(stem, fn_stem, type, size) \
  2528. do { \
  2529. scm_t_signed_bits i; \
  2530. const scm_t_ ## type *int_ptr; \
  2531. ARGS2 (bv, idx); \
  2532. \
  2533. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
  2534. i = SCM_I_INUM (idx); \
  2535. int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2536. \
  2537. if (SCM_LIKELY (SCM_I_INUMP (idx) \
  2538. && (i >= 0) \
  2539. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2540. && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
  2541. RETURN (SCM_I_MAKINUM (*int_ptr)); \
  2542. else \
  2543. { \
  2544. SYNC_IP (); \
  2545. RETURN (scm_bytevector_ ## fn_stem ## _ref (bv, idx)); \
  2546. } \
  2547. } while (0)
  2548. #define BV_INT_REF(stem, type, size) \
  2549. do { \
  2550. scm_t_signed_bits i; \
  2551. const scm_t_ ## type *int_ptr; \
  2552. ARGS2 (bv, idx); \
  2553. \
  2554. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
  2555. i = SCM_I_INUM (idx); \
  2556. int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2557. \
  2558. if (SCM_LIKELY (SCM_I_INUMP (idx) \
  2559. && (i >= 0) \
  2560. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2561. && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
  2562. { \
  2563. scm_t_ ## type x = *int_ptr; \
  2564. if (SCM_FIXABLE (x)) \
  2565. RETURN (SCM_I_MAKINUM (x)); \
  2566. else \
  2567. { \
  2568. SYNC_IP (); \
  2569. RETURN (scm_from_ ## type (x)); \
  2570. } \
  2571. } \
  2572. else \
  2573. { \
  2574. SYNC_IP (); \
  2575. RETURN (scm_bytevector_ ## stem ## _native_ref (bv, idx)); \
  2576. } \
  2577. } while (0)
  2578. #define BV_FLOAT_REF(stem, fn_stem, type, size) \
  2579. do { \
  2580. scm_t_signed_bits i; \
  2581. const type *float_ptr; \
  2582. ARGS2 (bv, idx); \
  2583. \
  2584. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
  2585. i = SCM_I_INUM (idx); \
  2586. float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2587. \
  2588. SYNC_IP (); \
  2589. if (SCM_LIKELY (SCM_I_INUMP (idx) \
  2590. && (i >= 0) \
  2591. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2592. && (ALIGNED_P (float_ptr, type)))) \
  2593. RETURN (scm_from_double (*float_ptr)); \
  2594. else \
  2595. RETURN (scm_bytevector_ ## fn_stem ## _native_ref (bv, idx)); \
  2596. } while (0)
  2597. VM_DEFINE_OP (116, bv_u8_ref, "bv-u8-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2598. BV_FIXABLE_INT_REF (u8, u8, uint8, 1);
  2599. VM_DEFINE_OP (117, bv_s8_ref, "bv-s8-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2600. BV_FIXABLE_INT_REF (s8, s8, int8, 1);
  2601. VM_DEFINE_OP (118, bv_u16_ref, "bv-u16-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2602. BV_FIXABLE_INT_REF (u16, u16_native, uint16, 2);
  2603. VM_DEFINE_OP (119, bv_s16_ref, "bv-s16-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2604. BV_FIXABLE_INT_REF (s16, s16_native, int16, 2);
  2605. VM_DEFINE_OP (120, bv_u32_ref, "bv-u32-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2606. #if SIZEOF_VOID_P > 4
  2607. BV_FIXABLE_INT_REF (u32, u32_native, uint32, 4);
  2608. #else
  2609. BV_INT_REF (u32, uint32, 4);
  2610. #endif
  2611. VM_DEFINE_OP (121, bv_s32_ref, "bv-s32-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2612. #if SIZEOF_VOID_P > 4
  2613. BV_FIXABLE_INT_REF (s32, s32_native, int32, 4);
  2614. #else
  2615. BV_INT_REF (s32, int32, 4);
  2616. #endif
  2617. VM_DEFINE_OP (122, bv_u64_ref, "bv-u64-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2618. BV_INT_REF (u64, uint64, 8);
  2619. VM_DEFINE_OP (123, bv_s64_ref, "bv-s64-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2620. BV_INT_REF (s64, int64, 8);
  2621. VM_DEFINE_OP (124, bv_f32_ref, "bv-f32-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2622. BV_FLOAT_REF (f32, ieee_single, float, 4);
  2623. VM_DEFINE_OP (125, bv_f64_ref, "bv-f64-ref", OP1 (X8_S8_S8_S8) | OP_DST)
  2624. BV_FLOAT_REF (f64, ieee_double, double, 8);
  2625. /* bv-u8-set! dst:8 idx:8 src:8
  2626. * bv-s8-set! dst:8 idx:8 src:8
  2627. * bv-u16-set! dst:8 idx:8 src:8
  2628. * bv-s16-set! dst:8 idx:8 src:8
  2629. * bv-u32-set! dst:8 idx:8 src:8
  2630. * bv-s32-set! dst:8 idx:8 src:8
  2631. * bv-u64-set! dst:8 idx:8 src:8
  2632. * bv-s64-set! dst:8 idx:8 src:8
  2633. * bv-f32-set! dst:8 idx:8 src:8
  2634. * bv-f64-set! dst:8 idx:8 src:8
  2635. *
  2636. * Store SRC into the bytevector DST at byte offset IDX. Multibyte
  2637. * values are written using native endianness.
  2638. */
  2639. #define BV_FIXABLE_INT_SET(stem, fn_stem, type, min, max, size) \
  2640. do { \
  2641. scm_t_uint8 dst, idx, src; \
  2642. scm_t_signed_bits i, j = 0; \
  2643. SCM bv, scm_idx, val; \
  2644. scm_t_ ## type *int_ptr; \
  2645. \
  2646. UNPACK_8_8_8 (op, dst, idx, src); \
  2647. bv = SP_REF (dst); \
  2648. scm_idx = SP_REF (idx); \
  2649. val = SP_REF (src); \
  2650. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set!"); \
  2651. i = SCM_I_INUM (scm_idx); \
  2652. int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2653. \
  2654. if (SCM_LIKELY (SCM_I_INUMP (scm_idx) \
  2655. && (i >= 0) \
  2656. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2657. && (ALIGNED_P (int_ptr, scm_t_ ## type)) \
  2658. && (SCM_I_INUMP (val)) \
  2659. && ((j = SCM_I_INUM (val)) >= min) \
  2660. && (j <= max))) \
  2661. *int_ptr = (scm_t_ ## type) j; \
  2662. else \
  2663. { \
  2664. SYNC_IP (); \
  2665. scm_bytevector_ ## fn_stem ## _set_x (bv, scm_idx, val); \
  2666. } \
  2667. NEXT (1); \
  2668. } while (0)
  2669. #define BV_INT_SET(stem, type, size) \
  2670. do { \
  2671. scm_t_uint8 dst, idx, src; \
  2672. scm_t_signed_bits i; \
  2673. SCM bv, scm_idx, val; \
  2674. scm_t_ ## type *int_ptr; \
  2675. \
  2676. UNPACK_8_8_8 (op, dst, idx, src); \
  2677. bv = SP_REF (dst); \
  2678. scm_idx = SP_REF (idx); \
  2679. val = SP_REF (src); \
  2680. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set!"); \
  2681. i = SCM_I_INUM (scm_idx); \
  2682. int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2683. \
  2684. if (SCM_LIKELY (SCM_I_INUMP (scm_idx) \
  2685. && (i >= 0) \
  2686. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2687. && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
  2688. *int_ptr = scm_to_ ## type (val); \
  2689. else \
  2690. { \
  2691. SYNC_IP (); \
  2692. scm_bytevector_ ## stem ## _native_set_x (bv, scm_idx, val); \
  2693. } \
  2694. NEXT (1); \
  2695. } while (0)
  2696. #define BV_FLOAT_SET(stem, fn_stem, type, size) \
  2697. do { \
  2698. scm_t_uint8 dst, idx, src; \
  2699. scm_t_signed_bits i; \
  2700. SCM bv, scm_idx, val; \
  2701. type *float_ptr; \
  2702. \
  2703. UNPACK_8_8_8 (op, dst, idx, src); \
  2704. bv = SP_REF (dst); \
  2705. scm_idx = SP_REF (idx); \
  2706. val = SP_REF (src); \
  2707. VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set!"); \
  2708. i = SCM_I_INUM (scm_idx); \
  2709. float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
  2710. \
  2711. if (SCM_LIKELY (SCM_I_INUMP (scm_idx) \
  2712. && (i >= 0) \
  2713. && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
  2714. && (ALIGNED_P (float_ptr, type)))) \
  2715. *float_ptr = scm_to_double (val); \
  2716. else \
  2717. { \
  2718. SYNC_IP (); \
  2719. scm_bytevector_ ## fn_stem ## _native_set_x (bv, scm_idx, val); \
  2720. } \
  2721. NEXT (1); \
  2722. } while (0)
  2723. VM_DEFINE_OP (126, bv_u8_set, "bv-u8-set!", OP1 (X8_S8_S8_S8))
  2724. BV_FIXABLE_INT_SET (u8, u8, uint8, 0, SCM_T_UINT8_MAX, 1);
  2725. VM_DEFINE_OP (127, bv_s8_set, "bv-s8-set!", OP1 (X8_S8_S8_S8))
  2726. BV_FIXABLE_INT_SET (s8, s8, int8, SCM_T_INT8_MIN, SCM_T_INT8_MAX, 1);
  2727. VM_DEFINE_OP (128, bv_u16_set, "bv-u16-set!", OP1 (X8_S8_S8_S8))
  2728. BV_FIXABLE_INT_SET (u16, u16_native, uint16, 0, SCM_T_UINT16_MAX, 2);
  2729. VM_DEFINE_OP (129, bv_s16_set, "bv-s16-set!", OP1 (X8_S8_S8_S8))
  2730. BV_FIXABLE_INT_SET (s16, s16_native, int16, SCM_T_INT16_MIN, SCM_T_INT16_MAX, 2);
  2731. VM_DEFINE_OP (130, bv_u32_set, "bv-u32-set!", OP1 (X8_S8_S8_S8))
  2732. #if SIZEOF_VOID_P > 4
  2733. BV_FIXABLE_INT_SET (u32, u32_native, uint32, 0, SCM_T_UINT32_MAX, 4);
  2734. #else
  2735. BV_INT_SET (u32, uint32, 4);
  2736. #endif
  2737. VM_DEFINE_OP (131, bv_s32_set, "bv-s32-set!", OP1 (X8_S8_S8_S8))
  2738. #if SIZEOF_VOID_P > 4
  2739. BV_FIXABLE_INT_SET (s32, s32_native, int32, SCM_T_INT32_MIN, SCM_T_INT32_MAX, 4);
  2740. #else
  2741. BV_INT_SET (s32, int32, 4);
  2742. #endif
  2743. VM_DEFINE_OP (132, bv_u64_set, "bv-u64-set!", OP1 (X8_S8_S8_S8))
  2744. BV_INT_SET (u64, uint64, 8);
  2745. VM_DEFINE_OP (133, bv_s64_set, "bv-s64-set!", OP1 (X8_S8_S8_S8))
  2746. BV_INT_SET (s64, int64, 8);
  2747. VM_DEFINE_OP (134, bv_f32_set, "bv-f32-set!", OP1 (X8_S8_S8_S8))
  2748. BV_FLOAT_SET (f32, ieee_single, float, 4);
  2749. VM_DEFINE_OP (135, bv_f64_set, "bv-f64-set!", OP1 (X8_S8_S8_S8))
  2750. BV_FLOAT_SET (f64, ieee_double, double, 8);
  2751. VM_DEFINE_OP (136, unused_136, NULL, NOP)
  2752. VM_DEFINE_OP (137, unused_137, NULL, NOP)
  2753. VM_DEFINE_OP (138, unused_138, NULL, NOP)
  2754. VM_DEFINE_OP (139, unused_139, NULL, NOP)
  2755. VM_DEFINE_OP (140, unused_140, NULL, NOP)
  2756. VM_DEFINE_OP (141, unused_141, NULL, NOP)
  2757. VM_DEFINE_OP (142, unused_142, NULL, NOP)
  2758. VM_DEFINE_OP (143, unused_143, NULL, NOP)
  2759. VM_DEFINE_OP (144, unused_144, NULL, NOP)
  2760. VM_DEFINE_OP (145, unused_145, NULL, NOP)
  2761. VM_DEFINE_OP (146, unused_146, NULL, NOP)
  2762. VM_DEFINE_OP (147, unused_147, NULL, NOP)
  2763. VM_DEFINE_OP (148, unused_148, NULL, NOP)
  2764. VM_DEFINE_OP (149, unused_149, NULL, NOP)
  2765. VM_DEFINE_OP (150, unused_150, NULL, NOP)
  2766. VM_DEFINE_OP (151, unused_151, NULL, NOP)
  2767. VM_DEFINE_OP (152, unused_152, NULL, NOP)
  2768. VM_DEFINE_OP (153, unused_153, NULL, NOP)
  2769. VM_DEFINE_OP (154, unused_154, NULL, NOP)
  2770. VM_DEFINE_OP (155, unused_155, NULL, NOP)
  2771. VM_DEFINE_OP (156, unused_156, NULL, NOP)
  2772. VM_DEFINE_OP (157, unused_157, NULL, NOP)
  2773. VM_DEFINE_OP (158, unused_158, NULL, NOP)
  2774. VM_DEFINE_OP (159, unused_159, NULL, NOP)
  2775. VM_DEFINE_OP (160, unused_160, NULL, NOP)
  2776. VM_DEFINE_OP (161, unused_161, NULL, NOP)
  2777. VM_DEFINE_OP (162, unused_162, NULL, NOP)
  2778. VM_DEFINE_OP (163, unused_163, NULL, NOP)
  2779. VM_DEFINE_OP (164, unused_164, NULL, NOP)
  2780. VM_DEFINE_OP (165, unused_165, NULL, NOP)
  2781. VM_DEFINE_OP (166, unused_166, NULL, NOP)
  2782. VM_DEFINE_OP (167, unused_167, NULL, NOP)
  2783. VM_DEFINE_OP (168, unused_168, NULL, NOP)
  2784. VM_DEFINE_OP (169, unused_169, NULL, NOP)
  2785. VM_DEFINE_OP (170, unused_170, NULL, NOP)
  2786. VM_DEFINE_OP (171, unused_171, NULL, NOP)
  2787. VM_DEFINE_OP (172, unused_172, NULL, NOP)
  2788. VM_DEFINE_OP (173, unused_173, NULL, NOP)
  2789. VM_DEFINE_OP (174, unused_174, NULL, NOP)
  2790. VM_DEFINE_OP (175, unused_175, NULL, NOP)
  2791. VM_DEFINE_OP (176, unused_176, NULL, NOP)
  2792. VM_DEFINE_OP (177, unused_177, NULL, NOP)
  2793. VM_DEFINE_OP (178, unused_178, NULL, NOP)
  2794. VM_DEFINE_OP (179, unused_179, NULL, NOP)
  2795. VM_DEFINE_OP (180, unused_180, NULL, NOP)
  2796. VM_DEFINE_OP (181, unused_181, NULL, NOP)
  2797. VM_DEFINE_OP (182, unused_182, NULL, NOP)
  2798. VM_DEFINE_OP (183, unused_183, NULL, NOP)
  2799. VM_DEFINE_OP (184, unused_184, NULL, NOP)
  2800. VM_DEFINE_OP (185, unused_185, NULL, NOP)
  2801. VM_DEFINE_OP (186, unused_186, NULL, NOP)
  2802. VM_DEFINE_OP (187, unused_187, NULL, NOP)
  2803. VM_DEFINE_OP (188, unused_188, NULL, NOP)
  2804. VM_DEFINE_OP (189, unused_189, NULL, NOP)
  2805. VM_DEFINE_OP (190, unused_190, NULL, NOP)
  2806. VM_DEFINE_OP (191, unused_191, NULL, NOP)
  2807. VM_DEFINE_OP (192, unused_192, NULL, NOP)
  2808. VM_DEFINE_OP (193, unused_193, NULL, NOP)
  2809. VM_DEFINE_OP (194, unused_194, NULL, NOP)
  2810. VM_DEFINE_OP (195, unused_195, NULL, NOP)
  2811. VM_DEFINE_OP (196, unused_196, NULL, NOP)
  2812. VM_DEFINE_OP (197, unused_197, NULL, NOP)
  2813. VM_DEFINE_OP (198, unused_198, NULL, NOP)
  2814. VM_DEFINE_OP (199, unused_199, NULL, NOP)
  2815. VM_DEFINE_OP (200, unused_200, NULL, NOP)
  2816. VM_DEFINE_OP (201, unused_201, NULL, NOP)
  2817. VM_DEFINE_OP (202, unused_202, NULL, NOP)
  2818. VM_DEFINE_OP (203, unused_203, NULL, NOP)
  2819. VM_DEFINE_OP (204, unused_204, NULL, NOP)
  2820. VM_DEFINE_OP (205, unused_205, NULL, NOP)
  2821. VM_DEFINE_OP (206, unused_206, NULL, NOP)
  2822. VM_DEFINE_OP (207, unused_207, NULL, NOP)
  2823. VM_DEFINE_OP (208, unused_208, NULL, NOP)
  2824. VM_DEFINE_OP (209, unused_209, NULL, NOP)
  2825. VM_DEFINE_OP (210, unused_210, NULL, NOP)
  2826. VM_DEFINE_OP (211, unused_211, NULL, NOP)
  2827. VM_DEFINE_OP (212, unused_212, NULL, NOP)
  2828. VM_DEFINE_OP (213, unused_213, NULL, NOP)
  2829. VM_DEFINE_OP (214, unused_214, NULL, NOP)
  2830. VM_DEFINE_OP (215, unused_215, NULL, NOP)
  2831. VM_DEFINE_OP (216, unused_216, NULL, NOP)
  2832. VM_DEFINE_OP (217, unused_217, NULL, NOP)
  2833. VM_DEFINE_OP (218, unused_218, NULL, NOP)
  2834. VM_DEFINE_OP (219, unused_219, NULL, NOP)
  2835. VM_DEFINE_OP (220, unused_220, NULL, NOP)
  2836. VM_DEFINE_OP (221, unused_221, NULL, NOP)
  2837. VM_DEFINE_OP (222, unused_222, NULL, NOP)
  2838. VM_DEFINE_OP (223, unused_223, NULL, NOP)
  2839. VM_DEFINE_OP (224, unused_224, NULL, NOP)
  2840. VM_DEFINE_OP (225, unused_225, NULL, NOP)
  2841. VM_DEFINE_OP (226, unused_226, NULL, NOP)
  2842. VM_DEFINE_OP (227, unused_227, NULL, NOP)
  2843. VM_DEFINE_OP (228, unused_228, NULL, NOP)
  2844. VM_DEFINE_OP (229, unused_229, NULL, NOP)
  2845. VM_DEFINE_OP (230, unused_230, NULL, NOP)
  2846. VM_DEFINE_OP (231, unused_231, NULL, NOP)
  2847. VM_DEFINE_OP (232, unused_232, NULL, NOP)
  2848. VM_DEFINE_OP (233, unused_233, NULL, NOP)
  2849. VM_DEFINE_OP (234, unused_234, NULL, NOP)
  2850. VM_DEFINE_OP (235, unused_235, NULL, NOP)
  2851. VM_DEFINE_OP (236, unused_236, NULL, NOP)
  2852. VM_DEFINE_OP (237, unused_237, NULL, NOP)
  2853. VM_DEFINE_OP (238, unused_238, NULL, NOP)
  2854. VM_DEFINE_OP (239, unused_239, NULL, NOP)
  2855. VM_DEFINE_OP (240, unused_240, NULL, NOP)
  2856. VM_DEFINE_OP (241, unused_241, NULL, NOP)
  2857. VM_DEFINE_OP (242, unused_242, NULL, NOP)
  2858. VM_DEFINE_OP (243, unused_243, NULL, NOP)
  2859. VM_DEFINE_OP (244, unused_244, NULL, NOP)
  2860. VM_DEFINE_OP (245, unused_245, NULL, NOP)
  2861. VM_DEFINE_OP (246, unused_246, NULL, NOP)
  2862. VM_DEFINE_OP (247, unused_247, NULL, NOP)
  2863. VM_DEFINE_OP (248, unused_248, NULL, NOP)
  2864. VM_DEFINE_OP (249, unused_249, NULL, NOP)
  2865. VM_DEFINE_OP (250, unused_250, NULL, NOP)
  2866. VM_DEFINE_OP (251, unused_251, NULL, NOP)
  2867. VM_DEFINE_OP (252, unused_252, NULL, NOP)
  2868. VM_DEFINE_OP (253, unused_253, NULL, NOP)
  2869. VM_DEFINE_OP (254, unused_254, NULL, NOP)
  2870. VM_DEFINE_OP (255, unused_255, NULL, NOP)
  2871. {
  2872. vm_error_bad_instruction (op);
  2873. abort (); /* never reached */
  2874. }
  2875. END_DISPATCH_SWITCH;
  2876. }
  2877. #undef ABORT_CONTINUATION_HOOK
  2878. #undef ALIGNED_P
  2879. #undef APPLY_HOOK
  2880. #undef ARGS1
  2881. #undef ARGS2
  2882. #undef BEGIN_DISPATCH_SWITCH
  2883. #undef BINARY_INTEGER_OP
  2884. #undef BR_ARITHMETIC
  2885. #undef BR_BINARY
  2886. #undef BR_NARGS
  2887. #undef BR_UNARY
  2888. #undef BV_FIXABLE_INT_REF
  2889. #undef BV_FIXABLE_INT_SET
  2890. #undef BV_FLOAT_REF
  2891. #undef BV_FLOAT_SET
  2892. #undef BV_INT_REF
  2893. #undef BV_INT_SET
  2894. #undef CACHE_REGISTER
  2895. #undef END_DISPATCH_SWITCH
  2896. #undef FREE_VARIABLE_REF
  2897. #undef INIT
  2898. #undef INUM_MAX
  2899. #undef INUM_MIN
  2900. #undef FP_REF
  2901. #undef FP_SET
  2902. #undef FP_SLOT
  2903. #undef SP_REF
  2904. #undef SP_SET
  2905. #undef NEXT
  2906. #undef NEXT_HOOK
  2907. #undef NEXT_JUMP
  2908. #undef POP_CONTINUATION_HOOK
  2909. #undef PUSH_CONTINUATION_HOOK
  2910. #undef RETURN
  2911. #undef RETURN_ONE_VALUE
  2912. #undef RETURN_VALUE_LIST
  2913. #undef RUN_HOOK
  2914. #undef RUN_HOOK0
  2915. #undef RUN_HOOK1
  2916. #undef SYNC_IP
  2917. #undef UNPACK_8_8_8
  2918. #undef UNPACK_8_16
  2919. #undef UNPACK_16_8
  2920. #undef UNPACK_12_12
  2921. #undef UNPACK_24
  2922. #undef VARIABLE_BOUNDP
  2923. #undef VARIABLE_REF
  2924. #undef VARIABLE_SET
  2925. #undef VM_CHECK_FREE_VARIABLE
  2926. #undef VM_CHECK_OBJECT
  2927. #undef VM_CHECK_UNDERFLOW
  2928. #undef VM_DEFINE_OP
  2929. #undef VM_INSTRUCTION_TO_LABEL
  2930. #undef VM_USE_HOOKS
  2931. #undef VM_VALIDATE_BYTEVECTOR
  2932. #undef VM_VALIDATE_PAIR
  2933. #undef VM_VALIDATE_STRUCT
  2934. /*
  2935. (defun renumber-ops ()
  2936. "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
  2937. (interactive "")
  2938. (save-excursion
  2939. (let ((counter -1)) (goto-char (point-min))
  2940. (while (re-search-forward "^ *VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
  2941. (replace-match
  2942. (number-to-string (setq counter (1+ counter)))
  2943. t t nil 1)))))
  2944. (renumber-ops)
  2945. */
  2946. /*
  2947. Local Variables:
  2948. c-file-style: "gnu"
  2949. End:
  2950. */