bytes1.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638
  1. /*
  2. * bytes1.c Copyright (C) 1991-2002, Codemist Ltd
  3. *
  4. *
  5. * Bytecode interpreter for Lisp
  6. */
  7. /*
  8. * This code may be used and modified, and redistributed in binary
  9. * or source form, subject to the "CCL Public License", which should
  10. * accompany it. This license is a variant on the BSD license, and thus
  11. * permits use of code derived from this in either open and commercial
  12. * projects: but it does require that updates to this code be made
  13. * available back to the originators of the package.
  14. * Before merging other code in with this or linking this code
  15. * with other packages or libraries please check that the license terms
  16. * of the other material are compatible with those of this.
  17. */
  18. /* Signature: 6aaf56de 10-Oct-2002 */
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #ifdef __WATCOMC__
  23. #include <float.h>
  24. #endif
  25. #include "machine.h"
  26. #include "tags.h"
  27. #include "cslerror.h"
  28. #include "externs.h"
  29. #include "arith.h"
  30. #include "entries.h"
  31. #ifdef TIMEOUT
  32. #include "timeout.h"
  33. #endif
  34. #if defined DEMO_MODE || defined DEMO_BUILD
  35. #include "demobyte.h" /* Alternate bytecode mapping used by demo version */
  36. #else
  37. #include "bytes.h"
  38. #endif
  39. #include "entries.h"
  40. /*
  41. * I put all the code that handles property lists in this file since then
  42. * I can arrange that the option that allows me to count the number of byte
  43. * opcodes that are executed also lets me collect statistics on which
  44. * indicators are most heavily used with PUT and GET.
  45. */
  46. #ifdef RECORD_GET
  47. void record_get(Lisp_Object tag, CSLbool found)
  48. {
  49. Lisp_Object nil = C_nil;
  50. Lisp_Object w;
  51. push(tag);
  52. w = Lget_hash_2(nil, tag, get_counts);
  53. pop(tag);
  54. errexitv();
  55. if (w == nil)
  56. { w = cons_no_gc(fixnum_of_int(0), fixnum_of_int(0));
  57. push(w);
  58. Lput_hash(nil, 3, tag, get_counts, w);
  59. pop(w);
  60. errexitv();
  61. }
  62. if (found) qcar(w) += 0x10;
  63. else qcdr(w) += 0x10;
  64. }
  65. #endif
  66. /*
  67. * Here is a short essay on the interaction between flags and properties.
  68. * It is written because the issue appears to be delicate, especially in the
  69. * face of a scheme that I use to speed things up.
  70. * (a) If you use FLAG, REMFLAG and FLAGP with some indicator then that
  71. * indicator is known as a flag.
  72. * (b) If you use PUT, REMPROP and GET with an indicator then what you
  73. * have is a property.
  74. * (c) Providing the names of flags and properties are disjoint no difficulty
  75. * whatever should arise.
  76. * (d) If you use PLIST to gain direct access to a property list then flags
  77. * are visible as pairs (tag . t) and properties as (tag . value).
  78. * (e) Using RPLACx operations on the result of PLIST may cause system
  79. * damage. It is to be considered illegal. Also changes made that
  80. * way may not be matched in any accelerating caches that I keep.
  81. * (f) After (FLAG '(id) 'tag) [when id did not previously have any flags
  82. * or properties] a call (GET 'id 'tag) will return t.
  83. * (g) After (PUT 'id 'tag 'anything) a call (FLAGP 'id 'tag) will return t
  84. * whatever the value of "anything". A call (GET 'id 'tag) will return
  85. * the saved value (which might be nil). Thus FLAGP can be thought of
  86. * as a function that tests if a given property is attached to a
  87. * symbol.
  88. * (h) As a consequence of (g) REMPROP and REMFLAG are really the same
  89. * operation.
  90. */
  91. #ifndef COMMON
  92. Lisp_Object get(Lisp_Object a, Lisp_Object b)
  93. {
  94. Lisp_Object pl, prev, w, nil = C_nil;
  95. int n;
  96. /*
  97. * In CSL mode plists are structured like association lists, and
  98. * NOT as lists with alternate tags and values. There is also
  99. * a bitmap that can provide a fast test for the presence of a
  100. * property...
  101. */
  102. if (!symbolp(a))
  103. {
  104. #ifdef RECORD_GET
  105. record_get(b, NO);
  106. errexit();
  107. #endif
  108. return onevalue(nil);
  109. }
  110. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  111. { if ((w = qfastgets(a)) == nil)
  112. {
  113. #ifdef RECORD_GET
  114. record_get(b, NO);
  115. errexit();
  116. #endif
  117. return onevalue(nil);
  118. }
  119. w = elt(w, n-1);
  120. if (w == SPID_NOPROP) w = nil;
  121. #ifdef RECORD_GET
  122. push(w);
  123. record_get(b, w != nil);
  124. pop(w);
  125. errexit();
  126. #endif
  127. return onevalue(w);
  128. }
  129. pl = qplist(a);
  130. if (pl == nil)
  131. {
  132. #ifdef RECORD_GET
  133. record_get(b, NO);
  134. errexit();
  135. #endif
  136. return onevalue(nil);
  137. }
  138. w = qcar(pl);
  139. if (qcar(w) == b)
  140. {
  141. #ifdef RECORD_GET
  142. push(w);
  143. record_get(b, YES);
  144. pop(w);
  145. errexit();
  146. #endif
  147. return onevalue(qcdr(w));
  148. }
  149. pl = qcdr(pl);
  150. if (pl == nil)
  151. {
  152. #ifdef RECORD_GET
  153. record_get(b, NO);
  154. errexit();
  155. #endif
  156. return onevalue(nil);
  157. }
  158. w = qcar(pl);
  159. if (qcar(w) == b)
  160. {
  161. #ifdef RECORD_GET
  162. push(w);
  163. record_get(b, YES);
  164. pop(w);
  165. errexit();
  166. #endif
  167. return onevalue(qcdr(w));
  168. }
  169. prev = pl;
  170. pl = qcdr(pl);
  171. if (pl == prev) return aerror("looped up plist in get");
  172. if (pl == nil)
  173. {
  174. #ifdef RECORD_GET
  175. record_get(b, NO);
  176. errexit();
  177. #endif
  178. return onevalue(nil);
  179. }
  180. for (;;)
  181. { w = qcar(pl);
  182. /*
  183. * If I find the item anywhere beyond the first two places in the plist I
  184. * migrate it up to the front so that next time will be faster
  185. */
  186. if (qcar(w) == b)
  187. { qcdr(prev) = qcdr(pl);
  188. qcdr(pl) = qplist(a);
  189. qplist(a) = pl;
  190. #ifdef RECORD_GET
  191. push(w);
  192. record_get(b, YES);
  193. pop(w);
  194. errexit();
  195. #endif
  196. return onevalue(qcdr(w));
  197. }
  198. prev = pl;
  199. pl = qcdr(pl);
  200. if (pl == prev) return aerror("looped up plist in get");
  201. if (pl == nil)
  202. {
  203. #ifdef RECORD_GET
  204. record_get(b, NO);
  205. errexit();
  206. #endif
  207. return onevalue(nil);
  208. }
  209. }
  210. }
  211. Lisp_Object putprop(Lisp_Object a, Lisp_Object b, Lisp_Object c)
  212. {
  213. Lisp_Object nil = C_nil;
  214. Lisp_Object pl;
  215. int n;
  216. if (!symbolp(a)) return c;
  217. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  218. { pl = qfastgets(a);
  219. if (pl == nil)
  220. { push3(a, b, c);
  221. pl = getvector_init(CELL+CELL*fastget_size, SPID_NOPROP);
  222. pop3(c, b, a);
  223. errexit();
  224. qfastgets(a) = pl;
  225. }
  226. elt(pl, n-1) = c;
  227. return c; /* NB the property is NOT on the plist */
  228. }
  229. pl = qplist(a);
  230. while (pl != nil)
  231. { Lisp_Object w = qcar(pl);
  232. if (qcar(w) == b)
  233. { qcdr(w) = c;
  234. return c;
  235. }
  236. else pl = qcdr(pl);
  237. }
  238. stackcheck3(0, a, b, c);
  239. nil = C_nil;
  240. push2(a, c);
  241. b = acons(b, c, qplist(a));
  242. pop2(c, a);
  243. errexit();
  244. qplist(a) = b;
  245. return c;
  246. }
  247. static Lisp_Object remprop(Lisp_Object a, Lisp_Object b)
  248. {
  249. Lisp_Object pl, prevp;
  250. Lisp_Object nil = C_nil;
  251. int n;
  252. if (!symbolp(a)) return nil;
  253. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  254. { pl = qfastgets(a);
  255. if (pl != nil) elt(pl, n-1) = SPID_NOPROP;
  256. return nil;
  257. }
  258. prevp = nil;
  259. pl = qplist(a);
  260. while (pl != nil)
  261. { Lisp_Object w = qcar(pl);
  262. if (qcar(w) == b)
  263. { pl = qcdr(pl);
  264. if (prevp == nil) qplist(a) = pl;
  265. else qcdr(prevp) = pl;
  266. return qcdr(w);
  267. }
  268. prevp = pl;
  269. pl = qcdr(prevp);
  270. if (pl == prevp) return aerror("looped up plist in remprop");
  271. }
  272. return nil;
  273. }
  274. #else /* in a COMMON world I have to use flat plists */
  275. Lisp_Object get(Lisp_Object a, Lisp_Object b, Lisp_Object c)
  276. {
  277. Lisp_Object nil = C_nil;
  278. Lisp_Object pl;
  279. int n;
  280. if (!symbolp(a))
  281. {
  282. #ifdef RECORD_GET
  283. record_get(b, NO);
  284. errexit();
  285. #endif
  286. return c;
  287. }
  288. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  289. { if ((pl = qfastgets(a)) == nil)
  290. {
  291. #ifdef RECORD_GET
  292. push(c);
  293. record_get(b, NO);
  294. pop(c);
  295. errexit();
  296. #endif
  297. return onevalue(c);
  298. }
  299. pl = elt(pl, n-1);
  300. if (pl == SPID_NOPROP)
  301. {
  302. #ifdef RECORD_GET
  303. push(c);
  304. record_get(b, NO);
  305. pop(c);
  306. errexit();
  307. #endif
  308. return onevalue(c);
  309. }
  310. #ifdef RECORD_GET
  311. push(pl);
  312. record_get(b, YES);
  313. pop(pl);
  314. errexit();
  315. #endif
  316. return onevalue(pl);
  317. }
  318. pl = qplist(a);
  319. while (pl != nil)
  320. { if (qcar(pl) == b)
  321. {
  322. #ifdef RECORD_GET
  323. push(pl);
  324. record_get(b, YES);
  325. pop(pl);
  326. errexit();
  327. #endif
  328. return qcar(qcdr(pl));
  329. }
  330. else pl = qcdr(qcdr(pl));
  331. }
  332. #ifdef RECORD_GET
  333. record_get(b, NO);
  334. errexit();
  335. #endif
  336. return c;
  337. }
  338. Lisp_Object putprop(Lisp_Object a, Lisp_Object b, Lisp_Object c)
  339. {
  340. Lisp_Object nil = C_nil;
  341. Lisp_Object pl;
  342. int n;
  343. if (!symbolp(a)) return c;
  344. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  345. { pl = qfastgets(a);
  346. if (pl == nil)
  347. { push3(a, b, c);
  348. pl = getvector_init(CELL+CELL*fastget_size, SPID_NOPROP);
  349. pop3(c, b, a);
  350. errexit();
  351. qfastgets(a) = pl;
  352. }
  353. elt(pl, n-1) = c;
  354. return c; /* NB the property in NOT on the plist */
  355. }
  356. pl = qplist(a);
  357. while (pl != nil)
  358. { if (qcar(pl) == b)
  359. { pl = qcdr(pl);
  360. qcar(pl) = c;
  361. return c;
  362. }
  363. else pl = qcdr(qcdr(pl));
  364. }
  365. stackcheck3(0, a, b, c);
  366. nil = C_nil;
  367. push2(a, c);
  368. b = list2star(b, c, qplist(a));
  369. pop2(c, a);
  370. errexit();
  371. qplist(a) = b;
  372. return c;
  373. }
  374. static Lisp_Object remprop(Lisp_Object a, Lisp_Object b)
  375. {
  376. Lisp_Object nil = C_nil;
  377. Lisp_Object pl, prevp = nil;
  378. int n;
  379. if (!symbolp(a)) return nil;
  380. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  381. { pl = qfastgets(a);
  382. if (pl != nil) elt(pl, n-1) = SPID_NOPROP;
  383. return nil;
  384. }
  385. pl = qplist(a);
  386. while (pl != nil)
  387. { if (qcar(pl) == b)
  388. { Lisp_Object v = qcdr(pl);
  389. pl = qcdr(v);
  390. if (prevp == nil) qplist(a) = pl;
  391. else qcdr(prevp) = pl;
  392. return lisp_true;
  393. }
  394. prevp = qcdr(pl);
  395. pl = qcdr(prevp);
  396. if (pl == prevp) return aerror("looped up plist in remprop (1)");
  397. }
  398. return nil;
  399. }
  400. #endif /* end of property list stuff */
  401. #ifndef COMMON
  402. Lisp_Object Lget(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  403. {
  404. Lisp_Object pl, prev, w;
  405. int n;
  406. /*
  407. * In CSL mode plists are structured like association lists, and
  408. * NOT as lists with alternate tags and values. There is also
  409. * a bitmap that can provide a fast test for the presence of a
  410. * property...
  411. */
  412. if (!symbolp(a))
  413. {
  414. #ifdef RECORD_GET
  415. record_get(b, NO);
  416. errexit();
  417. #endif
  418. return onevalue(nil);
  419. }
  420. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  421. { if ((w = qfastgets(a)) == nil)
  422. {
  423. #ifdef RECORD_GET
  424. record_get(b, NO);
  425. errexit();
  426. #endif
  427. return onevalue(nil);
  428. }
  429. w = elt(w, n-1);
  430. if (w == SPID_NOPROP) w = nil;
  431. #ifdef RECORD_GET
  432. push(w);
  433. record_get(b, w != nil);
  434. pop(w);
  435. errexit();
  436. #endif
  437. return onevalue(w);
  438. }
  439. pl = qplist(a);
  440. if (pl == nil)
  441. {
  442. #ifdef RECORD_GET
  443. record_get(b, NO);
  444. errexit();
  445. #endif
  446. return onevalue(nil);
  447. }
  448. w = qcar(pl);
  449. if (qcar(w) == b)
  450. {
  451. #ifdef RECORD_GET
  452. push(w);
  453. record_get(b, YES);
  454. pop(w);
  455. errexit();
  456. #endif
  457. return onevalue(qcdr(w));
  458. }
  459. pl = qcdr(pl);
  460. if (pl == nil)
  461. {
  462. #ifdef RECORD_GET
  463. record_get(b, NO);
  464. errexit();
  465. #endif
  466. return onevalue(nil);
  467. }
  468. w = qcar(pl);
  469. if (qcar(w) == b)
  470. {
  471. #ifdef RECORD_GET
  472. push(w);
  473. record_get(b, YES);
  474. pop(w);
  475. errexit();
  476. #endif
  477. return onevalue(qcdr(w));
  478. }
  479. prev = pl;
  480. pl = qcdr(pl);
  481. if (pl == prev) return aerror("looped up plist in Lget");
  482. if (pl == nil)
  483. {
  484. #ifdef RECORD_GET
  485. record_get(b, NO);
  486. errexit();
  487. #endif
  488. return onevalue(nil);
  489. }
  490. for (;;)
  491. { w = qcar(pl);
  492. /*
  493. * If I find the item anywhere beyond the first two places in the plist I
  494. * migrate it up to the front so that next time will be faster
  495. */
  496. if (qcar(w) == b)
  497. { qcdr(prev) = qcdr(pl);
  498. qcdr(pl) = qplist(a);
  499. qplist(a) = pl;
  500. #ifdef RECORD_GET
  501. push(w);
  502. record_get(b, YES);
  503. pop(w);
  504. errexit();
  505. #endif
  506. return onevalue(qcdr(w));
  507. }
  508. prev = pl;
  509. pl = qcdr(pl);
  510. if (pl == prev) return aerror("looped up plist in Lget");
  511. if (pl == nil)
  512. {
  513. #ifdef RECORD_GET
  514. record_get(b, NO);
  515. errexit();
  516. #endif
  517. return onevalue(nil);
  518. }
  519. }
  520. }
  521. #else
  522. Lisp_Object MS_CDECL Lget_3(Lisp_Object nil, int nargs, ...)
  523. {
  524. va_list aa;
  525. Lisp_Object a, b, c;
  526. CSL_IGNORE(nil);
  527. if (nargs != 3) return aerror("get");
  528. va_start(aa, nargs);
  529. a = va_arg(aa, Lisp_Object);
  530. b = va_arg(aa, Lisp_Object);
  531. c = va_arg(aa, Lisp_Object);
  532. va_end(aa);
  533. return onevalue(get(a, b, c));
  534. }
  535. Lisp_Object Lget(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  536. {
  537. return onevalue(get(a, b, nil));
  538. }
  539. #endif
  540. Lisp_Object MS_CDECL Lputprop(Lisp_Object nil, int nargs, ...)
  541. {
  542. va_list aa;
  543. Lisp_Object a, b, c;
  544. argcheck(nargs, 3, "put");
  545. CSL_IGNORE(nil);
  546. va_start(aa, nargs);
  547. a = va_arg(aa, Lisp_Object);
  548. b = va_arg(aa, Lisp_Object);
  549. c = va_arg(aa, Lisp_Object);
  550. va_end(aa);
  551. a = putprop(a, b, c);
  552. errexit();
  553. return onevalue(a);
  554. }
  555. #ifdef COMMON
  556. Lisp_Object Lflagp(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  557. {
  558. a = get(a, b, unset_var);
  559. errexit();
  560. return onevalue(a == unset_var ? nil : lisp_true);
  561. }
  562. Lisp_Object Lflagpcar(Lisp_Object nil,
  563. Lisp_Object a, Lisp_Object b)
  564. {
  565. /* Fairly heavily used by Reduce test file - hence in here */
  566. if (!consp(a)) return onevalue(nil);
  567. a = qcar(a);
  568. a = get(a, b, unset_var);
  569. errexit();
  570. return onevalue(a == unset_var ? nil : lisp_true);
  571. }
  572. Lisp_Object Lflag(Lisp_Object nil,
  573. Lisp_Object a, Lisp_Object b)
  574. {
  575. while (consp(a))
  576. { Lisp_Object v = qcar(a);
  577. a = qcdr(a);
  578. if (!symbolp(v)) continue;
  579. push2(a, b);
  580. putprop(v, b, lisp_true);
  581. pop2(b, a);
  582. errexit();
  583. }
  584. return onevalue(nil);
  585. }
  586. Lisp_Object Lremflag(Lisp_Object nil,
  587. Lisp_Object a, Lisp_Object b)
  588. {
  589. while (consp(a))
  590. { Lisp_Object v = qcar(a);
  591. a = qcdr(a);
  592. if (!symbolp(v)) continue;
  593. push2(a, b);
  594. remprop(v, b);
  595. pop2(b, a);
  596. errexit();
  597. }
  598. return onevalue(nil);
  599. }
  600. #else
  601. Lisp_Object Lflagp(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  602. {
  603. Lisp_Object pl, prev, w;
  604. int n;
  605. if (!symbolp(a))
  606. {
  607. #ifdef RECORD_GET
  608. record_get(b, NO);
  609. errexit();
  610. #endif
  611. return onevalue(nil);
  612. }
  613. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  614. { if ((w = qfastgets(a)) == nil)
  615. {
  616. #ifdef RECORD_GET
  617. record_get(b, NO);
  618. errexit();
  619. #endif
  620. return onevalue(nil);
  621. }
  622. w = elt(w, n-1);
  623. if (w == SPID_NOPROP)
  624. {
  625. #ifdef RECORD_GET
  626. record_get(b, NO);
  627. errexit();
  628. #endif
  629. return onevalue(nil);
  630. }
  631. #ifdef RECORD_GET
  632. record_get(b, YES);
  633. errexit();
  634. #endif
  635. return onevalue(lisp_true);
  636. }
  637. pl = qplist(a);
  638. if (pl == nil)
  639. {
  640. #ifdef RECORD_GET
  641. record_get(b, NO);
  642. errexit();
  643. #endif
  644. return onevalue(nil);
  645. }
  646. w = qcar(pl);
  647. if (qcar(w) == b)
  648. {
  649. #ifdef RECORD_GET
  650. record_get(b, YES);
  651. errexit();
  652. #endif
  653. return onevalue(lisp_true);
  654. }
  655. pl = qcdr(pl);
  656. if (pl == nil)
  657. {
  658. #ifdef RECORD_GET
  659. record_get(b, NO);
  660. errexit();
  661. #endif
  662. return onevalue(nil);
  663. }
  664. w = qcar(pl);
  665. if (qcar(w) == b)
  666. {
  667. #ifdef RECORD_GET
  668. record_get(b, YES);
  669. errexit();
  670. #endif
  671. return onevalue(lisp_true);
  672. }
  673. prev = pl;
  674. pl = qcdr(pl);
  675. if (pl == prev) return aerror("looped up plist in Lflagp");
  676. if (pl == nil)
  677. {
  678. #ifdef RECORD_GET
  679. record_get(b, NO);
  680. errexit();
  681. #endif
  682. return onevalue(nil);
  683. }
  684. for (;;)
  685. { w = qcar(pl);
  686. /*
  687. * If I find the item anywhere beyond the first two places in the plist I
  688. * migrate it up to the front so that next time will be faster
  689. */
  690. if (qcar(w) == b)
  691. { qcdr(prev) = qcdr(pl);
  692. qcdr(pl) = qplist(a);
  693. qplist(a) = pl;
  694. #ifdef RECORD_GET
  695. record_get(b, YES);
  696. errexit();
  697. #endif
  698. return onevalue(lisp_true);
  699. }
  700. prev = pl;
  701. pl = qcdr(pl);
  702. if (pl == prev) return aerror("looped up plist in Lflagp");
  703. if (pl == nil)
  704. {
  705. #ifdef RECORD_GET
  706. record_get(b, NO);
  707. errexit();
  708. #endif
  709. return onevalue(nil);
  710. }
  711. }
  712. }
  713. Lisp_Object Lflagpcar(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  714. {
  715. Lisp_Object pl, prev, w;
  716. int n;
  717. /* Fairly heavily used by Reduce test file - hence in here */
  718. if (a != nil)
  719. { if (!consp(a))
  720. {
  721. #ifdef RECORD_GET
  722. record_get(b, NO);
  723. errexit();
  724. #endif
  725. return onevalue(nil);
  726. }
  727. a = qcar(a);
  728. if (!symbolp(a))
  729. {
  730. #ifdef RECORD_GET
  731. record_get(b, NO);
  732. errexit();
  733. #endif
  734. return onevalue(nil);
  735. }
  736. }
  737. if (symbolp(b) && (n = header_fastget(qheader(b))) != 0)
  738. { if ((w = qfastgets(a)) == nil)
  739. {
  740. #ifdef RECORD_GET
  741. record_get(b, NO);
  742. errexit();
  743. #endif
  744. return onevalue(nil);
  745. }
  746. w = elt(w, n-1);
  747. if (w == SPID_NOPROP)
  748. {
  749. #ifdef RECORD_GET
  750. record_get(b, NO);
  751. errexit();
  752. #endif
  753. return onevalue(nil);
  754. }
  755. #ifdef RECORD_GET
  756. record_get(b, YES);
  757. errexit();
  758. #endif
  759. return onevalue(lisp_true);
  760. }
  761. pl = qplist(a);
  762. if (pl == nil)
  763. {
  764. #ifdef RECORD_GET
  765. record_get(b, NO);
  766. errexit();
  767. #endif
  768. return onevalue(nil);
  769. }
  770. w = qcar(pl);
  771. if (qcar(w) == b)
  772. {
  773. #ifdef RECORD_GET
  774. record_get(b, YES);
  775. errexit();
  776. #endif
  777. return onevalue(lisp_true);
  778. }
  779. pl = qcdr(pl);
  780. if (pl == nil)
  781. {
  782. #ifdef RECORD_GET
  783. record_get(b, NO);
  784. errexit();
  785. #endif
  786. return onevalue(nil);
  787. }
  788. w = qcar(pl);
  789. if (qcar(w) == b)
  790. {
  791. #ifdef RECORD_GET
  792. record_get(b, YES);
  793. errexit();
  794. #endif
  795. return onevalue(lisp_true);
  796. }
  797. prev = pl;
  798. pl = qcdr(pl);
  799. if (pl == prev) return aerror("looped up plist in flagpcar");
  800. if (pl == nil)
  801. {
  802. #ifdef RECORD_GET
  803. record_get(b, NO);
  804. errexit();
  805. #endif
  806. return onevalue(nil);
  807. }
  808. for (;;)
  809. { w = qcar(pl);
  810. /*
  811. * If I find the item anywhere beyond the first two places in the plist I
  812. * migrate it up to the front so that next time will be faster
  813. */
  814. if (qcar(w) == b)
  815. { qcdr(prev) = qcdr(pl);
  816. qcdr(pl) = qplist(a);
  817. qplist(a) = pl;
  818. #ifdef RECORD_GET
  819. record_get(b, YES);
  820. errexit();
  821. #endif
  822. return onevalue(lisp_true);
  823. }
  824. prev = pl;
  825. pl = qcdr(pl);
  826. if (pl == prev) return aerror("looped up plist in flagpcar");
  827. if (pl == nil)
  828. {
  829. #ifdef RECORD_GET
  830. record_get(b, NO);
  831. errexit();
  832. #endif
  833. return onevalue(nil);
  834. }
  835. }
  836. }
  837. Lisp_Object Lflag(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  838. {
  839. int n = 0;
  840. if (symbolp(b)) n = header_fastget(qheader(b));
  841. while (consp(a))
  842. { Lisp_Object v = qcar(a), pl;
  843. a = qcdr(a);
  844. if (!symbolp(v)) continue;
  845. /*
  846. * I store FLAGS just as if they were PROPERTIES that have the value
  847. * T, so after (flag '(a b c) 'd) if anybody goes (get 'a 'd) they get back
  848. * the value T.
  849. */
  850. if (n)
  851. { pl = qfastgets(v);
  852. if (pl == nil)
  853. { push2(v, b);
  854. pl = getvector_init(CELL+CELL*fastget_size, SPID_NOPROP);
  855. pop2(b, v);
  856. errexit();
  857. qfastgets(v) = pl;
  858. }
  859. elt(pl, n-1) = lisp_true;
  860. continue;
  861. }
  862. push2(a, b);
  863. pl = qplist(v);
  864. while (pl != nil)
  865. { Lisp_Object w = qcar(pl);
  866. if (qcar(w) == b)
  867. { qcdr(w) = lisp_true;
  868. goto already_flagged;
  869. }
  870. else pl = qcdr(pl);
  871. }
  872. push(v);
  873. b = acons(b, lisp_true, qplist(v));
  874. errexitn(3);
  875. pop(v);
  876. qplist(v) = b;
  877. already_flagged:
  878. pop2(b, a);
  879. }
  880. return onevalue(nil);
  881. }
  882. Lisp_Object Lremflag(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  883. {
  884. int n = 0;
  885. if (symbolp(b)) n = header_fastget(qheader(b));
  886. while (consp(a))
  887. { Lisp_Object pl, prevp, v = qcar(a);
  888. a = qcdr(a);
  889. if (!symbolp(v)) continue;
  890. if (n)
  891. { pl = qfastgets(v);
  892. if (pl != nil) elt(pl, n-1) = SPID_NOPROP;
  893. continue;
  894. }
  895. prevp = nil;
  896. pl = qplist(v);
  897. while (pl != nil)
  898. { Lisp_Object w = qcar(pl);
  899. if (qcar(w) == b)
  900. { pl = qcdr(pl);
  901. if (prevp == nil) qplist(v) = pl;
  902. else qcdr(prevp) = pl;
  903. break;
  904. }
  905. prevp = pl;
  906. pl = qcdr(prevp);
  907. if (pl == prevp) return aerror("looped up plist in remflag");
  908. }
  909. }
  910. return onevalue(nil);
  911. }
  912. #endif
  913. Lisp_Object Lremprop(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
  914. {
  915. CSL_IGNORE(nil);
  916. return onevalue(remprop(a, b));
  917. }
  918. Lisp_Object Lplist(Lisp_Object nil, Lisp_Object a)
  919. {
  920. Lisp_Object r;
  921. int i;
  922. CSL_IGNORE(nil);
  923. if (!symbolp(a)) return aerror1("plist", a);
  924. r = qplist(a);
  925. a = qfastgets(a);
  926. if (a == nil) return onevalue(r);
  927. for (i=0; i<fastget_size; i++)
  928. { Lisp_Object w = elt(a, i);
  929. if (w != SPID_NOPROP)
  930. { push(a);
  931. #ifdef COMMON
  932. r = list2star(elt(fastget_names, i), w, r);
  933. #else
  934. r = acons(elt(fastget_names, i), w, r);
  935. #endif
  936. pop(a);
  937. errexit();
  938. }
  939. }
  940. return onevalue(r);
  941. }
  942. #ifndef NO_BYTECOUNT
  943. /*
  944. * Unless NO_BYTECOUNT is set I keep two sorts of counts - first
  945. * ones that show how many bytecodes are executed in each separate
  946. * piece of code that the user runs. These can be inspected by
  947. * calling MAPSTORE. Then ones that show (overall) which particular
  948. * byte opcodes are most heavily used. This information is displayed
  949. * when you call BYTECOUNTS.
  950. */
  951. extern int profile_count_mode;
  952. #define OPCOUNT (profile_count_mode ? 1 : opcodes)
  953. #ifndef DEMO_MODE
  954. #include "opnames.c"
  955. #endif
  956. static int32 total = 0, frequencies[256];
  957. #endif
  958. Lisp_Object MS_CDECL bytecounts(Lisp_Object nil, int nargs, ...)
  959. {
  960. int32 i;
  961. #ifdef RECORD_GET
  962. int32 size;
  963. Lisp_Object v;
  964. double tot;
  965. #endif
  966. argcheck(nargs, 0, "bytecounts");
  967. #ifdef NO_BYTECOUNT
  968. i = 0;
  969. trace_printf("bytecode statistics not available\n");
  970. #else
  971. #ifdef DEMO_MODE
  972. i = 0;
  973. trace_printf("bytecode statistics not available in demo version\n");
  974. #else
  975. trace_printf("\nFrequencies of each bytecode (%ld total)", total);
  976. if (total == 0) total = 1;
  977. for (i=0; i<256; i++)
  978. { if ((i & 3) == 0) trace_printf("\n");
  979. trace_printf("%-9.9s%7.4f ",
  980. opnames[i],
  981. 100.0*(double)frequencies[i]/(double)total);
  982. }
  983. trace_printf("\n");
  984. #endif
  985. #endif
  986. #ifdef RECORD_GET
  987. v = elt(get_counts, 4);
  988. if (v == nil) return onevalue(nil);
  989. size = length_of_header(vechdr(v));
  990. size = (size - CELL)/CELL;
  991. term_printf("\n %%SCORE TOTAL NOTFOUND INDICATOR-NAME\n");
  992. tot = 0.0;
  993. for (i=1; i<size; i+=2)
  994. { Lisp_Object key = elt(v, i), val = elt(v, i+1);
  995. int32 yes, no;
  996. if (key == SPID_HASH0 || key == SPID_HASH1) continue;
  997. yes = no = 0;
  998. if (consp(val)) yes = int_of_fixnum(qcar(val)),
  999. no = int_of_fixnum(qcdr(val));
  1000. tot += (double)(yes+2*no);
  1001. }
  1002. tot /= 100.0;
  1003. for (i=1; i<size; i+=2)
  1004. { Lisp_Object key = elt(v, i), val = elt(v, i+1);
  1005. int32 yes, no;
  1006. if (key == SPID_HASH0 || key == SPID_HASH1) continue;
  1007. yes = no = 0;
  1008. if (consp(val)) yes = int_of_fixnum(qcar(val)),
  1009. no = int_of_fixnum(qcdr(val));
  1010. trace_printf("%7.2f %10d %10d ", (double)(yes+2*no)/tot, yes+no, no);
  1011. errexit();
  1012. loop_print_trace(key);
  1013. trace_printf("\n");
  1014. }
  1015. v = Lmkhash(nil, 3, fixnum_of_int(5), fixnum_of_int(0), nil);
  1016. errexit();
  1017. get_counts = v;
  1018. #endif
  1019. return onevalue(nil);
  1020. }
  1021. #ifdef __CC_NORCROFT
  1022. /*
  1023. * I want to write all the code out in-line to save time
  1024. * even at the cost of using extra space, so I disable crossjump
  1025. * optimisation here. It is quite probable that other C compilers
  1026. * support similar control over optimisation strategy, and since the
  1027. * code in this file is performance critical it may be worth trying
  1028. * out various possibilities.
  1029. */
  1030. # pragma no_optimise_crossjump
  1031. #endif
  1032. Lisp_Object *C_stack;
  1033. /*
  1034. * Throughout most of the system I use the name "stack" as a synonym for
  1035. * the external variable "C_stack", but in the main byte-code interpreter
  1036. * loop I disable that mapping and use a register variable as stack
  1037. * pointer, updating the extern value from time to time as necessary.
  1038. */
  1039. #undef stack
  1040. static int errcode;
  1041. static Lisp_Object *do_freebind(Lisp_Object bvec, Lisp_Object *stack)
  1042. {
  1043. int32 n, k;
  1044. n = length_of_header(vechdr(bvec));
  1045. for (k=CELL; k<n; k+=CELL)
  1046. { Lisp_Object v = *(Lisp_Object *)((intxx)bvec + k - TAG_VECTOR);
  1047. push(qvalue(v));
  1048. qvalue(v) = C_nil;
  1049. }
  1050. /*
  1051. * TAG_FBIND is a value that can NEVER occur elsewhere in the Lisp system,
  1052. * and so it unambiguously marks a block of fluid bindings on that stack.
  1053. */
  1054. push2(bvec, (Lisp_Object)SPID_FBIND);
  1055. return stack;
  1056. }
  1057. static Lisp_Object *do_freerstr(Lisp_Object *stack)
  1058. {
  1059. Lisp_Object bv;
  1060. int32 n;
  1061. popv(1);
  1062. pop(bv);
  1063. n = length_of_header(vechdr(bv));
  1064. while (n>CELL)
  1065. { Lisp_Object v = *(Lisp_Object *)((intxx)bv + n - (CELL + TAG_VECTOR));
  1066. n -= CELL;
  1067. pop(qvalue(v));
  1068. }
  1069. return stack;
  1070. }
  1071. /*
  1072. * If OUT_OF_LINE is defined than various fragments of code are written
  1073. * as subroutines called from the main body of bytestream_interpret.
  1074. * This may hurt speed a little, but reduces the size of the one huge
  1075. * function in this file, and may be useful either when memory is at
  1076. * a huge premium (ugh) or [more plausibly] when C compilers get very
  1077. * unhappy with the bulk of the code when all written out in place.
  1078. * The default case I leave (with OUT_OF_LINE undefined) is the one that
  1079. * prefers a few percent speed-up to a fraction of a percent space
  1080. * saving.
  1081. */
  1082. #ifdef OUT_OF_LINE
  1083. static Lisp_Object poll_jump_back(Lisp_Object *stack, Lisp_Object A_reg)
  1084. {
  1085. Lisp_Object nil = C_nil;
  1086. #ifdef SOFTWARE_TICKS
  1087. if (--countdown < 0) deal_with_tick();
  1088. #endif
  1089. C_stack = stack;
  1090. if (stack >= stacklimit)
  1091. { A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  1092. nil = C_nil;
  1093. if (exception_pending()) return SPID_ERROR;
  1094. }
  1095. return A_reg;
  1096. }
  1097. #endif
  1098. #ifdef COMMON
  1099. static Lisp_Object *do_pvbind(Lisp_Object vals, Lisp_Object vars,
  1100. Lisp_Object *stack)
  1101. {
  1102. Lisp_Object val, var, nil = C_nil;
  1103. push4(nil, SPID_PVBIND, vars, vals);
  1104. while (consp(vars))
  1105. { var = qcar(vars);
  1106. vars = qcdr(vars);
  1107. if (!symbolp(var) || var == nil) continue;
  1108. push(vars);
  1109. C_stack = stack;
  1110. var = acons(var, qvalue(var), stack[-4]);
  1111. stack = C_stack;
  1112. nil = C_nil;
  1113. if (exception_pending()) { popv(2); return stack; }
  1114. stack[-4] = var;
  1115. pop(vars);
  1116. }
  1117. pop2(vals, vars);
  1118. while (consp(vars))
  1119. { if (consp(vals)) val = qcar(vals), vals = qcdr(vals);
  1120. else val = unset_var;
  1121. var = qcar(vars);
  1122. if (symbolp(var) && var != nil) qvalue(var) = val;
  1123. vars = qcdr(vars);
  1124. }
  1125. return stack;
  1126. }
  1127. static Lisp_Object *do_pvrestore(Lisp_Object *stack)
  1128. {
  1129. Lisp_Object w, nil = C_nil;
  1130. popv(1);
  1131. pop(w);
  1132. while (w != nil)
  1133. { Lisp_Object q = qcar(w);
  1134. qvalue(qcar(q)) = qcdr(q);
  1135. w = qcdr(w);
  1136. }
  1137. return stack;
  1138. }
  1139. #endif
  1140. static Lisp_Object encapsulate_sp(Lisp_Object *sp)
  1141. /*
  1142. * Creates a boxed up representation of a pointer into the stack.
  1143. */
  1144. { Lisp_Object w = getvector(TAG_VECTOR, TYPE_SP, 2*CELL);
  1145. Lisp_Object nil;
  1146. errexit();
  1147. elt(w, 0) = (Lisp_Object)sp;
  1148. return w;
  1149. }
  1150. static void trace_print_0(Lisp_Object name, Lisp_Object *stack)
  1151. {
  1152. freshline_trace();
  1153. trace_printf("Tail calling ");
  1154. loop_print_trace(name);
  1155. trace_printf(" (no args) from ");
  1156. loop_print_trace(*stack);
  1157. trace_printf("\n");
  1158. }
  1159. static void trace_print_1(Lisp_Object name, Lisp_Object *stack)
  1160. {
  1161. freshline_trace();
  1162. trace_printf("Tail calling ");
  1163. loop_print_trace(name);
  1164. trace_printf(" (1 arg) from ");
  1165. loop_print_trace(*stack);
  1166. trace_printf("\n");
  1167. trace_printf("Arg1: ");
  1168. loop_print_trace(stack[-3]);
  1169. trace_printf("\n");
  1170. }
  1171. static void trace_print_2(Lisp_Object name, Lisp_Object *stack)
  1172. {
  1173. freshline_trace();
  1174. trace_printf("Tail calling ");
  1175. loop_print_trace(name);
  1176. trace_printf(" (2 args) from ");
  1177. loop_print_trace(*stack);
  1178. trace_printf("\n");
  1179. trace_printf("Arg1: "); loop_print_trace(stack[-4]);
  1180. trace_printf("\nArg2: "); loop_print_trace(stack[-3]);
  1181. trace_printf("\n");
  1182. }
  1183. static void trace_print_3(Lisp_Object name, Lisp_Object *stack)
  1184. {
  1185. freshline_trace();
  1186. trace_printf("Tail calling ");
  1187. loop_print_trace(name);
  1188. trace_printf(" (3 args) from ");
  1189. loop_print_trace(*stack);
  1190. trace_printf("\n");
  1191. trace_printf("Arg1: "); loop_print_trace(stack[-5]);
  1192. trace_printf("\nArg2: "); loop_print_trace(stack[-4]);
  1193. trace_printf("\nArg3: "); loop_print_trace(stack[-3]);
  1194. trace_printf("\n");
  1195. }
  1196. #define save_pc() pc = (unsigned int)(ppc - \
  1197. (unsigned char *)data_of_bps(codevec))
  1198. #define restore_pc() ppc = (unsigned char *)data_of_bps(codevec) + pc
  1199. #ifdef MEMORY_TRACE
  1200. #define next_byte (cmemory_reference((intxx)ppc), *ppc++)
  1201. #else
  1202. #define next_byte *ppc++
  1203. #endif
  1204. #ifdef __powerc
  1205. /* If you have trouble compiling this just comment it out, please */
  1206. #pragma options(!global_optimizer)
  1207. #endif
  1208. Lisp_Object bytestream_interpret(Lisp_Object code, Lisp_Object lit,
  1209. Lisp_Object *entry_stack)
  1210. {
  1211. register unsigned char *ppc;
  1212. register Lisp_Object A_reg;
  1213. Lisp_Object nil = C_nil;
  1214. Lisp_Object *stack = C_stack;
  1215. /*
  1216. * The variables above this line are by a significant margin the
  1217. * most important ones for this code. It may be useful to use
  1218. * 'register' declarations even with good optimising compilers, since
  1219. * the structure of a bytestream interpreter can draw too much attention to
  1220. * individual cases and not enough to the full outer loop. Here the most
  1221. * common paths are the "switch (*ppc++)" and various of the very short
  1222. * and simple opcodes that are dispatched to.
  1223. */
  1224. Lisp_Object r1, r2, r3;
  1225. one_args *f1;
  1226. two_args *f2;
  1227. n_args *f345;
  1228. unsigned int fname, pc, w;
  1229. int32 n, k;
  1230. unsigned char *xppc;
  1231. /*
  1232. * I declare all the other variables I need here up at the top of the function
  1233. * since at least on some C compilers putting the declarations more locally
  1234. * seems to be unexpectedly costly. In some cases moving the stack pointer
  1235. * may be a pain, in others code like
  1236. * { int x; ...} { int x; ... } { int x; ... }
  1237. * end up allocating three stack locations (one for each instance of x) and
  1238. * hence makes this function overall have much to big a stack frame.
  1239. */
  1240. #ifndef NO_BYTECOUNT
  1241. int32 opcodes = 30; /* Attribute 30-bytecode overhead to entry sequence */
  1242. #endif
  1243. #ifdef DEBUG
  1244. /*
  1245. * ffname will (at least until a garbage collection occurs) point to the
  1246. * (C) string that is the name of the function being interpreted. This is
  1247. * jolly useful if one is in a debugger trying to understand what has
  1248. * been going on! Note that the executable code here does not use this
  1249. * variable at all: it is JUST so that I have a simple "char *" variable
  1250. * that a symbolic debugger can inspect to find my function name without
  1251. * me having to mess about too much.
  1252. */
  1253. char *ffname = &celt(qpname(elt(lit, 0)), 0); /* DEBUG */
  1254. CSL_IGNORE(ffname);
  1255. #endif
  1256. /*
  1257. * The byte-stream interpreter here uses the lisp stack and two
  1258. * special registers, called A, and B which act as a mini stack.
  1259. */
  1260. #ifdef CHECK_STACK
  1261. if (check_stack(ffname,__LINE__)) return aerror("stack overflow");
  1262. #endif
  1263. litvec = lit;
  1264. /*
  1265. * The next lines are used to allow for functions with > 3 args, and for
  1266. * &optional and &rest cases. Some of these need one or two bytes at the
  1267. * start of the code-vector to indicate just how many arguments are
  1268. * expected. In such cases the byte program-counter must start off
  1269. * positioned just beyond these extra bytes. The way that a code pointer
  1270. * is packed in CSL means that for garbage collection a code-pointer is
  1271. * stored with bottom 4 bits '0010', and it can address to a resolution of
  1272. * one word (4 bytes). However, the actual argument passed into this code
  1273. * does not have to be garbage-collector safe until there is the first
  1274. * chance of a garbage collection, and I exploit that to allow for 0, 1
  1275. * 2 or 3 initial information bytes. The ((code & ~3) + 2) restores
  1276. * proper tagging, and (code & 3) holds an offset.
  1277. */
  1278. ppc = (unsigned char *)data_of_bps(code);
  1279. ppc = ppc + ((int32)code & 3);
  1280. codevec = (Lisp_Object)(((int32)code & ~3) + 2);
  1281. /*
  1282. * I am careful to reload stack from C_stack after any
  1283. * function call, to allow that the garbage collector may relocate the
  1284. * whole stack region. But at present I do not protect entry_stack in
  1285. * this way, so if the garbage collector moves my stack and subsequently
  1286. * I take an error exit I will get in a big mess. At present the garbage
  1287. * collector is not that enthusiastic, so the problem will not arise. If
  1288. * I was sure it NEVER would I could avoid a few cases of "stack = C_stack"
  1289. * here and speed things up by some utterly insignificant amount.
  1290. */
  1291. A_reg = nil;
  1292. for (;;)
  1293. {
  1294. #ifndef NO_BYTECOUNT
  1295. opcodes++;
  1296. total++;
  1297. frequencies[*ppc]++;
  1298. #endif
  1299. #ifdef __APOLLO__
  1300. /*
  1301. * On an Apollo a version of this code that just went switch (*++ppc) went
  1302. * amazingly slowly as a result of clumsy compilation when the value that was
  1303. * switched upon was a char not an int. The cast written here appears to
  1304. * work around the difficulty. Also the same compiler was made very unhappy
  1305. * by having regular labels inside the block just after "switch". I have moved
  1306. * all such labels to be outside the scope of the switch. Note that I have now
  1307. * altered the code to read "switch (*ppc++)", which may or may not make a
  1308. * difference.
  1309. */
  1310. switch ((unsigned int)next_byte)
  1311. #else
  1312. /*
  1313. * With at least some compilers (eg Watcom) if I cast the value obtained here
  1314. * to something other than unsigned char I get worse code, because the fact
  1315. * that the switch range is exactly 0-255 and my control value must be in that
  1316. * range gets lost.
  1317. */
  1318. switch (next_byte)
  1319. #endif
  1320. {
  1321. /*
  1322. * I give labels for all 256 possible cases here so that a sufficiently
  1323. * clever compiler can understand that there is no "default" that can possibly
  1324. * be activated.
  1325. */
  1326. case OP_SPARE1:
  1327. case OP_SPARE2:
  1328. default:
  1329. /*
  1330. * Here I have an unrecognised opcode - the result of a compiler error
  1331. */
  1332. err_printf("\nUnrecognized opcode byte %x\n", *(ppc-1));
  1333. aerror("compiler failure");
  1334. nil = C_nil;
  1335. C_stack = stack;
  1336. goto error_exit;
  1337. case OP_LOC0EXIT:
  1338. A_reg = stack[0];
  1339. #ifdef COMMON
  1340. /*
  1341. * At a load of places here I set exit_count to 1 so that if I then return
  1342. * it will be clear how many values are involved. As currently organized
  1343. * this FAILS to set the number of values in cases like
  1344. * (setq a (values 1 2 3))
  1345. * and
  1346. * (cond
  1347. * ((values 1 2 3)))
  1348. * where in each case the 3 values shown will be (improperly) preserved.
  1349. * I suspect that hardly anybody minds if too many values are occasionally
  1350. * returned, and so will NOT put the overhead of extra reference to
  1351. * exit_count after STORE instructions or conditional branches.
  1352. */
  1353. exit_count = 1;
  1354. #endif
  1355. #ifndef NO_BYTECOUNT
  1356. qcount(elt(litvec, 0)) += OPCOUNT;
  1357. #endif
  1358. C_stack = entry_stack;
  1359. return A_reg;
  1360. case OP_LOC1EXIT:
  1361. A_reg = stack[-1];
  1362. #ifdef COMMON
  1363. exit_count = 1;
  1364. #endif
  1365. #ifndef NO_BYTECOUNT
  1366. qcount(elt(litvec, 0)) += OPCOUNT;
  1367. #endif
  1368. C_stack = entry_stack;
  1369. return A_reg;
  1370. case OP_LOC2EXIT:
  1371. A_reg = stack[-2];
  1372. #ifdef COMMON
  1373. exit_count = 1;
  1374. #endif
  1375. #ifndef NO_BYTECOUNT
  1376. qcount(elt(litvec, 0)) += OPCOUNT;
  1377. #endif
  1378. C_stack = entry_stack;
  1379. return A_reg;
  1380. case OP_NILEXIT:
  1381. #ifndef NO_BYTECOUNT
  1382. qcount(elt(litvec, 0)) += OPCOUNT;
  1383. #endif
  1384. C_stack = entry_stack;
  1385. return onevalue(nil);
  1386. case OP_FREEBIND:
  1387. stack = do_freebind(elt(litvec, next_byte), stack);
  1388. continue;
  1389. case OP_FREERSTR:
  1390. stack = do_freerstr(stack);
  1391. continue;
  1392. #ifdef COMMON
  1393. case OP_PVBIND:
  1394. save_pc();
  1395. stack = do_pvbind(A_reg, B_reg, stack);
  1396. nil = C_nil;
  1397. if (exception_pending()) goto error_exit;
  1398. restore_pc();
  1399. continue;
  1400. case OP_PVRESTORE:
  1401. stack = do_pvrestore(stack);
  1402. continue;
  1403. #endif
  1404. case OP_STOREFREE:
  1405. qvalue(elt(litvec, next_byte)) = A_reg; /* store into special var */
  1406. continue;
  1407. case OP_STOREFREE1:
  1408. qvalue(elt(litvec, 1)) = A_reg;
  1409. continue;
  1410. case OP_STOREFREE2:
  1411. qvalue(elt(litvec, 2)) = A_reg;
  1412. continue;
  1413. case OP_STOREFREE3:
  1414. qvalue(elt(litvec, 3)) = A_reg;
  1415. continue;
  1416. case OP_PUSHNILS:
  1417. n = next_byte;
  1418. for (k=0; k<n; k++) push(nil);
  1419. continue;
  1420. case OP_VNIL:
  1421. B_reg = A_reg;
  1422. A_reg = nil;
  1423. #ifdef COMMON
  1424. exit_count = 1;
  1425. #endif
  1426. continue;
  1427. case OP_SWOP:
  1428. r1 = B_reg;
  1429. B_reg = A_reg;
  1430. A_reg = r1;
  1431. #ifdef COMMON
  1432. exit_count = 1;
  1433. #endif
  1434. continue;
  1435. #ifdef OP_LABEL
  1436. case OP_LABEL: /* Just useful to keep statistics straight */
  1437. continue;
  1438. #endif
  1439. case OP_NCONS: /* A_reg = cons(A_reg, nil); */
  1440. #ifndef OUT_OF_LINE
  1441. /* NB preserves B register */
  1442. r1 = (Lisp_Object)((char *)fringe - sizeof(Cons_Cell));
  1443. qcar(r1) = A_reg;
  1444. qcdr(r1) = nil;
  1445. fringe = r1;
  1446. if ((char *)r1 <= (char *)heaplimit)
  1447. { push(B_reg);
  1448. save_pc();
  1449. C_stack = stack;
  1450. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1451. "bytecoded ncons", GC_CONS, 0);
  1452. nil = C_nil;
  1453. if (exception_pending()) goto error_exit;
  1454. stack = C_stack; /* may have been changed by GC */
  1455. restore_pc();
  1456. pop(B_reg);
  1457. }
  1458. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1459. #else
  1460. /*
  1461. * What this example shows is that IN_LINE is not always such a bad deal.
  1462. * Making everything safe across the potential garbage collection here
  1463. * is a big mess!
  1464. */
  1465. push(B_reg);
  1466. save_pc();
  1467. C_stack = stack;
  1468. A_reg = ncons(A_reg);
  1469. nil = C_nil;
  1470. if (exception_pending()) goto error_exit;
  1471. stack = C_stack; /* may have been changed by GC */
  1472. restore_pc();
  1473. pop(B_reg);
  1474. #endif
  1475. #ifdef COMMON
  1476. exit_count = 1;
  1477. #endif
  1478. continue;
  1479. case OP_XCONS: /* A_reg = cons(A_reg, B_reg); */
  1480. #ifndef OUT_OF_LINE
  1481. r1 = (Lisp_Object)((char *)fringe - sizeof(Cons_Cell));
  1482. qcar(r1) = A_reg;
  1483. qcdr(r1) = B_reg;
  1484. fringe = r1;
  1485. if ((char *)r1 <= (char *)heaplimit)
  1486. { save_pc();
  1487. C_stack = stack;
  1488. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1489. "bytecoded xcons", GC_CONS, 0);
  1490. nil = C_nil;
  1491. if (exception_pending()) goto error_exit;
  1492. stack = C_stack; /* may have been changed by GC */
  1493. restore_pc();
  1494. }
  1495. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1496. #else
  1497. save_pc();
  1498. C_stack = stack;
  1499. A_reg = cons(A_reg, B_reg);
  1500. nil = C_nil;
  1501. if (exception_pending()) goto error_exit;
  1502. stack = C_stack; /* may have been changed by GC */
  1503. restore_pc();
  1504. #endif
  1505. #ifdef COMMON
  1506. exit_count = 1;
  1507. #endif
  1508. continue;
  1509. case OP_LIST2: /* A_reg = cons(B_reg, cons(A_reg, nil)); */
  1510. #ifndef OUT_OF_LINE
  1511. r1 = (Lisp_Object)((char *)fringe - 2*sizeof(Cons_Cell));
  1512. qcar(r1) = B_reg;
  1513. qcdr(r1) = (Lisp_Object)((char *)r1 +
  1514. sizeof(Cons_Cell) + TAG_CONS);
  1515. qcar((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = A_reg;
  1516. qcdr((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = nil;
  1517. fringe = r1;
  1518. if ((char *)r1 <= (char *)heaplimit)
  1519. { save_pc();
  1520. C_stack = stack;
  1521. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1522. "bytecoded list2", GC_CONS, 0);
  1523. nil = C_nil;
  1524. if (exception_pending()) goto error_exit;
  1525. stack = C_stack;
  1526. restore_pc();
  1527. }
  1528. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1529. #else
  1530. save_pc();
  1531. C_stack = stack;
  1532. A_reg = list2(B_reg, A_reg);
  1533. nil = C_nil;
  1534. if (exception_pending()) goto error_exit;
  1535. stack = C_stack; /* may have been changed by GC */
  1536. restore_pc();
  1537. #endif
  1538. #ifdef COMMON
  1539. exit_count = 1;
  1540. #endif
  1541. continue;
  1542. case OP_ACONS: /* A_reg = acons(pop(), B_reg, A_reg); */
  1543. /* = (pop() . B) . A */
  1544. #ifndef OUT_OF_LINE
  1545. r1 = (Lisp_Object)((char *)fringe - 2*sizeof(Cons_Cell));
  1546. qcar(r1) = (Lisp_Object)((char *)r1 +
  1547. sizeof(Cons_Cell) + TAG_CONS);
  1548. qcdr(r1) = A_reg;
  1549. pop(qcar((Lisp_Object)((char *)r1+sizeof(Cons_Cell))));
  1550. qcdr((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = B_reg;
  1551. fringe = r1;
  1552. if ((char *)r1 <= (char *)heaplimit)
  1553. { save_pc();
  1554. C_stack = stack;
  1555. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1556. "bytecoded acons", GC_CONS, 0);
  1557. nil = C_nil;
  1558. if (exception_pending()) goto error_exit;
  1559. stack = C_stack;
  1560. restore_pc();
  1561. }
  1562. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1563. #else
  1564. pop(r1);
  1565. save_pc();
  1566. C_stack = stack;
  1567. A_reg = acons(r1, B_reg, A_reg);
  1568. nil = C_nil;
  1569. if (exception_pending()) goto error_exit;
  1570. stack = C_stack; /* may have been changed by GC */
  1571. restore_pc();
  1572. #endif
  1573. #ifdef COMMON
  1574. exit_count = 1;
  1575. #endif
  1576. continue;
  1577. /*
  1578. * For the next two opcodes the first argument to the current function
  1579. * must have been an environment pointer as set up with CLOSURE. I do
  1580. * not check that I have a closure object - perhaps I can excuse that by
  1581. * claiming that all creation and management of encapsulated closures
  1582. * will have been introduced by the compiler, which I propose to trust!
  1583. * (actually as of April 2002 I think there may be bugs I need to fix...)
  1584. */
  1585. case OP_LOADLEX:
  1586. r1 = elt(stack[1-(int)next_byte], 0);
  1587. B_reg = A_reg;
  1588. w = next_byte; /* Number of levels to chain */
  1589. while (w != 0) r1 = ((Lisp_Object *)r1)[1], w--;
  1590. A_reg = ((Lisp_Object *)r1)[next_byte];
  1591. #ifdef COMMON
  1592. exit_count = 1;
  1593. #endif
  1594. continue;
  1595. case OP_STORELEX:
  1596. r1 = elt(stack[1-(int)next_byte], 0);
  1597. w = next_byte; /* Number of levels to chain */
  1598. while (w != 0) r1 = ((Lisp_Object *)r1)[1], w--;
  1599. ((Lisp_Object *)r1)[next_byte] = A_reg;
  1600. continue;
  1601. case OP_CLOSURE:
  1602. push2(B_reg, A_reg);
  1603. /*
  1604. * This will be the address where the first arg of this function lives on
  1605. * the stack. It provides a hook for the called function to access lexical
  1606. * variables.
  1607. */
  1608. w = next_byte;
  1609. goto create_closure;
  1610. case OP_BIGSTACK: /* LOADLOC, STORELOC, CLOSURE etc */
  1611. /*
  1612. * This opcode allows me to support functions that use up to
  1613. * 2047-deep stack frames using LOADLEX and STORELEX, or
  1614. * up to 4095 deep if just using LOADLOC and STORELOC. I hope
  1615. * that such cases are very uncommon, but examples have been
  1616. * shown to me where my previous limit of 256-item frames was
  1617. * inadequate. The BIGSTACK opcode is followed by a byte that
  1618. * contains a few bits selecting which operation is to be
  1619. * performed, plus an extension to the address byte that follows.
  1620. */
  1621. w = next_byte; /* contains sub-opcode */
  1622. switch (w & 0xc0)
  1623. {
  1624. case 0x00: /* LOADLOC extended */
  1625. B_reg = A_reg;
  1626. w = (w & 0x3f) << 8;
  1627. A_reg = stack[-(int)(w + next_byte)];
  1628. #ifdef COMMON
  1629. exit_count = 1;
  1630. #endif
  1631. continue;
  1632. case 0x40: /* STORELOC extended */
  1633. w = (w & 0x3f) << 8;
  1634. stack[-(int)(w + next_byte)] = A_reg;
  1635. continue;
  1636. case 0x80: /* CLOSURE extended */
  1637. push2(B_reg, A_reg);
  1638. w = ((w & 0x3f) << 8) + next_byte;
  1639. goto create_closure;
  1640. case 0xc0: /* LOADLEX, STORELEX extended */
  1641. n = next_byte;
  1642. k = next_byte;
  1643. n = (n << 4) | (k >> 4);
  1644. k = ((k & 0xf) << 8) | next_byte;
  1645. r1 = elt(stack[1-n], 0);
  1646. B_reg = A_reg;
  1647. n = w & 0x1f;
  1648. while (n != 0) r1 = ((Lisp_Object *)r1)[1], n--;
  1649. if ((w & 0x20) == 0)
  1650. { A_reg = ((Lisp_Object *)r1)[k];
  1651. #ifdef COMMON
  1652. exit_count = 1;
  1653. #endif
  1654. }
  1655. else ((Lisp_Object *)r1)[k] = A_reg;
  1656. continue;
  1657. }
  1658. case OP_LIST2STAR: /* A_reg = list2!*(pop(), B_reg, A_reg); */
  1659. /* = pop() . (B . A) */
  1660. #ifndef OUT_OF_LINE
  1661. r1 = (Lisp_Object)((char *)fringe - 2*sizeof(Cons_Cell));
  1662. pop(qcar(r1));
  1663. qcdr(r1) = (Lisp_Object)((char *)r1 +
  1664. sizeof(Cons_Cell) + TAG_CONS);
  1665. qcar((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = B_reg;
  1666. qcdr((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = A_reg;
  1667. fringe = r1;
  1668. if ((char *)r1 <= (char *)heaplimit)
  1669. { save_pc();
  1670. C_stack = stack;
  1671. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1672. "bytecoded list2*", GC_CONS, 0);
  1673. nil = C_nil;
  1674. if (exception_pending()) goto error_exit;
  1675. stack = C_stack;
  1676. restore_pc();
  1677. }
  1678. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1679. #else
  1680. pop(r1);
  1681. save_pc();
  1682. C_stack = stack;
  1683. A_reg = list2star(r1, B_reg, A_reg);
  1684. nil = C_nil;
  1685. if (exception_pending()) goto error_exit;
  1686. stack = C_stack; /* may have been changed by GC */
  1687. restore_pc();
  1688. #endif
  1689. #ifdef COMMON
  1690. exit_count = 1;
  1691. #endif
  1692. continue;
  1693. case OP_LIST3: /* A_reg = list3(pop(), B_reg, A_reg); */
  1694. /* = pop() . (B . (A . nil)) */
  1695. #ifndef OUT_OF_LINE
  1696. r1 = (Lisp_Object)((char *)fringe - 3*sizeof(Cons_Cell));
  1697. pop(qcar(r1));
  1698. qcdr(r1) = (Lisp_Object)((char *)r1 +
  1699. sizeof(Cons_Cell) + TAG_CONS);
  1700. qcar((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) = B_reg;
  1701. qcdr((Lisp_Object)((char *)r1+sizeof(Cons_Cell))) =
  1702. (Lisp_Object)((char *)r1 +
  1703. 2*sizeof(Cons_Cell) + TAG_CONS);
  1704. qcar((Lisp_Object)((char *)r1+2*sizeof(Cons_Cell))) = A_reg;
  1705. qcdr((Lisp_Object)((char *)r1+2*sizeof(Cons_Cell))) = nil;
  1706. fringe = r1;
  1707. if ((char *)r1 <= (char *)heaplimit)
  1708. { save_pc();
  1709. C_stack = stack;
  1710. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  1711. "bytecoded list3", GC_CONS, 0);
  1712. nil = C_nil;
  1713. if (exception_pending()) goto error_exit;
  1714. stack = C_stack;
  1715. restore_pc();
  1716. }
  1717. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  1718. #else
  1719. pop(r1);
  1720. save_pc();
  1721. C_stack = stack;
  1722. A_reg = list3(r1, B_reg, A_reg);
  1723. nil = C_nil;
  1724. if (exception_pending()) goto error_exit;
  1725. stack = C_stack; /* may have been changed by GC */
  1726. restore_pc();
  1727. #endif
  1728. #ifdef COMMON
  1729. exit_count = 1;
  1730. #endif
  1731. continue;
  1732. case OP_ADD1:
  1733. if (is_fixnum(A_reg) && A_reg != fixnum_of_int(0x07ffffff))
  1734. {
  1735. A_reg += 0x10;
  1736. #ifdef COMMON
  1737. exit_count = 1;
  1738. #endif
  1739. continue;
  1740. }
  1741. /*
  1742. * I drop through in the case of floating, bignum or error arithmetic.
  1743. */
  1744. save_pc();
  1745. C_stack = stack;
  1746. A_reg = plus2(A_reg, fixnum_of_int(1));
  1747. nil = C_nil;
  1748. if (exception_pending()) goto error_exit;
  1749. stack = C_stack;
  1750. restore_pc();
  1751. #ifdef COMMON
  1752. exit_count = 1;
  1753. #endif
  1754. continue;
  1755. case OP_PLUS2:
  1756. if (is_fixnum(A_reg) && is_fixnum(B_reg))
  1757. { n = int_of_fixnum(A_reg) + int_of_fixnum(B_reg);
  1758. k = n & fix_mask;
  1759. if (k == 0 || k == fix_mask)
  1760. { A_reg = fixnum_of_int(n);
  1761. #ifdef COMMON
  1762. exit_count = 1;
  1763. #endif
  1764. continue;
  1765. }
  1766. }
  1767. /*
  1768. * I drop through in the case of floating, bignum or error arithmetic.
  1769. */
  1770. save_pc();
  1771. C_stack = stack;
  1772. A_reg = plus2(B_reg, A_reg);
  1773. nil = C_nil;
  1774. if (exception_pending()) goto error_exit;
  1775. stack = C_stack;
  1776. restore_pc();
  1777. #ifdef COMMON
  1778. exit_count = 1;
  1779. #endif
  1780. continue;
  1781. case OP_SUB1:
  1782. if (is_fixnum(A_reg) && A_reg != fixnum_of_int(~0x07ffffff))
  1783. {
  1784. A_reg -= 0x10;
  1785. #ifdef COMMON
  1786. exit_count = 1;
  1787. #endif
  1788. continue;
  1789. }
  1790. /*
  1791. * I drop through in the case of floating, bignum or error arithmetic.
  1792. */
  1793. save_pc();
  1794. C_stack = stack;
  1795. A_reg = plus2(A_reg, fixnum_of_int(-1));
  1796. nil = C_nil;
  1797. if (exception_pending()) goto error_exit;
  1798. stack = C_stack;
  1799. restore_pc();
  1800. #ifdef COMMON
  1801. exit_count = 1;
  1802. #endif
  1803. continue;
  1804. case OP_DIFFERENCE:
  1805. if (is_fixnum(A_reg) && is_fixnum(B_reg))
  1806. { n = int_of_fixnum(B_reg) - int_of_fixnum(A_reg);
  1807. k = n & fix_mask;
  1808. if (k == 0 || k == fix_mask)
  1809. { A_reg = fixnum_of_int(n);
  1810. #ifdef COMMON
  1811. exit_count = 1;
  1812. #endif
  1813. continue;
  1814. }
  1815. }
  1816. /*
  1817. * Although computing A-B as A+(-B) is a bit clumsy here, it is only
  1818. * done when there is a bignum or float involved - the important case
  1819. * where everything is a small integer is handled directly in-line.
  1820. */
  1821. save_pc();
  1822. push(B_reg);
  1823. C_stack = stack;
  1824. A_reg = negate(A_reg);
  1825. stack = C_stack;
  1826. pop(B_reg);
  1827. C_stack = stack;
  1828. nil = C_nil;
  1829. if (exception_pending()) goto error_exit;
  1830. A_reg = plus2(B_reg, A_reg);
  1831. nil = C_nil;
  1832. if (exception_pending()) goto error_exit;
  1833. stack = C_stack;
  1834. restore_pc();
  1835. #ifdef COMMON
  1836. exit_count = 1;
  1837. #endif
  1838. continue;
  1839. case OP_TIMES2:
  1840. /*
  1841. * I do not in-line even the integer case here, since overflow checking
  1842. * is a slight mess.
  1843. */
  1844. save_pc();
  1845. C_stack = stack;
  1846. A_reg = times2(B_reg, A_reg);
  1847. nil = C_nil;
  1848. if (exception_pending()) goto error_exit;
  1849. stack = C_stack;
  1850. restore_pc();
  1851. #ifdef COMMON
  1852. exit_count = 1;
  1853. #endif
  1854. continue;
  1855. case OP_LESSP:
  1856. if (is_fixnum(B_reg) && is_fixnum(A_reg)) w = B_reg < A_reg;
  1857. else
  1858. { save_pc();
  1859. C_stack = stack;
  1860. w = lessp2(B_reg, A_reg);
  1861. nil = C_nil;
  1862. if (exception_pending()) goto error_exit;
  1863. stack = C_stack;
  1864. restore_pc();
  1865. }
  1866. A_reg = Lispify_predicate(w);
  1867. #ifdef COMMON
  1868. exit_count = 1;
  1869. #endif
  1870. continue;
  1871. case OP_GREATERP:
  1872. if (is_fixnum(B_reg) && is_fixnum(A_reg)) w = B_reg > A_reg;
  1873. else
  1874. { save_pc();
  1875. C_stack = stack;
  1876. w = lessp2(A_reg, B_reg);
  1877. nil = C_nil;
  1878. if (exception_pending()) goto error_exit;
  1879. stack = C_stack;
  1880. restore_pc();
  1881. }
  1882. A_reg = Lispify_predicate(w);
  1883. #ifdef COMMON
  1884. exit_count = 1;
  1885. #endif
  1886. continue;
  1887. case OP_FLAGP: /* A = flagp(B, A) */
  1888. #ifdef COMMON
  1889. save_pc(); C_stack = stack;
  1890. A_reg = get(B_reg, A_reg, unset_var);
  1891. nil = C_nil;
  1892. if (exception_pending()) goto error_exit;
  1893. stack = C_stack; restore_pc();
  1894. if (A_reg == unset_var) A_reg = nil;
  1895. else A_reg = lisp_true;
  1896. exit_count = 1;
  1897. continue;
  1898. #else
  1899. #ifndef OUT_OF_LINE
  1900. if (!symbolp(B_reg))
  1901. {
  1902. #ifdef RECORD_GET
  1903. save_pc(); C_stack = stack;
  1904. record_get(A_reg, NO);
  1905. nil = C_nil;
  1906. if (exception_pending()) goto error_exit;
  1907. stack = C_stack; restore_pc();
  1908. #endif
  1909. A_reg = nil;
  1910. continue;
  1911. }
  1912. else if (symbolp(A_reg) &&
  1913. (n = header_fastget(qheader(A_reg))) != 0)
  1914. { r1 = qfastgets(B_reg);
  1915. if (r1 == nil)
  1916. {
  1917. #ifdef RECORD_GET
  1918. save_pc(); C_stack = stack;
  1919. record_get(A_reg, NO);
  1920. nil = C_nil;
  1921. if (exception_pending()) goto error_exit;
  1922. stack = C_stack; restore_pc();
  1923. #endif
  1924. continue;
  1925. }
  1926. r1 = elt(r1, n-1);
  1927. #ifdef RECORD_GET
  1928. push(r1);
  1929. save_pc(); C_stack = stack;
  1930. record_get(A_reg, r1 != SPID_NOPROP);
  1931. nil = C_nil;
  1932. if (exception_pending()) goto error_exit;
  1933. stack = C_stack; restore_pc();
  1934. pop(r1);
  1935. #endif
  1936. if (r1 == SPID_NOPROP) A_reg = nil; else A_reg = lisp_true;
  1937. continue;
  1938. }
  1939. else
  1940. { r1 = qplist(B_reg);
  1941. if (r1 == nil)
  1942. {
  1943. #ifdef RECORD_GET
  1944. save_pc(); C_stack = stack;
  1945. record_get(A_reg, NO);
  1946. nil = C_nil;
  1947. if (exception_pending()) goto error_exit;
  1948. stack = C_stack; restore_pc();
  1949. #endif
  1950. A_reg = nil;
  1951. continue;
  1952. }
  1953. r3 = qcar(r1);
  1954. if (qcar(r3) == A_reg)
  1955. {
  1956. #ifdef RECORD_GET
  1957. save_pc(); C_stack = stack;
  1958. record_get(A_reg, YES);
  1959. nil = C_nil;
  1960. if (exception_pending()) goto error_exit;
  1961. stack = C_stack; restore_pc();
  1962. #endif
  1963. A_reg = lisp_true;
  1964. continue;
  1965. }
  1966. r1 = qcdr(r1);
  1967. if (r1 == nil)
  1968. {
  1969. #ifdef RECORD_GET
  1970. save_pc(); C_stack = stack;
  1971. record_get(A_reg, NO);
  1972. nil = C_nil;
  1973. if (exception_pending()) goto error_exit;
  1974. stack = C_stack; restore_pc();
  1975. #endif
  1976. A_reg = nil;
  1977. continue;
  1978. }
  1979. r3 = qcar(r1);
  1980. if (qcar(r3) == A_reg)
  1981. {
  1982. #ifdef RECORD_GET
  1983. save_pc(); C_stack = stack;
  1984. record_get(A_reg, YES);
  1985. nil = C_nil;
  1986. if (exception_pending()) goto error_exit;
  1987. stack = C_stack; restore_pc();
  1988. #endif
  1989. A_reg = lisp_true;
  1990. continue;
  1991. }
  1992. r2 = r1;
  1993. r1 = qcdr(r1);
  1994. if (r1 == nil)
  1995. {
  1996. #ifdef RECORD_GET
  1997. save_pc(); C_stack = stack;
  1998. record_get(A_reg, NO);
  1999. nil = C_nil;
  2000. if (exception_pending()) goto error_exit;
  2001. stack = C_stack; restore_pc();
  2002. #endif
  2003. A_reg = nil;
  2004. continue;
  2005. }
  2006. for (;;)
  2007. { r3 = qcar(r1);
  2008. if (qcar(r3) == A_reg)
  2009. { qcdr(r2) = qcdr(r1);
  2010. qcdr(r1) = qplist(B_reg);
  2011. qplist(B_reg) = r1;
  2012. #ifdef RECORD_GET
  2013. save_pc(); C_stack = stack;
  2014. record_get(A_reg, NO);
  2015. nil = C_nil;
  2016. if (exception_pending()) goto error_exit;
  2017. stack = C_stack; restore_pc();
  2018. #endif
  2019. A_reg = lisp_true;
  2020. break;
  2021. }
  2022. r2 = r1;
  2023. r1 = qcdr(r1);
  2024. if (r1 == nil)
  2025. {
  2026. #ifdef RECORD_GET
  2027. save_pc(); C_stack = stack;
  2028. record_get(A_reg, NO);
  2029. nil = C_nil;
  2030. if (exception_pending()) goto error_exit;
  2031. stack = C_stack; restore_pc();
  2032. #endif
  2033. A_reg = nil;
  2034. break;
  2035. }
  2036. }
  2037. }
  2038. continue;
  2039. #else
  2040. A_reg = Lflagp(nil, B_reg, A_reg);
  2041. nil = C_nil;
  2042. if (exception_pending()) goto error_exit;
  2043. exit_count = 1;
  2044. continue;
  2045. #endif
  2046. #endif
  2047. case OP_APPLY1:
  2048. save_pc();
  2049. if (is_symbol(B_reg)) /* can optimise this case, I guess */
  2050. { f1 = qfn1(B_reg);
  2051. #ifdef DEBUG
  2052. if (f1 == NULL)
  2053. { term_printf("Illegal function\n");
  2054. my_exit(EXIT_FAILURE);
  2055. }
  2056. #endif
  2057. push(B_reg);
  2058. C_stack = stack;
  2059. A_reg = f1(qenv(B_reg), A_reg);
  2060. nil = C_nil;
  2061. if (exception_pending()) goto stack_apply_error;
  2062. stack = C_stack;
  2063. popv(1);
  2064. restore_pc();
  2065. continue;
  2066. }
  2067. push(A_reg);
  2068. C_stack = stack;
  2069. A_reg = apply(B_reg, 1, nil, B_reg);
  2070. nil = C_nil;
  2071. if (exception_pending()) goto apply_error;
  2072. stack = C_stack;
  2073. restore_pc();
  2074. continue;
  2075. case OP_APPLY2:
  2076. save_pc();
  2077. r2 = *stack;
  2078. if (is_symbol(r2)) /* can optimise this case, I guess */
  2079. { f2 = qfn2(r2);
  2080. #ifdef DEBUG
  2081. if (f2 == NULL)
  2082. { term_printf("Illegal function\n");
  2083. my_exit(EXIT_FAILURE);
  2084. }
  2085. #endif
  2086. C_stack = stack;
  2087. A_reg = f2(qenv(r2), B_reg, A_reg);
  2088. nil = C_nil;
  2089. if (exception_pending()) goto stack_apply_error;
  2090. stack = C_stack;
  2091. popv(1);
  2092. restore_pc();
  2093. continue;
  2094. }
  2095. *stack = B_reg;
  2096. push(A_reg);
  2097. C_stack = stack;
  2098. A_reg = apply(r2, 2, nil, r2);
  2099. nil = C_nil;
  2100. if (exception_pending()) goto apply_error;
  2101. stack = C_stack;
  2102. restore_pc();
  2103. continue;
  2104. case OP_APPLY3:
  2105. save_pc();
  2106. pop(r1);
  2107. r2 = *stack;
  2108. if (is_symbol(r2)) /* can optimise this case, I guess */
  2109. { f345 = qfnn(r2);
  2110. #ifdef DEBUG
  2111. if (f345 == NULL)
  2112. { term_printf("Illegal function\n");
  2113. my_exit(EXIT_FAILURE);
  2114. }
  2115. #endif
  2116. C_stack = stack;
  2117. A_reg = f345(qenv(r2), 3, r1, B_reg, A_reg);
  2118. nil = C_nil;
  2119. if (exception_pending()) goto stack_apply_error;
  2120. stack = C_stack;
  2121. popv(1);
  2122. restore_pc();
  2123. continue;
  2124. }
  2125. *stack = r1;
  2126. push2(B_reg, A_reg);
  2127. C_stack = stack;
  2128. A_reg = apply(r2, 3, nil, r2);
  2129. nil = C_nil;
  2130. if (exception_pending()) goto apply_error;
  2131. stack = C_stack;
  2132. restore_pc();
  2133. continue;
  2134. case OP_APPLY4:
  2135. /*
  2136. * It is not yet clear that APPLY4 is important enough to justify the
  2137. * mess it would involve here...
  2138. */
  2139. err_printf("\nAPPLY4 not implemented yet\n");
  2140. aerror("unfinished work in bytes1.c");
  2141. nil = C_nil;
  2142. C_stack = stack;
  2143. goto error_exit;
  2144. #ifdef COMMON
  2145. #define EQUAL cl_equal
  2146. #else
  2147. #define EQUAL equal
  2148. #endif
  2149. case OP_EQUAL: /* A = equal(B, A) */
  2150. A_reg = EQUAL(B_reg, A_reg) ? lisp_true : nil;
  2151. nil = C_nil;
  2152. if (exception_pending()) goto error_exit;
  2153. #ifdef COMMON
  2154. exit_count = 1;
  2155. #endif
  2156. continue;
  2157. case OP_EQ: /* A = eq(B, A) */
  2158. if (A_reg == B_reg) A_reg = lisp_true;
  2159. else A_reg = nil;
  2160. #ifdef COMMON
  2161. exit_count = 1;
  2162. #endif
  2163. continue;
  2164. case OP_NUMBERP: /* A = numberp(A) */
  2165. A_reg = Lispify_predicate(is_number(A_reg));
  2166. #ifdef COMMON
  2167. exit_count = 1;
  2168. #endif
  2169. continue;
  2170. case OP_QGETV: /* A_reg = getv(B_reg, A_reg) */
  2171. /*
  2172. * Note - this is an UNCHECKED vector access, used when carcheck(nil) has
  2173. * been selected because the user prefers speed to security. This is in
  2174. * here because the Reduce factoriser test uses getv VERY heavily indeed
  2175. * and both use of a special opcode here and removal of the checking make
  2176. * noticable differences to performance.
  2177. */
  2178. A_reg = *(Lisp_Object *)(
  2179. (char *)B_reg +
  2180. (CELL - TAG_VECTOR) +
  2181. (CELL*int_of_fixnum(A_reg)));
  2182. #ifdef COMMON
  2183. exit_count = 1;
  2184. #endif
  2185. continue;
  2186. case OP_GETV: /* A_reg = getv(B_reg, A_reg) */
  2187. #ifndef OUT_OF_LINE
  2188. if (!(is_vector(B_reg)) ||
  2189. vector_holds_binary(k = vechdr(B_reg)))
  2190. { aerror1("getv", B_reg);
  2191. nil = C_nil;
  2192. goto error_exit;
  2193. }
  2194. else if (!is_fixnum(A_reg))
  2195. { aerror1("getv offset not fixnum", A_reg);
  2196. nil = C_nil;
  2197. goto error_exit;
  2198. }
  2199. k = (length_of_header(k) - CELL)/CELL;
  2200. n = int_of_fixnum(A_reg);
  2201. if (n < 0 || n >= k)
  2202. { aerror1("getv index range", A_reg);
  2203. nil = C_nil;
  2204. goto error_exit;
  2205. }
  2206. A_reg = *(Lisp_Object *)(
  2207. (char *)B_reg +
  2208. (CELL - TAG_VECTOR) +
  2209. CELL*int_of_fixnum(A_reg));
  2210. #else
  2211. save_pc();
  2212. C_stack = stack;
  2213. A_reg = Lgetv(nil, B_reg, A_reg);
  2214. nil = C_nil;
  2215. if (exception_pending()) goto error_exit;
  2216. stack = C_stack; /* may have been changed by GC */
  2217. restore_pc();
  2218. #endif
  2219. #ifdef COMMON
  2220. exit_count = 1;
  2221. #endif
  2222. continue;
  2223. case OP_QGETVN: /* A_reg = getv(A_reg, n) */
  2224. /*
  2225. * Note - this is an UNCHECKED vector access, and only applicable to simple
  2226. * vectors that hold general Lisp data. The offset is passed in the
  2227. * byte stream. It is expected that it will help with code that passes
  2228. * around vectors of guff and use (getv vvv 0) etc (aka svref) to
  2229. * grab stuff out.
  2230. */
  2231. A_reg = *(Lisp_Object *)(
  2232. (char *)A_reg + (CELL - TAG_VECTOR) + (CELL*(next_byte)));
  2233. #ifdef COMMON
  2234. exit_count = 1;
  2235. #endif
  2236. continue;
  2237. case OP_EQCAR:
  2238. if (car_legal(B_reg) && A_reg == qcar(B_reg)) A_reg = lisp_true;
  2239. else A_reg = nil;
  2240. #ifdef COMMON
  2241. exit_count = 1;
  2242. #endif
  2243. continue;
  2244. case OP_LENGTH:
  2245. save_pc();
  2246. C_stack = stack;
  2247. A_reg = Llength(nil, A_reg);
  2248. nil = C_nil;
  2249. if (exception_pending()) goto error_exit;
  2250. stack = C_stack;
  2251. restore_pc();
  2252. #ifdef COMMON
  2253. exit_count = 1;
  2254. #endif
  2255. continue;
  2256. /*
  2257. * The following combinations feel a little odd, but ONE of them showed up
  2258. * very clearly in REDUCE tests, and adding the other few seems liable
  2259. * (on sentiment, not measurement!) to make reasonable sense.
  2260. */
  2261. case OP_LOC0LOC1:
  2262. B_reg = stack[-0];
  2263. A_reg = stack[-1];
  2264. #ifdef COMMON
  2265. exit_count = 1;
  2266. #endif
  2267. continue;
  2268. case OP_LOC1LOC2:
  2269. B_reg = stack[-1];
  2270. A_reg = stack[-2];
  2271. #ifdef COMMON
  2272. exit_count = 1;
  2273. #endif
  2274. continue;
  2275. case OP_LOC2LOC3:
  2276. B_reg = stack[-2];
  2277. A_reg = stack[-3];
  2278. #ifdef COMMON
  2279. exit_count = 1;
  2280. #endif
  2281. continue;
  2282. case OP_LOC1LOC0:
  2283. B_reg = stack[-1];
  2284. A_reg = stack[-0];
  2285. #ifdef COMMON
  2286. exit_count = 1;
  2287. #endif
  2288. continue;
  2289. case OP_LOC2LOC1:
  2290. B_reg = stack[-2];
  2291. A_reg = stack[-1];
  2292. #ifdef COMMON
  2293. exit_count = 1;
  2294. #endif
  2295. continue;
  2296. case OP_LOC3LOC2:
  2297. B_reg = stack[-3];
  2298. A_reg = stack[-2];
  2299. #ifdef COMMON
  2300. exit_count = 1;
  2301. #endif
  2302. continue;
  2303. case OP_CDRLOC0:
  2304. B_reg = A_reg;
  2305. A_reg = stack[-0];
  2306. if (car_legal(A_reg))
  2307. { A_reg = qcdr(A_reg);
  2308. #ifdef COMMON
  2309. exit_count = 1;
  2310. #endif
  2311. continue;
  2312. }
  2313. errcode = err_bad_cdr;
  2314. C_stack = stack;
  2315. goto error_1_A;
  2316. case OP_CDRLOC1:
  2317. B_reg = A_reg;
  2318. A_reg = stack[-1];
  2319. if (car_legal(A_reg))
  2320. { A_reg = qcdr(A_reg);
  2321. #ifdef COMMON
  2322. exit_count = 1;
  2323. #endif
  2324. continue;
  2325. }
  2326. errcode = err_bad_cdr;
  2327. C_stack = stack;
  2328. goto error_1_A;
  2329. case OP_CDRLOC2:
  2330. B_reg = A_reg;
  2331. A_reg = stack[-2];
  2332. if (car_legal(A_reg))
  2333. { A_reg = qcdr(A_reg);
  2334. #ifdef COMMON
  2335. exit_count = 1;
  2336. #endif
  2337. continue;
  2338. }
  2339. errcode = err_bad_cdr;
  2340. C_stack = stack;
  2341. goto error_1_A;
  2342. case OP_CDRLOC3:
  2343. B_reg = A_reg;
  2344. A_reg = stack[-3];
  2345. if (car_legal(A_reg))
  2346. { A_reg = qcdr(A_reg);
  2347. #ifdef COMMON
  2348. exit_count = 1;
  2349. #endif
  2350. continue;
  2351. }
  2352. errcode = err_bad_cdr;
  2353. C_stack = stack;
  2354. goto error_1_A;
  2355. case OP_CDRLOC4:
  2356. B_reg = A_reg;
  2357. A_reg = stack[-4];
  2358. if (car_legal(A_reg))
  2359. { A_reg = qcdr(A_reg);
  2360. #ifdef COMMON
  2361. exit_count = 1;
  2362. #endif
  2363. continue;
  2364. }
  2365. errcode = err_bad_cdr;
  2366. C_stack = stack;
  2367. goto error_1_A;
  2368. case OP_CDRLOC5:
  2369. B_reg = A_reg;
  2370. A_reg = stack[-5];
  2371. if (car_legal(A_reg))
  2372. { A_reg = qcdr(A_reg);
  2373. #ifdef COMMON
  2374. exit_count = 1;
  2375. #endif
  2376. continue;
  2377. }
  2378. errcode = err_bad_cdr;
  2379. C_stack = stack;
  2380. goto error_1_A;
  2381. case OP_CAARLOC0:
  2382. B_reg = A_reg;
  2383. A_reg = stack[-0];
  2384. goto caar;
  2385. case OP_CAARLOC1:
  2386. B_reg = A_reg;
  2387. A_reg = stack[-1];
  2388. goto caar;
  2389. case OP_CAARLOC2:
  2390. B_reg = A_reg;
  2391. A_reg = stack[-2];
  2392. goto caar;
  2393. case OP_CAARLOC3:
  2394. B_reg = A_reg;
  2395. A_reg = stack[-3];
  2396. goto caar;
  2397. case OP_CAAR:
  2398. goto caar;
  2399. case OP_CADR:
  2400. if (car_legal(A_reg)) A_reg = qcdr(A_reg);
  2401. else
  2402. { errcode = err_bad_cdr;
  2403. C_stack = stack;
  2404. goto error_1_A;
  2405. }
  2406. if (car_legal(A_reg))
  2407. { A_reg = qcar(A_reg);
  2408. #ifdef COMMON
  2409. exit_count = 1;
  2410. #endif
  2411. continue;
  2412. }
  2413. errcode = err_bad_car;
  2414. C_stack = stack;
  2415. goto error_1_A;
  2416. case OP_CDAR:
  2417. if (car_legal(A_reg)) A_reg = qcar(A_reg);
  2418. else
  2419. { errcode = err_bad_car;
  2420. C_stack = stack;
  2421. goto error_1_A;
  2422. }
  2423. if (car_legal(A_reg))
  2424. { A_reg = qcdr(A_reg);
  2425. #ifdef COMMON
  2426. exit_count = 1;
  2427. #endif
  2428. continue;
  2429. }
  2430. errcode = err_bad_cdr;
  2431. C_stack = stack;
  2432. goto error_1_A;
  2433. case OP_CDDR:
  2434. if (car_legal(A_reg)) A_reg = qcdr(A_reg);
  2435. else
  2436. { errcode = err_bad_cdr;
  2437. C_stack = stack;
  2438. goto error_1_A;
  2439. }
  2440. if (car_legal(A_reg))
  2441. { A_reg = qcdr(A_reg);
  2442. #ifdef COMMON
  2443. exit_count = 1;
  2444. #endif
  2445. continue;
  2446. }
  2447. errcode = err_bad_cdr;
  2448. C_stack = stack;
  2449. goto error_1_A;
  2450. /*
  2451. * The ICASE opcode is followed by a byte (n say) that indicates the number
  2452. * of cases that follow, followed by n+1 double-byte label values.
  2453. * If these addresses are called L<dflt>, L<0>, L<1>, ... L<n-1> then if the
  2454. * A register contains an integer in the range 0 <= k < n then control is
  2455. * transferred to L<k>, while if the A register does not hold an integer or
  2456. * if its value is out of range then control goes to L<dflt>.
  2457. */
  2458. case OP_ICASE:
  2459. w = next_byte;
  2460. if (is_fixnum(A_reg) &&
  2461. (n = int_of_fixnum(A_reg)) >= 0 &&
  2462. n < (int)w) ppc += 2*n + 2;
  2463. w = next_byte;
  2464. /*
  2465. * I support backwards jumps here by setting their top bit. At present I do
  2466. * poll for interrupts on a backwards case-branch. And the encoding used means
  2467. * that case branches can not reach quite as far as regular jumps.
  2468. */
  2469. if (w & 0x80) ppc = ppc - (((w & 0x7f) << 8) + *ppc);
  2470. else ppc = ppc + (w << 8) + *ppc;
  2471. continue;
  2472. /*
  2473. * There are a bunch of special-case jumps here - they are only
  2474. * provided with the variants that jump forwards by small offsets,
  2475. * but are expected to pick up a useful number of cases (for both speed and
  2476. * compactness) all the same.
  2477. */
  2478. case OP_JUMPL0NIL:
  2479. xppc = ppc;
  2480. ppc++;
  2481. if (stack[0] == nil) ppc = ppc + *xppc;
  2482. continue;
  2483. case OP_JUMPL0T:
  2484. xppc = ppc;
  2485. ppc++;
  2486. if (stack[0] != nil) ppc = ppc + *xppc;
  2487. continue;
  2488. case OP_JUMPL1NIL:
  2489. xppc = ppc;
  2490. ppc++;
  2491. if (stack[-1] == nil) ppc = ppc + *xppc;
  2492. continue;
  2493. case OP_JUMPL1T:
  2494. xppc = ppc;
  2495. ppc++;
  2496. if (stack[-1] != nil) ppc = ppc + *xppc;
  2497. continue;
  2498. case OP_JUMPL2NIL:
  2499. xppc = ppc;
  2500. ppc++;
  2501. if (stack[-2] == nil) ppc = ppc + *xppc;
  2502. continue;
  2503. case OP_JUMPL2T:
  2504. xppc = ppc;
  2505. ppc++;
  2506. if (stack[-2] != nil) ppc = ppc + *xppc;
  2507. continue;
  2508. case OP_JUMPL3NIL:
  2509. xppc = ppc;
  2510. ppc++;
  2511. if (stack[-3] == nil) ppc = ppc + *xppc;
  2512. continue;
  2513. case OP_JUMPL3T:
  2514. xppc = ppc;
  2515. ppc++;
  2516. if (stack[-3] != nil) ppc = ppc + *xppc;
  2517. continue;
  2518. case OP_JUMPL4NIL:
  2519. xppc = ppc;
  2520. ppc++;
  2521. if (stack[-4] == nil) ppc = ppc + *xppc;
  2522. continue;
  2523. case OP_JUMPL4T:
  2524. xppc = ppc;
  2525. ppc++;
  2526. if (stack[-4] != nil) ppc = ppc + *xppc;
  2527. continue;
  2528. case OP_JUMPL0ATOM:
  2529. xppc = ppc;
  2530. ppc++;
  2531. if (!consp(stack[0])) ppc = ppc + *xppc;
  2532. continue;
  2533. case OP_JUMPL0NATOM:
  2534. xppc = ppc;
  2535. ppc++;
  2536. if (consp(stack[0])) ppc = ppc + *xppc;
  2537. continue;
  2538. case OP_JUMPL1ATOM:
  2539. xppc = ppc;
  2540. ppc++;
  2541. if (!consp(stack[-1])) ppc = ppc + *xppc;
  2542. continue;
  2543. case OP_JUMPL1NATOM:
  2544. xppc = ppc;
  2545. ppc++;
  2546. if (consp(stack[-1])) ppc = ppc + *xppc;
  2547. continue;
  2548. case OP_JUMPL2ATOM:
  2549. xppc = ppc;
  2550. ppc++;
  2551. if (!consp(stack[-2])) ppc = ppc + *xppc;
  2552. continue;
  2553. case OP_JUMPL2NATOM:
  2554. xppc = ppc;
  2555. ppc++;
  2556. if (consp(stack[-2])) ppc = ppc + *xppc;
  2557. continue;
  2558. case OP_JUMPL3ATOM:
  2559. xppc = ppc;
  2560. ppc++;
  2561. if (!consp(stack[-3])) ppc = ppc + *xppc;
  2562. continue;
  2563. case OP_JUMPL3NATOM:
  2564. xppc = ppc;
  2565. ppc++;
  2566. if (consp(stack[-3])) ppc = ppc + *xppc;
  2567. continue;
  2568. case OP_JUMPST0NIL:
  2569. xppc = ppc;
  2570. ppc++;
  2571. if ((stack[0] = A_reg) == nil) ppc = ppc + *xppc;
  2572. continue;
  2573. case OP_JUMPST0T:
  2574. xppc = ppc;
  2575. ppc++;
  2576. if ((stack[0] = A_reg) != nil) ppc = ppc + *xppc;
  2577. continue;
  2578. case OP_JUMPST1NIL:
  2579. xppc = ppc;
  2580. ppc++;
  2581. if ((stack[-1] = A_reg) == nil) ppc = ppc + *xppc;
  2582. continue;
  2583. case OP_JUMPST1T:
  2584. xppc = ppc;
  2585. ppc++;
  2586. if ((stack[-1] = A_reg) != nil) ppc = ppc + *xppc;
  2587. continue;
  2588. case OP_JUMPST2NIL:
  2589. xppc = ppc;
  2590. ppc++;
  2591. if ((stack[-2] = A_reg) == nil) ppc = ppc + *xppc;
  2592. continue;
  2593. case OP_JUMPST2T:
  2594. xppc = ppc;
  2595. ppc++;
  2596. if ((stack[-2] = A_reg) != nil) ppc = ppc + *xppc;
  2597. continue;
  2598. case OP_JUMPFREE1NIL:
  2599. xppc = ppc;
  2600. ppc++;
  2601. if (qvalue(elt(litvec, 1)) == nil) ppc = ppc + *xppc;
  2602. continue;
  2603. case OP_JUMPFREE1T:
  2604. xppc = ppc;
  2605. ppc++;
  2606. if (qvalue(elt(litvec, 1)) != nil) ppc = ppc + *xppc;
  2607. continue;
  2608. case OP_JUMPFREE2NIL:
  2609. xppc = ppc;
  2610. ppc++;
  2611. if (qvalue(elt(litvec, 2)) == nil) ppc = ppc + *xppc;
  2612. continue;
  2613. case OP_JUMPFREE2T:
  2614. xppc = ppc;
  2615. ppc++;
  2616. if (qvalue(elt(litvec, 2)) != nil) ppc = ppc + *xppc;
  2617. continue;
  2618. case OP_JUMPFREE3NIL:
  2619. xppc = ppc;
  2620. ppc++;
  2621. if (qvalue(elt(litvec, 3)) == nil) ppc = ppc + *xppc;
  2622. continue;
  2623. case OP_JUMPFREE3T:
  2624. xppc = ppc;
  2625. ppc++;
  2626. if (qvalue(elt(litvec, 3)) != nil) ppc = ppc + *xppc;
  2627. continue;
  2628. case OP_JUMPFREE4NIL:
  2629. xppc = ppc;
  2630. ppc++;
  2631. if (qvalue(elt(litvec, 4)) == nil) ppc = ppc + *xppc;
  2632. continue;
  2633. case OP_JUMPFREE4T:
  2634. xppc = ppc;
  2635. ppc++;
  2636. if (qvalue(elt(litvec, 4)) != nil) ppc = ppc + *xppc;
  2637. continue;
  2638. case OP_JUMPLIT1EQ:
  2639. xppc = ppc;
  2640. ppc++;
  2641. if (elt(litvec, 1) == A_reg) ppc = ppc + *xppc;
  2642. continue;
  2643. case OP_JUMPLIT1NE:
  2644. xppc = ppc;
  2645. ppc++;
  2646. if (elt(litvec, 1) != A_reg) ppc = ppc + *xppc;
  2647. continue;
  2648. case OP_JUMPLIT2EQ:
  2649. xppc = ppc;
  2650. ppc++;
  2651. if (elt(litvec, 2) == A_reg) ppc = ppc + *xppc;
  2652. continue;
  2653. case OP_JUMPLIT2NE:
  2654. xppc = ppc;
  2655. ppc++;
  2656. if (elt(litvec, 2) != A_reg) ppc = ppc + *xppc;
  2657. continue;
  2658. case OP_JUMPLIT3EQ:
  2659. xppc = ppc;
  2660. ppc++;
  2661. if (elt(litvec, 3) == A_reg) ppc = ppc + *xppc;
  2662. continue;
  2663. case OP_JUMPLIT3NE:
  2664. xppc = ppc;
  2665. ppc++;
  2666. if (elt(litvec, 3) != A_reg) ppc = ppc + *xppc;
  2667. continue;
  2668. case OP_JUMPLIT4EQ:
  2669. xppc = ppc;
  2670. ppc++;
  2671. if (elt(litvec, 4) == A_reg) ppc = ppc + *xppc;
  2672. continue;
  2673. case OP_JUMPLIT4NE:
  2674. xppc = ppc;
  2675. ppc++;
  2676. if (elt(litvec, 4) != A_reg) ppc = ppc + *xppc;
  2677. continue;
  2678. case OP_JUMPFREENIL:
  2679. w = next_byte;
  2680. xppc = ppc;
  2681. ppc++;
  2682. if (qvalue(elt(litvec, w)) == nil) ppc = ppc + *xppc;
  2683. continue;
  2684. case OP_JUMPFREET:
  2685. w = next_byte;
  2686. xppc = ppc;
  2687. ppc++;
  2688. if (qvalue(elt(litvec, w)) != nil) ppc = ppc + *xppc;
  2689. continue;
  2690. case OP_JUMPLITEQ:
  2691. w = next_byte;
  2692. xppc = ppc;
  2693. ppc++;
  2694. if (elt(litvec, w) == A_reg) ppc = ppc + *xppc;
  2695. continue;
  2696. case OP_JUMPLITNE:
  2697. w = next_byte;
  2698. xppc = ppc;
  2699. ppc++;
  2700. if (elt(litvec, w) != A_reg) ppc = ppc + *xppc;
  2701. continue;
  2702. case OP_JUMPB1NIL:
  2703. f1 = one_arg_functions[next_byte];
  2704. save_pc();
  2705. C_stack = stack;
  2706. A_reg = f1(nil, A_reg);
  2707. nil = C_nil;
  2708. if (exception_pending()) goto call_error_exit;
  2709. stack = C_stack;
  2710. restore_pc();
  2711. xppc = ppc;
  2712. ppc++;
  2713. if (A_reg == nil) ppc = ppc + *xppc;
  2714. continue;
  2715. case OP_JUMPB1T:
  2716. f1 = one_arg_functions[next_byte];
  2717. save_pc();
  2718. C_stack = stack;
  2719. A_reg = f1(nil, A_reg);
  2720. nil = C_nil;
  2721. if (exception_pending()) goto call_error_exit;
  2722. stack = C_stack;
  2723. restore_pc();
  2724. xppc = ppc;
  2725. ppc++;
  2726. if (A_reg != nil) ppc = ppc + *xppc;
  2727. continue;
  2728. case OP_JUMPB2NIL:
  2729. f2 = two_arg_functions[next_byte];
  2730. save_pc();
  2731. C_stack = stack;
  2732. A_reg = f2(nil, B_reg, A_reg);
  2733. nil = C_nil;
  2734. if (exception_pending()) goto error_exit;
  2735. stack = C_stack;
  2736. restore_pc();
  2737. xppc = ppc;
  2738. ppc++;
  2739. if (A_reg == nil) ppc = ppc + *xppc;
  2740. continue;
  2741. case OP_JUMPB2T:
  2742. f2 = two_arg_functions[next_byte];
  2743. save_pc();
  2744. C_stack = stack;
  2745. A_reg = f2(nil, B_reg, A_reg);
  2746. nil = C_nil;
  2747. if (exception_pending()) goto error_exit;
  2748. stack = C_stack;
  2749. restore_pc();
  2750. xppc = ppc;
  2751. ppc++;
  2752. if (A_reg != nil) ppc = ppc + *xppc;
  2753. continue;
  2754. case OP_JUMPEQCAR: /* jump if eqcar(A, <some literal>) */
  2755. w = next_byte;
  2756. xppc = ppc;
  2757. ppc++;
  2758. if (car_legal(A_reg) &&
  2759. elt(litvec, w) == qcar(A_reg)) ppc = ppc + *xppc;
  2760. continue;
  2761. case OP_JUMPNEQCAR:
  2762. w = next_byte;
  2763. xppc = ppc;
  2764. ppc++;
  2765. if (!car_legal(A_reg) ||
  2766. elt(litvec, w) != qcar(A_reg)) ppc = ppc + *xppc;
  2767. continue;
  2768. case OP_JUMPFLAGP:
  2769. w = next_byte;
  2770. xppc = ppc;
  2771. ppc++;
  2772. if (!symbolp(A_reg)) continue;
  2773. else
  2774. #ifdef COMMON
  2775. { save_pc(); C_stack = stack;
  2776. r1 = get(A_reg, elt(litvec, w), unset_var);
  2777. nil = C_nil;
  2778. if (exception_pending()) goto error_exit;
  2779. stack = C_stack; restore_pc();
  2780. if (r1 != unset_var) ppc = ppc + *xppc;
  2781. continue;
  2782. }
  2783. #else
  2784. #ifndef OUT_OF_LINE
  2785. B_reg = elt(litvec, w);
  2786. if (symbolp(B_reg) &&
  2787. (n = header_fastget(qheader(B_reg))) != 0)
  2788. { r1 = qfastgets(A_reg);
  2789. if (r1 == nil)
  2790. {
  2791. #ifdef RECORD_GET
  2792. save_pc(); C_stack = stack;
  2793. record_get(B_reg, NO);
  2794. nil = C_nil;
  2795. if (exception_pending()) goto error_exit;
  2796. stack = C_stack; restore_pc();
  2797. #endif
  2798. continue;
  2799. }
  2800. r1 = elt(r1, n-1);
  2801. #ifdef RECORD_GET
  2802. push(r1);
  2803. save_pc(); C_stack = stack;
  2804. record_get(B_reg, r1 != SPID_NOPROP);
  2805. nil = C_nil;
  2806. if (exception_pending()) goto error_exit;
  2807. stack = C_stack; restore_pc();
  2808. pop(r1);
  2809. #endif
  2810. if (r1 != SPID_NOPROP) ppc = ppc + *xppc;
  2811. continue;
  2812. }
  2813. r1 = qplist(A_reg);
  2814. if (r1 == nil)
  2815. {
  2816. #ifdef RECORD_GET
  2817. save_pc(); C_stack = stack;
  2818. record_get(B_reg, NO);
  2819. nil = C_nil;
  2820. if (exception_pending()) goto error_exit;
  2821. stack = C_stack; restore_pc();
  2822. #endif
  2823. continue;
  2824. }
  2825. r3 = qcar(r1);
  2826. if (qcar(r3) == B_reg)
  2827. { ppc = ppc + *xppc;
  2828. #ifdef RECORD_GET
  2829. save_pc(); C_stack = stack;
  2830. record_get(B_reg, YES);
  2831. nil = C_nil;
  2832. if (exception_pending()) goto error_exit;
  2833. stack = C_stack; restore_pc();
  2834. #endif
  2835. continue;
  2836. }
  2837. r1 = qcdr(r1);
  2838. if (r1 == nil)
  2839. {
  2840. #ifdef RECORD_GET
  2841. save_pc(); C_stack = stack;
  2842. record_get(B_reg, NO);
  2843. nil = C_nil;
  2844. if (exception_pending()) goto error_exit;
  2845. stack = C_stack; restore_pc();
  2846. #endif
  2847. continue;
  2848. }
  2849. r3 = qcar(r1);
  2850. if (qcar(r3) == B_reg)
  2851. { ppc = ppc + *xppc;
  2852. #ifdef RECORD_GET
  2853. save_pc(); C_stack = stack;
  2854. record_get(B_reg, YES);
  2855. nil = C_nil;
  2856. if (exception_pending()) goto error_exit;
  2857. stack = C_stack; restore_pc();
  2858. #endif
  2859. continue;
  2860. }
  2861. r2 = r1;
  2862. r1 = qcdr(r1);
  2863. if (r1 == nil)
  2864. {
  2865. #ifdef RECORD_GET
  2866. save_pc(); C_stack = stack;
  2867. record_get(B_reg, NO);
  2868. nil = C_nil;
  2869. if (exception_pending()) goto error_exit;
  2870. stack = C_stack; restore_pc();
  2871. #endif
  2872. continue;
  2873. }
  2874. for (;;)
  2875. { r3 = qcar(r1);
  2876. if (qcar(r3) == B_reg)
  2877. { qcdr(r2) = qcdr(r1);
  2878. qcdr(r1) = qplist(A_reg);
  2879. qplist(A_reg) = r1;
  2880. ppc = ppc + *xppc;
  2881. #ifdef RECORD_GET
  2882. save_pc(); C_stack = stack;
  2883. record_get(B_reg, YES);
  2884. nil = C_nil;
  2885. if (exception_pending()) goto error_exit;
  2886. stack = C_stack; restore_pc();
  2887. #endif
  2888. break;
  2889. }
  2890. r2 = r1;
  2891. r1 = qcdr(r1);
  2892. if (r1 == nil)
  2893. {
  2894. #ifdef RECORD_GET
  2895. save_pc(); C_stack = stack;
  2896. record_get(B_reg, NO);
  2897. nil = C_nil;
  2898. if (exception_pending()) goto error_exit;
  2899. stack = C_stack; restore_pc();
  2900. #endif
  2901. break;
  2902. }
  2903. }
  2904. continue;
  2905. #else
  2906. r1 = Lflagp(nil, A_reg, elt(litvec, w));
  2907. nil = C_nil;
  2908. if (exception_pending()) goto error_exit;
  2909. if (r1 != nil) ppc = ppc + *xppc;
  2910. continue;
  2911. #endif
  2912. #endif
  2913. case OP_JUMPNFLAGP:
  2914. w = next_byte;
  2915. xppc = ppc;
  2916. ppc++;
  2917. if (!symbolp(A_reg))
  2918. { ppc = ppc + *xppc;
  2919. continue;
  2920. }
  2921. else
  2922. #ifdef COMMON
  2923. { save_pc(); C_stack = stack;
  2924. r1 = get(A_reg, elt(litvec, w), unset_var);
  2925. nil = C_nil;
  2926. if (exception_pending()) goto error_exit;
  2927. stack = C_stack; restore_pc();
  2928. if (r1 == unset_var) ppc = ppc + *xppc;
  2929. continue;
  2930. }
  2931. #else
  2932. #ifndef OUT_OF_LINE
  2933. B_reg = elt(litvec, w);
  2934. if (symbolp(B_reg) &&
  2935. (n = header_fastget(qheader(B_reg))) != 0)
  2936. { r1 = qfastgets(A_reg);
  2937. if (r1 == nil)
  2938. {
  2939. #ifdef RECORD_GET
  2940. save_pc(); C_stack = stack;
  2941. record_get(B_reg, NO);
  2942. nil = C_nil;
  2943. if (exception_pending()) goto error_exit;
  2944. stack = C_stack; restore_pc();
  2945. #endif
  2946. ppc = ppc + *xppc;
  2947. continue;
  2948. }
  2949. r1 = elt(r1, n-1);
  2950. #ifdef RECORD_GET
  2951. push(r1);
  2952. save_pc(); C_stack = stack;
  2953. record_get(B_reg, r1 != SPID_NOPROP);
  2954. nil = C_nil;
  2955. if (exception_pending()) goto error_exit;
  2956. stack = C_stack; restore_pc();
  2957. pop(r1);
  2958. #endif
  2959. if (r1 == SPID_NOPROP) ppc = ppc + *xppc;
  2960. continue;
  2961. }
  2962. r1 = qplist(A_reg);
  2963. if (r1 == nil)
  2964. { ppc = ppc + *xppc;
  2965. #ifdef RECORD_GET
  2966. save_pc(); C_stack = stack;
  2967. record_get(B_reg, NO);
  2968. nil = C_nil;
  2969. if (exception_pending()) goto error_exit;
  2970. stack = C_stack; restore_pc();
  2971. #endif
  2972. continue;
  2973. }
  2974. r3 = qcar(r1);
  2975. if (qcar(r3) == B_reg)
  2976. {
  2977. #ifdef RECORD_GET
  2978. save_pc(); C_stack = stack;
  2979. record_get(B_reg, YES);
  2980. nil = C_nil;
  2981. if (exception_pending()) goto error_exit;
  2982. stack = C_stack; restore_pc();
  2983. #endif
  2984. continue;
  2985. }
  2986. r1 = qcdr(r1);
  2987. if (r1 == nil)
  2988. { ppc = ppc + *xppc;
  2989. #ifdef RECORD_GET
  2990. save_pc(); C_stack = stack;
  2991. record_get(B_reg, NO);
  2992. nil = C_nil;
  2993. if (exception_pending()) goto error_exit;
  2994. stack = C_stack; restore_pc();
  2995. #endif
  2996. continue;
  2997. }
  2998. r3 = qcar(r1);
  2999. if (qcar(r3) == B_reg)
  3000. {
  3001. #ifdef RECORD_GET
  3002. save_pc(); C_stack = stack;
  3003. record_get(B_reg, YES);
  3004. nil = C_nil;
  3005. if (exception_pending()) goto error_exit;
  3006. stack = C_stack; restore_pc();
  3007. #endif
  3008. continue;
  3009. }
  3010. r2 = r1;
  3011. r1 = qcdr(r1);
  3012. if (r1 == nil)
  3013. { ppc = ppc + *xppc;
  3014. #ifdef RECORD_GET
  3015. save_pc(); C_stack = stack;
  3016. record_get(B_reg, NO);
  3017. nil = C_nil;
  3018. if (exception_pending()) goto error_exit;
  3019. stack = C_stack; restore_pc();
  3020. #endif
  3021. continue;
  3022. }
  3023. for (;;)
  3024. { r3 = qcar(r1);
  3025. if (qcar(r3) == B_reg)
  3026. { qcdr(r2) = qcdr(r1);
  3027. qcdr(r1) = qplist(A_reg);
  3028. qplist(A_reg) = r1;
  3029. #ifdef RECORD_GET
  3030. save_pc(); C_stack = stack;
  3031. record_get(B_reg, YES);
  3032. nil = C_nil;
  3033. if (exception_pending()) goto error_exit;
  3034. stack = C_stack; restore_pc();
  3035. #endif
  3036. break;
  3037. }
  3038. r2 = r1;
  3039. r1 = qcdr(r1);
  3040. if (r1 == nil)
  3041. { ppc = ppc + *xppc;
  3042. #ifdef RECORD_GET
  3043. save_pc(); C_stack = stack;
  3044. record_get(B_reg, NO);
  3045. nil = C_nil;
  3046. if (exception_pending()) goto error_exit;
  3047. stack = C_stack; restore_pc();
  3048. #endif
  3049. break;
  3050. }
  3051. }
  3052. continue;
  3053. #else
  3054. r1 = Lflagp(nil, A_reg, elt(litvec, w));
  3055. nil = C_nil;
  3056. if (exception_pending()) goto error_exit;
  3057. if (r1 == nil) ppc = ppc + *xppc;
  3058. continue;
  3059. #endif
  3060. #endif
  3061. /*
  3062. * Now the general jumps. Each has four variants - forwards and backwards
  3063. * and long and short offsets. Backwards jumps poll for interrupts so that
  3064. * all loops will be interruptible.
  3065. */
  3066. case OP_JUMPATOM:
  3067. xppc = ppc;
  3068. ppc++;
  3069. if (!consp(A_reg)) ppc = ppc + *xppc;
  3070. continue;
  3071. case OP_JUMPATOM_B:
  3072. xppc = ppc;
  3073. ppc++;
  3074. if (!consp(A_reg))
  3075. { ppc = ppc - *xppc;
  3076. #ifndef OUT_OF_LINE
  3077. #ifdef SOFTWARE_TICKS
  3078. if (--countdown < 0) deal_with_tick();
  3079. #endif
  3080. if (stack >= stacklimit)
  3081. { C_stack = stack;
  3082. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3083. nil = C_nil;
  3084. if (exception_pending()) goto error_exit;
  3085. stack = C_stack; /* may have been changed by GC */
  3086. }
  3087. #else
  3088. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3089. goto error_exit;
  3090. stack = C_stack;
  3091. #endif
  3092. }
  3093. continue;
  3094. case OP_JUMPNATOM:
  3095. xppc = ppc;
  3096. ppc++;
  3097. if (consp(A_reg)) ppc = ppc + *xppc;
  3098. continue;
  3099. case OP_JUMPNATOM_B:
  3100. xppc = ppc;
  3101. ppc++;
  3102. if (consp(A_reg))
  3103. { ppc = ppc - *xppc;
  3104. #ifndef OUT_OF_LINE
  3105. #ifdef SOFTWARE_TICKS
  3106. if (--countdown < 0) deal_with_tick();
  3107. #endif
  3108. if (stack >= stacklimit)
  3109. { C_stack = stack;
  3110. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3111. nil = C_nil;
  3112. if (exception_pending()) goto error_exit;
  3113. stack = C_stack; /* may have been changed by GC */
  3114. }
  3115. #else
  3116. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3117. goto error_exit;
  3118. stack = C_stack;
  3119. #endif
  3120. }
  3121. continue;
  3122. case OP_JUMPEQ:
  3123. xppc = ppc;
  3124. ppc++;
  3125. if (A_reg == B_reg) ppc = ppc + *xppc;
  3126. continue;
  3127. case OP_JUMPEQ_B:
  3128. xppc = ppc;
  3129. ppc++;
  3130. if (A_reg == B_reg)
  3131. { ppc = ppc - *xppc;
  3132. #ifndef OUT_OF_LINE
  3133. #ifdef SOFTWARE_TICKS
  3134. if (--countdown < 0) deal_with_tick();
  3135. #endif
  3136. if (stack >= stacklimit)
  3137. { C_stack = stack;
  3138. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3139. nil = C_nil;
  3140. if (exception_pending()) goto error_exit;
  3141. stack = C_stack; /* may have been changed by GC */
  3142. }
  3143. #else
  3144. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3145. goto error_exit;
  3146. stack = C_stack;
  3147. #endif
  3148. }
  3149. continue;
  3150. case OP_JUMPNE:
  3151. xppc = ppc;
  3152. ppc++;
  3153. if (A_reg != B_reg) ppc = ppc + *xppc;
  3154. continue;
  3155. case OP_JUMPNE_B:
  3156. xppc = ppc;
  3157. ppc++;
  3158. if (A_reg != B_reg)
  3159. { ppc = ppc - *xppc;
  3160. #ifndef OUT_OF_LINE
  3161. #ifdef SOFTWARE_TICKS
  3162. if (--countdown < 0) deal_with_tick();
  3163. #endif
  3164. if (stack >= stacklimit)
  3165. { C_stack = stack;
  3166. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3167. nil = C_nil;
  3168. if (exception_pending()) goto error_exit;
  3169. stack = C_stack; /* may have been changed by GC */
  3170. }
  3171. #else
  3172. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3173. goto error_exit;
  3174. stack = C_stack;
  3175. #endif
  3176. }
  3177. continue;
  3178. case OP_JUMPEQUAL:
  3179. xppc = ppc;
  3180. ppc++;
  3181. if (EQUAL(A_reg, B_reg)) ppc = ppc + *xppc;
  3182. continue;
  3183. case OP_JUMPEQUAL_B:
  3184. xppc = ppc;
  3185. ppc++;
  3186. if (EQUAL(A_reg, B_reg))
  3187. { ppc = ppc - *xppc;
  3188. #ifndef OUT_OF_LINE
  3189. #ifdef SOFTWARE_TICKS
  3190. if (--countdown < 0) deal_with_tick();
  3191. #endif
  3192. if (stack >= stacklimit)
  3193. { C_stack = stack;
  3194. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3195. nil = C_nil;
  3196. if (exception_pending()) goto error_exit;
  3197. stack = C_stack; /* may have been changed by GC */
  3198. }
  3199. #else
  3200. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3201. goto error_exit;
  3202. stack = C_stack;
  3203. #endif
  3204. }
  3205. continue;
  3206. case OP_JUMPNEQUAL:
  3207. xppc = ppc;
  3208. ppc++;
  3209. if (!EQUAL(A_reg, B_reg)) ppc = ppc + *xppc;
  3210. continue;
  3211. case OP_JUMPNEQUAL_B:
  3212. xppc = ppc;
  3213. ppc++;
  3214. if (!EQUAL(A_reg, B_reg))
  3215. { ppc = ppc - *xppc;
  3216. #ifndef OUT_OF_LINE
  3217. #ifdef SOFTWARE_TICKS
  3218. if (--countdown < 0) deal_with_tick();
  3219. #endif
  3220. if (stack >= stacklimit)
  3221. { C_stack = stack;
  3222. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3223. nil = C_nil;
  3224. if (exception_pending()) goto error_exit;
  3225. stack = C_stack; /* may have been changed by GC */
  3226. }
  3227. #else
  3228. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3229. goto error_exit;
  3230. stack = C_stack;
  3231. #endif
  3232. }
  3233. continue;
  3234. case OP_JUMP:
  3235. ppc = ppc + *ppc + 1;
  3236. continue;
  3237. case OP_JUMP_B:
  3238. ppc = ppc - *ppc + 1;
  3239. #ifndef OUT_OF_LINE
  3240. #ifdef SOFTWARE_TICKS
  3241. if (--countdown < 0) deal_with_tick();
  3242. #endif
  3243. if (stack >= stacklimit)
  3244. { C_stack = stack;
  3245. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3246. nil = C_nil;
  3247. if (exception_pending()) goto error_exit;
  3248. stack = C_stack; /* may have been changed by GC */
  3249. }
  3250. #else
  3251. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3252. goto error_exit;
  3253. stack = C_stack;
  3254. #endif
  3255. continue;
  3256. case OP_JUMPATOM_L:
  3257. w = next_byte;
  3258. xppc = ppc;
  3259. ppc++;
  3260. if (!consp(A_reg)) ppc = ppc + ((w << 8) + *xppc);
  3261. continue;
  3262. case OP_JUMPATOM_BL:
  3263. w = next_byte;
  3264. xppc = ppc;
  3265. ppc++;
  3266. if (!consp(A_reg))
  3267. { ppc = ppc - ((w << 8) + *xppc);
  3268. #ifndef OUT_OF_LINE
  3269. #ifdef SOFTWARE_TICKS
  3270. if (--countdown < 0) deal_with_tick();
  3271. #endif
  3272. if (stack >= stacklimit)
  3273. { C_stack = stack;
  3274. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3275. nil = C_nil;
  3276. if (exception_pending()) goto error_exit;
  3277. stack = C_stack; /* may have been changed by GC */
  3278. }
  3279. #else
  3280. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3281. goto error_exit;
  3282. stack = C_stack;
  3283. #endif
  3284. }
  3285. continue;
  3286. case OP_JUMPNATOM_L:
  3287. w = next_byte;
  3288. xppc = ppc;
  3289. ppc++;
  3290. if (consp(A_reg)) ppc = ppc + ((w << 8) + *xppc);
  3291. continue;
  3292. case OP_JUMPNATOM_BL:
  3293. w = next_byte;
  3294. xppc = ppc;
  3295. ppc++;
  3296. if (consp(A_reg))
  3297. { ppc = ppc - ((w << 8) + *xppc);
  3298. #ifndef OUT_OF_LINE
  3299. #ifdef SOFTWARE_TICKS
  3300. if (--countdown < 0) deal_with_tick();
  3301. #endif
  3302. if (stack >= stacklimit)
  3303. { C_stack = stack;
  3304. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3305. nil = C_nil;
  3306. if (exception_pending()) goto error_exit;
  3307. stack = C_stack; /* may have been changed by GC */
  3308. }
  3309. #else
  3310. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3311. goto error_exit;
  3312. stack = C_stack;
  3313. #endif
  3314. }
  3315. continue;
  3316. case OP_JUMPEQ_L:
  3317. w = next_byte;
  3318. xppc = ppc;
  3319. ppc++;
  3320. if (A_reg == B_reg) ppc = ppc + ((w << 8) + *xppc);
  3321. continue;
  3322. case OP_JUMPEQ_BL:
  3323. w = next_byte;
  3324. xppc = ppc;
  3325. ppc++;
  3326. if (A_reg == B_reg)
  3327. { ppc = ppc - ((w << 8) + *xppc);
  3328. #ifndef OUT_OF_LINE
  3329. #ifdef SOFTWARE_TICKS
  3330. if (--countdown < 0) deal_with_tick();
  3331. #endif
  3332. if (stack >= stacklimit)
  3333. { C_stack = stack;
  3334. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3335. nil = C_nil;
  3336. if (exception_pending()) goto error_exit;
  3337. stack = C_stack; /* may have been changed by GC */
  3338. }
  3339. #else
  3340. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3341. goto error_exit;
  3342. stack = C_stack;
  3343. #endif
  3344. }
  3345. continue;
  3346. case OP_JUMPNE_L:
  3347. w = next_byte;
  3348. xppc = ppc;
  3349. ppc++;
  3350. if (A_reg != B_reg) ppc = ppc + ((w << 8) + *xppc);
  3351. continue;
  3352. case OP_JUMPNE_BL:
  3353. w = next_byte;
  3354. xppc = ppc;
  3355. ppc++;
  3356. if (A_reg != B_reg)
  3357. { ppc = ppc - ((w << 8) + *xppc);
  3358. #ifndef OUT_OF_LINE
  3359. #ifdef SOFTWARE_TICKS
  3360. if (--countdown < 0) deal_with_tick();
  3361. #endif
  3362. if (stack >= stacklimit)
  3363. { C_stack = stack;
  3364. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3365. nil = C_nil;
  3366. if (exception_pending()) goto error_exit;
  3367. stack = C_stack; /* may have been changed by GC */
  3368. }
  3369. #else
  3370. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3371. goto error_exit;
  3372. stack = C_stack;
  3373. #endif
  3374. }
  3375. continue;
  3376. case OP_JUMPEQUAL_L:
  3377. w = next_byte;
  3378. xppc = ppc;
  3379. ppc++;
  3380. if (EQUAL(A_reg, B_reg))
  3381. ppc = ppc + ((w << 8) + *xppc);
  3382. continue;
  3383. case OP_JUMPEQUAL_BL:
  3384. w = next_byte;
  3385. xppc = ppc;
  3386. ppc++;
  3387. if (EQUAL(A_reg, B_reg))
  3388. { ppc = ppc - ((w << 8) + *xppc);
  3389. #ifndef OUT_OF_LINE
  3390. #ifdef SOFTWARE_TICKS
  3391. if (--countdown < 0) deal_with_tick();
  3392. #endif
  3393. if (stack >= stacklimit)
  3394. { C_stack = stack;
  3395. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3396. nil = C_nil;
  3397. if (exception_pending()) goto error_exit;
  3398. stack = C_stack; /* may have been changed by GC */
  3399. }
  3400. #else
  3401. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3402. goto error_exit;
  3403. stack = C_stack;
  3404. #endif
  3405. }
  3406. continue;
  3407. case OP_JUMPNEQUAL_L:
  3408. w = next_byte;
  3409. xppc = ppc;
  3410. ppc++;
  3411. if (!EQUAL(A_reg, B_reg))
  3412. ppc = ppc + ((w << 8) + *xppc);
  3413. continue;
  3414. case OP_JUMPNEQUAL_BL:
  3415. w = next_byte;
  3416. xppc = ppc;
  3417. ppc++;
  3418. if (!EQUAL(A_reg, B_reg))
  3419. { ppc = ppc - ((w << 8) + *xppc);
  3420. #ifndef OUT_OF_LINE
  3421. #ifdef SOFTWARE_TICKS
  3422. if (--countdown < 0) deal_with_tick();
  3423. #endif
  3424. if (stack >= stacklimit)
  3425. { C_stack = stack;
  3426. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3427. nil = C_nil;
  3428. if (exception_pending()) goto error_exit;
  3429. stack = C_stack; /* may have been changed by GC */
  3430. }
  3431. #else
  3432. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3433. goto error_exit;
  3434. stack = C_stack;
  3435. #endif
  3436. }
  3437. continue;
  3438. case OP_JUMP_L:
  3439. w = next_byte;
  3440. ppc = ppc + ((w << 8) + *ppc) + 1;
  3441. continue;
  3442. case OP_JUMP_BL:
  3443. w = next_byte;
  3444. ppc = ppc - ((w << 8) + *ppc) + 1;
  3445. #ifndef OUT_OF_LINE
  3446. #ifdef SOFTWARE_TICKS
  3447. if (--countdown < 0) deal_with_tick();
  3448. #endif
  3449. if (stack >= stacklimit)
  3450. { C_stack = stack;
  3451. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  3452. nil = C_nil;
  3453. if (exception_pending()) goto error_exit;
  3454. stack = C_stack; /* may have been changed by GC */
  3455. }
  3456. #else
  3457. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  3458. goto error_exit;
  3459. stack = C_stack;
  3460. #endif
  3461. continue;
  3462. case OP_CATCH:
  3463. w = (unsigned int)((ppc + *ppc) -
  3464. (unsigned char *)data_of_bps(codevec));
  3465. ppc++;
  3466. goto catcher;
  3467. case OP_CATCH_B:
  3468. w = (unsigned int)((ppc - *ppc) -
  3469. (unsigned char *)data_of_bps(codevec));
  3470. ppc++;
  3471. goto catcher;
  3472. case OP_CATCH_L:
  3473. w = next_byte;
  3474. w = (unsigned int)((ppc + (w << 8) + *ppc) -
  3475. (unsigned char *)data_of_bps(codevec));
  3476. ppc++;
  3477. goto catcher;
  3478. case OP_CATCH_BL:
  3479. w = next_byte;
  3480. w = (unsigned int)((ppc - ((w << 8) + *ppc)) -
  3481. (unsigned char *)data_of_bps(codevec));
  3482. ppc++;
  3483. goto catcher;
  3484. case OP_UNCATCH:
  3485. popv(1); pop(r1); popv(1);
  3486. catch_tags = qcdr(r1);
  3487. qcar(r1) = r1; qcdr(r1) = nil;
  3488. continue;
  3489. case OP_PROTECT:
  3490. /*
  3491. * This is used to support UNWIND-PROTECT.
  3492. * This needs to save A_reg, all the multiple-result registers,
  3493. * and the exit_count. Also something to indicate that there had not been
  3494. * an error.
  3495. */
  3496. popv(3);
  3497. #ifdef COMMON
  3498. A_reg = Lmv_list(nil, A_reg);
  3499. nil = C_nil;
  3500. if (exception_pending()) goto error_exit;
  3501. #endif
  3502. push3(nil, fixnum_of_int(UNWIND_NULL), A_reg);
  3503. continue;
  3504. case OP_UNPROTECT:
  3505. /*
  3506. * This must restore all the results (including exit_count). If the
  3507. * PROTECT had been done by an unwinding then exit_reason and exit_tag
  3508. * must also be restored, and the unwind condition must be re-instated.
  3509. */
  3510. pop3(A_reg, B_reg, exit_tag);
  3511. exit_reason = int_of_fixnum(B_reg);
  3512. #ifdef COMMON
  3513. /*
  3514. * Here I have multiple values to restore.
  3515. */
  3516. exit_count = 0;
  3517. B_reg = A_reg;
  3518. A_reg = nil;
  3519. if (consp(B_reg))
  3520. { A_reg = qcar(B_reg);
  3521. B_reg = qcdr(B_reg);
  3522. exit_count++;
  3523. while (consp(B_reg))
  3524. { (&mv_1)[exit_count++] = qcar(B_reg);
  3525. B_reg = qcdr(B_reg);
  3526. }
  3527. }
  3528. #endif
  3529. exit_value = A_reg;
  3530. if (exit_reason != UNWIND_NULL) goto pop_stack_and_exit;
  3531. continue;
  3532. case OP_THROW:
  3533. pop(r1); /* the tag to throw to */
  3534. for (r2 = catch_tags; r2!=nil; r2=qcdr(r2))
  3535. if (r1 == qcar(r2)) break;
  3536. if (r2==nil)
  3537. { aerror1("throw: tag not found", r1);
  3538. nil = C_nil;
  3539. goto error_exit;
  3540. }
  3541. catch_tags = qcdr(r2);
  3542. exit_tag = r2;
  3543. exit_value = A_reg;
  3544. exit_reason = UNWIND_THROW;
  3545. flip_exception();
  3546. /*
  3547. * NOTE WELL: this means that at error_exit (after all the possible cases
  3548. * where something I call returns with NIL marked) it is essential to check
  3549. * for THROW as well as just error returns.
  3550. */
  3551. goto error_exit;
  3552. /*
  3553. * I expect that calling functions with 0, 1, 2 or 3 arguments will
  3554. * be enormously important for Lisp, and so separate opcodes are provided
  3555. * for these cases. The operand in each case selects the function to be
  3556. * called, which MUST be a symbol (loaded from the literal vector),
  3557. * and arguments are taken from A and B as necessary. If several
  3558. * arguments are needed the first argument will be loaded first, and thus
  3559. * it is the LAST argument that end up in the A register.
  3560. */
  3561. case OP_CALL0_0: /* Calling myself... */
  3562. fname = 0;
  3563. goto call0;
  3564. case OP_CALL0_1:
  3565. fname = 1;
  3566. goto call0;
  3567. case OP_CALL0_2:
  3568. fname = 2;
  3569. goto call0;
  3570. case OP_CALL0_3:
  3571. fname = 3;
  3572. goto call0;
  3573. case OP_CALL0:
  3574. fname = next_byte;
  3575. goto call0;
  3576. case OP_JCALL:
  3577. /*
  3578. * This version has the number of args and the target packed into a
  3579. * single operand byte. JCALLN is functionally similar but allows
  3580. * for more extreme cases by using one byte to specify the target
  3581. * and another to give the number of arguments being passed.
  3582. */
  3583. w = next_byte;
  3584. fname = w & 0x1f;
  3585. w = (w >> 5) & 0x7;
  3586. switch (w)
  3587. {
  3588. case 0: goto jcall0;
  3589. case 1: goto jcall1;
  3590. case 2: goto jcall2;
  3591. case 3: goto jcall3;
  3592. default:goto jcalln;
  3593. }
  3594. case OP_JCALLN:
  3595. fname = next_byte;
  3596. w = next_byte;
  3597. switch (w)
  3598. {
  3599. case 0: goto jcall0;
  3600. case 1: goto jcall1;
  3601. case 2: goto jcall2;
  3602. case 3: goto jcall3;
  3603. default:goto jcalln;
  3604. }
  3605. case OP_BIGCALL:
  3606. /*
  3607. * This provides for calls (and a few other operations!) where the literal
  3608. * to be referenced is beyond position 256 in the literal vector. The
  3609. * encoding is that BIGCALL is followed by two bytes. The top half of the
  3610. * first of these is a sub opcode, while the remaining 12 bits provide
  3611. * support for literal vectors with up to 4096 elements. At present I
  3612. * will just not support code bigger than that. Note that if I were feeling
  3613. * keen here I could easily arrange that the 12-bit offset here started at
  3614. * 256 and went on upwards. But for simplicity in a first version I will
  3615. * leave a bit of redundancy.
  3616. */
  3617. w = next_byte;
  3618. fname = next_byte + ((w & 0xf) << 8);
  3619. switch (w >> 4)
  3620. {
  3621. case 0: goto call0;
  3622. case 1: goto call1;
  3623. case 2: goto call2;
  3624. case 3: goto call3;
  3625. case 4:
  3626. /*
  3627. * Here I write out a variant on the CALLN code.
  3628. */
  3629. push2(B_reg, A_reg);
  3630. save_pc();
  3631. C_stack = stack;
  3632. A_reg = elt(litvec, fname);
  3633. A_reg = apply(A_reg, (int)(*ppc), nil, A_reg);
  3634. nil = C_nil;
  3635. if (exception_pending()) goto ncall_error_exit;
  3636. stack = C_stack; /* args were popped by apply */
  3637. restore_pc();
  3638. ppc++;
  3639. continue;
  3640. case 5: goto call2r;
  3641. /*
  3642. * sub-opcodes 6 and 7 are use for LOADFREE and STOREFREE - this is a bit
  3643. * odd but fits the required operations tightly into the opcode map.
  3644. */
  3645. case 6:
  3646. B_reg = A_reg;
  3647. A_reg = qvalue(elt(litvec, fname));
  3648. #ifdef COMMON
  3649. exit_count = 1;
  3650. #endif
  3651. continue;
  3652. case 7:
  3653. qvalue(elt(litvec, fname)) = A_reg; /* store into special var */
  3654. continue;
  3655. case 8: goto jcall0;
  3656. case 9: goto jcall1;
  3657. case 10:goto jcall2;
  3658. case 11:goto jcall3;
  3659. /* The codes for big JCALLs take a further byte that give the number of args */
  3660. case 12:w = next_byte; goto jcalln;
  3661. /*
  3662. * Codes 13 and 14 do FREEBIND and LITGET, which completes the list of
  3663. * byte operations that access big literals.
  3664. */
  3665. case 13:stack = do_freebind(elt(litvec, fname), stack);
  3666. continue;
  3667. case 14:B_reg = A_reg;
  3668. A_reg = elt(litvec, fname);
  3669. goto perform_get;
  3670. /*
  3671. * Code 15 is LOADLIT with a long offset, which may be used as an alternative
  3672. * to the LOADLIT/QGETVN mechanism that I otherwise support.
  3673. */
  3674. case 15:B_reg = A_reg;
  3675. A_reg = elt(litvec, fname);
  3676. #ifdef COMMON
  3677. exit_count = 1;
  3678. #endif
  3679. continue;
  3680. }
  3681. case OP_CALL1_0:
  3682. /*
  3683. * Note that this is spotted and treated as a direct call to the
  3684. * current function (because offset zero in the literal vector is reserved
  3685. * for the name of the function). I can NOT avoid the overhead of stacking
  3686. * and restoring codevec and litvec here, even the values used in the called
  3687. * function are the same as the present ones, because the lower level call
  3688. * might itself do a JCALL and corrupt them! Also I know that the current
  3689. * function is bytecoded, so I avoid the overhead of (re-)discovering that.
  3690. */
  3691. push3(codevec, litvec, A_reg); /* the argument */
  3692. save_pc();
  3693. C_stack = stack;
  3694. #ifdef SOFTWARE_TICKS
  3695. if (--countdown < 0) deal_with_tick();
  3696. #endif
  3697. if (stack >= stacklimit)
  3698. { reclaim(nil, "stack", GC_STACK, 0);
  3699. nil = C_nil;
  3700. if (exception_pending()) goto callself_error_exit;
  3701. }
  3702. A_reg = bytestream_interpret(codevec-2, litvec, stack-1);
  3703. nil = C_nil;
  3704. if (exception_pending()) goto callself_error_exit;
  3705. stack = C_stack;
  3706. pop2(litvec, codevec);
  3707. restore_pc();
  3708. continue;
  3709. case OP_CALL1_1:
  3710. fname = 1;
  3711. goto call1;
  3712. case OP_CALL1_2:
  3713. fname = 2;
  3714. goto call1;
  3715. case OP_CALL1_3:
  3716. fname = 3;
  3717. goto call1;
  3718. case OP_CALL1_4:
  3719. fname = 4;
  3720. goto call1;
  3721. case OP_CALL1_5:
  3722. fname = 5;
  3723. goto call1;
  3724. case OP_CALL1:
  3725. fname = next_byte;
  3726. goto call1;
  3727. case OP_CALL2_0:
  3728. push4(codevec, litvec, B_reg, A_reg);
  3729. save_pc();
  3730. C_stack = stack;
  3731. #ifdef SOFTWARE_TICKS
  3732. if (--countdown < 0) deal_with_tick();
  3733. #endif
  3734. if (stack >= stacklimit)
  3735. { reclaim(nil, "stack", GC_STACK, 0);
  3736. nil = C_nil;
  3737. if (exception_pending()) goto callself_error_exit;
  3738. }
  3739. A_reg = bytestream_interpret(codevec-2, litvec, stack-2);
  3740. nil = C_nil;
  3741. if (exception_pending()) goto callself_error_exit;
  3742. stack = C_stack;
  3743. pop2(litvec, codevec);
  3744. restore_pc();
  3745. continue;
  3746. case OP_CALL2_1:
  3747. fname = 1;
  3748. goto call2;
  3749. case OP_CALL2_2:
  3750. fname = 2;
  3751. goto call2;
  3752. case OP_CALL2_3:
  3753. fname = 3;
  3754. goto call2;
  3755. case OP_CALL2_4:
  3756. fname = 4;
  3757. goto call2;
  3758. case OP_CALL2:
  3759. fname = next_byte;
  3760. goto call2;
  3761. case OP_CALL2R:
  3762. fname = next_byte;
  3763. goto call2r;
  3764. case OP_CALL3:
  3765. fname = next_byte;
  3766. goto call3;
  3767. case OP_CALLN:
  3768. /*
  3769. * Here the first post-byte indicates the function to be called,
  3770. * and the second is the number of args (>= 4) to be passed. All but the
  3771. * last two args have been pushed onto the stack already. The last two are
  3772. * in A and B.
  3773. */
  3774. push2(B_reg, A_reg);
  3775. save_pc();
  3776. C_stack = stack;
  3777. A_reg = elt(litvec, *ppc);
  3778. /*
  3779. * Note that I never need to call something with 0, 1, 2 or 3 args here.
  3780. */
  3781. A_reg = apply(A_reg, (int)(*(ppc+1)), nil, A_reg);
  3782. nil = C_nil;
  3783. if (exception_pending()) goto ncall_error_exit;
  3784. stack = C_stack; /* args were popped by apply */
  3785. restore_pc();
  3786. ppc = ppc + 2;
  3787. continue;
  3788. case OP_BUILTIN0:
  3789. f345 = zero_arg_functions[next_byte];
  3790. /* BUILTIN0: A=fn() */
  3791. save_pc();
  3792. C_stack = stack;
  3793. A_reg = f345(nil, 0);
  3794. nil = C_nil;
  3795. if (exception_pending()) goto error_exit;
  3796. stack = C_stack;
  3797. restore_pc();
  3798. continue;
  3799. case OP_BUILTIN2R:
  3800. f2 = two_arg_functions[next_byte];
  3801. /* BUILTIN2R: A=fn(A,B); NOTE arg order reversed */
  3802. save_pc();
  3803. C_stack = stack;
  3804. A_reg = f2(nil, A_reg, B_reg);
  3805. nil = C_nil;
  3806. if (exception_pending()) goto error_exit;
  3807. stack = C_stack;
  3808. restore_pc();
  3809. continue;
  3810. case OP_BUILTIN3:
  3811. f345 = three_arg_functions[next_byte];
  3812. /* CALL3: A=fn(pop(),B,A); */
  3813. save_pc();
  3814. pop(r1);
  3815. C_stack = stack;
  3816. A_reg = f345(nil, 3, r1, B_reg, A_reg);
  3817. nil = C_nil;
  3818. if (exception_pending()) goto error_exit;
  3819. stack = C_stack;
  3820. restore_pc();
  3821. continue;
  3822. /*
  3823. * Now here in a neat block I will have the cases that seem to occur most
  3824. * frequently, at least when I tested things running REDUCE. By collecting
  3825. * these together I hope to (slightly) improve the cache locality behaviour
  3826. * for this code - maybe...
  3827. */
  3828. case OP_LOADLOC:
  3829. B_reg = A_reg;
  3830. A_reg = stack[-(int)next_byte];
  3831. #ifdef COMMON
  3832. exit_count = 1;
  3833. #endif
  3834. continue;
  3835. case OP_LOADLOC0:
  3836. B_reg = A_reg;
  3837. A_reg = stack[-0];
  3838. #ifdef COMMON
  3839. exit_count = 1;
  3840. #endif
  3841. continue;
  3842. case OP_LOADLOC1:
  3843. B_reg = A_reg;
  3844. A_reg = stack[-1];
  3845. #ifdef COMMON
  3846. exit_count = 1;
  3847. #endif
  3848. continue;
  3849. case OP_LOADLOC2:
  3850. B_reg = A_reg;
  3851. A_reg = stack[-2];
  3852. #ifdef COMMON
  3853. exit_count = 1;
  3854. #endif
  3855. continue;
  3856. case OP_LOADLOC3:
  3857. B_reg = A_reg;
  3858. A_reg = stack[-3];
  3859. #ifdef COMMON
  3860. exit_count = 1;
  3861. #endif
  3862. continue;
  3863. case OP_LOADLOC4:
  3864. B_reg = A_reg;
  3865. A_reg = stack[-4];
  3866. #ifdef COMMON
  3867. exit_count = 1;
  3868. #endif
  3869. continue;
  3870. case OP_LOADLOC5:
  3871. B_reg = A_reg;
  3872. A_reg = stack[-5];
  3873. #ifdef COMMON
  3874. exit_count = 1;
  3875. #endif
  3876. continue;
  3877. case OP_LOADLOC6:
  3878. B_reg = A_reg;
  3879. A_reg = stack[-6];
  3880. #ifdef COMMON
  3881. exit_count = 1;
  3882. #endif
  3883. continue;
  3884. case OP_LOADLOC7:
  3885. B_reg = A_reg;
  3886. A_reg = stack[-7];
  3887. #ifdef COMMON
  3888. exit_count = 1;
  3889. #endif
  3890. continue;
  3891. case OP_LOADLOC8:
  3892. B_reg = A_reg;
  3893. A_reg = stack[-8];
  3894. #ifdef COMMON
  3895. exit_count = 1;
  3896. #endif
  3897. continue;
  3898. case OP_LOADLOC9:
  3899. B_reg = A_reg;
  3900. A_reg = stack[-9];
  3901. #ifdef COMMON
  3902. exit_count = 1;
  3903. #endif
  3904. continue;
  3905. case OP_LOADLOC10:
  3906. B_reg = A_reg;
  3907. A_reg = stack[-10];
  3908. #ifdef COMMON
  3909. exit_count = 1;
  3910. #endif
  3911. continue;
  3912. case OP_LOADLOC11:
  3913. B_reg = A_reg;
  3914. A_reg = stack[-11];
  3915. #ifdef COMMON
  3916. exit_count = 1;
  3917. #endif
  3918. continue;
  3919. case OP_CAR:
  3920. if (car_legal(A_reg))
  3921. { A_reg = qcar(A_reg);
  3922. #ifdef COMMON
  3923. exit_count = 1;
  3924. #endif
  3925. continue;
  3926. }
  3927. errcode = err_bad_car;
  3928. C_stack = stack;
  3929. goto error_1_A;
  3930. case OP_CARLOC0:
  3931. B_reg = A_reg;
  3932. A_reg = stack[-0];
  3933. if (car_legal(A_reg))
  3934. { A_reg = qcar(A_reg);
  3935. #ifdef COMMON
  3936. exit_count = 1;
  3937. #endif
  3938. continue;
  3939. }
  3940. errcode = err_bad_car;
  3941. C_stack = stack;
  3942. goto error_1_A;
  3943. case OP_CARLOC1:
  3944. B_reg = A_reg;
  3945. A_reg = stack[-1];
  3946. if (car_legal(A_reg))
  3947. { A_reg = qcar(A_reg);
  3948. #ifdef COMMON
  3949. exit_count = 1;
  3950. #endif
  3951. continue;
  3952. }
  3953. errcode = err_bad_car;
  3954. C_stack = stack;
  3955. goto error_1_A;
  3956. case OP_CARLOC2:
  3957. B_reg = A_reg;
  3958. A_reg = stack[-2];
  3959. if (car_legal(A_reg))
  3960. { A_reg = qcar(A_reg);
  3961. #ifdef COMMON
  3962. exit_count = 1;
  3963. #endif
  3964. continue;
  3965. }
  3966. errcode = err_bad_car;
  3967. C_stack = stack;
  3968. goto error_1_A;
  3969. case OP_CARLOC3:
  3970. B_reg = A_reg;
  3971. A_reg = stack[-3];
  3972. if (car_legal(A_reg))
  3973. { A_reg = qcar(A_reg);
  3974. #ifdef COMMON
  3975. exit_count = 1;
  3976. #endif
  3977. continue;
  3978. }
  3979. errcode = err_bad_car;
  3980. C_stack = stack;
  3981. goto error_1_A;
  3982. case OP_CARLOC4:
  3983. B_reg = A_reg;
  3984. A_reg = stack[-4];
  3985. if (car_legal(A_reg))
  3986. { A_reg = qcar(A_reg);
  3987. #ifdef COMMON
  3988. exit_count = 1;
  3989. #endif
  3990. continue;
  3991. }
  3992. errcode = err_bad_car;
  3993. C_stack = stack;
  3994. goto error_1_A;
  3995. case OP_CARLOC5:
  3996. B_reg = A_reg;
  3997. A_reg = stack[-5];
  3998. if (car_legal(A_reg))
  3999. { A_reg = qcar(A_reg);
  4000. #ifdef COMMON
  4001. exit_count = 1;
  4002. #endif
  4003. continue;
  4004. }
  4005. errcode = err_bad_car;
  4006. C_stack = stack;
  4007. goto error_1_A;
  4008. case OP_CARLOC6:
  4009. B_reg = A_reg;
  4010. A_reg = stack[-6];
  4011. if (car_legal(A_reg))
  4012. { A_reg = qcar(A_reg);
  4013. #ifdef COMMON
  4014. exit_count = 1;
  4015. #endif
  4016. continue;
  4017. }
  4018. errcode = err_bad_car;
  4019. C_stack = stack;
  4020. goto error_1_A;
  4021. case OP_CARLOC7:
  4022. B_reg = A_reg;
  4023. A_reg = stack[-7];
  4024. if (car_legal(A_reg))
  4025. { A_reg = qcar(A_reg);
  4026. #ifdef COMMON
  4027. exit_count = 1;
  4028. #endif
  4029. continue;
  4030. }
  4031. errcode = err_bad_car;
  4032. C_stack = stack;
  4033. goto error_1_A;
  4034. case OP_CARLOC8:
  4035. B_reg = A_reg;
  4036. A_reg = stack[-8];
  4037. if (car_legal(A_reg))
  4038. { A_reg = qcar(A_reg);
  4039. #ifdef COMMON
  4040. exit_count = 1;
  4041. #endif
  4042. continue;
  4043. }
  4044. errcode = err_bad_car;
  4045. C_stack = stack;
  4046. goto error_1_A;
  4047. case OP_CARLOC9:
  4048. B_reg = A_reg;
  4049. A_reg = stack[-9];
  4050. if (car_legal(A_reg))
  4051. { A_reg = qcar(A_reg);
  4052. #ifdef COMMON
  4053. exit_count = 1;
  4054. #endif
  4055. continue;
  4056. }
  4057. errcode = err_bad_car;
  4058. C_stack = stack;
  4059. goto error_1_A;
  4060. case OP_CARLOC10:
  4061. B_reg = A_reg;
  4062. A_reg = stack[-10];
  4063. if (car_legal(A_reg))
  4064. { A_reg = qcar(A_reg);
  4065. #ifdef COMMON
  4066. exit_count = 1;
  4067. #endif
  4068. continue;
  4069. }
  4070. errcode = err_bad_car;
  4071. C_stack = stack;
  4072. goto error_1_A;
  4073. case OP_CARLOC11:
  4074. B_reg = A_reg;
  4075. A_reg = stack[-11];
  4076. if (car_legal(A_reg))
  4077. { A_reg = qcar(A_reg);
  4078. #ifdef COMMON
  4079. exit_count = 1;
  4080. #endif
  4081. continue;
  4082. }
  4083. errcode = err_bad_car;
  4084. C_stack = stack;
  4085. goto error_1_A;
  4086. case OP_CDR:
  4087. if (car_legal(A_reg))
  4088. { A_reg = qcdr(A_reg);
  4089. #ifdef COMMON
  4090. exit_count = 1;
  4091. #endif
  4092. continue;
  4093. }
  4094. errcode = err_bad_cdr;
  4095. C_stack = stack;
  4096. goto error_1_A;
  4097. case OP_STORELOC:
  4098. stack[-(int)next_byte] = A_reg;
  4099. /* NB this opcode does not pop the A/B stack */
  4100. continue;
  4101. case OP_STORELOC0:
  4102. stack[-0] = A_reg;
  4103. continue;
  4104. case OP_STORELOC1:
  4105. stack[-1] = A_reg;
  4106. continue;
  4107. case OP_STORELOC2:
  4108. stack[-2] = A_reg;
  4109. continue;
  4110. case OP_STORELOC3:
  4111. stack[-3] = A_reg;
  4112. continue;
  4113. case OP_STORELOC4:
  4114. stack[-4] = A_reg;
  4115. continue;
  4116. case OP_STORELOC5:
  4117. stack[-5] = A_reg;
  4118. continue;
  4119. case OP_STORELOC6:
  4120. stack[-6] = A_reg;
  4121. continue;
  4122. case OP_STORELOC7:
  4123. stack[-7] = A_reg;
  4124. continue;
  4125. case OP_LOADLIT:
  4126. /*
  4127. * Associated with each body of byte-codes there is a literal vector,
  4128. * and this opcode loads values from same. The literal vector has a
  4129. * header word and is tagged as a Lisp vector.
  4130. */
  4131. B_reg = A_reg;
  4132. A_reg = elt(litvec, next_byte);
  4133. #ifdef COMMON
  4134. exit_count = 1;
  4135. #endif
  4136. continue;
  4137. case OP_LOADLIT1:
  4138. B_reg = A_reg;
  4139. A_reg = elt(litvec, 1);
  4140. #ifdef COMMON
  4141. exit_count = 1;
  4142. #endif
  4143. continue;
  4144. case OP_LOADLIT2:
  4145. B_reg = A_reg;
  4146. A_reg = elt(litvec, 2);
  4147. #ifdef COMMON
  4148. exit_count = 1;
  4149. #endif
  4150. continue;
  4151. case OP_LOADLIT3:
  4152. B_reg = A_reg;
  4153. A_reg = elt(litvec, 3);
  4154. #ifdef COMMON
  4155. exit_count = 1;
  4156. #endif
  4157. continue;
  4158. case OP_LOADLIT4:
  4159. B_reg = A_reg;
  4160. A_reg = elt(litvec, 4);
  4161. #ifdef COMMON
  4162. exit_count = 1;
  4163. #endif
  4164. continue;
  4165. case OP_LOADLIT5:
  4166. B_reg = A_reg;
  4167. A_reg = elt(litvec, 5);
  4168. #ifdef COMMON
  4169. exit_count = 1;
  4170. #endif
  4171. continue;
  4172. case OP_LOADLIT6:
  4173. B_reg = A_reg;
  4174. A_reg = elt(litvec, 6);
  4175. #ifdef COMMON
  4176. exit_count = 1;
  4177. #endif
  4178. continue;
  4179. case OP_LOADLIT7:
  4180. B_reg = A_reg;
  4181. A_reg = elt(litvec, 7);
  4182. #ifdef COMMON
  4183. exit_count = 1;
  4184. #endif
  4185. continue;
  4186. case OP_LOADFREE:
  4187. /*
  4188. * Load the value of a free (GLOBAL, SPECIAL, FLUID) variable
  4189. */
  4190. B_reg = A_reg;
  4191. A_reg = qvalue(elt(litvec, next_byte));
  4192. #ifdef COMMON
  4193. exit_count = 1;
  4194. #endif
  4195. continue;
  4196. case OP_LOADFREE1:
  4197. B_reg = A_reg;
  4198. A_reg = qvalue(elt(litvec, 1));
  4199. #ifdef COMMON
  4200. exit_count = 1;
  4201. #endif
  4202. continue;
  4203. case OP_LOADFREE2:
  4204. B_reg = A_reg;
  4205. A_reg = qvalue(elt(litvec, 2));
  4206. #ifdef COMMON
  4207. exit_count = 1;
  4208. #endif
  4209. continue;
  4210. case OP_LOADFREE3:
  4211. B_reg = A_reg;
  4212. A_reg = qvalue(elt(litvec, 3));
  4213. #ifdef COMMON
  4214. exit_count = 1;
  4215. #endif
  4216. continue;
  4217. case OP_LOADFREE4:
  4218. B_reg = A_reg;
  4219. A_reg = qvalue(elt(litvec, 4));
  4220. #ifdef COMMON
  4221. exit_count = 1;
  4222. #endif
  4223. continue;
  4224. case OP_JUMPNIL:
  4225. xppc = ppc;
  4226. ppc++;
  4227. if (A_reg == nil) ppc = ppc + *xppc;
  4228. continue;
  4229. case OP_JUMPNIL_B:
  4230. xppc = ppc;
  4231. ppc++;
  4232. if (A_reg == nil)
  4233. { ppc = ppc - *xppc;
  4234. /*
  4235. * To ensure that all code is interruptable I poll on every backwards
  4236. * jump. The SIGINT event simulates a stack overflow, and the
  4237. * consequent entry to the garbage collector then handles the event.
  4238. */
  4239. #ifndef OUT_OF_LINE
  4240. #ifdef SOFTWARE_TICKS
  4241. if (--countdown < 0) deal_with_tick();
  4242. #endif
  4243. if (stack >= stacklimit)
  4244. { C_stack = stack;
  4245. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4246. nil = C_nil;
  4247. if (exception_pending()) goto error_exit;
  4248. stack = C_stack; /* may have been changed by GC */
  4249. }
  4250. #else
  4251. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4252. goto error_exit;
  4253. stack = C_stack;
  4254. #endif
  4255. }
  4256. continue;
  4257. case OP_JUMPT:
  4258. xppc = ppc;
  4259. ppc++;
  4260. if (A_reg != nil) ppc = ppc + *xppc;
  4261. continue;
  4262. case OP_JUMPT_B:
  4263. xppc = ppc;
  4264. ppc++;
  4265. if (A_reg != nil)
  4266. { ppc = ppc - *xppc;
  4267. #ifndef OUT_OF_LINE
  4268. #ifdef SOFTWARE_TICKS
  4269. if (--countdown < 0) deal_with_tick();
  4270. #endif
  4271. if (stack >= stacklimit)
  4272. { C_stack = stack;
  4273. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4274. nil = C_nil;
  4275. if (exception_pending()) goto error_exit;
  4276. stack = C_stack; /* may have been changed by GC */
  4277. }
  4278. #else
  4279. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4280. goto error_exit;
  4281. stack = C_stack;
  4282. #endif
  4283. }
  4284. continue;
  4285. case OP_JUMPNIL_L:
  4286. w = next_byte;
  4287. xppc = ppc;
  4288. ppc++;
  4289. if (A_reg == nil) ppc = ppc + ((w << 8) + *xppc);
  4290. continue;
  4291. case OP_JUMPNIL_BL:
  4292. w = next_byte;
  4293. xppc = ppc;
  4294. ppc++;
  4295. if (A_reg == nil)
  4296. { ppc = ppc - ((w << 8) + *xppc);
  4297. #ifndef OUT_OF_LINE
  4298. #ifdef SOFTWARE_TICKS
  4299. if (--countdown < 0) deal_with_tick();
  4300. #endif
  4301. if (stack >= stacklimit)
  4302. { C_stack = stack;
  4303. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4304. nil = C_nil;
  4305. if (exception_pending()) goto error_exit;
  4306. stack = C_stack; /* may have been changed by GC */
  4307. }
  4308. #else
  4309. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4310. goto error_exit;
  4311. stack = C_stack;
  4312. #endif
  4313. }
  4314. continue;
  4315. case OP_JUMPT_L:
  4316. w = next_byte;
  4317. xppc = ppc;
  4318. ppc++;
  4319. if (A_reg != nil) ppc = ppc + ((w << 8) + *xppc);
  4320. continue;
  4321. case OP_JUMPT_BL:
  4322. w = next_byte;
  4323. xppc = ppc;
  4324. ppc++;
  4325. if (A_reg != nil)
  4326. { ppc = ppc - ((w << 8) + *xppc);
  4327. #ifndef OUT_OF_LINE
  4328. #ifdef SOFTWARE_TICKS
  4329. if (--countdown < 0) deal_with_tick();
  4330. #endif
  4331. if (stack >= stacklimit)
  4332. { C_stack = stack;
  4333. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4334. nil = C_nil;
  4335. if (exception_pending()) goto error_exit;
  4336. stack = C_stack; /* may have been changed by GC */
  4337. }
  4338. #else
  4339. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4340. goto error_exit;
  4341. stack = C_stack;
  4342. #endif
  4343. }
  4344. continue;
  4345. case OP_BUILTIN1:
  4346. f1 = one_arg_functions[next_byte];
  4347. /* BUILTIN1: A=fn(A); */
  4348. save_pc();
  4349. C_stack = stack;
  4350. A_reg = f1(nil, A_reg);
  4351. nil = C_nil;
  4352. if (exception_pending()) goto error_exit;
  4353. stack = C_stack;
  4354. restore_pc();
  4355. continue;
  4356. case OP_BUILTIN2:
  4357. f2 = two_arg_functions[next_byte];
  4358. /* BUILTIN2: A=fn(B,A); */
  4359. save_pc();
  4360. C_stack = stack;
  4361. A_reg = f2(nil, B_reg, A_reg);
  4362. nil = C_nil;
  4363. if (exception_pending()) goto error_exit;
  4364. stack = C_stack;
  4365. restore_pc();
  4366. continue;
  4367. case OP_EXIT:
  4368. /*
  4369. * Here I assume that exit_count has been set up already. Note also that
  4370. * there is no need to do any LOSE operations just before an EXIT since the
  4371. * stack gets reset automatically here.
  4372. */
  4373. #ifndef NO_BYTECOUNT
  4374. qcount(elt(litvec, 0)) += OPCOUNT;
  4375. #endif
  4376. C_stack = entry_stack;
  4377. return A_reg;
  4378. case OP_PUSH:
  4379. push(A_reg);
  4380. continue;
  4381. case OP_PUSHNIL:
  4382. push(nil);
  4383. continue;
  4384. case OP_PUSHNIL2:
  4385. push2(nil, nil);
  4386. continue;
  4387. case OP_PUSHNIL3:
  4388. push3(nil, nil, nil);
  4389. continue;
  4390. case OP_POP:
  4391. B_reg = A_reg;
  4392. pop(A_reg);
  4393. #ifdef COMMON
  4394. exit_count = 1;
  4395. #endif
  4396. continue;
  4397. case OP_LOSE:
  4398. popv(1);
  4399. continue;
  4400. case OP_LOSE2:
  4401. popv(2);
  4402. continue;
  4403. case OP_LOSE3:
  4404. popv(3);
  4405. continue;
  4406. case OP_LOSES:
  4407. popv(next_byte);
  4408. continue;
  4409. case OP_CONS: /* A_reg = cons(B_reg, A_reg); */
  4410. #ifndef OUT_OF_LINE
  4411. r1 = (Lisp_Object)((char *)fringe - sizeof(Cons_Cell));
  4412. qcar(r1) = B_reg;
  4413. qcdr(r1) = A_reg;
  4414. fringe = r1;
  4415. if ((char *)r1 <= (char *)heaplimit)
  4416. { save_pc();
  4417. C_stack = stack;
  4418. A_reg = reclaim((Lisp_Object)((char *)r1 + TAG_CONS),
  4419. "bytecoded cons", GC_CONS, 0);
  4420. nil = C_nil;
  4421. if (exception_pending()) goto error_exit;
  4422. stack = C_stack; /* may have been changed by GC */
  4423. restore_pc();
  4424. }
  4425. else A_reg = (Lisp_Object)((char *)r1 + TAG_CONS);
  4426. #else
  4427. save_pc();
  4428. C_stack = stack;
  4429. A_reg = cons(B_reg, A_reg);
  4430. nil = C_nil;
  4431. if (exception_pending()) goto error_exit;
  4432. stack = C_stack; /* may have been changed by GC */
  4433. restore_pc();
  4434. #endif
  4435. #ifdef DEBUG
  4436. if (((int)A_reg & (2*CELL-1)) != 0)
  4437. { term_printf("badly aligned CONS\n");
  4438. ensure_screen();
  4439. abort();
  4440. }
  4441. #endif
  4442. #ifdef COMMON
  4443. exit_count = 1;
  4444. #endif
  4445. continue;
  4446. /*
  4447. * FASTGET n
  4448. * 0 <= n < 64 (GET A_reg property_n)
  4449. * 64 <= n < 128 (GET A_reg property_n B_reg)
  4450. * 128 <= n < 192 (FLAGP A_reg property_n)
  4451. */
  4452. case OP_FASTGET:
  4453. w = next_byte;
  4454. #ifdef RECORD_GET
  4455. n = 0;
  4456. #endif
  4457. if (symbolp(A_reg))
  4458. { r1 = qfastgets(A_reg);
  4459. if (r1 == nil)
  4460. { if (w & 0x40) A_reg = B_reg;
  4461. else A_reg = nil;
  4462. }
  4463. else
  4464. { A_reg = elt(r1, w & 0x7f);
  4465. if (A_reg == SPID_NOPROP)
  4466. { if (w & 0x40) A_reg = B_reg;
  4467. else A_reg = nil;
  4468. #ifdef RECORD_GET
  4469. n = 1;
  4470. #endif
  4471. }
  4472. else if (w & 0x80) A_reg = lisp_true;
  4473. }
  4474. }
  4475. else A_reg = nil;
  4476. #ifdef RECORD_GET
  4477. save_pc(); C_stack = stack;
  4478. record_get(elt(fastget_names, w & 0x7f), n);
  4479. nil = C_nil;
  4480. if (exception_pending()) goto error_exit;
  4481. stack = C_stack; restore_pc();
  4482. #endif
  4483. continue;
  4484. case OP_LITGET:
  4485. B_reg = A_reg;
  4486. A_reg = elt(litvec, next_byte);
  4487. goto perform_get;
  4488. case OP_GET: /* A = get(B, A) */
  4489. goto perform_get;
  4490. }
  4491. /*
  4492. * Now various code-fragments that want to be inside the "for (;;)" loop
  4493. * but outside the "switch".
  4494. */
  4495. perform_get:
  4496. #ifdef COMMON
  4497. /*
  4498. * This direct byte code supports the 2-argument version of GET. The
  4499. * 3-arg version should be done as a regular general call.
  4500. */
  4501. save_pc(); C_stack = stack;
  4502. A_reg = get(B_reg, A_reg, nil);
  4503. nil = C_nil;
  4504. if (exception_pending()) goto error_exit;
  4505. stack = C_stack; restore_pc();
  4506. exit_count = 1;
  4507. continue;
  4508. #else
  4509. #ifndef OUT_OF_LINE
  4510. /*
  4511. * Get is very heavily used - so I have in-lined it here since it is fairly
  4512. * short code and ought not to overload register allocation. See "fns1.c"
  4513. * for the regular version of this code.
  4514. */
  4515. if (!symbolp(B_reg))
  4516. {
  4517. #ifdef RECORD_GET
  4518. save_pc(); C_stack = stack;
  4519. record_get(A_reg, NO);
  4520. nil = C_nil;
  4521. if (exception_pending()) goto error_exit;
  4522. stack = C_stack; restore_pc();
  4523. #endif
  4524. A_reg = nil;
  4525. continue;
  4526. }
  4527. else
  4528. { if (symbolp(A_reg) &&
  4529. (n = header_fastget(qheader(A_reg))) != 0)
  4530. { if ((r1 = qfastgets(B_reg)) == nil)
  4531. {
  4532. #ifdef RECORD_GET
  4533. save_pc(); C_stack = stack;
  4534. record_get(A_reg, NO);
  4535. nil = C_nil;
  4536. if (exception_pending()) goto error_exit;
  4537. stack = C_stack; restore_pc();
  4538. #endif
  4539. continue;
  4540. }
  4541. #ifdef RECORD_GET
  4542. push(r1);
  4543. save_pc(); C_stack = stack;
  4544. record_get(A_reg, elt(r1, n-1) != nil);
  4545. nil = C_nil;
  4546. if (exception_pending()) goto error_exit;
  4547. stack = C_stack; restore_pc();
  4548. pop(r1);
  4549. #endif
  4550. A_reg = elt(r1, n-1);
  4551. if (A_reg == SPID_NOPROP) A_reg = nil;
  4552. continue;
  4553. }
  4554. /*
  4555. * I write out the check on the first two items in the property list
  4556. * longhand, expecting that a match will most often occur there. If
  4557. * I get a match later on I will migrate the entry to the front of the list.
  4558. */
  4559. r1 = qplist(B_reg);
  4560. if (r1 == nil)
  4561. {
  4562. #ifdef RECORD_GET
  4563. save_pc(); C_stack = stack;
  4564. record_get(A_reg, NO);
  4565. nil = C_nil;
  4566. if (exception_pending()) goto error_exit;
  4567. stack = C_stack; restore_pc();
  4568. #endif
  4569. A_reg = nil;
  4570. continue;
  4571. }
  4572. r3 = qcar(r1);
  4573. if (qcar(r3) == A_reg)
  4574. {
  4575. #ifdef RECORD_GET
  4576. save_pc(); C_stack = stack;
  4577. record_get(A_reg, YES);
  4578. nil = C_nil;
  4579. if (exception_pending()) goto error_exit;
  4580. stack = C_stack; restore_pc();
  4581. #endif
  4582. A_reg = qcdr(r3);
  4583. continue;
  4584. }
  4585. r1 = qcdr(r1);
  4586. if (r1 == nil)
  4587. {
  4588. #ifdef RECORD_GET
  4589. save_pc(); C_stack = stack;
  4590. record_get(A_reg, NO);
  4591. nil = C_nil;
  4592. if (exception_pending()) goto error_exit;
  4593. stack = C_stack; restore_pc();
  4594. #endif
  4595. A_reg = nil;
  4596. continue;
  4597. }
  4598. r3 = qcar(r1);
  4599. if (qcar(r3) == A_reg)
  4600. {
  4601. #ifdef RECORD_GET
  4602. save_pc(); C_stack = stack;
  4603. record_get(A_reg, YES);
  4604. nil = C_nil;
  4605. if (exception_pending()) goto error_exit;
  4606. stack = C_stack; restore_pc();
  4607. #endif
  4608. A_reg = qcdr(r3);
  4609. continue;
  4610. }
  4611. r2 = r1;
  4612. r1 = qcdr(r1);
  4613. if (r1 == nil)
  4614. {
  4615. #ifdef RECORD_GET
  4616. save_pc(); C_stack = stack;
  4617. record_get(A_reg, NO);
  4618. nil = C_nil;
  4619. if (exception_pending()) goto error_exit;
  4620. stack = C_stack; restore_pc();
  4621. #endif
  4622. A_reg = nil;
  4623. continue;
  4624. }
  4625. for (;;)
  4626. { r3 = qcar(r1);
  4627. if (qcar(r3) == A_reg)
  4628. { qcdr(r2) = qcdr(r1);
  4629. qcdr(r1) = qplist(B_reg);
  4630. qplist(B_reg) = r1;
  4631. #ifdef RECORD_GET
  4632. save_pc(); C_stack = stack;
  4633. record_get(A_reg, YES);
  4634. nil = C_nil;
  4635. if (exception_pending()) goto error_exit;
  4636. stack = C_stack; restore_pc();
  4637. #endif
  4638. A_reg = qcdr(r3);
  4639. break;
  4640. }
  4641. r2 = r1;
  4642. r1 = qcdr(r1);
  4643. if (r1 == nil)
  4644. {
  4645. #ifdef RECORD_GET
  4646. save_pc(); C_stack = stack;
  4647. record_get(A_reg, NO);
  4648. nil = C_nil;
  4649. if (exception_pending()) goto error_exit;
  4650. stack = C_stack; restore_pc();
  4651. #endif
  4652. A_reg = nil;
  4653. break;
  4654. }
  4655. }
  4656. }
  4657. continue;
  4658. #else
  4659. save_pc(); C_stack = stack;
  4660. A_reg = get(B_reg, A_reg);
  4661. nil = C_nil;
  4662. if (exception_pending()) goto error_exit;
  4663. stack = C_stack; restore_pc();
  4664. exit_count = 1;
  4665. continue;
  4666. #endif
  4667. #endif
  4668. caar:
  4669. if (car_legal(A_reg)) A_reg = qcar(A_reg);
  4670. else
  4671. { errcode = err_bad_car;
  4672. C_stack = stack;
  4673. goto error_1_A;
  4674. }
  4675. if (car_legal(A_reg))
  4676. { A_reg = qcar(A_reg);
  4677. #ifdef COMMON
  4678. exit_count = 1;
  4679. #endif
  4680. continue;
  4681. }
  4682. errcode = err_bad_car;
  4683. C_stack = stack;
  4684. goto error_1_A;
  4685. catcher:
  4686. A_reg = cons(A_reg, catch_tags);
  4687. nil = C_nil;
  4688. if (exception_pending()) goto error_exit;
  4689. catch_tags = A_reg;
  4690. push3(fixnum_of_int(w+1), catch_tags, SPID_CATCH);
  4691. continue;
  4692. call0: r1 = elt(litvec, fname);
  4693. /*
  4694. * NB I set fname to be the literal-vector offset in the line above so that
  4695. * it will be possible to find the name of the function that was called
  4696. * if I have to display a backtrace.
  4697. */
  4698. f345 = qfnn(r1);
  4699. /* CALL0: A=fn() */
  4700. #ifdef DEBUG
  4701. if (f345 == NULL)
  4702. { term_printf("Illegal function\n");
  4703. my_exit(EXIT_FAILURE);
  4704. }
  4705. #endif
  4706. save_pc();
  4707. C_stack = stack;
  4708. A_reg = f345(qenv(r1), 0);
  4709. nil = C_nil;
  4710. if (exception_pending()) goto call_error_exit;
  4711. stack = C_stack;
  4712. restore_pc();
  4713. continue;
  4714. jcall0: r1 = elt(litvec, fname);
  4715. f345 = qfnn(r1);
  4716. #ifdef DEBUG
  4717. if (f345 == NULL)
  4718. { term_printf("Illegal function\n");
  4719. my_exit(EXIT_FAILURE);
  4720. }
  4721. #endif
  4722. #ifndef NO_BYTECOUNT
  4723. qcount(elt(litvec, 0)) += OPCOUNT;
  4724. opcodes = 30;
  4725. #endif
  4726. #ifndef DO_NOT_BOTHER_TO_POLL_ON_TAILCALL
  4727. /*
  4728. * The issue here is cases such as
  4729. * (de f1 (x) (f2 x))
  4730. * (de f2 (x) (f1 x))
  4731. * where the bodies of the functions so not do enough work that polling
  4732. * for interrupts or for window-system updates will happen. Thus it seems
  4733. * I need to perform a polling operation as part of the tail-call sequence.
  4734. * I leave a (long-winded) option to disable this and thereby save a really
  4735. * minor amount of time and space at the loss of a fairly minor amount of
  4736. * safety.
  4737. */
  4738. #ifndef OUT_OF_LINE
  4739. #ifdef SOFTWARE_TICKS
  4740. if (--countdown < 0) deal_with_tick();
  4741. #endif
  4742. if (stack >= stacklimit)
  4743. { C_stack = stack;
  4744. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4745. nil = C_nil;
  4746. if (exception_pending()) goto error_exit;
  4747. stack = C_stack; /* may have been changed by GC */
  4748. }
  4749. #else
  4750. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4751. goto error_exit;
  4752. stack = C_stack;
  4753. #endif
  4754. #endif
  4755. if (f345 == bytecoded0)
  4756. { lit = qenv(r1);
  4757. codevec = qcar(lit);
  4758. litvec = qcdr(lit);
  4759. stack = entry_stack;
  4760. ppc = (unsigned char *)data_of_bps(codevec);
  4761. continue;
  4762. }
  4763. else if (f345 == tracebytecoded0)
  4764. { r2 = elt(litvec, 0);
  4765. lit = qenv(r1);
  4766. codevec = qcar(lit);
  4767. litvec = qcdr(lit);
  4768. /*
  4769. * I make TRACECODED a special case, in effect writing it out in-line
  4770. * here, to avoid some ugly confusion with backtraces following tail calls.
  4771. */
  4772. stack = entry_stack;
  4773. push3(litvec, codevec, r2);
  4774. C_stack = stack;
  4775. trace_print_0(elt(litvec, 0), stack);
  4776. nil = C_nil;
  4777. if (exception_pending()) goto error_exit;
  4778. popv(1);
  4779. pop2(codevec, litvec);
  4780. ppc = (unsigned char *)data_of_bps(codevec);
  4781. continue;
  4782. }
  4783. C_stack = entry_stack;
  4784. return f345(qenv(r1), 0);
  4785. call1: r1 = elt(litvec, fname);
  4786. f1 = qfn1(r1);
  4787. #ifdef DEBUG
  4788. if (f1 == NULL)
  4789. { term_printf("Illegal function\n");
  4790. my_exit(EXIT_FAILURE);
  4791. }
  4792. #endif
  4793. /* CALL1: A=fn(A); */
  4794. save_pc();
  4795. C_stack = stack;
  4796. A_reg = f1(qenv(r1), A_reg);
  4797. nil = C_nil;
  4798. if (exception_pending()) goto call_error_exit;
  4799. stack = C_stack;
  4800. restore_pc();
  4801. continue;
  4802. jcall1: r1 = elt(litvec, fname);
  4803. f1 = qfn1(r1);
  4804. #ifdef DEBUG
  4805. if (f1 == NULL)
  4806. { term_printf("Illegal function\n");
  4807. my_exit(EXIT_FAILURE);
  4808. }
  4809. #endif
  4810. #ifndef NO_BYTECOUNT
  4811. qcount(elt(litvec, 0)) += OPCOUNT;
  4812. opcodes = 30;
  4813. #endif
  4814. #ifndef DO_NOT_BOTHER_TO_POLL_ON_TAILCALL
  4815. /*
  4816. * The issue here is cases such as
  4817. * (de f1 (x) (f2 x))
  4818. * (de f2 (x) (f1 x))
  4819. * where the bodies of the functions so not do enough work that polling
  4820. * for interrupts or for window-system updates will happen. Thus it seems
  4821. * I need to perform a polling operation as part of the tail-call sequence.
  4822. * I leave a (long-winded) option to disable this and thereby save a really
  4823. * minor amount of time and space at the loss of a fairly minor amount of
  4824. * safety.
  4825. */
  4826. #ifndef OUT_OF_LINE
  4827. #ifdef SOFTWARE_TICKS
  4828. if (--countdown < 0) deal_with_tick();
  4829. #endif
  4830. if (stack >= stacklimit)
  4831. { C_stack = stack;
  4832. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4833. nil = C_nil;
  4834. if (exception_pending()) goto error_exit;
  4835. stack = C_stack; /* may have been changed by GC */
  4836. }
  4837. #else
  4838. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4839. goto error_exit;
  4840. stack = C_stack;
  4841. #endif
  4842. #endif
  4843. if (f1 == bytecoded1)
  4844. { lit = qenv(r1);
  4845. codevec = qcar(lit);
  4846. litvec = qcdr(lit);
  4847. stack = entry_stack;
  4848. push(A_reg);
  4849. ppc = (unsigned char *)data_of_bps(codevec);
  4850. continue;
  4851. }
  4852. else if (f1 == tracebytecoded1)
  4853. { r2 = elt(litvec, 0);
  4854. lit = qenv(r1);
  4855. codevec = qcar(lit);
  4856. litvec = qcdr(lit);
  4857. stack = entry_stack;
  4858. push(A_reg);
  4859. push3(litvec, codevec, r2);
  4860. C_stack = stack;
  4861. trace_print_1(elt(litvec, 0), stack);
  4862. nil = C_nil;
  4863. if (exception_pending()) goto error_exit;
  4864. popv(1);
  4865. pop2(codevec, litvec);
  4866. ppc = (unsigned char *)data_of_bps(codevec);
  4867. continue;
  4868. }
  4869. C_stack = entry_stack;
  4870. return f1(qenv(r1), A_reg);
  4871. call2: r1 = elt(litvec, fname);
  4872. f2 = qfn2(r1);
  4873. #ifdef DEBUG
  4874. if (f2 == NULL)
  4875. { term_printf("Illegal function\n");
  4876. my_exit(EXIT_FAILURE);
  4877. }
  4878. #endif
  4879. /* CALL2: A=fn(B,A); */
  4880. save_pc();
  4881. C_stack = stack;
  4882. A_reg = f2(qenv(r1), B_reg, A_reg);
  4883. nil = C_nil;
  4884. if (exception_pending()) goto call_error_exit;
  4885. stack = C_stack;
  4886. restore_pc();
  4887. continue;
  4888. call2r: r1 = elt(litvec, fname);
  4889. f2 = qfn2(r1);
  4890. #ifdef DEBUG
  4891. if (f2 == NULL)
  4892. { term_printf("Illegal function\n");
  4893. my_exit(EXIT_FAILURE);
  4894. }
  4895. #endif
  4896. /* CALL2R: A=fn(A,B); NOTE arg order reversed */
  4897. save_pc();
  4898. C_stack = stack;
  4899. A_reg = f2(qenv(r1), A_reg, B_reg);
  4900. nil = C_nil;
  4901. if (exception_pending()) goto call_error_exit;
  4902. stack = C_stack;
  4903. restore_pc();
  4904. continue;
  4905. jcall2: r1 = elt(litvec, fname);
  4906. f2 = qfn2(r1);
  4907. #ifdef DEBUG
  4908. if (f2 == NULL)
  4909. { term_printf("Illegal function\n");
  4910. my_exit(EXIT_FAILURE);
  4911. }
  4912. #endif
  4913. #ifndef NO_BYTECOUNT
  4914. qcount(elt(litvec, 0)) += OPCOUNT;
  4915. opcodes = 30;
  4916. #endif
  4917. #ifndef DO_NOT_BOTHER_TO_POLL_ON_TAILCALL
  4918. /*
  4919. * The issue here is cases such as
  4920. * (de f1 (x) (f2 x))
  4921. * (de f2 (x) (f1 x))
  4922. * where the bodies of the functions so not do enough work that polling
  4923. * for interrupts or for window-system updates will happen. Thus it seems
  4924. * I need to perform a polling operation as part of the tail-call sequence.
  4925. * I leave a (long-winded) option to disable this and thereby save a really
  4926. * minor amount of time and space at the loss of a fairly minor amount of
  4927. * safety.
  4928. */
  4929. #ifndef OUT_OF_LINE
  4930. #ifdef SOFTWARE_TICKS
  4931. if (--countdown < 0) deal_with_tick();
  4932. #endif
  4933. if (stack >= stacklimit)
  4934. { C_stack = stack;
  4935. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  4936. nil = C_nil;
  4937. if (exception_pending()) goto error_exit;
  4938. stack = C_stack; /* may have been changed by GC */
  4939. }
  4940. #else
  4941. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  4942. goto error_exit;
  4943. stack = C_stack;
  4944. #endif
  4945. #endif
  4946. if (f2 == bytecoded2)
  4947. { lit = qenv(r1);
  4948. codevec = qcar(lit);
  4949. litvec = qcdr(lit);
  4950. stack = entry_stack;
  4951. push2(B_reg, A_reg);
  4952. ppc = (unsigned char *)data_of_bps(codevec);
  4953. continue;
  4954. }
  4955. else if (f2 == tracebytecoded2)
  4956. { r2 = elt(litvec, 0);
  4957. lit = qenv(r1);
  4958. codevec = qcar(lit);
  4959. litvec = qcdr(lit);
  4960. stack = entry_stack;
  4961. push2(B_reg, A_reg);
  4962. push3(litvec, codevec, r2);
  4963. C_stack = stack;
  4964. trace_print_2(elt(litvec, 0), stack);
  4965. nil = C_nil;
  4966. if (exception_pending()) goto error_exit;
  4967. popv(1);
  4968. pop2(codevec, litvec);
  4969. ppc = (unsigned char *)data_of_bps(codevec);
  4970. continue;
  4971. }
  4972. C_stack = entry_stack;
  4973. return f2(qenv(r1), B_reg, A_reg);
  4974. call3: r1 = elt(litvec, fname);
  4975. f345 = qfnn(r1);
  4976. #ifdef DEBUG
  4977. if (f345 == NULL)
  4978. { term_printf("Illegal function\n");
  4979. my_exit(EXIT_FAILURE);
  4980. }
  4981. #endif
  4982. /* CALL3: A=fn(pop(),B,A); */
  4983. save_pc();
  4984. pop(r2);
  4985. C_stack = stack;
  4986. A_reg = f345(qenv(r1), 3, r2, B_reg, A_reg);
  4987. nil = C_nil;
  4988. if (exception_pending()) goto call_error_exit;
  4989. stack = C_stack;
  4990. restore_pc();
  4991. continue;
  4992. jcall3: r1 = elt(litvec, fname);
  4993. f345 = qfnn(r1);
  4994. #ifdef DEBUG
  4995. if (f345 == NULL)
  4996. { term_printf("Illegal function\n");
  4997. my_exit(EXIT_FAILURE);
  4998. }
  4999. #endif
  5000. pop(r2);
  5001. #ifndef NO_BYTECOUNT
  5002. qcount(elt(litvec, 0)) += OPCOUNT;
  5003. opcodes = 30;
  5004. #endif
  5005. #ifndef DO_NOT_BOTHER_TO_POLL_ON_TAILCALL
  5006. /*
  5007. * The issue here is cases such as
  5008. * (de f1 (x) (f2 x))
  5009. * (de f2 (x) (f1 x))
  5010. * where the bodies of the functions so not do enough work that polling
  5011. * for interrupts or for window-system updates will happen. Thus it seems
  5012. * I need to perform a polling operation as part of the tail-call sequence.
  5013. * I leave a (long-winded) option to disable this and thereby save a really
  5014. * minor amount of time and space at the loss of a fairly minor amount of
  5015. * safety.
  5016. */
  5017. #ifndef OUT_OF_LINE
  5018. #ifdef SOFTWARE_TICKS
  5019. if (--countdown < 0) deal_with_tick();
  5020. #endif
  5021. if (stack >= stacklimit)
  5022. { C_stack = stack;
  5023. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  5024. nil = C_nil;
  5025. if (exception_pending()) goto error_exit;
  5026. stack = C_stack; /* may have been changed by GC */
  5027. }
  5028. #else
  5029. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  5030. goto error_exit;
  5031. stack = C_stack;
  5032. #endif
  5033. #endif
  5034. if (f345 == bytecoded3)
  5035. { lit = qenv(r1);
  5036. codevec = qcar(lit);
  5037. litvec = qcdr(lit);
  5038. stack = entry_stack;
  5039. push3(r2, B_reg, A_reg);
  5040. ppc = (unsigned char *)data_of_bps(codevec);
  5041. continue;
  5042. }
  5043. else if (f345 == tracebytecoded3)
  5044. { r3 = elt(litvec, 0);
  5045. lit = qenv(r1);
  5046. codevec = qcar(lit);
  5047. litvec = qcdr(lit);
  5048. stack = entry_stack;
  5049. push3(r2, B_reg, A_reg);
  5050. push3(litvec, codevec, r3);
  5051. C_stack = stack;
  5052. trace_print_3(elt(litvec, 0), stack);
  5053. nil = C_nil;
  5054. if (exception_pending()) goto error_exit;
  5055. popv(1);
  5056. pop2(codevec, litvec);
  5057. ppc = (unsigned char *)data_of_bps(codevec);
  5058. continue;
  5059. }
  5060. C_stack = entry_stack;
  5061. return f345(qenv(r1), 3, r2, B_reg, A_reg);
  5062. jcalln:
  5063. #ifndef NO_BYTECOUNT
  5064. qcount(elt(litvec, 0)) += OPCOUNT;
  5065. opcodes = 30;
  5066. #endif
  5067. #ifndef DO_NOT_BOTHER_TO_POLL_ON_TAILCALL
  5068. /*
  5069. * The issue here is cases such as
  5070. * (de f1 (x) (f2 x))
  5071. * (de f2 (x) (f1 x))
  5072. * where the bodies of the functions so not do enough work that polling
  5073. * for interrupts or for window-system updates will happen. Thus it seems
  5074. * I need to perform a polling operation as part of the tail-call sequence.
  5075. * I leave a (long-winded) option to disable this and thereby save a really
  5076. * minor amount of time and space at the loss of a fairly minor amount of
  5077. * safety.
  5078. */
  5079. #ifndef OUT_OF_LINE
  5080. #ifdef SOFTWARE_TICKS
  5081. if (--countdown < 0) deal_with_tick();
  5082. #endif
  5083. if (stack >= stacklimit)
  5084. { C_stack = stack;
  5085. A_reg = reclaim(A_reg, "stack", GC_STACK, 0);
  5086. nil = C_nil;
  5087. if (exception_pending()) goto error_exit;
  5088. stack = C_stack; /* may have been changed by GC */
  5089. }
  5090. #else
  5091. if ((A_reg = poll_jump_back(stack, A_reg)) == SPID_ERROR)
  5092. goto error_exit;
  5093. stack = C_stack;
  5094. #endif
  5095. #endif
  5096. /*
  5097. * here I could shuffle the stack down quite a lot...
  5098. */
  5099. push2(B_reg, A_reg);
  5100. C_stack = stack;
  5101. A_reg = elt(litvec, fname);
  5102. /*
  5103. * Also if the function is byte-coded I can enter it more directly.
  5104. * It is strongly desirable that I do so so that backtraces will work
  5105. * better.
  5106. */
  5107. A_reg = apply(A_reg, (int)w, nil, A_reg);
  5108. nil = C_nil;
  5109. if (exception_pending()) goto ncall_error_exit;
  5110. #ifndef NO_BYTECOUNT
  5111. qcount(elt(litvec, 0)) += OPCOUNT;
  5112. #endif
  5113. C_stack = entry_stack;
  5114. return A_reg;
  5115. create_closure:
  5116. save_pc();
  5117. A_reg = encapsulate_sp(&stack[-2-(int)w]);
  5118. nil = C_nil;
  5119. if (exception_pending()) goto error_exit;
  5120. pop(B_reg);
  5121. C_stack = stack;
  5122. A_reg = list2star(cfunarg, B_reg, A_reg);
  5123. nil = C_nil;
  5124. if (exception_pending()) goto error_exit;
  5125. stack = C_stack; /* may have been changed by GC */
  5126. restore_pc();
  5127. pop(B_reg);
  5128. continue;
  5129. /*****************************************************************************/
  5130. call_error_exit:
  5131. flip_exception();
  5132. C_stack = stack;
  5133. #ifdef REMOVED_CODE
  5134. /*
  5135. * I suspect that the next few lines are UNHELPFUL now, so maybe I should
  5136. * get rid of them...
  5137. */
  5138. if ((exit_reason & UNWIND_ERROR) != 0)
  5139. { A_reg = elt(litvec, fname);
  5140. err_printf("Calling: ");
  5141. loop_print_error(A_reg);
  5142. err_printf("\n");
  5143. nil = C_nil;
  5144. if (exception_pending()) flip_exception();
  5145. }
  5146. #endif
  5147. goto pop_stack_and_exit;
  5148. ncall_error_exit:
  5149. flip_exception();
  5150. goto pop_stack_and_exit;
  5151. callself_error_exit:
  5152. flip_exception();
  5153. goto pop_stack_and_exit;
  5154. stack_apply_error:
  5155. { flip_exception();
  5156. stack = C_stack;
  5157. pop(r1);
  5158. C_stack = stack;
  5159. /*
  5160. * I suspect that the next few lines are UNHELPFUL now, so maybe I should
  5161. * get rid of them...
  5162. */
  5163. if ((exit_reason & UNWIND_ERROR) != 0)
  5164. { err_printf("apply: ");
  5165. loop_print_error(r1);
  5166. err_printf("\n");
  5167. nil = C_nil;
  5168. if (exception_pending()) flip_exception();
  5169. }
  5170. }
  5171. goto pop_stack_and_exit;
  5172. apply_error:
  5173. flip_exception();
  5174. C_stack = stack;
  5175. /*
  5176. * I suspect that the next few lines are UNHELPFUL now, so maybe I should
  5177. * get rid of them...
  5178. */
  5179. if ((exit_reason & UNWIND_ERROR) != 0)
  5180. { err_printf("apply: ");
  5181. loop_print_error(A_reg);
  5182. err_printf("\n");
  5183. nil = C_nil;
  5184. if (exception_pending()) flip_exception();
  5185. }
  5186. goto pop_stack_and_exit;
  5187. error_exit:
  5188. flip_exception();
  5189. goto pop_stack_and_exit;
  5190. error_1_A:
  5191. C_stack = stack;
  5192. error(1, errcode, A_reg);
  5193. nil = C_nil;
  5194. flip_exception();
  5195. goto pop_stack_and_exit;
  5196. pop_stack_and_exit:
  5197. stack = C_stack;
  5198. /*
  5199. * What follows is my current guess for a good diagnostic...
  5200. */
  5201. if ((exit_reason & UNWIND_ERROR) != 0)
  5202. { err_printf("Inside: ");
  5203. loop_print_error(elt(litvec, 0));
  5204. err_printf("\n");
  5205. nil = C_nil;
  5206. if (exception_pending()) flip_exception();
  5207. }
  5208. /*
  5209. * Here I need to scan down the current stack-frame looking for either a
  5210. * CATCH or an UNWIND-PROTECT marker.
  5211. */
  5212. for (;;)
  5213. { unwind_stack(entry_stack, YES);
  5214. if (C_stack == entry_stack)
  5215. { w = 0;
  5216. break;
  5217. }
  5218. /* Here I have a CATCH/UNWIND record within the current function */
  5219. stack = C_stack;
  5220. pop2(r1, r2);
  5221. C_stack = stack;
  5222. /*
  5223. * If the tag matches exit_tag then I must reset pc based on offset (r2)
  5224. * and continue. NB need to restore A_reg from exit_value.
  5225. */
  5226. w = int_of_fixnum(r2);
  5227. if (qcar(r1) == SPID_PROTECT)
  5228. { /* This is an UNWIND catcher */
  5229. push2(exit_tag, fixnum_of_int(exit_reason));
  5230. #ifdef COMMON
  5231. C_stack = stack;
  5232. A_reg = Lmv_list(nil, exit_value);
  5233. nil = C_nil;
  5234. if (exception_pending()) goto error_exit;
  5235. #endif
  5236. push(A_reg);
  5237. ppc = (unsigned char *)data_of_bps(codevec) + w;
  5238. w = 1;
  5239. break;
  5240. }
  5241. else if (exit_reason == UNWIND_THROW && r1 == exit_tag)
  5242. { ppc = (unsigned char *)data_of_bps(codevec) + w;
  5243. w = 1;
  5244. break;
  5245. }
  5246. }
  5247. if (w)
  5248. { A_reg = exit_value;
  5249. continue;
  5250. }
  5251. #ifndef NO_BYTECOUNT
  5252. qcount(elt(litvec, 0)) += OPCOUNT;
  5253. #endif
  5254. C_stack = entry_stack;
  5255. flip_exception();
  5256. return nil;
  5257. }
  5258. }
  5259. #ifdef __powerc
  5260. /* If you have trouble compiling this just comment it out, please */
  5261. #pragma options(global_optimizer)
  5262. #endif
  5263. /* end of bytes1.c */