G.Cousineau, P-L.Curien and B.Robinet Editors,

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

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

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

资源描述

1In:CombinatorsandFunctionalProgrammingLanguagesG.Cousineau,P-L.CurienandB.RobinetEditors,LectureNotesinComputerSciencen.242,Springer-Verlag,1986AmberLucaCardelli1AT&TBellLaboratories,MurrayHill,NJ07974IntroductionTheAmberlanguageembedsmanyrecentideasinprogramminglanguagedesign,andtriestointroduceallthefeaturesintheirminimal,essential,form.Oneofitsmaingoalsistosafelyblendstatictypingwiththedynamicrequirementsofasystemprogramminglanguage.Forthispurpose,multipleinheritanceandpersistentobjectsareintegratedinastronglytypedlanguage.Otherfeaturesincludegraphics,higher-orderfunctions,modulesandconcurrency.Amberisaspin-offoftheMLprogramminglanguage[Milner84].TheMLlanguageisnowbeingstandardized,andassuchisnotverysuitableforexperimentation.Amberisintendedasatoolfortryingoutnewideasinlanguageimplementation,languagedesign,andlanguageenvironments,whilebeingdeeplyinfluencedbytheMLexperience.Asaprogramminglanguage,Amberwasdefinedtoexperimentwithanewstyleofpolymorphism[Cardelli84b]which,unliketheML-styleparametricpolymorphism[Milner78],isbasedonanotionoftypeinclusion,andcanbeusedtointerpretmanyprogrammingconceptsfoundinobject-orientedlanguages[GoldbergRobson83].Inthisview,themainfeaturesoffunctionalandobject-orientedlanguagescanbenaturallyintegrated,andthecombinationofhigher-orderfunctionsandmultipleinheritancecanbestronglytyped.SometypecheckinganomaliesarestillpresentinAmber,andcurrentresearchisaimedatsolvingthemandintegratinginclusionpolymorphismwithparametricpolymorphism.Typeinclusionalsoplaysanimportantroleinmodularization.Amberprogramscanbepartitionedintomodulesandseparatelycompiled.Moduleshaveimport-exportlistsfortypesandvalues.Whenatypeisimported,itsactualdefinitionisnotaccessible:thisisaformofdataabstractionrealizedthroughthemodulemechanism,andimpliesthatmodulescanbecompiledinanyorder.Itispossibletospecifythattwoimportedtypes,althoughunknown,areoneasubtypeoftheother,sothatinheritancecanbemadetoworkacrossmoduleboundaries.Attheprogrammingsystemlevel,theimplementationisheavilybasedontheabilitytoexportandimportarbitraryvaluesto/frompersistentstorage.Thisfeatureisprovidedatthe1Currentaddresss:DECSRC,130LyttonAve,PaloAlto,CA94301.2lowestlevel,andguaranteesthepreservationofanycircularityorsharingpresentinthedatastructures.Asthelanguageisstaticallyscopedandtheimplementationoffunctionsisbasedonclosures,exportingafunctionwillautomaticallyexporteverythingthefunctionneedstorunwhenitisimported.Complexdatastructures,liketreesorfonts,canbeexportedandimportedwithouthavingtowritead-hocroutinestounparseandreparsethem.Separatecompilationisalsobasedonpersistence,andinvolvesimportingandexportingmoduledatastructures.Moreover,persistentdataarestronglytyped,sothatatypeerrorisgenerated(atruntime)ifonehappenstoimportthewrongkindofobject.Alimitationisthatonecanonlyimport/exportwholeobjects;hopefullyaschemewillbefoundtostorepartialobjects,alongthelinesof[AtkinsonBaileyChisholmCockshottMorrison83].Attheimplementationlevel,theAmbersystemisorganizedinthreelayers.Atthebottomthereisakernelwhichprovidesinput-output,graphics,heapmanagementand(inthefuture)processscheduling.Heapmanagementconsistsofdataallocation,collectionandpersistentstorage.Thislevelislargelyindependentofanyparticularlanguage,andonlydealswithfourbasicdataformats:immediates(suchasbooleans,integersandpointers),stringsofbytes,arraysofimmediatesandbitmaps.Thesecondlayerisanabstractmachine,similartotheonein[Cardelli84a],whichprovidesaninstructionsetanddatatypes(suchasrecords,functionalclosures,etc.)basedontheunderlyingdataformats.Programsareatthemomentencodedasbytestreamstobeinterpreted,butnothingwouldpreventthemfrombeingcompiledtomachinecode(exceptforportabilityconsiderations).Thislevelismildlylanguage-dependent,andcanbeusedtoimplementdifferentlanguagesinthesamegenericclasswithfewchanges.ThethirdlayeristhecompiledAmbercompiler,anditssourcewhichiswritteninAmber.Thecompilerhasalreadygonethroughdozensofgenerations,eachtimerecompilinganewversionofitself.ThesystemhasbeenportedtothreedifferentmachinesandcurrentlyrunsonanAppleMacintosh.FeaturesThissectionsummarizesthemainlanguagefeatures,beforegoingintomoredetailinthefollowingsections.Amberisinteractive.Everytimeaphraseisenteredatthetoplevel,thephraseisanalyzed,compiledandexecuted.Aphrasecanbeassimpleasevaluating1+2,orascomplicatedascompilingandlinkingaprogrammodule.Amberisstaticallyscoped.Everyvariableisboundtothenearestenclosingdefiningoccurrenceofthatvariable.Functionsreferringtoglobalvariablescanbetreatedasself-containedobjectswhichcanbepassedtootherfunctions,returnedfromotherfunctions,storedintodatastructuresandexportedtopersistentstorage.Staticscopingisalsorespectedatthetoplevel.Amberisasafelanguage.Staticanddynamictypecheckingensurestheconsistentuseofdataandoperations.Typecheckingismostlystatic,withsomeprovisionsfordynamicchecks,3asdescribedbelow.Amberhassafedynamictypes.Anyvalueinthelanguagecanbebundledintoadynamicvalue,whichcarriesitsfulltypewithit.Dynamicvaluescanlaterbecoercedtosomespecifictype,strippingthemofthedynamictypeinformati

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

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

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

×
保存成功