• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評(píng)論-2670  文章-0  trackbacks-0
                經(jīng)過(guò)1個(gè)小時(shí)的奮斗,修了3個(gè)bug,終于使得Kernel FP能運(yùn)行的代碼漸漸多了起來(lái)。現(xiàn)在可以看看純函數(shù)式語(yǔ)言簡(jiǎn)潔的代碼及運(yùn)行結(jié)果啦!

                下面是很多用于測(cè)試的main函數(shù):
             1 module startup
             2 import list
             3 
             4 def main0 = length "vczh"
             5 def main1 = head "vczh"
             6 def main2 = tail "vczh"
             7 def main3 = concat "genius" " vczh!"
             8 def main4 = isempty ""
             9 def main5 = isempty "vczh"
            10 def main6 = transform (iadd 1) (list 1 (list 2 (list 3 empty)))
            11 def main7 = reverse "abcde"
            12 def main8 = intersperse '|' "vczh"
            13 def main9 = flatten (list "vczh" (list " library" (list " ++" empty)))
            14 def main10 = pairlist "genius" "vczh"
            15 def main11 = fold 0 iadd (list 1 (list 2 (list 3 empty)))
            16 def main12 = all (iequ 0) (list 0 (list 1 (list 2 empty)))
            17 def main13 = any (iequ 0) (list 0 (list 1 (list 2 empty)))
            18 def main14 = take 5 (iterate (iadd 10)
            19 def main15 = take 5 (repeat 99)
            20 def main16 = take 5 (cycle (list 1 (list 2 empty)))
            21 def main17 = drop 5 "genius vczh!"

                通過(guò)類(lèi)型推導(dǎo)、模板實(shí)例化和運(yùn)行時(shí)assembly的生成之后,就可以得到運(yùn)行結(jié)果了:
             1 CTOR : system.empty=0,0
             2 CTOR : system.false=1,0
             3 CTOR : system.list=2,2
             4 CTOR : system.true=3,0
             5 CTOR : sysutils.pair=4,2
             6 FUNC : startup.main0, 8
             7 FUNC : startup.main1, 7
             8 FUNC : startup.main10, 6
             9 FUNC : startup.main11, 16
            10 FUNC : startup.main12, 17
            11 FUNC : startup.main13, 18
            12 FUNC : startup.main14, 19
            13 FUNC : startup.main15, 27
            14 FUNC : startup.main16, 26
            15 FUNC : startup.main17, 24
            16 FUNC : startup.main2, 36
            17 FUNC : startup.main3, 29
            18 FUNC : startup.main4, 39
            19 FUNC : startup.main5, 38
            20 FUNC : startup.main6, 14
            21 FUNC : startup.main7, 41
            22 FUNC : startup.main8, 45
            23 FUNC : startup.main9, 10
            24 FUNC : sysutils.and, 5
            25 FUNC : sysutils.ineg, 1
            26 FUNC : sysutils.not, 3
            27 FUNC : sysutils.or, 2
            28 FUNC : sysutils.xor, 0
            29 EXTR : kernelfp::iadd=1
            30 EXTR : kernelfp::iequ=2
            31 EXTR : kernelfp::isub=0
            32 main0返回值:4
            33 main1返回值:v
            34 main2返回值:[c , z , h]
            35 main3返回值:[g , e , n , i , u , s ,   , v , c , z , h , !]
            36 main4返回值:system.true
            37 main5返回值:system.false
            38 main6返回值:[2 , 3 , 4]
            39 main7返回值:[e , d , c , b , a]
            40 main8返回值:[v , | , c , | , z , | , h]
            41 main9返回值:[v , c , z , h ,   , l , i , b , r , a , r , y ,   , + , +]
            42 main10返回值:[(sysutils.pair g v) , (sysutils.pair e c) , (sysutils.pair n z) ,
            43  (sysutils.pair i h)]
            44 main11返回值:6
            45 main12返回值:system.false
            46 main13返回值:system.true
            47 main14返回值:[0 , 1 , 2 , 3 , 4]
            48 main15返回值:[99 , 99 , 99 , 99 , 99]
            49 main16返回值:[1 , 2 , 1 , 2 , 1]
            50 main17返回值:[s ,   , v , c , z , h , !]
            51 

                調(diào)用這些函數(shù)的C++代碼如下:
              1 #include "..\..\..\..\VL++\Library\Platform\VL_Console.h"
              2 #include "..\..\..\..\VL++\Library\Script\KernelFP\VL_KFPScript.h"
              3 #include "..\..\..\..\VL++\Library\Data\VL_Stream.h"
              4 #include "..\..\..\..\VL++\Library\Data\VL_System.h"
              5 #include "..\..\..\..\VL++\Library\Data\VL_Uniop.h"
              6 
              7 using namespace vl;
              8 using namespace vl::platform;
              9 using namespace vl::kernalfp;
             10 using namespace vl::stream;
             11 using namespace vl::system;
             12 using namespace vl::uniop;
             13 
             14 VUnicodeString ToString(VL_KfpError::List& Errors)
             15 {
             16     VUnicodeString Result=L"";
             17     for(VInt i=0;i<Errors.GetCount();i++)
             18     {
             19         Result+=L"錯(cuò)誤["+VUnicodeString(i+1)+L"]\t模塊:"+Errors[i]->Module+L"\t行號(hào):"+VUnicodeString(Errors[i]->Token.LineInFile+1)+L"\r\n";
             20         Result+=L"信息:"+Errors[i]->Message+L"\r\n";
             21     }
             22     return Result;
             23 }
             24 
             25 void RunProgram(VL_KfpMachine::Ptr Machine)
             26 {
             27     MyPlugin Plugin;
             28     Machine->AddPlugin(&Plugin,false);
             29 
             30     VInt Index=0;
             31     while(true)
             32     {
             33         VInt ID=Machine->GetFunctionFirstIdByName(L"startup.main"+VUnicodeString(Index));
             34         if(ID==-1)
             35         {
             36             break;
             37         }
             38         else
             39         {
             40             GetConsole()->Write(L"main"+VUnicodeString(Index)+L"返回值:");
             41             VL_KfpValue MainFunction=Machine->CreateFunction(ID);
             42             GetConsole()->Write(ValueToString(MainFunction)+L"\r\n");
             43         }
             44         Index++;
             45     }
             46 }
             47 
             48 void vlmain()
             49 {
             50     GetConsole()->SetTitle(L"Vczh Kernal FP");
             51     GetConsole()->SetPauseOnExit(true);
             52     GetConsole()->SetTestMemoryLeaks(true);
             53 
             54     VUnicodeString TestDataPath=VFileName(GetConsole()->GetAppPath()).MakeAbsolute(L"..\\TestData\\").GetStrW();
             55     VUnicodeString TestOutput;
             56     VL_UniStrings CodeFiles;
             57     {
             58         VL_FileStream Stream(TestDataPath+L"Project.txt",VL_FileStream::vfomRead);
             59         VUnicodeString Project=ReadText(&Stream);
             60         CodeFiles.SetText(Project);
             61     }
             62 
             63     VL_KfpSymbol Symbol;
             64     VBool ErrorOccurred=false;
             65 
             66     for(VInt i=0;i<CodeFiles.GetCount();i++)
             67     {
             68         VL_FileStream Stream(TestDataPath+CodeFiles[i],VL_FileStream::vfomRead);
             69         VUnicodeString TestCode=ReadText(&Stream);
             70 
             71         VL_KfpError::List Errors;
             72         Symbol.AddUnit(TestCode,Errors);
             73         if(Errors.GetCount())
             74         {
             75             TestOutput+=L"文件\""+VUnicodeString(CodeFiles[i])+L"\"含有語(yǔ)法錯(cuò)誤:\r\n";
             76             TestOutput+=ToString(Errors);
             77             ErrorOccurred=true;
             78         }
             79     }
             80     if(!ErrorOccurred)
             81     {
             82         VL_KfpError::List Errors;
             83         Symbol.PreCompile(Errors);
             84         if(Errors.GetCount())
             85         {
             86             TestOutput+=L"生成符號(hào)表時(shí)發(fā)生錯(cuò)誤\r\n";
             87             TestOutput+=ToString(Errors);
             88             ErrorOccurred=true;
             89         }
             90     }
             91     if(!ErrorOccurred)
             92     {
             93         VL_KfpMachine::Ptr Machine=Symbol.CreateMachine();
             94         TestOutput=Symbol.GetReport();
             95         for(VInt i=0;i<Machine->GetCtorCount();i++)
             96         {
             97             VUnicodeString Name=Machine->GetCtorNameByIndex(i);
             98             VInt CtorID=Machine->GetCtorIDByIndex(i);
             99             VInt ParamCount=Machine->GetCtorParameterCountByID(CtorID);
            100             GetConsole()->Write(L"CTOR : "+Name+L"="+VUnicodeString(CtorID)+L","+VUnicodeString(ParamCount)+L"\r\n");
            101         }
            102         for(VInt i=0;i<Machine->GetFunctionNameCount();i++)
            103         {
            104             GetConsole()->Write(L"FUNC : "+Machine->GetFunctionNameByIndex(i));
            105             VL_List<VInt , true> IDs;
            106             Machine->GetFunctionIDsByIndex(i,IDs);
            107             for(VInt j=0;j<IDs.GetCount();j++)
            108             {
            109                 GetConsole()->Write(L""+VUnicodeString(IDs[j]));
            110             }
            111             GetConsole()->Write(L"\r\n");
            112         }
            113         for(VInt i=0;i<Machine->GetExternalCount();i++)
            114         {
            115             VUnicodeString Name=Machine->GetExternalNameByIndex(i);
            116             VInt ExternalID=Machine->GetExternalIDByIndex(i);
            117             GetConsole()->Write(L"EXTR : "+Name+L"="+VUnicodeString(ExternalID)+L"\r\n");
            118         }
            119         RunProgram(Machine);
            120     }
            121     else
            122     {
            123         GetConsole()->Write(TestOutput);
            124     }
            125     {
            126         VL_FileStream Stream(TestDataPath+L"Output.txt",VL_FileStream::vfomWrite);
            127         WriteText(&Stream,vceUtf16,true,TestOutput);
            128     }
            129     {
            130         VL_FileStream Stream(TestDataPath+L"Debug.txt",VL_FileStream::vfomWrite);
            131         WriteText(&Stream,vceUtf16,true,Symbol.GetDebugInformation());
            132     }
            133 }
            posted on 2008-12-12 10:03 陳梓瀚(vczh) 閱讀(1451) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): 腳本技術(shù)

            評(píng)論:
            # re: Kernel FP成功運(yùn)行一部分列表處理程序 2008-12-16 00:57 | 肥仔
            永不停息的強(qiáng)人。
            這是一個(gè)人的戰(zhàn)斗!  回復(fù)  更多評(píng)論
              
            久久婷婷五月综合国产尤物app| 免费久久人人爽人人爽av| 日韩欧美亚洲综合久久| 久久精品国产99国产电影网 | 伊人热热久久原色播放www| 无码超乳爆乳中文字幕久久| 色婷婷久久久SWAG精品| 久久精品成人免费国产片小草| 青草影院天堂男人久久| 久久国产成人精品国产成人亚洲| 精品国产一区二区三区久久| 99国产精品久久| 热re99久久精品国产99热| 久久久久久综合一区中文字幕 | 精品久久777| 久久久国产精品网站| 99久久国产免费福利| 国产成人久久久精品二区三区| 久久亚洲国产午夜精品理论片| 77777亚洲午夜久久多喷| 久久亚洲国产中v天仙www| 91精品国产色综久久| 久久亚洲欧洲国产综合| 97精品伊人久久久大香线蕉 | 丰满少妇高潮惨叫久久久| 韩国无遮挡三级久久| 国产午夜精品久久久久九九电影| 久久久久久久亚洲精品| 久久精品国产亚洲AV蜜臀色欲| 亚洲精品白浆高清久久久久久| 久久精品麻豆日日躁夜夜躁| 青青青青久久精品国产| 久久午夜综合久久| 亚洲人成伊人成综合网久久久 | 91久久九九无码成人网站| 欧美日韩中文字幕久久久不卡 | 99久久精品费精品国产| 中文字幕无码久久精品青草| 久久无码人妻一区二区三区| 久久国产乱子精品免费女| 2021最新久久久视精品爱|