🎨 format
Some checks failed
Nasal Interpreter Test / mac-aarch64 (push) Has been cancelled
Nasal Interpreter Test / linux-x86_64 (push) Has been cancelled

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

@@ -63,7 +63,7 @@ var add_event = func(name,interval,function) {
fg_globals.event[name]=coroutine.create(func {
var timestamp=maketimestamp();
timestamp.stamp();
while(timestamp.elapsedMSec()<interval*1000)
while (timestamp.elapsedMSec()<interval*1000)
coroutine.yield();
println("[\e[32m",name,"\e[0m] [",os.time(),"] type:\e[33mevent\e[0m interval:\e[34m",interval,"\e[0m");
function();
@@ -75,10 +75,10 @@ var add_task = func(name,interval,function) {
fg_globals.task[name]=coroutine.create(func {
var counter=0;
var timestamp=maketimestamp();
while(1) {
while (1) {
counter+=1;
timestamp.stamp();
while(timestamp.elapsedMSec()<interval*1000)
while (timestamp.elapsedMSec()<interval*1000)
coroutine.yield();
println("[\e[32m",name,"\e[0m] [",os.time(),"] type:\e[34mtask\e[0m interval:\e[34m",interval,"\e[0m invoke-time:\e[96m",counter,"\e[0m");
function();
@@ -145,7 +145,7 @@ var settimer = func() {
println("[\e[32m maketimer \e[0m] [",os.time(),"] test func simulation()");
var simulation = func() {
var running=1;
while(running) {
while (running) {
running=0;
foreach(var i;keys(fg_globals.task)) {
if (!contains(fg_globals.task,i))
@@ -542,7 +542,7 @@ func() {
srand();
var tmp=nil;
var vec=[props.globals];
while(size(vec)) {
while (size(vec)) {
tmp=[];
foreach(var i;vec) {
if (typeof(i.val)=="hash") {

View File

@@ -53,7 +53,7 @@ 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);
}
@@ -71,7 +71,7 @@ var recursive_find_files = func(path) {
dir: path,
files: []
};
while(var n = unix.readdir(dd)) {
while (var n = unix.readdir(dd)) {
if (unix.isfile(path ~ "/" ~ n)) {
append(res.files, n);
} elsif (unix.isdir(path ~ "/" ~ n) and n != "." and n != "..") {
@@ -92,7 +92,7 @@ var recursive_find_files_flat = func(path) {
}
var flat = [];
var bfs = [tree_files];
while(size(bfs) != 0) {
while (size(bfs) != 0) {
var first = pop(bfs);
foreach(var file_record; first.files) {
if (ishash(file_record)) {

View File

@@ -231,12 +231,12 @@ 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 cmp(tmp,vec[j])) {
while (i<j) {
while (i<j and cmp(tmp,vec[j])) {
j -= 1;
}
vec[i] = vec[j];
while(i<j and cmp(vec[i],tmp)) {
while (i<j and cmp(vec[i],tmp)) {
i += 1;
}
vec[j] = vec[i];

View File

@@ -220,7 +220,7 @@ var bp_example = func() {
var epoch=0;
var total=1e6;
while(total>0.001) {
while (total>0.001) {
epoch+=1;
if (epoch>1e4) {
println("Training failed after ",epoch," epoch.");

View File

@@ -37,7 +37,7 @@ var _connect = func(hostname, port) {
socket.IPPROTO_TCP
);
var ip_info = hostname~":"~port;
while((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) {
while ((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) {
println(_get_time(), " failed to connect ", ip_info, ": ", socket.errno());
unix.sleep(1);
}
@@ -67,7 +67,7 @@ var new = func(hostname, port) {
# get total message
var total_source = message.str;
# 0\r\n\r\n is the tail of chunked http info
while(find("0\r\n\r\n", total_source)<0) {
while (find("0\r\n\r\n", total_source)<0) {
message = socket.recv(sd, 1024);
total_source ~= message.str;
}

View File

@@ -112,11 +112,11 @@ var spinner = func() {
for (var i=0;i<len;i+=1) {
tmp=pop(vec)~tmp;
append(res,tmp);
while(size(res[-1])!=16)
while (size(res[-1])!=16)
res[-1]~=" ";
}
tmp=res[-1];
while(tmp!=" ") {
while (tmp!=" ") {
tmp=" "~substr(tmp,0,15);
append(res,tmp);
}

View File

@@ -5,7 +5,7 @@ use std.unix;
var udp_server = func(hostname, port, retry_delay = 5) {
var socket = libnasock.socket;
var server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
while(socket.bind(server, hostname, port) < 0) {
while (socket.bind(server, hostname, port) < 0) {
println("[", os.time(), "] failed to bind socket "~server~" at ", hostname, ":", port, ".");
unix.sleep(retry_delay);
println("[", os.time(), "] retrying...");
@@ -29,7 +29,7 @@ var udp_client = func(hostname = "", port = -1, retry_delay = 5) {
var socket = libnasock.socket;
var client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
if (port > 0 and size(hostname) != 0) {
while(socket.bind(client, hostname, port)<0) {
while (socket.bind(client, hostname, port)<0) {
println("[",os.time(),"] failed to bind socket "~client~" at ", hostname, ":", port, ".");
unix.sleep(retry_delay);
println("[",os.time(),"] retrying...");