<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>fleurer &#187; 备忘</title>
	<atom:link href="http://www.fleurer-lee.com/category/%e5%a4%87%e5%bf%98/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fleurer-lee.com</link>
	<description>rage and love, story of my life.</description>
	<lastBuildDate>Thu, 02 Sep 2010 11:07:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>数据结构课设，表达式计算</title>
		<link>http://www.fleurer-lee.com/2010/06/30/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e8%af%be%e8%ae%be%ef%bc%8c%e8%a1%a8%e8%be%be%e5%bc%8f%e8%ae%a1%e7%ae%97/</link>
		<comments>http://www.fleurer-lee.com/2010/06/30/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e8%af%be%e8%ae%be%ef%bc%8c%e8%a1%a8%e8%be%be%e5%bc%8f%e8%ae%a1%e7%ae%97/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:28:34 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645901</guid>
		<description><![CDATA[随便写了下，没仔细调试。
大约这么定义
double parse_expr(char *input, char **output);
input就是表达式的字符串，output是解析剩下的部分。如果output==input，就是解析失败。如果正确，返回运算结果。
用起来大约这样

    char *out, *exp=&#34;2+(1+3)*4&#34;;
    double r = parse_expr&#40;exp, &#38;out&#41;;
    if &#40;out==exp&#41;&#123;
        printf&#40;&#34;parse fail\n&#34;&#41;;
        return 0;
    &#125;
    printf&#40;&#34;%s =&#62; %f \n&#34;, exp, r&#41;;

回头想下，思路跟以前写的parser几乎是葫芦画瓢，也该算是递归下降吧。
代码如下
exp.h

double [...]]]></description>
			<content:encoded><![CDATA[<p>随便写了下，没仔细调试。</p>
<p>大约这么定义<br />
double parse_expr(char *input, char **output);</p>
<p>input就是表达式的字符串，output是解析剩下的部分。如果output==input，就是解析失败。如果正确，返回运算结果。</p>
<p>用起来大约这样</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>exp<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;2+(1+3)*4&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">double</span> r <span style="color: #339933;">=</span> parse_expr<span style="color: #009900;">&#40;</span>exp<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>out<span style="color: #339933;">==</span>exp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;parse fail<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s =&gt; %f <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> exp<span style="color: #339933;">,</span> r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>回头想下，思路跟<a href="http://github.com/Fleurer/FParser">以前写的parser</a>几乎是葫芦画瓢，也该算是递归下降吧。</p>
<p>代码如下</p>
<p>exp.h</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">double</span> parse_expr<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">double</span> parse_term<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">double</span> parse_fact<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">double</span> parse_numb<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>exp.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;exp.h&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// expr ::= term {[+-] term}</span>
<span style="color: #993333;">double</span> parse_expr<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span> r<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>tmp<span style="color: #339933;">,</span> op<span style="color: #339933;">;</span>
    tmp <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// factor</span>
    r <span style="color: #339933;">=</span> parse_term<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>output<span style="color: #339933;">==</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// {[+-] term}</span>
    tmp <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>output<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>op<span style="color: #339933;">=*</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'+'</span> <span style="color: #339933;">||</span> op<span style="color: #339933;">==</span><span style="color: #ff0000;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">double</span> r2 <span style="color: #339933;">=</span> parse_term<span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>tmp<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">==*</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #339933;">*</span>output <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        r <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>op<span style="color: #339933;">==</span><span style="color: #ff0000;">'+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span> r<span style="color: #339933;">+</span>r2<span style="color: #339933;">:</span> r<span style="color: #339933;">-</span>r2<span style="color: #339933;">;</span>
        tmp <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>output<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// term ::= factor {[*/] factor}</span>
<span style="color: #993333;">double</span> parse_term<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span> r<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>tmp<span style="color: #339933;">,</span> op<span style="color: #339933;">;</span>
    tmp <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// factor</span>
    r <span style="color: #339933;">=</span> parse_fact<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>output<span style="color: #339933;">==</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// {[*/] factor}</span>
    tmp <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>output<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>op<span style="color: #339933;">=*</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'*'</span> <span style="color: #339933;">||</span> op<span style="color: #339933;">==</span><span style="color: #ff0000;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">double</span> r2 <span style="color: #339933;">=</span> parse_fact<span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>tmp<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">==*</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #339933;">*</span>output <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        r <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>op<span style="color: #339933;">==</span><span style="color: #ff0000;">'*'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span> r<span style="color: #339933;">*</span>r2<span style="color: #339933;">:</span> r<span style="color: #339933;">/</span>r2<span style="color: #339933;">;</span>
        tmp <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>output<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// fact ::= (expr) | numb</span>
<span style="color: #993333;">double</span> parse_fact<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span> r<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>tmp<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// (expr)</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>input<span style="color: #339933;">==</span><span style="color: #ff0000;">'('</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        tmp <span style="color: #339933;">=</span> input<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        r <span style="color: #339933;">=</span> parse_expr<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">**</span>output<span style="color: #339933;">==</span><span style="color: #ff0000;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">++;</span>
            <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">// if fail, output == input</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #339933;">*</span>output <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// numb</span>
    r <span style="color: #339933;">=</span> parse_numb<span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">double</span> parse_numb<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>input<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span>  r <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> ch<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>tmp<span style="color: #339933;">=</span>input<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ch <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>tmp<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span><span style="color: #ff0000;">'0'</span> <span style="color: #339933;">&amp;&amp;</span> ch<span style="color: #339933;">&lt;=</span><span style="color: #ff0000;">'9'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        r <span style="color: #339933;">=</span> r<span style="color: #339933;">*</span><span style="color: #0000dd;">10</span><span style="color: #339933;">+</span>ch<span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">*</span>output <span style="color: #339933;">=</span> tmp<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>main.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span> r<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">,</span> exp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    scanf<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%256s&quot;</span><span style="color: #339933;">,</span> exp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    r <span style="color: #339933;">=</span> parse_expr<span style="color: #009900;">&#40;</span>exp<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>out<span style="color: #339933;">==</span>exp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;parse fail<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s =&gt; %f <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> exp<span style="color: #339933;">,</span> r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/06/30/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e8%af%be%e8%ae%be%ef%bc%8c%e8%a1%a8%e8%be%be%e5%bc%8f%e8%ae%a1%e7%ae%97/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>写一个bootsector</title>
		<link>http://www.fleurer-lee.com/2010/05/26/%e5%86%99%e4%b8%80%e4%b8%aabootsector/</link>
		<comments>http://www.fleurer-lee.com/2010/05/26/%e5%86%99%e4%b8%80%e4%b8%aabootsector/#comments</comments>
		<pubDate>Wed, 26 May 2010 13:40:12 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[ASM]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[OS]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645873</guid>
		<description><![CDATA[看的这个教程 http://share.solrex.org/WriteOS/
仿照《自己动手写操作系统》的格式，除却gas确实很囧的因素，大体上还是不错的。万事开头难，在开头的bootloader这里卡了好久的说&#8230;不过动手写一下也不过半小时的功夫 TvT
机器在启动的时候可能是遍历每个磁盘分区，若有发现第512字节位置是个0xAA55的魔数，就认为这是个引导的分区了。然后就把它的前512字节装入内存，从0&#215;7c00位置开始执行。这就是最简单的引导方式了好像。
我们把汇编代码编译成一个512bytes的二进制文件，再把它放到一个软盘的映像里就好。
boot.S

&#91;bits 16&#93;                       ;real mode
&#91;org 0x7c00&#93;                  ;put code start at 0x7c00
&#91;section .text&#93;
&#160;
_start:
    [...]]]></description>
			<content:encoded><![CDATA[<p>看的这个教程 http://share.solrex.org/WriteOS/</p>
<p>仿照《自己动手写操作系统》的格式，除却gas确实很囧的因素，大体上还是不错的。万事开头难，在开头的bootloader这里卡了好久的说&#8230;不过动手写一下也不过半小时的功夫 TvT</p>
<p>机器在启动的时候可能是遍历每个磁盘分区，若有发现第512字节位置是个0xAA55的魔数，就认为这是个引导的分区了。然后就把它的前512字节装入内存，从0&#215;7c00位置开始执行。这就是最简单的引导方式了好像。</p>
<p>我们把汇编代码编译成一个512bytes的二进制文件，再把它放到一个软盘的映像里就好。</p>
<p>boot.S</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>bits <span style="color: #0000ff;">16</span><span style="color: #009900; font-weight: bold;">&#93;</span>                       <span style="color: #666666; font-style: italic;">;real mode</span>
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">org</span> <span style="color: #0000ff;">0x7c00</span><span style="color: #009900; font-weight: bold;">&#93;</span>                  <span style="color: #666666; font-style: italic;">;put code start at 0x7c00</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>section <span style="color: #339933;">.</span>text<span style="color: #009900; font-weight: bold;">&#93;</span>
&nbsp;
_start<span style="color: #339933;">:</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">ax</span><span style="color: #339933;">,</span> <span style="color: #00007f;">cs</span>            <span style="color: #666666; font-style: italic;">; init seg registers</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">ds</span><span style="color: #339933;">,</span> <span style="color: #00007f;">ax</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">es</span><span style="color: #339933;">,</span> <span style="color: #00007f;">ax</span>
    <span style="color: #00007f; font-weight: bold;">call</span>    _print_str      
&nbsp;
_print_str<span style="color: #339933;">:</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">ax</span><span style="color: #339933;">,</span> <span style="color: #00007f; font-weight: bold;">str</span>            
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">cx</span><span style="color: #339933;">,</span> len    
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">bp</span><span style="color: #339933;">,</span> <span style="color: #00007f;">ax</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">bx</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0x000c</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">dl</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span>
    <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">ax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0x1301</span>
    <span style="color: #00007f; font-weight: bold;">int</span>     <span style="color: #0000ff;">0x10</span>                              <span style="color: #666666; font-style: italic;">;int 0x10, just as manual says</span>
&nbsp;
_loop<span style="color: #339933;">:</span> 
    <span style="color: #00007f; font-weight: bold;">jmp</span>     _loop                             <span style="color: #666666; font-style: italic;">; forever loop</span>
&nbsp;
<span style="color: #00007f; font-weight: bold;">str</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">db</span>      <span style="color: #7f007f;">&quot;screw you guys all fucked up~&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">10</span><span style="color: #339933;">,</span><span style="color: #0000ff;">13</span>
len<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;"> equ</span>     $<span style="color: #339933;">-</span><span style="color: #00007f; font-weight: bold;">str</span>
&nbsp;
times <span style="color: #0000ff;">510</span><span style="color: #339933;">-</span><span style="color: #009900; font-weight: bold;">&#40;</span>$<span style="color: #339933;">-</span>$$<span style="color: #009900; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">db</span> <span style="color: #0000ff;">0</span>                   <span style="color: #666666; font-style: italic;">; fill the rest with 0</span>
<span style="color: #000000; font-weight: bold;">dw</span> <span style="color: #0000ff;">0xAA55</span>                                  <span style="color: #666666; font-style: italic;">; magic number</span></pre></div></div>

<p>编译之</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">nasm -f bin boot.S</pre></div></div>

<p>生成一个boot.bin，下一步搞个软盘镜像</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">dd if=boot.bin of=boot.img bs=512 count=1
dd if=/dev/zero of=boot.img skip=1 seek=1 bs=512 count=2879</pre></div></div>

<p>ls -l 下，大约会是这样</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-rwxr-xr-x 1 ssword ssword     512 2010-05-26 21:28 boot.bin
-rw-r--r-- 1 ssword ssword 1474560 2010-05-26 21:28 boot.img
-rw-r--r-- 1 ssword ssword     399 2010-05-26 21:28 boot.S</pre></div></div>

<p>然后打开virtualbox，设置软驱映像为boot.img。启动虚拟机就可以看到一个可爱的&#8221;screw you all&#8221;什么的了 >v<</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/05/26/%e5%86%99%e4%b8%80%e4%b8%aabootsector/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>使用rake编译C程序</title>
		<link>http://www.fleurer-lee.com/2010/05/20/%e4%bd%bf%e7%94%a8rake%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f/</link>
		<comments>http://www.fleurer-lee.com/2010/05/20/%e4%bd%bf%e7%94%a8rake%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f/#comments</comments>
		<pubDate>Thu, 20 May 2010 15:11:40 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645864</guid>
		<description><![CDATA[每次修改代码一般只会涉及一部分文件，大部分代码都是不必重复编译的。而且编译明显是分步骤也有依赖关系，比如要测试程序就得先链接出一个可执行文件，要链接就得先编译成.o。。。所以就有了make，自动分析任务的依赖关系，只对有变更的文件执行编译，省心省时间。
不过make的语法晦涩啊&#8230;就有了rake
rake提供了file函数可以指明文件的依赖关系，比如：

file 'fdict.o' =&#62; &#91;'src/fdict.c', 'src/fdict.h'&#93; do
  sh 'gcc -Wall -c src/fdict.c'
end
file 'test.o' =&#62; &#91;'src/test.c'&#93; do 
  sh 'gcc -Wall -c src/test.c'
end

file就是个ruby的函数调用，把重复的东西去掉很简单

CFlags = '-Wall'
&#160;
&#91;
  &#91;'src/fdict.c', 'src/fdict.h'&#93;,
  &#91;'src/test.c'&#93;
&#93;.each do &#124;fn_c, *_&#124;
  fn_o = File.basename&#40;fn_c&#41;.ext&#40;'o'&#41;
  file fn_o =&#62; &#91;fn_c, *_&#93; do
    sh &#34;gcc #{CFlags} -c #{fn_c}&#34;
  end
end

再就是链接和执行

OFiles = [...]]]></description>
			<content:encoded><![CDATA[<p>每次修改代码一般只会涉及一部分文件，大部分代码都是不必重复编译的。而且编译明显是分步骤也有依赖关系，比如要测试程序就得先链接出一个可执行文件，要链接就得先编译成.o。。。所以就有了make，自动分析任务的依赖关系，只对有变更的文件执行编译，省心省时间。</p>
<p>不过make的语法晦涩啊&#8230;就有了rake</p>
<p>rake提供了file函数可以指明文件的依赖关系，比如：</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">file <span style="color:#996600;">'fdict.o'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'src/fdict.c'</span>, <span style="color:#996600;">'src/fdict.h'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  sh <span style="color:#996600;">'gcc -Wall -c src/fdict.c'</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
file <span style="color:#996600;">'test.o'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'src/test.c'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
  sh <span style="color:#996600;">'gcc -Wall -c src/test.c'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>file就是个ruby的函数调用，把重复的东西去掉很简单</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">CFlags = <span style="color:#996600;">'-Wall'</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&#91;</span>
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'src/fdict.c'</span>, <span style="color:#996600;">'src/fdict.h'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'src/test.c'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>fn_c, <span style="color:#006600; font-weight:bold;">*</span>_<span style="color:#006600; font-weight:bold;">|</span>
  fn_o = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>fn_c<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">ext</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'o'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  file fn_o <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>fn_c, <span style="color:#006600; font-weight:bold;">*</span>_<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sh <span style="color:#996600;">&quot;gcc #{CFlags} -c #{fn_c}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>再就是链接和执行</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">OFiles = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>fdict.<span style="color:#9900CC;">o</span> test.<span style="color:#9900CC;">o</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:run</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:link</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
  sh <span style="color:#996600;">&quot;./test&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:link</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> OFiles <span style="color:#9966CC; font-weight:bold;">do</span>
  sh <span style="color:#996600;">&quot;gcc #{CFlags} #{OFiles.join(' ')} -o test&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>每修改两行C程序到控制台下边一个rake run就可以立即执行，这一来写c就有点像写脚本了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/05/20/%e4%bd%bf%e7%94%a8rake%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails使用paperclip插件上传时遇到500 Internal Server Error</title>
		<link>http://www.fleurer-lee.com/2010/05/11/rails%e4%bd%bf%e7%94%a8paperclip%e6%8f%92%e4%bb%b6%e4%b8%8a%e4%bc%a0%e6%97%b6%e9%81%87%e5%88%b0505-server-error/</link>
		<comments>http://www.fleurer-lee.com/2010/05/11/rails%e4%bd%bf%e7%94%a8paperclip%e6%8f%92%e4%bb%b6%e4%b8%8a%e4%bc%a0%e6%97%b6%e9%81%87%e5%88%b0505-server-error/#comments</comments>
		<pubDate>Tue, 11 May 2010 07:57:27 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645842</guid>
		<description><![CDATA[有可能是imageMagick没装利索。找不到imagemagick，显示错误信息的时候试图把上传的文件对象序列化，就505了。

sudo apt-get install imagemagick --fix-missing

使用三方库就得做好不可预料事件的准备哇
关于paperclip的使用，这两篇简介好像不错：
http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/
http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip
ps: 又遇到了个没预料的问题，上传validates_attachment_content_type指定的类型之外的文件时候同样会遇到个500 internal server error，未解中。
]]></description>
			<content:encoded><![CDATA[<p>有可能是imageMagick没装利索。找不到imagemagick，显示错误信息的时候试图把上传的文件对象序列化，就505了。</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">sudo apt-get install imagemagick --fix-missing</pre></div></div>

<p>使用三方库就得做好不可预料事件的准备哇</p>
<p>关于paperclip的使用，这两篇简介好像不错：<br />
<a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/">http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/</a><br />
<a href="http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip">http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip</a></p>
<p>ps: 又遇到了个没预料的问题，上传validates_attachment_content_type指定的类型之外的文件时候同样会遇到个500 internal server error，未解中。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/05/11/rails%e4%bd%bf%e7%94%a8paperclip%e6%8f%92%e4%bb%b6%e4%b8%8a%e4%bc%a0%e6%97%b6%e9%81%87%e5%88%b0505-server-error/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>踩踩数据结构什么的 =“=</title>
		<link>http://www.fleurer-lee.com/2010/05/08/%e8%b8%a9%e8%b8%a9%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%bb%80%e4%b9%88%e7%9a%84-%e2%80%9c/</link>
		<comments>http://www.fleurer-lee.com/2010/05/08/%e8%b8%a9%e8%b8%a9%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%bb%80%e4%b9%88%e7%9a%84-%e2%80%9c/#comments</comments>
		<pubDate>Sat, 08 May 2010 00:51:14 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[数据结构]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645833</guid>
		<description><![CDATA[发觉算法太弱了 =&#8221;=
当年在ACM那里呆了两天就隐身了，可惜那个老师非常非常非常好的（实验室里还有空调 >_]]></description>
			<content:encoded><![CDATA[<p>发觉算法太弱了 =&#8221;=</p>
<p>当年在ACM那里呆了两天就隐身了，可惜那个老师非常非常非常好的（实验室里还有空调 >_<）。总觉得这玩意水太深，掉进去就出不来了....“不成熟的优化乃万恶之源”这话又正好应了惰性心理，心安理得地“出了性能问题再说之前先弄出来再说管算法干嘛”...可现实往往是，不会算法你压根就弄不出来...</p>
<p>先从一棵二叉查找树开始好了。挖坑慢慢填，时间有的是(?)</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> BTree <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> BTree a b <span style="color: #339933; font-weight: bold;">=</span> Empty 
               <span style="color: #339933; font-weight: bold;">|</span> BNode <span style="color: green;">&#123;</span>
                    kv <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> 
                    left <span style="color: #339933; font-weight: bold;">::</span> BTree a b<span style="color: #339933; font-weight: bold;">,</span>
                    right <span style="color: #339933; font-weight: bold;">::</span> BTree a b
               <span style="color: green;">&#125;</span> 
               <span style="color: #06c; font-weight: bold;">deriving</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: green;">&#41;</span>
&nbsp;
insert <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b
insert <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> Empty <span style="color: #339933; font-weight: bold;">=</span> BNode <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span> v<span style="color: green;">&#41;</span> Empty Empty
insert <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> pnode<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>BNode <span style="color: green;">&#40;</span>pk<span style="color: #339933; font-weight: bold;">,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> lnode rnode<span style="color: green;">&#41;</span> 
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">==</span> pk   <span style="color: #339933; font-weight: bold;">=</span> pnode <span style="color: green;">&#123;</span> kv <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&lt;</span>  pk   <span style="color: #339933; font-weight: bold;">=</span> pnode <span style="color: green;">&#123;</span> left  <span style="color: #339933; font-weight: bold;">=</span> insert <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> lnode <span style="color: green;">&#125;</span>
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&gt;</span>  pk   <span style="color: #339933; font-weight: bold;">=</span> pnode <span style="color: green;">&#123;</span> right <span style="color: #339933; font-weight: bold;">=</span> insert <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> rnode <span style="color: green;">&#125;</span>
&nbsp;
find <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> b
find k Empty <span style="color: #339933; font-weight: bold;">=</span> Nothing
find k <span style="color: green;">&#40;</span>BNode <span style="color: green;">&#40;</span>pk<span style="color: #339933; font-weight: bold;">,</span>pv<span style="color: green;">&#41;</span> lnode rnode<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">==</span> pk <span style="color: #339933; font-weight: bold;">=</span> Just pv
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&lt;=</span> pk <span style="color: #339933; font-weight: bold;">=</span> find k lnode
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&gt;</span>  pk <span style="color: #339933; font-weight: bold;">=</span> find k rnode
find <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> Nothing
&nbsp;
remove <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b
remove k Empty <span style="color: #339933; font-weight: bold;">=</span> Empty
remove k pnode<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>BNode <span style="color: green;">&#40;</span>pk<span style="color: #339933; font-weight: bold;">,</span>pv<span style="color: green;">&#41;</span> lnode rnode<span style="color: green;">&#41;</span> 
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">==</span> pk <span style="color: #339933; font-weight: bold;">=</span> merge lnode rnode
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&lt;=</span> pk <span style="color: #339933; font-weight: bold;">=</span> pnode <span style="color: green;">&#123;</span> left <span style="color: #339933; font-weight: bold;">=</span> remove k lnode <span style="color: green;">&#125;</span>
    <span style="color: #339933; font-weight: bold;">|</span> k <span style="color: #339933; font-weight: bold;">&gt;</span>  pk <span style="color: #339933; font-weight: bold;">=</span> pnode <span style="color: green;">&#123;</span> right <span style="color: #339933; font-weight: bold;">=</span> remove k rnode <span style="color: green;">&#125;</span>
&nbsp;
merge <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b
merge lnode rnode <span style="color: #339933; font-weight: bold;">=</span> fromList <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>toList lnode<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>toList rnode<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--helper</span>
isEmpty Empty <span style="color: #339933; font-weight: bold;">=</span> True 
isEmpty <span style="color: #339933; font-weight: bold;">_</span>     <span style="color: #339933; font-weight: bold;">=</span> False
&nbsp;
fromList <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span>b<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> BTree a b
fromList <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">foldl</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">flip</span> insert<span style="color: green;">&#41;</span> Empty 
&nbsp;
toList <span style="color: #339933; font-weight: bold;">::</span> BTree a b <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span>b<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span>
toList Empty <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> 
toList <span style="color: green;">&#40;</span>BNode <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> lnode rnode<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> 
    <span style="color: green;">&#40;</span>toList lnode<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>toList rnode<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- for test</span>
root <span style="color: #339933; font-weight: bold;">=</span> fromList <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#91;</span>
    <span style="color: green;">&#40;</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;fleurer&quot;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> 
    <span style="color: green;">&#40;</span><span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;ssword&quot;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> 
    <span style="color: green;">&#40;</span><span style="color: red;">100</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;ssword&quot;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> 
    <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;xx&quot;</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span></pre></div></div>

<p>haskell做数据结构好像别扭的很&#8230;不用ST Monad或者IO的话什么都是值还不能引用，像二叉树的旋转什么的就没想出常数时间的办法。像上面那个remove就直接简单粗暴了orz</p>
<p>(邪恶音：用ST Monad不就好了嘛)<br />
(ST Monad都用了还用haskell干嘛 TvT)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/05/08/%e8%b8%a9%e8%b8%a9%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%bb%80%e4%b9%88%e7%9a%84-%e2%80%9c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>git使用入门</title>
		<link>http://www.fleurer-lee.com/2010/04/02/git%e4%bd%bf%e7%94%a8%e5%85%a5%e9%97%a8/</link>
		<comments>http://www.fleurer-lee.com/2010/04/02/git%e4%bd%bf%e7%94%a8%e5%85%a5%e9%97%a8/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 14:30:11 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/2010/04/02/git%e4%bd%bf%e7%94%a8%e5%85%a5%e9%97%a8/</guid>
		<description><![CDATA[自己写小东西什么的还是git最省心 ^_^
版本控制工具里的命令什么还真够多的，所幸一个人要求不高，平时用的功能也就这么几个了。所以&#8230;..忘掉svn吧！ =V=
开始

git init 
git add .
git commit -a -m &#34;commit message&#34;

git init就是创建当前目录的版本库，所有信息都在.git这一个文件夹里面。比起svn的每个目录下边都一个.svn可要清爽多了 :)
git add . 将目录中的所有文件加入跟踪，新建文件时候别忘了这个。
git commit 就是提交啦~注意下这个commit只是提交到本地。
git是跟踪代码变动的工具，而不是上传工具。commit时候需要注意的一点就是不要把二进制什么的文件交进去。记得在根目录下边加个.gitignore文件，内容大约可以这样：

*.o
*.so
*.a
*.exe
*~

代码杯具了怎么办~

git checkout -- blah.c

这样就把blah.c恢复到了commit时的状态，存档复活~
要恢复到之前的版本就用git reset了，git在每次提交的时候都有个hash作为标记，知道这个hash就行了（例如git log或者直接翻github的history之类）

git reset --hard 4df38hdf29f

（reset好像有三种？初学者不用刨根究底的 =v=）
分支

git branch blah 
git checkout blah

就创建出了一个名为blah的分支了~
git checkout 的功能就是将当前工作目录转向blah~
合并分支&#8230;

git branch master
git merge blah

blah就合并进master啦~ 
github
ssh密钥好像比较绕&#8230;github使用ssh协议传输东东也做了身份验证嘛，所以需要一个双向的密匙。具体的操作步骤忘了囧，不过照着提示来也就一次性的工作啦~

git config --global user.name 'Fleurer'
git config --global user.email me.ssword@gmail.com
&#160;
git remote add origin git@github.com:（你的名字，这里是Fleurer~）/项目名.git  
git push [...]]]></description>
			<content:encoded><![CDATA[<p>自己写小东西什么的还是git最省心 ^_^</p>
<p>版本控制工具里的命令什么还真够多的，所幸一个人要求不高，平时用的功能也就这么几个了。所以&#8230;..忘掉svn吧！ =V=</p>
<p><b>开始</b></p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git init 
git add .
git commit -a -m &quot;commit message&quot;</pre></div></div>

<p>git init就是创建当前目录的版本库，所有信息都在.git这一个文件夹里面。比起svn的每个目录下边都一个.svn可要清爽多了 :)<br />
git add . 将目录中的所有文件加入跟踪，新建文件时候别忘了这个。<br />
git commit 就是提交啦~注意下这个commit只是提交到本地。</p>
<p>git是跟踪代码变动的工具，而不是上传工具。commit时候需要注意的一点就是不要把二进制什么的文件交进去。记得在根目录下边加个.gitignore文件，内容大约可以这样：</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">*.o
*.so
*.a
*.exe
*~</pre></div></div>

<p><b>代码杯具了怎么办~</b></p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git checkout -- blah.c</pre></div></div>

<p>这样就把blah.c恢复到了commit时的状态，存档复活~</p>
<p>要恢复到之前的版本就用git reset了，git在每次提交的时候都有个hash作为标记，知道这个hash就行了（例如git log或者直接翻github的history之类）</p>
<pre lang="">
git reset --hard 4df38hdf29f
</pre>
<p>（reset好像有三种？初学者不用刨根究底的 =v=）</p>
<p><b>分支</b></p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git branch blah 
git checkout blah</pre></div></div>

<p>就创建出了一个名为blah的分支了~<br />
git checkout 的功能就是将当前工作目录转向blah~</p>
<p>合并分支&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git branch master
git merge blah</pre></div></div>

<p>blah就合并进master啦~ </p>
<p><b>github</b></p>
<p>ssh密钥好像比较绕&#8230;github使用ssh协议传输东东也做了身份验证嘛，所以需要一个双向的密匙。具体的操作步骤忘了囧，不过照着提示来也就一次性的工作啦~</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git config --global user.name 'Fleurer'
git config --global user.email me.ssword@gmail.com
&nbsp;
git remote add origin git@github.com:（你的名字，这里是Fleurer~）/项目名.git  
git push origin master</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/04/02/git%e4%bd%bf%e7%94%a8%e5%85%a5%e9%97%a8/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fleurer’s Stack VM</title>
		<link>http://www.fleurer-lee.com/2010/02/03/fleurers-stack-vm/</link>
		<comments>http://www.fleurer-lee.com/2010/02/03/fleurers-stack-vm/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 05:09:18 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[fsvm]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645706</guid>
		<description><![CDATA[http://github.com/Fleurer/fsvm
尝试用C写的堆栈机，好像烂尾了 &#8211; -!
只是个运行时，无视了语法分析。随便写的东西也没什么规划，编写的时候就郁闷不知道哪部分该归分析器那部分该归vm，也不知道现有的部分能不能真用到解释器上，于是华丽地烂尾～只实现了20来条指令，可以递归可以闭包，不过不能算乘法&#8230;囧，很简陋啦~ 
好像是第一次写C，不会make就先凑合了rake &#8211; -！ 对C不熟悉，满地的Segmentation Fault对我们只会用printf调试的菜鸟太残酷了&#8230;用了那个保守式的gc库Boehm GC，面对满地的malloc而无free不清楚泄漏起来会怎样&#8230;囧
本来是对C++那套OO无爱，想单用struct和函数也可以OO么。于是用了C，然后就后悔了：我不想重新实现hashmap之类的东西，C++那stl多好&#8230;T_T。倒也找到了个C的泛型库khash，不过宏终究不如模板来的好看&#8230;现在想来，信息学奥赛acm中用C的那些同学做题的时候都是自己实现一遍各个数据结构么？
拿段伪代码：

def main:
     sum&#40;10&#41;
&#160;
def sum&#40;i&#41;:
     if &#40;i==0&#41; : return 0;
     else: return&#40;i+sum&#40;i-1&#41;&#41;;

放到fsvm下大约是这样：

int test_rec&#40;&#41;&#123;
    Op op_main&#91;&#93;=&#123;
        OP_PUSH_NUM, 10, 
        OP_PUSH_CONST, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/Fleurer/fsvm">http://github.com/Fleurer/fsvm</a><br />
尝试用C写的堆栈机，好像烂尾了 &#8211; -!</p>
<p>只是个运行时，无视了语法分析。随便写的东西也没什么规划，编写的时候就郁闷不知道哪部分该归分析器那部分该归vm，也不知道现有的部分能不能真用到解释器上，于是华丽地烂尾～只实现了20来条指令，可以递归可以闭包，不过不能算乘法&#8230;囧，很简陋啦~ </p>
<p>好像是第一次写C，不会make就先凑合了rake &#8211; -！ 对C不熟悉，满地的Segmentation Fault对我们只会用printf调试的菜鸟太残酷了&#8230;用了那个保守式的gc库Boehm GC，面对满地的malloc而无free不清楚泄漏起来会怎样&#8230;囧</p>
<p>本来是对C++那套OO无爱，想单用struct和函数也可以OO么。于是用了C，然后就后悔了：我不想重新实现hashmap之类的东西，C++那stl多好&#8230;T_T。倒也找到了个C的泛型库khash，不过宏终究不如模板来的好看&#8230;现在想来，信息学奥赛acm中用C的那些同学做题的时候都是自己实现一遍各个数据结构么？</p>
<p>拿段伪代码：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> main:
     <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:
     <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i==<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> : <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</span>
     <span style="color: #ff7700;font-weight:bold;">else</span>: <span style="color: #ff7700;font-weight:bold;">return</span><span style="color: black;">&#40;</span>i+<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>i-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>放到fsvm下大约是这样：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> test_rec<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    Op op_main<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>
        OP_PUSH_NUM<span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> 
        OP_PUSH_CONST<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//&quot;sum&quot;  </span>
        OP_PUSH_VAR<span style="color: #339933;">,</span> 
        OP_CALL<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
        OP_RET
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    Op op_sum<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>
        OP_PUSH_CONST<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//&quot;i&quot;</span>
        OP_PUSH_VAR<span style="color: #339933;">,</span> 
        OP_POP_TMP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//store i</span>
        OP_PUSH_TMP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//push i</span>
        OP_PUSH_NUM<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> 
        OP_EQ<span style="color: #339933;">,</span>
        OP_NOT<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// i!=0?</span>
        OP_BRANCH<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> 
            OP_PUSH_NUM<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>
            OP_RET<span style="color: #339933;">,</span>
        <span style="color: #666666; font-style: italic;">//else</span>
            OP_PUSH_TMP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> 
            OP_PUSH_NUM<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//1</span>
            OP_SUB<span style="color: #339933;">,</span> 
            OP_PUSH_CONST<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//&quot;sum&quot;</span>
            OP_PUSH_VAR<span style="color: #339933;">,</span> 
            OP_CALL<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">//sum(tmp[0]-1)</span>
            OP_PUSH_TMP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> 
            OP_PRINT_STACK<span style="color: #339933;">,</span> 
            OP_ADD<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//tmp[0]+sum(tmp[0]-1)</span>
        OP_RET
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    Env <span style="color: #339933;">*</span>env<span style="color: #339933;">=</span>fnew_env<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    Proto <span style="color: #339933;">*</span>p_main <span style="color: #339933;">=</span> fnew_proto<span style="color: #009900;">&#40;</span>op_main<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fset_const<span style="color: #009900;">&#40;</span>p_main<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> fstr<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sum&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Func<span style="color: #339933;">*</span> f_main<span style="color: #339933;">=</span>fnew_func<span style="color: #009900;">&#40;</span>p_main<span style="color: #339933;">,</span> env<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Obj o_main<span style="color: #339933;">=</span>ffunc<span style="color: #009900;">&#40;</span>f_main<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    Proto<span style="color: #339933;">*</span> p_sum<span style="color: #339933;">=</span>fnew_proto<span style="color: #009900;">&#40;</span>op_sum<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fset_const<span style="color: #009900;">&#40;</span>p_sum<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> fstr<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;i&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fset_const<span style="color: #009900;">&#40;</span>p_sum<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> fstr<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sum&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Func<span style="color: #339933;">*</span> f_sum<span style="color: #339933;">=</span>fnew_func<span style="color: #009900;">&#40;</span>p_sum<span style="color: #339933;">,</span> env<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Obj o_sum<span style="color: #339933;">=</span>ffunc<span style="color: #009900;">&#40;</span>f_sum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    fbind_var<span style="color: #009900;">&#40;</span>env<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;sum&quot;</span><span style="color: #339933;">,</span> o_sum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    fio_puts<span style="color: #009900;">&#40;</span>fcall<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> f_main<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>创建函数的那几个函数我自己也看着别扭&#8230;不过写C还是老实点好 >_<</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/02/03/fleurers-stack-vm/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>C的泛型库khash</title>
		<link>http://www.fleurer-lee.com/2010/01/30/c%e7%9a%84%e6%b3%9b%e5%9e%8b/</link>
		<comments>http://www.fleurer-lee.com/2010/01/30/c%e7%9a%84%e6%b3%9b%e5%9e%8b/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 03:39:43 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645695</guid>
		<description><![CDATA[写小东西需要用到哈希表这样的数据结构时候才后悔没用C++，最起码还有stl能用来着。虽说C也能搞泛型，不过宏实现的泛型&#8230;真的好恐怖。
tinyrb用了khash做哈希表，据作者说已经是一个稳定的实现了。
khash.h的内容：
http://attractivechaos.awardspace.com/khash.h.html
大体可以这么用：

#include &#34;stdio.h&#34;
#include &#34;khash.h&#34;
KHASH_MAP_INIT_STR&#40;str, int&#41; //以“str”这名字初始化一个类型的map，键类型为字符串，值类型为int
int main&#40;&#41; &#123;
    int ret, is_missing;
    khiter_t k; //khash的索引器，好像就是个int
    khash_t&#40;str&#41; *h = kh_init&#40;str&#41;; //str只是个名字，初始化
    k = kh_put&#40;str, h, &#34;test&#34;, &#38;ret&#41;; //“test”即键，ret判定操作是否成功，返回k为索引器
&#160;
    if &#40;!ret&#41; kh_del&#40;str, h, k&#41;; //如果h中已经存在了这个键，就删除之
    kh_value&#40;h, k&#41; = 10; //设置键“test”对应的值（10）
&#160;
  [...]]]></description>
			<content:encoded><![CDATA[<p>写小东西需要用到哈希表这样的数据结构时候才后悔没用C++，最起码还有stl能用来着。虽说C也能搞泛型，不过宏实现的泛型&#8230;真的好恐怖。</p>
<p>tinyrb用了khash做哈希表，据作者说已经是一个稳定的实现了。</p>
<p>khash.h的内容：<br />
<a href="http://attractivechaos.awardspace.com/khash.h.html">http://attractivechaos.awardspace.com/khash.h.html</a></p>
<p>大体可以这么用：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdio.h&quot;</span>
<span style="color: #339933;">#include &quot;khash.h&quot;</span>
KHASH_MAP_INIT_STR<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//以“str”这名字初始化一个类型的map，键类型为字符串，值类型为int</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> ret<span style="color: #339933;">,</span> is_missing<span style="color: #339933;">;</span>
    khiter_t k<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//khash的索引器，好像就是个int</span>
    khash_t<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span>h <span style="color: #339933;">=</span> kh_init<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//str只是个名字，初始化</span>
    k <span style="color: #339933;">=</span> kh_put<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> h<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//“test”即键，ret判定操作是否成功，返回k为索引器</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ret<span style="color: #009900;">&#41;</span> kh_del<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> h<span style="color: #339933;">,</span> k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//如果h中已经存在了这个键，就删除之</span>
    kh_value<span style="color: #009900;">&#40;</span>h<span style="color: #339933;">,</span> k<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//设置键“test”对应的值（10）</span>
&nbsp;
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> kh_val<span style="color: #009900;">&#40;</span>h<span style="color: #339933;">,</span>k<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//kh_val(h,k)即10</span>
&nbsp;
    k <span style="color: #339933;">=</span> kh_get<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> h<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//获得“test”对应的索引器k</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> kh_val<span style="color: #009900;">&#40;</span>h<span style="color: #339933;">,</span>k<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//得10</span>
&nbsp;
    kh_destroy<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>终究不如模板来的自然，呵呵~不过也不错了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/01/30/c%e7%9a%84%e6%b3%9b%e5%9e%8b/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>折腾grub小记</title>
		<link>http://www.fleurer-lee.com/2010/01/26/%e6%8a%98%e8%85%begrub%e5%b0%8f%e8%ae%b0/</link>
		<comments>http://www.fleurer-lee.com/2010/01/26/%e6%8a%98%e8%85%begrub%e5%b0%8f%e8%ae%b0/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:33:07 +0000</pubDate>
		<dc:creator>fleurer</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[grub]]></category>

		<guid isPermaLink="false">http://www.fleurer-lee.com/?p=645690</guid>
		<description><![CDATA[蛋疼用PQMagic改了下/swap分区的大小，重启发现mbr没了。
拿手机google下之后，找了张windows me的光盘（初一时候买的盘还能用&#8230;orz）引导进入dos，fdisk /mbr，windows原地满血复活&#8230;满血，是的，windows又把mbr占了&#8230;
接着装个wingrub，折腾半天找回了原先的menu.lst，重启，接着是：

Error 2: Bad file or directory type

而且在grub命令下无法列出ext3分区的文件，当时冷汗天杀的PQMagic没把我盘格了吧&#8230;回头想下，感情这个wingrub好像不认ext3&#8230;
下载个live-CD，进去发现可以读那个分区。apt-get一个grub，进入命令行之后：

root (hd0, 4)
setup (hd0)

提示成功。重启，原先的grub回来了&#8230;
]]></description>
			<content:encoded><![CDATA[<p>蛋疼用PQMagic改了下/swap分区的大小，重启发现mbr没了。</p>
<p>拿手机google下之后，找了张windows me的光盘（初一时候买的盘还能用&#8230;orz）引导进入dos，fdisk /mbr，windows原地满血复活&#8230;满血，是的，windows又把mbr占了&#8230;</p>
<p>接着装个wingrub，折腾半天找回了原先的menu.lst，重启，接着是：</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">Error 2: Bad file or directory type</pre></div></div>

<p>而且在grub命令下无法列出ext3分区的文件，当时冷汗天杀的PQMagic没把我盘格了吧&#8230;回头想下，感情这个wingrub好像不认ext3&#8230;</p>
<p>下载个live-CD，进去发现可以读那个分区。apt-get一个grub，进入命令行之后：</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">root (hd0, 4)
setup (hd0)</pre></div></div>

<p>提示成功。重启，原先的grub回来了&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2010/01/26/%e6%8a%98%e8%85%begrub%e5%b0%8f%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于进程的疑问集</title>
		<link>http://www.fleurer-lee.com/2009/11/29/%e5%85%b3%e4%ba%8e%e8%bf%9b%e7%a8%8b%e7%9a%84%e7%96%91%e9%97%ae%e9%9b%86/</link>
		<comments>http://www.fleurer-lee.com/2009/11/29/%e5%85%b3%e4%ba%8e%e8%bf%9b%e7%a8%8b%e7%9a%84%e7%96%91%e9%97%ae%e9%9b%86/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 15:13:42 +0000</pubDate>
		<dc:creator>ssword</dc:creator>
				<category><![CDATA[备忘]]></category>
		<category><![CDATA[Kernel]]></category>

		<guid isPermaLink="false">http://swdpress.cn/?p=645549</guid>
		<description><![CDATA[
如何在有限的空间（如内存和硬盘，可以将其看作一个大数组）内储存不定长度不定生命周期的个体（如进程或者文件）？
如何限制一个进程在运行时无法访问或修改其他进程的数据？
如何实现共享库或者系统调用？
能否把进程的调度、连续对象（字节、页）的分配抽象为纯粹的最优问题？

最近看几本linux内核的书，貌似开始弄明白了点门道。通过分页机制实现一个虚拟地址空间貌似就可以解决上述的问题。不过现在只了解其机制，而不解其策略。纸上谈兵显然还差的远。
大约去年这时候曾经问过FlowerCode一些关于分页的东西，当时fc说分页有点像文件系统，现在才越想越觉得有道理。后知后觉了一些，呵呵 :)
]]></description>
			<content:encoded><![CDATA[<ol>
<li>如何在有限的空间（如内存和硬盘，可以将其看作一个大数组）内储存不定长度不定生命周期的个体（如进程或者文件）？</li>
<li>如何限制一个进程在运行时无法访问或修改其他进程的数据？</li>
<li>如何实现共享库或者系统调用？</li>
<li>能否把进程的调度、连续对象（字节、页）的分配抽象为纯粹的最优问题？</li>
</ol>
<p>最近看几本linux内核的书，貌似开始弄明白了点门道。通过分页机制实现一个虚拟地址空间貌似就可以解决上述的问题。不过现在只了解其机制，而不解其策略。纸上谈兵显然还差的远。</p>
<p>大约去年这时候曾经问过FlowerCode一些关于分页的东西，当时fc说分页有点像文件系统，现在才越想越觉得有道理。后知后觉了一些，呵呵 :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fleurer-lee.com/2009/11/29/%e5%85%b3%e4%ba%8e%e8%bf%9b%e7%a8%8b%e7%9a%84%e7%96%91%e9%97%ae%e9%9b%86/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
