📝 update scripts

This commit is contained in:
ValKmjolnir
2023-11-16 23:19:03 +08:00
parent 50322f9286
commit 270e6e568f
72 changed files with 1285 additions and 1237 deletions
+12
View File
@@ -110,3 +110,15 @@ And we use this bf interpreter to draw a mandelbrot set.
In 2022/2/17 update we added `\e` into the lexer. And the `bfcolored.nas` uses this special ASCII code. Here is the result: In 2022/2/17 update we added `\e` into the lexer. And the `bfcolored.nas` uses this special ASCII code. Here is the result:
![mandelbrot](../doc/pic/mandelbrot.png) ![mandelbrot](../doc/pic/mandelbrot.png)
## More nasal generated pictures
![mandelbrotset](../doc/pic/mandelbrotset.png)
![mandelbrotset_reverse](../doc/pic/mandelbrotset_reverse.png)
![burningship](../doc/pic/burningship.png)
![burningship_reverse](../doc/pic/burningship_reverse.png)
![feigenbaum](../doc/pic/feigenbaum.png)
+2 -2
View File
@@ -128,10 +128,10 @@
<li><a href="/lexer.nas">lexer.nas</a></li> <li><a href="/lexer.nas">lexer.nas</a></li>
<li><a href="/life.nas">life.nas</a></li> <li><a href="/life.nas">life.nas</a></li>
<li><a href="/loop.nas">loop.nas</a></li> <li><a href="/loop.nas">loop.nas</a></li>
<li><a href="/mandel.nas">mandel.nas</a></li>
<li><a href="/mandelbrot.nas">mandelbrot.nas</a></li> <li><a href="/mandelbrot.nas">mandelbrot.nas</a></li>
<li><a href="/mandelbrotset.nas">mandelbrotset.nas</a></li>
<li><a href="/mcpu.nas">mcpu.nas</a></li> <li><a href="/mcpu.nas">mcpu.nas</a></li>
<li><a href="/md5.nas">md5.nas</a></li> <li><a href="/md5_self.nas">md5_self.nas</a></li>
<li><a href="/md5compare.nas">md5compare.nas</a></li> <li><a href="/md5compare.nas">md5compare.nas</a></li>
</ul> </ul>
</td> </td>
Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

