🎨 format

This commit is contained in:
ValKmjolnir
2025-06-02 13:43:00 +08:00
parent 2cc5bb8625
commit af3d93ab64
53 changed files with 185 additions and 185 deletions

View File

@@ -209,7 +209,7 @@ var bf = func(program) {
f~="print(chr(paper[ptr]));\n";
} elsif (c=='[') {
f~=padding(size(stack));
f~="while(paper[ptr]) {\n";
f~="while (paper[ptr]) {\n";
append(stack,0);
} elsif (c==']') {
if (!size(stack)) {

View File

@@ -32,7 +32,7 @@ var bfs = func(begin,end) {
map[end[0]][end[1]]=0;
if (map[1][0]==1 and map[0][1]==1)
map[1][0]=0;
while(!que.empty()) {
while (!que.empty()) {
var vertex=que.front();
que.pop();
foreach(var i;move) {

View File

@@ -107,7 +107,7 @@ var backward = func(x) {
}
var (cnt,error)=(0,100);
while(error>0.0005) {
while (error>0.0005) {
error=0;
for (var i=0;i<4;i+=1) {
forward(i);

View File

@@ -15,7 +15,7 @@ var fib = func() {
var (a, b) = (1, 1);
coroutine.yield(a);
coroutine.yield(b);
while(1) {
while (1) {
(a, b) = (b, a + b);
coroutine.yield(b);
}
@@ -95,7 +95,7 @@ println("[2] ok\n");
# pressure test
for (var t = 0; t < 10; t += 1) {
var productor = func() {
while(1) {
while (1) {
coroutine.yield(i);
}
}

View File

@@ -83,7 +83,7 @@ var select = func(n) {
var left=0;
var right=size(message)-1;
var data=c[2];
while(left<=right) {
while (left<=right) {
var mid=int((left+right)/2);
var res=message[mid][0];
if (data==res) {

View File

@@ -42,7 +42,7 @@ var myers = func(src,dst,show_table=0) {
var (total,path,vec)=([],[],[[0,0,-1]]);
visited[0]=1;
while(size(vec)) {
while (size(vec)) {
append(total,vec);
var tmp=[];
forindex(var i;vec) {

View File

@@ -7,7 +7,7 @@ var files = func(path) {
return [];
var dd=unix.opendir(path);
var res=[];
while(var n=unix.readdir(dd))
while (var n=unix.readdir(dd))
append(res,n);
unix.closedir(dd);
return res;

View File

@@ -10,7 +10,7 @@ var chars = "abcdefghijklmnopqrstuvwxyz" ~
chars = split("", chars);
print("\ec");
while(1) {
while (1) {
var key = libkey.nonblock();
if (key!=nil and chr(key)=="q") {
break;

View File

@@ -1,7 +1,7 @@
use std.unix;
var count = 0;
while(1) {
while (1) {
unix.sleep(0.1);
count += 0.1;
println("process running time: ", count);

View File

@@ -10,7 +10,7 @@ var http = func() {
return {
establish:func(ip,port) {
sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP);
while(socket.bind(sd,ip,port)<0) {
while (socket.bind(sd,ip,port)<0) {
println("[",os.time(),"] failed to bind socket "~sd~" at IP: "~ip~" port: "~port~".");
unix.sleep(5);
println("[",os.time(),"] retrying...");
@@ -98,7 +98,7 @@ var html_read_file = func(filename) {
s=char(file_text[index]);
}
while(1) {
while (1) {
if (next()>=len)
break;
if (s==">")
@@ -111,7 +111,7 @@ var html_read_file = func(filename) {
content~="<code class=\"opr\">"~s~"</code>";
elsif (s=="_" or ("a"[0]<=s[0] and s[0]<="z"[0]) or ("A"[0]<=s[0] and s[0]<="Z"[0]) or s[0]<0 or s[0]>=128) {
var tmp=""~s; # generate a new string
while(1) {
while (1) {
if (next()>=len)
break;
if (s=="_" or ("a"[0]<=s[0] and s[0]<="z"[0]) or ("A"[0]<=s[0] and s[0]<="Z"[0]) or ("0"[0]<=s[0] and s[0]<="9"[0]) or s[0]<0 or s[0]>=128)
@@ -138,7 +138,7 @@ var html_read_file = func(filename) {
}
if (s=="o") {
content~="o";
while(1) {
while (1) {
if (next()>=len)
break;
if ("0"[0]<=s[0] and s[0]<="7"[0])
@@ -150,7 +150,7 @@ var html_read_file = func(filename) {
prev();
} elsif (s=="x") {
content~="x";
while(1) {
while (1) {
if (next()>=len)
break;
if (("0"[0]<=s[0] and s[0]<="9"[0]) or ("a"[0]<=s[0] and s[0]<='f') or ("A"[0]<=s[0] or s[0]<="F"))
@@ -161,7 +161,7 @@ var html_read_file = func(filename) {
content~="</code>";
prev();
} elsif (("0"[0]<=s[0] and s[0]<="9"[0]) or s=="." or s=="e") {
while("0"[0]<=s[0] and s[0]<="9"[0]) {
while ("0"[0]<=s[0] and s[0]<="9"[0]) {
content~=s;
if (next()>=len)
break;
@@ -171,7 +171,7 @@ var html_read_file = func(filename) {
if (next()>=len)
break;
}
while("0"[0]<=s[0] and s[0]<="9"[0]) {
while ("0"[0]<=s[0] and s[0]<="9"[0]) {
content~=s;
if (next()>=len)
break;
@@ -186,7 +186,7 @@ var html_read_file = func(filename) {
break;
}
}
while("0"[0]<=s[0] and s[0]<="9"[0]) {
while ("0"[0]<=s[0] and s[0]<="9"[0]) {
content~=s;
if (next()>=len)
break;
@@ -200,7 +200,7 @@ var html_read_file = func(filename) {
} elsif (s=="\"" or s=="'" or s=="`") {
var quot=s~""; # generate a new string
content~="<code class=\"str\">"~s;
while(1) {
while (1) {
if (next()>=len)
break;
if (s==quot) {
@@ -221,7 +221,7 @@ var html_read_file = func(filename) {
}
} elsif (s=="#") {
content~="<code class=\"note\">"~s;
while(1) {
while (1) {
if (next()>=len)
break;
if (s=="\n" or s=="\r") {
@@ -282,12 +282,12 @@ var respond={
var files = func() {
var res={};
var dd=unix.opendir("./test");
while((var name=unix.readdir(dd))!=nil)
while ((var name=unix.readdir(dd))!=nil)
res[name]=1;
return res;
}();
while(1) {
while (1) {
var client=http.accept();
var data=http.recv(client);
if (data==nil) {

View File

@@ -25,7 +25,7 @@ var jsonRPC = func() {
},
connect:func(ip,port) {
sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP);
while(socket.connect(sd,ip,port)<0) {
while (socket.connect(sd,ip,port)<0) {
println("[",gettime(),"] failed to connect socket ",sd," to ",ip,":",port);
unix.sleep(5);
}
@@ -75,9 +75,9 @@ var server = func(ip,port) {
};
jsonRPC.establish(ip,port);
while(1) {
while (1) {
var client=jsonRPC.accept();
while(1) {
while (1) {
var data=jsonRPC.recv(client);
if (data!=nil) {
data=json.parse(data);
@@ -112,7 +112,7 @@ var client = func(ip,port) {
var params=[["a","b"],["1","2"]];
var server=jsonRPC.connect(ip,port);
while(1) {
while (1) {
unix.sleep(5);
var data=json.stringify({jsonrpc:2.0, id:call_id, method:methods[rand()*size(methods)],params:params[rand()*size(params)]});
jsonRPC.send(server, data);

View File

@@ -91,7 +91,7 @@ var move = func {
map = temp_map;
}
while(1) {
while (1) {
print_map();
move();
unix.sleep(1/24);

View File

@@ -3,7 +3,7 @@ var n=4;
var input=[[0,1],[0,2],[1,2]];
var find_root = func(x,parent) {
while(parent[x]!=nil)
while (parent[x]!=nil)
x=parent[x];
return x;
}

View File

@@ -13,7 +13,7 @@ var lexer = func(file) {
}
return {
jmp_note:func() {
while(ptr<len and s[ptr]!='\n'[0])
while (ptr<len and s[ptr]!='\n'[0])
ptr+=1;
if (ptr<len and s[ptr]=='\n'[0])
line+=1;
@@ -21,7 +21,7 @@ var lexer = func(file) {
},
id_gen:func() {
var tmp="";
while(ptr<len) {
while (ptr<len) {
var c=s[ptr];
if (('a'[0]<=c and c<='z'[0])
or ('A'[0]<=c and c<='Z'[0])
@@ -38,7 +38,7 @@ var lexer = func(file) {
var str="";
var mark=chr(s[ptr]);
ptr+=1;
while(ptr<len and chr(s[ptr])!=mark) {
while (ptr<len and chr(s[ptr])!=mark) {
if (chr(s[ptr])=='\\') {
ptr+=1;
var c=chr(s[ptr]);
@@ -73,7 +73,7 @@ var lexer = func(file) {
ptr+=1;
if (ptr<len and chr(s[ptr])=='x') {
ptr+=1;
while(ptr<len and
while (ptr<len and
('a'[0]<=s[ptr] and s[ptr]<='f'[0]
or '0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
number~=chr(s[ptr]);
@@ -83,21 +83,21 @@ var lexer = func(file) {
return;
} elsif (ptr<len and chr(s[ptr])=='o') {
ptr+=1;
while(ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='7'[0])) {
while (ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='7'[0])) {
number~=chr(s[ptr]);
ptr+=1;
}
gen(num(number));
return;
}
while(ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
while (ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
number~=chr(s[ptr]);
ptr+=1;
}
if (ptr<len and chr(s[ptr])=='.') {
number~=chr(s[ptr]);
ptr+=1;
while(ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
while (ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
number~=chr(s[ptr]);
ptr+=1;
}
@@ -109,7 +109,7 @@ var lexer = func(file) {
number~=chr(s[ptr]);
ptr+=1;
}
while(ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
while (ptr<len and ('0'[0]<=s[ptr] and s[ptr]<='9'[0])) {
number~=chr(s[ptr]);
ptr+=1;
}
@@ -148,7 +148,7 @@ var lexer = func(file) {
},
compile:func() {
line=1;
while(ptr<len) {
while (ptr<len) {
var c=s[ptr];
if (c=='#'[0])
me.jmp_note();

View File

@@ -8,9 +8,9 @@ for (var i=1;;i+=1)break;
for (var i=1;i<10;i+=1)
print(i," ");
print("\n");
while(1)break;
while (1)break;
var j=0;
while(j<10) {
while (j<10) {
print(j," ");
j+=1;
}

View File

@@ -91,7 +91,7 @@ var ctx_info = func() {
}
var exec = func(info=1) {
println("[",os.time(),"] executing ...");
while(1) {
while (1) {
ir=[mem[pc],mem[pc+1],mem[pc+2],mem[pc+3]];
if (info)ctx_info();
var op=ir[0];

View File

@@ -34,7 +34,7 @@ var cpu_stat = func() {
var cpu_occupation = func() {
var first_in = 1;
while(1) {
while (1) {
var cpu0 = cpu_stat();
if (first_in) {
unix.sleep(0.05);
@@ -75,7 +75,7 @@ var random_generator = func() {
var total = 0;
var statistics = [];
setsize(statistics, 70);
while(1) {
while (1) {
for (var i=0;i<10;i+=1) {
total+=1;
var u=rand()*rand()*(rand()>0.5?-1:1);
@@ -127,7 +127,7 @@ func() {
var bar=process_bar.high_resolution_bar(48);
print("\ec");
while(limited_loop!=0) {
while (limited_loop!=0) {
limited_loop=limited_loop<0?limited_loop:limited_loop-1;
var mem=mem_occupation();
var mem_occ=(mem.MemTotal-mem.MemFree)/mem.MemTotal*100;
@@ -135,7 +135,7 @@ func() {
mem_occ=0;
}
var cpu_occ=nil;
while((cpu_occ=coroutine.resume(co)[0])==nil) {
while ((cpu_occ=coroutine.resume(co)[0])==nil) {
var key=libkey.nonblock();
coroutine.resume(rd);
if (key!=nil and chr(key)=="q")

View File

@@ -6,11 +6,11 @@ var var_sort = func() {
var base=left+int(rand()*(right-left));
(vec[left],vec[base])=(vec[base],vec[left]);
var (i,j,tmp)=(left,right,vec[left]);
while(i<j) {
while(i<j and tmp<vec[j])
while (i<j) {
while (i<j and tmp<vec[j])
j-=1;
vec[i]=vec[j];
while(i<j and vec[i]<tmp)
while (i<j and vec[i]<tmp)
i+=1;
vec[j]=vec[i];
j-=1;

View File

@@ -125,14 +125,14 @@ if (a and a.field == 42) {
#
# Looping constructs are mostly C-like. The differences are that
# there is no do{}while(); construct, and there is a foreach, which
# there is no do {} while (); construct, and there is a foreach, which
# takes a local variable name as its first argument and a vector as
# its second.
#
var doSomething = dummyFunc;
var stillGoing = 0;
while(stillGoing) { doSomething(); }
while (stillGoing) { doSomething(); }
for (var i=0; i < 3; i = i+1) {
elem = list1[i];

View File

@@ -35,7 +35,7 @@ var game = func(x,y) {
var gameover=0;
var setapple = func() {
var (cord_x,cord_y)=(int(rand()*x),int(rand()*y));
while(vec[cord_x][cord_y]!=0)
while (vec[cord_x][cord_y]!=0)
(cord_x,cord_y)=(int(rand()*x),int(rand()*y));
vec[cord_x][cord_y]=2;
}
@@ -112,7 +112,7 @@ var game = func(x,y) {
}
var co=coroutine.create(func() {
while(1) {
while (1) {
var moved=-1;
for (var i=0;i<30;i+=1) {
var ch=libkey.nonblock();
@@ -140,8 +140,8 @@ var main = func(argv) {
}
print("\r \r");
var counter=20;
while(1) {
while((var ch=coroutine.resume(co)[0])==nil);
while (1) {
while ((var ch=coroutine.resume(co)[0])==nil);
if (ch!=nil and ch!=-1) {
if (ch=='q'[0]) {
break;
@@ -165,7 +165,7 @@ var main = func(argv) {
if (should_skip) {
return;
}
while(libkey.getch()!='q'[0]);
while (libkey.getch()!='q'[0]);
}
main(runtime.argv());

View File

@@ -304,7 +304,7 @@ var main = func(argv) {
map.print();
var counter=init_counter;
while(1) {
while (1) {
# nonblock input one character
var ch=libkey.nonblock();
if (ch) {
@@ -350,7 +350,7 @@ var main = func(argv) {
"\e[35mt\e[36mo \e[94mq\e[95mu\e[91mi\e[92mt\e[0m\n"
);
if (!should_skip) {
while(libkey.getch()!='q'[0]);
while (libkey.getch()!='q'[0]);
}
};

View File

@@ -68,7 +68,7 @@ var run = func(table,start,stop) {
var (state,pointer)=(start,0);
prt(state,pointer,paper);
while(state!=stop) {
while (state!=stop) {
if (!contains(machine.states,state))
die("no matching function for state:"~state);
var found=0;

View File

@@ -4,13 +4,13 @@ use std.unix;
var argument = arg[0];
if (argument=="server") {
var server = udp.udp_server("127.0.0.1", 5506);
while(1) {
while (1) {
var message = server.recvfrom();
server.sendto(message.fromip, message.port, "from server");
}
} elsif (argument=="client") {
var client = udp.udp_client();
while(1) {
while (1) {
client.sendto("127.0.0.1", 5506, "hello");
var message = client.recvfrom();
println(message);

View File

@@ -53,7 +53,7 @@ if (size(argv)==2) {
var modified_time = io.fstat(filename).st_mtime;
println(os_time(), info_hd(), "watching ", filename, " ..");
while(1) {
while (1) {
unix.sleep(1);
if (!io.exists(filename)) {
println(os_time(), err_hd(), "file <", filename, "> does not exist");
@@ -75,7 +75,7 @@ while(1) {
# check if active every 0.5s
var exited = false;
while(1) {
while (1) {
unix.sleep(0.5);
if (!subprocess.active(subproc)) {
exited = true;