agentzh さんのプロフィールHuman & Machineフォトブログリストその他 ツール ヘルプ

ブログ


10月24日

A graphical tracer for Perl 6 regexes based on PCR

Tracing parse failures by hand while developing a compiler can be really a nightmare, since the real problem can appear everywhere -- the grammar definition, the input string being matched, or even the regex engine itself.

So I've implemented a graphical tracer for Perl 6 regexes atop PCR (Pugs::Compiler::Rule). You can find some small online demos here:

To generate the HTML pages (say, the first demo) yourself, simply check out the Pugs repository , ``cd'' into perl5/Pugs-Compiler-Rule, and enter the following commands:

  $ perl util/compile_p6grammar.pl -D examples/digits.grammar > Digits.pm
$ echo '7c3d54' > digits.input
$ perl -Ilib -MDigits -e 'print Digits->count(<>)->(), "\n"' \
digits.input > trace.out
$ perl util/gen-tracer-view.pl --outdir tmp/digits \
examples/digits.grammar digits.input < trace.out
$ firefox tmp/digits/index.html

The tracer interface still needs love and at the moment I'm adding cooler features like ``random jump'', ``stepping in a specified pace'', and ``stepping back''. If you like to help, just join #perl6 and get a Pugs commit bit ;)

I think this tool should be very useful for both regex engine developers and compiler writers, especially when parsing fails in an unexpected way. And it can also be beneficial to Perl 6 beginners who want to learn the shiny new regex syntax and complicated matching behaviors by just ``stepping through'' the real parsing process. moritz++ said on #perl6 that he would build a CGI script to make my demos above ``alive'' when he had the tuits; let's just wait and see ;)

It should be warned that the regex syntax supported by the current PCR implementation is already a little out-of-date regarding the lastest Synopsis 5 . (Thanks TimToady++ for tweaking the regex syntax during the meantime ;)) I'll try to port KindaPerl6 's perl5rx backend over to PCR later.

Hey, it'll be nicer to have KindaPerl6, PGE , or even the Perl 5 regex engine to work with my tracer as well :)

Stay tuned!

-agentzh

P.S. This entry was originally posted as http://pugs.blogs.com/pugs/2007/10/a-graphical-tra.html

5月1日

ulimit++

As seen on #perl6:

    <agentzh> oh, if i restrict each ./pugs instance to 100 MB RAM, only 77.25% of the test suite is in green.
<agentzh> when assigning 800 RM, the passing rate returns to the normal level (97.09%)
<agentzh> ulimit is so handy :)
<moritz> ulimit++ ;-)
<TimToady> careful, you might exceed ulimit's karma limit...
<agentzh> lol
<moritz> @karma ulimit
<lambdabot> ulimit has a karma of 1
<gaal> and then what, it'll kill itself? under some beliefs, that lowers its karma
<moritz> what was ulimit's limit again?
4月20日

Want a commit bit?

As seen on #perl6 today:

  <zxagent> agentzh: hello master
<agentz> zxagent: hello, boy :)
<agentz> zxagent: nice to see you here.
<agentz> zxagent: want a commit bit?
*** zxagent left the room (quit: Remote closed the connection).
<agentz> oops, too late
<TimToady> maybe you scared him off
<agentz> TimToady: *nod*

人物介绍

  TimToady: Larry Wall
zxagent: 我徒儿张星
agentzh: 我

结论

我徒弟实在是太有个性啦!

4月18日

给唐凤的生日礼物

今天是 唐凤 的生日,真的很开心啊,祝 Audrey 生日快乐!

根据  Gaal 的提议 , 这几日我成功地在  feather  服务器上建立了 Pugs 的自动化 smoke 设施, 算作是 给唐凤的生日礼物 。 :D

现在 feather 上的 cron 程序每隔 24 个小时就会自动运行最新版本的 Pugs 测试集,并生成包含“灵巧链接”的 Perl 6 Synopses 文档:

http://perlcabal.org/syn/

比如其中的 S04:

http://perlcabal.org/syn/S04.html

你在其中会看到,我的  smartlinks.pl 程序会将一组一组的测试插入到文档的对应位置上,并根据 Smoke 生成的测试报表,用 × 在对应的行上,标记每一个特定的测试。

唐凤的 Pugs 博客上的几篇文章就是介绍这种 smartlinking 技术的:

前两篇是我写的,第三篇是  Mark Stosberg  写的。Mark 为我们的 feather 网站做了许多工作:

http://use.perl.org/~markjugg/journal/30739

markstos++ ;)

