• <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  評論-2670  文章-0  trackbacks-0
                經(jīng)過1個小時的奮斗,修了3個bug,終于使得Kernel FP能運行的代碼漸漸多了起來。現(xiàn)在可以看看純函數(shù)式語言簡潔的代碼及運行結(jié)果啦!

                下面是很多用于測試的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!"

                通過類型推導(dǎo)、模板實例化和運行時assembly的生成之后,就可以得到運行結(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"錯誤["+VUnicodeString(i+1)+L"]\t模塊:"+Errors[i]->Module+L"\t行號:"+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"\"含有語法錯誤:\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"生成符號表時發(fā)生錯誤\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) 閱讀(1453) 評論(1)  編輯 收藏 引用 所屬分類: 腳本技術(shù)

            評論:
            # re: Kernel FP成功運行一部分列表處理程序 2008-12-16 00:57 | 肥仔
            永不停息的強(qiáng)人。
            這是一個人的戰(zhàn)斗!  回復(fù)  更多評論
              
            久久久综合香蕉尹人综合网| 精品久久一区二区| 久久夜色精品国产噜噜亚洲a| 伊人精品久久久久7777| 亚洲中文字幕久久精品无码APP| 亚洲精品无码久久久久| 91精品观看91久久久久久| 亚洲欧美日韩精品久久亚洲区| 无码伊人66久久大杳蕉网站谷歌| 久久国产高清字幕中文| 狠狠色狠狠色综合久久| 99久久精品国产一区二区| 色综合久久久久综合体桃花网 | 无码任你躁久久久久久久| 狠狠色丁香久久婷婷综合蜜芽五月| 久久婷婷五月综合色奶水99啪| 国产精品嫩草影院久久| 久久久久亚洲Av无码专| 久久精品国产精品亚洲精品 | 污污内射久久一区二区欧美日韩| 久久久久人妻精品一区| 久久久精品国产| 久久996热精品xxxx| 国产精品一久久香蕉国产线看| 国产欧美久久久精品影院| 天天综合久久久网| 久久精品国产亚洲麻豆| 久久精品国产亚洲AV无码娇色| 欧美黑人激情性久久| 午夜精品久久影院蜜桃| 久久久久无码中| 精品国产一区二区三区久久蜜臀| 999久久久无码国产精品| 99久久无色码中文字幕| 成人久久综合网| 26uuu久久五月天| 亚洲国产精品一区二区久久| 久久香蕉国产线看观看乱码| 青青青青久久精品国产h| 国产精品久久久久久久久久免费| 国产69精品久久久久99尤物 |