diff --git a/README.md b/README.md index eaf2b6d..71e3de4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ \_\ \/ \__,_|___/\__,_|_| ``` +![license](https://img.shields.io/badge/license-MIT-green?style=flat-square&logo=github) + ## __Contents__ * [__Introduction__](#introduction) diff --git a/module/nasocket.cpp b/module/nasocket.cpp index 46d8dba..070e38a 100644 --- a/module/nasocket.cpp +++ b/module/nasocket.cpp @@ -43,7 +43,6 @@ extern "C" nasal_ref nas_closesocket(std::vector& args,nasal_gc& gc){ } extern "C" nasal_ref nas_shutdown(std::vector& args,nasal_gc& gc){ - //shutdown(); if(args[0].type!=vm_num) return builtin_err("shutdown","\"sd\" must be a number"); if(args[1].type!=vm_num) diff --git a/test/httptest.nas b/test/httptest.nas index 2d37c5d..28fdb8b 100644 --- a/test/httptest.nas +++ b/test/httptest.nas @@ -3,7 +3,6 @@ import("module/libsock.nas"); var sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP); socket.bind(sd,"127.0.0.1",8080); socket.listen(sd,1); - var httpheader="Http/1.1 200 OK\n\n"; var httptail="\n"; var index=" @@ -11,16 +10,21 @@ var index=" nasal-http-test-web +
- Hello, this is a simple HTML document just for test.
- This simple http server is written in nasal.
- Nasal is an ECMAscript-like programming language that used in Flightgear.
- This language is designed by Andy Ross.
- + Hello, this is a simple HTML document just for test. This simple http server is written in nasal.
+ Nasal is an ECMAscript-like programming language that used in Flightgear designed by Andy Ross.

The interpreter is totally rewritten by ValKmjolnir 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.
- - Now this project uses MIT license(2021/5/4). Edit it if you want, use this project to learn or create more interesting things(But don't forget me XD). + But we really appreciate that Andy created this amazing programming language and his interpreter project.

+ Now this project uses MIT license(2021/5/4). Edit it if you want, use this project to learn or create more interesting things(But don't forget me XD).
+
+ +
+ + Here is the benchmark of different versions of nasal interpreter(left).
+ Look at this beautiful picture(right).
+ Nasal can run this test file(test/bfcolored.nas) in about 220 seconds.
+ In fact this test file cost over 2200 seconds before ver 8.0 .
"; @@ -35,12 +39,20 @@ var notfound=" "; +var files=func(){ + var res={}; + var dd=unix.opendir("./test"); + while((var name=unix.readdir(dd))!=nil) + res[name]=1; + return res; +}(); + while(1){ var client=socket.accept(sd); var recieve_data=socket.recv(client.sd,1024); if(!recieve_data.size){ println("[",client.ip,"] request connection closed"); - break; + continue; } var first=split("\n",recieve_data.str)[0]; var (type,path)=split(" ",first)[0,1]; @@ -48,9 +60,20 @@ while(1){ if(path=="/") socket.send(client.sd,httpheader~index~httptail); elsif(path=="/favicon.ico") - socket.send(client.sd,httpheader~io.fin("pic/favicon.ico")~httptail); - else - socket.send(client.sd,httpheader~notfound~httptail); + socket.send(client.sd,httpheader~io.fin("./pic/favicon.ico")~httptail); + elsif(path=="/nasal.png") + socket.send(client.sd,httpheader~io.fin("./pic/nasal.png")~httptail); + elsif(path=="/benchmark.png") + socket.send(client.sd,httpheader~io.fin("./pic/benchmark.png")~httptail); + elsif(path=="/mandelbrot.png") + socket.send(client.sd,httpheader~io.fin("./pic/mandelbrot.png")~httptail); + else{ + var filename=substr(path,1,size(path)-1); + if(contains(files,filename)) + socket.send(client.sd,httpheader~io.fin("./test/"~filename)~httptail) + else + socket.send(client.sd,httpheader~notfound~httptail); + } socket.closesocket(client.sd); } socket.closesocket(sd); \ No newline at end of file