📝 add new test file feigenbaum.nas
This commit is contained in:
parent
b4482792c8
commit
fd614a132c
|
@ -19,7 +19,7 @@
|
||||||
* [__开发历史__](../doc/dev_zh.md)
|
* [__开发历史__](../doc/dev_zh.md)
|
||||||
* [__测试数据__](../doc/benchmark.md)
|
* [__测试数据__](../doc/benchmark.md)
|
||||||
* [__特殊之处__](#与andy解释器的不同之处)
|
* [__特殊之处__](#与andy解释器的不同之处)
|
||||||
* [__堆栈追踪信息__](#trace-back-info)
|
* [__堆栈追踪信息__](#堆栈追踪信息)
|
||||||
* [__调试器__](#调试器)
|
* [__调试器__](#调试器)
|
||||||
|
|
||||||
__如果有好的意见或建议,欢迎联系我们!__
|
__如果有好的意见或建议,欢迎联系我们!__
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<p>
|
<p>
|
||||||
The interpreter is totally rewritten by <a href="https://github.com/ValKmjolnir">ValKmjolnir</a> using C++(-std=c++11) without reusing the code in Andy Ross's nasal interpreter.
|
The interpreter is totally rewritten by <a href="https://github.com/ValKmjolnir">ValKmjolnir</a> using C++(-std=c++11) without reusing the code in Andy Ross's nasal interpreter.
|
||||||
But we really appreciate that Andy created this amazing programming language and his interpreter project.
|
But we really appreciate that Andy created this amazing programming language and his interpreter project.
|
||||||
Now this project uses <a href="/license">GPL-2.0 license</a> (2021/5/4).<br/>
|
Now this project uses <a href="/license">GPL-2.0 license</a>.<br/>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
这个解释器是由<a href="https://github.com/ValKmjolnir">ValKmjolnir</a>用C++11编写的,完全没有复用Andy Ross版解释器的代码。但是我们仍然非常感谢Andy为我们带来了这么一款有趣的编程语言。
|
这个解释器是由<a href="https://github.com/ValKmjolnir">ValKmjolnir</a>用C++11编写的,完全没有复用Andy Ross版解释器的代码。但是我们仍然非常感谢Andy为我们带来了这么一款有趣的编程语言。
|
||||||
|
@ -71,14 +71,21 @@
|
||||||
nasal运行brainfuck绘制的曼德勃罗集合(右)。
|
nasal运行brainfuck绘制的曼德勃罗集合(右)。
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Nasal can run this test file(test/bfcolored.nas) to draw this picture in about 220 seconds.
|
Nasal can run this test file(test/bf.nas) to draw this picture in about 220 seconds.
|
||||||
In fact this test file cost over 2200 seconds before ver 8.0 .
|
In fact this test file cost over 2200 seconds before ver 8.0 .
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Nasal现在可以在220秒内运行该文件(test/bfcolored.nas)并绘制出这张图。
|
Nasal现在可以在220秒内运行该文件(test/bf.nas)并绘制出这张图。
|
||||||
在8.0版本中这个解释器需要跑超过2200秒来绘制这张图。
|
在8.0版本中这个解释器需要跑超过2200秒来绘制这张图。
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
The figure below is the feigenbaum-figure generated by ppm script written in nasal.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
下方是使用 nasal 的 ppm 生成脚本生成的 feigenbaum 图形。
|
||||||
|
</p>
|
||||||
</text>
|
</text>
|
||||||
|
<img src="/doc/pic/feigenbaum.png" width="900" height="550" style="margin-left: 15px;"><br /></img>
|
||||||
<h2> Example | 样例代码</h2>
|
<h2> Example | 样例代码</h2>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<text style="margin-left: 15px;"> </text>
|
<text style="margin-left: 15px;"> </text>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 161 KiB |
|
@ -369,16 +369,16 @@ var builtin_find(var* local, gc& ngc) {
|
||||||
|
|
||||||
var builtin_type(var* local, gc& ngc) {
|
var builtin_type(var* local, gc& ngc) {
|
||||||
switch(local[1].type) {
|
switch(local[1].type) {
|
||||||
case vm_none: return ngc.newstr("undefined");break;
|
case vm_none: return ngc.newstr("undefined");
|
||||||
case vm_nil: return ngc.newstr("nil"); break;
|
case vm_nil: return ngc.newstr("nil");
|
||||||
case vm_num: return ngc.newstr("num"); break;
|
case vm_num: return ngc.newstr("num");
|
||||||
case vm_str: return ngc.newstr("str"); break;
|
case vm_str: return ngc.newstr("str");
|
||||||
case vm_vec: return ngc.newstr("vec"); break;
|
case vm_vec: return ngc.newstr("vec");
|
||||||
case vm_hash: return ngc.newstr("hash"); break;
|
case vm_hash: return ngc.newstr("hash");
|
||||||
case vm_func: return ngc.newstr("func"); break;
|
case vm_func: return ngc.newstr("func");
|
||||||
case vm_obj: return ngc.newstr("obj"); break;
|
case vm_obj: return ngc.newstr("obj");
|
||||||
case vm_co: return ngc.newstr("coroutine");break;
|
case vm_co: return ngc.newstr("coroutine");
|
||||||
case vm_map: return ngc.newstr("mapper"); break;
|
case vm_map: return ngc.newstr("namespace");
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import.std.process_bar;
|
||||||
|
|
||||||
|
var ppm=func(filename, width, height, RGB){
|
||||||
|
# P3 use ASCII number
|
||||||
|
# P6 use binary character
|
||||||
|
var fd = io.open(filename, "wb");
|
||||||
|
io.write(fd, "P6\n"~width~" "~height~"\n255\n");
|
||||||
|
for(var i = 0; i<height; i+=1) {
|
||||||
|
for(var j = 0; j<width; j+=1) {
|
||||||
|
io.write(fd, RGB(i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
io.close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
var width = 1600;
|
||||||
|
var height = 900;
|
||||||
|
var bar=(os.platform()=="windows")?
|
||||||
|
process_bar.bar(front:"sharp",back:"point",sep:"line",length:50):
|
||||||
|
process_bar.high_resolution_bar(50);
|
||||||
|
|
||||||
|
var RGB = func(h, w) {
|
||||||
|
var r = 2+w*2/width;
|
||||||
|
var x = (height-h)/height;
|
||||||
|
|
||||||
|
var res = 0;
|
||||||
|
var tmp = 0.5;
|
||||||
|
for(var i = 0; i<50; i+=1) {
|
||||||
|
tmp = r*tmp*(1-tmp);
|
||||||
|
}
|
||||||
|
for(var i = 0; i<100; i+=1) {
|
||||||
|
tmp = r*tmp*(1-tmp);
|
||||||
|
if (math.abs(tmp-x)<0.001) {
|
||||||
|
res = 255;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var progress = (h*width+w+1)/(width*height);
|
||||||
|
if(progress*100-int(progress*100)==0){
|
||||||
|
print(bar.bar(progress), " ", progress*100, "% \r");
|
||||||
|
}
|
||||||
|
|
||||||
|
var c = char(res);
|
||||||
|
return c~c~c;
|
||||||
|
}
|
||||||
|
ppm("feigenbaum.ppm", width, height, RGB);
|
||||||
|
println();
|
|
@ -314,7 +314,10 @@ while(1){
|
||||||
http.send(client,respond.ok(io.readfile("./doc/pic/favicon.ico")));
|
http.send(client,respond.ok(io.readfile("./doc/pic/favicon.ico")));
|
||||||
elsif(path=="/license")
|
elsif(path=="/license")
|
||||||
http.send(client,respond.ok(io.readfile("./LICENSE")));
|
http.send(client,respond.ok(io.readfile("./LICENSE")));
|
||||||
elsif(path=="/doc/pic/nasal.png" or path=="/doc/pic/benchmark.png" or path=="/doc/pic/mandelbrot.png")
|
elsif(path=="/doc/pic/nasal.png" or
|
||||||
|
path=="/doc/pic/benchmark.png" or
|
||||||
|
path=="/doc/pic/mandelbrot.png" or
|
||||||
|
path=="/doc/pic/feigenbaum.png")
|
||||||
http.send(client,respond.ok(io.readfile("."~path)));
|
http.send(client,respond.ok(io.readfile("."~path)));
|
||||||
else{
|
else{
|
||||||
var filename=substr(path,1,size(path)-1);
|
var filename=substr(path,1,size(path)-1);
|
||||||
|
|
Loading…
Reference in New Issue