Duplication and Partial Evaluation--- For a Better

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

,,1{40()cKluwerAcademicPublishers,Boston.ManufacturedinTheNetherlands.DuplicationandPartialEvaluation|ForaBetterUnderstandingofReectiveLanguages|KENICHIASAIasai@is.s.u-tokyo.ac.jpDepartmentofInformationScience,FacultyofScience,TheUniversityofTokyo,7-3-1Hongo,Bunkyo-Ku,Tokyo,113,JapanSATOSHIMATSUOKAmatsu@ipl.t.u-tokyo.ac.jpDepartmentofMathematicalEngineering,FacultyofEngineering,TheUniversityofTokyo,7-3-1Hongo,Bunkyo-Ku,Tokyo,113,JapanAKINORIYONEZAWAyonezawa@is.s.u-tokyo.ac.jpDepartmentofInformationScience,FacultyofScience,TheUniversityofTokyo,7-3-1Hongo,Bunkyo-Ku,Tokyo,113,JapanReceivedOctober10,1993;RevisedAugust6,1994,March30,1995Editor:DanielP.FriedmanandAkinoriYonezawaAbstract.Thispaperpresentsageneralimplementationframeworkforreectivelanguages.Itallowsustosystematicallybuildreectivelanguageswhichhavethefollowingfavorableproper-ties:(1)userprogramsareallowedtoaccessandchange(partsof)metalevelinterpreters,(2)reectivefacilitiesareavailableateverylevel,(hencethereexistsconceptuallyaninnitetowerofinterpreters),and(3)theinterpreterrunsasecientlyastheconventional(directlyimplemented)metacircularinterpreterwhenreectionisnotused.Ourschemeisdividedintothreestages.First,wedeneinterpreterswhichgivetheoperationalsemanticsofeachlevel,andconceptuallyconstructtheinnitetoweroftheseinterpreters.Theyarethenduplicatedtoobtaindirectlyexecutedinterpreters,whileintroducingdoubleinterpretationtomaintainredenabilityofinter-preters.Finally,partialevaluationisemployedtocollapsethedoubleinterpretationintosingleinterpretation.WeillustrateourschemebyimplementingaparticularreectivelanguagecalledBlackinScheme,butitisgeneralenoughtobeappliedtootherreectivelanguages.ThepapergivesthecompleteSchemeimplementationofBlackanddemonstratessomeexamples.WealsoshowhowasystemwiththedeltaabstractionintroducedbyBlondcanbeconstructedinourframework.Keywords:reection,partialevaluation,metacircularinterpreter,directexecution,interpreta-tion,inniteregression\BlackisBlack|LosBravos1.IntroductionReectiveprogramminglanguagesprovidehighexibilityandextensibilitybyal-lowinguserprogramstoaccessandchangetheirlanguageimplementation(andtherebysemantics)fromwithinthemselves.Tochangethelanguagesemanticsinconventionalnon-reectivelanguages,weneedtofullyunderstandthelowlevel2implementationdetailsandcarefullyaltertheirimplementation(eitheraninter-preteroracompiler),whichisusuallywritteninlowerlevellanguages.Reectivelanguagesallowsuchmodicationswithinthesamelanguageframeworkusinghighlevelabstractionswithoutunderstandinglowlevelimplementation.Becauseofitsexibilityandextensibility,reectionisalsoimportantforpracticalpurposes,i.e.,asabasisfor\openimplementation[9].Animportantcharacteristicofreectivelanguagesistheirtowerstructure.Inreectivelanguages,userprogramsatthebaselevel(orlevel0)areinterpretedbytheinterpreterrunningatthelevelabove(level1,ormetalevel),whichisinturninterpretedbytheinterpreterrunningatlevel2,andsoon.Conceptually,thereisaninnitetowerofinterpreters.Reectivelanguagespermituserprogramstoexecuteprogramsatanylevelinthetower,possiblyaccessing(introspecting)ormodifyinginterpretersofupperlevels.However,theinnitetowerstructuremakesitdiculttoimplementreectivelan-guages.InconventionalLisp-basedreectivelanguages,suchasBrown[5][13]andBlond[2],thetowerissimulatedbylazilycreatinginterpreterswhicharedirectlyexecutedbymachine,insteadofbyinterpretationatthelevelabove.Althoughtheuseofdirectlyexecutedinterpretersispreferableforeciency,itbecomesimpos-sibleforuserprogramstoalter(partsof)theinterpretersselectively,sincetheyarealreadyinmachinecodeform.Forexample,supposewewanttomodifythemetalevelinterpretersothatitprintsoutalltheexpressionsitevaluates.Ifthestructureandimplementationofthemetalevelinterpreterwereavailabletouserprograms,wecouldachievethisjustbyinsertingaprintfunctionatanappropri-ateplaceintheinterpretercode.SuchmodicationsarenotpossibleinBrownandBlondsincetheinterpreterisdirectlyexecutedandavailableonlyasasinglemonolithicfunctioncalledmeaning.JeersonandFriedman,ontheotherhand,presentedaSimpleReectiveInter-preterIR[7],inwhichuserprogramsareallowedtoaccessandchangethemetalevelinterpreters.BecauseinIR,theinterpreterrunningateachlevelisimplementedasordinaryuser-denedfunctions,andactuallyinterpretedbytheinterpreteronelevelabove,wecanfreelyredeneittochangeitssubsequentbehavior.However,sinceIRisimplementedbyexecutingametacircularinterpreterontopofitself,ithastwodrawbacks:(1)itisextremelyinecientduetodouble(triple,etc.)interpretation,and(2)itrequirestheconstructionofaninnitetowerifwewanttoachievereectionateverylevel.Tobehighlyexibleandextensible,reectivelanguagesshouldfulllthefollowingrequirements:1.Userprogramsareallowedtoaccessandchange(partsof)metalevelinter-preters.2.Reectivefacilitiesareavailableateverylevel.3.Theinterpreterrunsecientlywhenreectionisnotused,andreasonablywellevenifpartsofitaremodied.3Inthispaper,wepresentageneralframeworkfortheimplementationofreectivelanguagesthatsatisfythesethreerequirements.Tobemorespecic,

1 / 40
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功