+1
View File
@@ -1,6 +1,7 @@
# flightgear developer environments simulator (beta) # flightgear developer environments simulator (beta)
# ValKmjolnir 2022 # ValKmjolnir 2022
use std.runtime; use std.runtime;
use std.coroutine;
println("-------------------------------------------------------------"); println("-------------------------------------------------------------");
println(" FlightGear simulated-env for developers project, since 2019"); println(" FlightGear simulated-env for developers project, since 2019");
+2 -1
View File
@@ -54,10 +54,11 @@ var find_all_files = func(path){
} }
var dd = unix.opendir(path); var dd = unix.opendir(path);
var res = []; var res = [];
while(var n = unix.readdir(dd)) while(var n = unix.readdir(dd)) {
if (unix.isfile(path~"/"~n)) { if (unix.isfile(path~"/"~n)) {
append(res, n); append(res, n);
} }
}
unix.closedir(dd); unix.closedir(dd);
return res; return res;
} }
-3
View File
@@ -1,12 +1,9 @@
# lib.nas # lib.nas
# 2019 ValKmjolnir # 2019 ValKmjolnir
use std.coroutine;
use std.math; use std.math;
use std.string; use std.string;
use std.io; use std.io;
use std.os; use std.os;
use std.bits;
use std.unix; use std.unix;
# print is used to print all things in nasal, try and see how it works. # print is used to print all things in nasal, try and see how it works.
+1
View File
@@ -4,6 +4,7 @@
# this provides safe usage of dylib # this provides safe usage of dylib
# when dylib is closed, # when dylib is closed,
# all the invalid functions cannot be called # all the invalid functions cannot be called
use std.dylib;
var module_call_func = func(fptr, args) { var module_call_func = func(fptr, args) {
return __dlcallv; return __dlcallv;
+1
View File
@@ -1,5 +1,6 @@
# unix.nas # unix.nas
# 2023 by ValKmjolnir # 2023 by ValKmjolnir
use std.bits;
var _S_IFDIR = 0x4000; var _S_IFDIR = 0x4000;
var _S_IFREG = 0x8000; var _S_IFREG = 0x8000;
+1
View File
@@ -1,5 +1,6 @@
# coroutine.nas by ValKmjolnir # coroutine.nas by ValKmjolnir
# 2022/5/19 # 2022/5/19
use std.coroutine;
use std.process_bar; use std.process_bar;
use std.padding; use std.padding;
+1
View File
@@ -44,5 +44,6 @@ var RGB = func(h, w) {
var c = char(res); var c = char(res);
return c~c~c; return c~c~c;
} }
ppm("feigenbaum.ppm", width, height, RGB); ppm("feigenbaum.ppm", width, height, RGB);
println(); println();
+1 -3
View File
@@ -1,8 +1,6 @@
var fib=func(x) var fib = func(x) {
{
if (x<2) return x; if (x<2) return x;
return fib(x-1)+fib(x-2); return fib(x-1)+fib(x-2);
} }
for(var i=0;i<31;i+=1) for(var i=0;i<31;i+=1)
print(fib(i),'\n'); print(fib(i),'\n');
+5 -6
View File
@@ -2,22 +2,21 @@
var n=4; var n=4;
var input=[[0,1],[0,2],[1,2]]; var input=[[0,1],[0,2],[1,2]];
var find_root=func(x,parent) var find_root = func(x,parent) {
{
while(parent[x]!=nil) while(parent[x]!=nil)
x=parent[x]; x=parent[x];
return x; return x;
} }
var union_root=func(x,y,parent)
{ var union_root = func(x,y,parent) {
var x_root=find_root(x,parent); var x_root=find_root(x,parent);
var y_root=find_root(y,parent); var y_root=find_root(y,parent);
if (x_root==y_root) return 0; if (x_root==y_root) return 0;
else parent[x_root]=y_root; else parent[x_root]=y_root;
return 1; return 1;
} }
var makeConnect=func(n,connections)
{ var makeConnect = func(n,connections) {
if (size(connections)<n-1) return -1; if (size(connections)<n-1) return -1;
var cnt=n-1; var cnt=n-1;
var parent=[]; var parent=[];
+1 -2
View File
@@ -1,5 +1,4 @@
var lexer=func(file) var lexer = func(file) {
{
var (ptr,token)=(0,[]); var (ptr,token)=(0,[]);
var s=io.readfile(file); var s=io.readfile(file);
var len=size(s); var len=size(s);
+2
View File
@@ -1,3 +1,5 @@
use std.bits;
var inst={ var inst={
inst_stop:0, inst_stop:0,
inst_mov_reg_reg:1, inst_mov_reg_reg:1,
+2
View File
@@ -1,3 +1,5 @@
use std.bits;
var check = func(x) { var check = func(x) {
if (x<0x100000000) if (x<0x100000000)
return x; return x;
+1
View File
@@ -1,3 +1,4 @@
use std.coroutine;
use std.process_bar; use std.process_bar;
use module.libkey; use module.libkey;
use std.runtime; use std.runtime;
+5 -3
View File
@@ -1,6 +1,7 @@
use module.libkey; use module.libkey;
use std.list; use std.list;
use std.runtime; use std.runtime;
use std.coroutine;
var game = func(x,y) { var game = func(x,y) {
rand(time(0)); rand(time(0));
@@ -142,15 +143,16 @@ var main=func(argv){
while(1) { while(1) {
while((var ch=coroutine.resume(co)[0])==nil); while((var ch=coroutine.resume(co)[0])==nil);
if (ch!=nil and ch!=-1) { if (ch!=nil and ch!=-1) {
if(ch=='q'[0]) if (ch=='q'[0]) {
break; break;
elsif(ch=='p'[0]){ } elsif (ch=='p'[0]) {
print("\rpress any key to continue..."); print("\rpress any key to continue...");
libkey.getch(); libkey.getch();
print("\r \r"); print("\r \r");
} } elsif (ch=='w'[0] or ch=='s'[0] or ch=='a'[0] or ch=='d'[0]) {
g.move(chr(ch)); g.move(chr(ch));
} }
}
g.next(); g.next();
if (g.gameover()) if (g.gameover())
+2 -1
View File
@@ -11,5 +11,6 @@ var fib=func(f){
} }
); );
for(var i=1;i<31;i+=1) for(var i = 1; i<31; i += 1) {
println(fib(i)); println(fib(i));
}
+29
View File
@@ -0,0 +1,29 @@
use std.file;
var check = func(dir_name) {
var ts = maketimestamp();
var f = file.find_all_files_with_extension(dir_name, "nas");
var res = [];
foreach(var k; f) {
ts.stamp();
if (system("nasal -c "~dir_name~"/"~k~" 1>/dev/null 2>/dev/null")!=0) {
println("\e[31merror\e[0m ", dir_name, "/", k);
append(res, dir_name~"/"~k);
}
println("compiling ", dir_name, "/", k, " in \e[32m", ts.elapsedMSec(), "\e[0m ms");
}
return res;
}
var result = [
check("./std"),
check("./module"),
check("./tools"),
check("./test")
];
println();
foreach(var i; result) {
foreach(var j; i) {
println("\e[31merror\e[0m ", j);
}
}