mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-05-02 19:00:47 +08:00
📝 update scripts
This commit is contained in:
@@ -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:
|
||||
|
||||

|
||||
|
||||
## More nasal generated pictures
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
@@ -128,10 +128,10 @@
|
||||
<li><a href="/lexer.nas">lexer.nas</a></li>
|
||||
<li><a href="/life.nas">life.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="/mandelbrotset.nas">mandelbrotset.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>
|
||||
</ul>
|
||||
</td>
|
||||
|
||||
BIN
doc/pic/mandelbrotset.png
Normal file
BIN
doc/pic/mandelbrotset.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 162 KiB |
@@ -1,6 +1,7 @@
|
||||
# flightgear developer environments simulator (beta)
|
||||
# ValKmjolnir 2022
|
||||
use std.runtime;
|
||||
use std.coroutine;
|
||||
|
||||
println("-------------------------------------------------------------");
|
||||
println(" FlightGear simulated-env for developers project, since 2019");
|
||||
|
||||
@@ -54,10 +54,11 @@ var find_all_files = func(path){
|
||||
}
|
||||
var dd = unix.opendir(path);
|
||||
var res = [];
|
||||
while(var n = unix.readdir(dd))
|
||||
while(var n = unix.readdir(dd)) {
|
||||
if (unix.isfile(path~"/"~n)) {
|
||||
append(res, n);
|
||||
}
|
||||
}
|
||||
unix.closedir(dd);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
# lib.nas
|
||||
# 2019 ValKmjolnir
|
||||
|
||||
use std.coroutine;
|
||||
use std.math;
|
||||
use std.string;
|
||||
use std.io;
|
||||
use std.os;
|
||||
use std.bits;
|
||||
use std.unix;
|
||||
|
||||
# print is used to print all things in nasal, try and see how it works.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# this provides safe usage of dylib
|
||||
# when dylib is closed,
|
||||
# all the invalid functions cannot be called
|
||||
use std.dylib;
|
||||
|
||||
var module_call_func = func(fptr, args) {
|
||||
return __dlcallv;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# unix.nas
|
||||
# 2023 by ValKmjolnir
|
||||
use std.bits;
|
||||
|
||||
var _S_IFDIR = 0x4000;
|
||||
var _S_IFREG = 0x8000;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# coroutine.nas by ValKmjolnir
|
||||
# 2022/5/19
|
||||
use std.coroutine;
|
||||
use std.process_bar;
|
||||
use std.padding;
|
||||
|
||||
|
||||
@@ -44,5 +44,6 @@ var RGB = func(h, w) {
|
||||
var c = char(res);
|
||||
return c~c~c;
|
||||
}
|
||||
|
||||
ppm("feigenbaum.ppm", width, height, RGB);
|
||||
println();
|
||||
@@ -1,8 +1,6 @@
|
||||
var fib=func(x)
|
||||
{
|
||||
var fib = func(x) {
|
||||
if (x<2) return x;
|
||||
return fib(x-1)+fib(x-2);
|
||||
}
|
||||
for(var i=0;i<31;i+=1)
|
||||
print(fib(i),'\n');
|
||||
|
||||
@@ -2,22 +2,21 @@
|
||||
var n=4;
|
||||
var input=[[0,1],[0,2],[1,2]];
|
||||
|
||||
var find_root=func(x,parent)
|
||||
{
|
||||
var find_root = func(x,parent) {
|
||||
while(parent[x]!=nil)
|
||||
x=parent[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 y_root=find_root(y,parent);
|
||||
if (x_root==y_root) return 0;
|
||||
else parent[x_root]=y_root;
|
||||
return 1;
|
||||
}
|
||||
var makeConnect=func(n,connections)
|
||||
{
|
||||
|
||||
var makeConnect = func(n,connections) {
|
||||
if (size(connections)<n-1) return -1;
|
||||
var cnt=n-1;
|
||||
var parent=[];
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var lexer=func(file)
|
||||
{
|
||||
var lexer = func(file) {
|
||||
var (ptr,token)=(0,[]);
|
||||
var s=io.readfile(file);
|
||||
var len=size(s);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std.bits;
|
||||
|
||||
var inst={
|
||||
inst_stop:0,
|
||||
inst_mov_reg_reg:1,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std.bits;
|
||||
|
||||
var check = func(x) {
|
||||
if (x<0x100000000)
|
||||
return x;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std.coroutine;
|
||||
use std.process_bar;
|
||||
use module.libkey;
|
||||
use std.runtime;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use module.libkey;
|
||||
use std.list;
|
||||
use std.runtime;
|
||||
use std.coroutine;
|
||||
|
||||
var game = func(x,y) {
|
||||
rand(time(0));
|
||||
@@ -142,15 +143,16 @@ var main=func(argv){
|
||||
while(1) {
|
||||
while((var ch=coroutine.resume(co)[0])==nil);
|
||||
if (ch!=nil and ch!=-1) {
|
||||
if(ch=='q'[0])
|
||||
if (ch=='q'[0]) {
|
||||
break;
|
||||
elsif(ch=='p'[0]){
|
||||
} elsif (ch=='p'[0]) {
|
||||
print("\rpress any key to continue...");
|
||||
libkey.getch();
|
||||
print("\r \r");
|
||||
}
|
||||
} elsif (ch=='w'[0] or ch=='s'[0] or ch=='a'[0] or ch=='d'[0]) {
|
||||
g.move(chr(ch));
|
||||
}
|
||||
}
|
||||
|
||||
g.next();
|
||||
if (g.gameover())
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
29
tools/compiling_test.nas
Normal file
29
tools/compiling_test.nas
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user