在 feather 上运行无人监管的自动化 smoke 在技术上需要一些特别的考虑:

  • cron 自动运行时刻的选择

    显然应该 smoke 的时间选在 feather 服务器一天当中负载最轻的时候。feather 的主人 Juerd 告诉我 在欧洲中部时间的晚上,一般会比较空闲,而白天 feather 的备份系统会比较地繁忙。因此我就在 crontab 中指定了 CET 1:00 AM.

  • CPU 和 RAM 资源的控制

    由于 Pugs 处于活跃的开发当中,在测试集运行的过程里,有些测试可能会陷入死循环,或者消耗掉所有内存, 而最终挂起或者让系统崩溃。由于 Juerd 并未对 feather 用户的资源进行限制,所以我需要自己使用 nice 和 ulimit 来进行资源限制。利用 nice 可以让 smoke 系统中的进程处于比较低的优先级,从而确保系统的其他用户仍能比较快地获得系统的响应。 而 ulimit 则可以限制 shell 实例中允许使用的总的内存量和 CPU 时间。

    目前,我为 smoke 系统中的进程分配的 NICE 数为 5 到 10 的样子, 而每一个 ./pugs 进程实例只允许使用最多 800 MB 的虚拟内存和 10 分钟的 CPU 时间。 一旦某个 ./pugs 实例超过了规定的时间或空间限制,系统就会 KILL 掉它,但这并不会中断整个 smoke 过程, 只不过对应的那组测试被标记为失败而已。

    说实话,nice 和 ulimit 还是 Juerd 向我介绍的 。 惭愧啊,呵呵。

    将 nice 和 ulimit 结合到一起,我便得到了一个“受限Pugs”,也就是下面这个 limited_pugs 脚本:

    http://svn.pugscode.org/pugs/util/limited_pugs

    关于其中一些 Bourne Shell 记法,我还 专门请教了 #perl6 频道中的高手们。

  • cron 活动的监视和诊断

    令人高兴地是, cron 在指定的时刻自动运行指定的命令的同时会记录下所有的 stdout 和 stderr 输出,并将之发送到我的 Gmail 信箱。 这样,监视和诊断远程 feather 服务器上的 auto-smoke 过程就是轻而易举的事情了。cron++

    今天早上我已经收到了 feather cron 发送给我的第一份 auto-smoke 的报告。看起来它工作得非常好。Yay!

我对 Perl 6 开发的贡献汇集

今天在看网上一篇关于我的评论的时候找到下面这个 URL:

http://groups.google.co.uk/groups?as_ugroup=perl.*&as_uauthors=Agent+Zhang

它汇集了有关我在过去一年中对 Perl 6 开发的贡献。可惜我没早些发现它,要不我的简历会更有力一些
,呵呵。

包含了该链接的 use perl 评论也很有趣:

http://use.perl.org/comments.pl?sid=33843&op=&threshold=0&commentsort=0&mode=thread&cid=52032
7月18日

抄写 Perl 6 的 Synopses

今天下午,我继续在母亲办公室中抄写 Perl 6 的核心文档。好不容易才抄完了 S02 (Synopsis 2),然后又预览了 S03 的前几页。

抄书确实有抄书的妙处。眼到,手到,心到。高一的时候,正是凭借抄书,我才得以在很短的时间内掌握了 VB, C 和 C++. 抄书与看书相比,缺点是苦了我的手指,优点是重要细节都不会疏漏。抄书可以强制性地放缓我的阅读速度,从而为每一句话都赢得了更多的思考时间,这的确是一件很好的事情。别看抄书似乎进度很慢,但从效果上看,却是大大地节约了时间。

之所以如此较真地学习 Perl 6,是因为我太想尽快掌握下一代的 Perl 语言了。多年来,接触了数不清的编程语言,可唯独 Perl 5 成为我“真正的语言”。如今,Perl 6 对 Perl 进行了重新的设计,抛弃了语言层面上的向后兼容性,从而给我们 Perl 社会带来了真正意义的“革命”。我很高兴地看到,许多 Perl 5 中令人不快的阴暗角落在 Perl 6 中都成为了宽敞明亮的殿堂。Perl 5 中令人陶醉的语言特性在 Perl 6 中都进化到了令人叹为观止的地步。如果说,Perl 5 带给我们的是魔法世界的话,Perl 6 带给我们的则是真实的神话。

抄写 S02 的过程对我来说是不断拍案的过程,相信 S03, S04, ... 惊喜还会不断延续。虽然大部分 Perl 6 的新特性我在过去的两年中早有所闻,但是经过抄写 Synopses 这样的如此近距离的接触,我对 Perl 6 的巨大威力有了更加深切的体会。

随着 v6-alpha,这个基于纯 Perl 5 的 Perl 6 编译器正在通过 Pugs 测试集中越来越多的测试,我学习 Perl 6 的愿望也越来越强烈起来。说实话,作为 v6-alpha 的用户本身就是一个很激动人心的事情了,但是我希望自己能进一步成为 v6-alpha 的贡献者之一,从而能够帮助台湾的 clkao (高嘉良)和巴西的 fglock 让 v6-alpha 更快地成熟起来。

现在我已经从 audreyt(唐凤)那里获得了 Pugs 项目的 commit bit,成为了 Pugs 团队的一员。虽然我可以直接上传改动了,但我仍然缺少相关的背景知识。首先,我得熟悉 Perl 6,从而知道我们到底要实现什么;其次,我得消化 fglock 的 Pugs::Compiler::RulePugs::Compiler::Perl6 以及 clkao 的 Data::BindSub::Multi, 当然还有 Stevan 的 Moose 和 Ingy 的 Module::Compile,从而知晓他们是如何实现的. 最后,我才可能真正参与到 v6-alpha 的开发工作中去.