📝 shrink size of README.md

This commit is contained in:
ValKmjolnir 2022-07-20 22:22:50 +08:00
parent f7cd3a027b
commit f68a512845
4 changed files with 39 additions and 192 deletions

106
README.md
View File

@ -122,15 +122,11 @@ __CAUTION__: If want to use the release zip/tar.gz file to build the interpreter
![clang++](https://img.shields.io/badge/LLVM-clang++-262D3A?style=flat-square&logo=LLVM)
![vs](https://img.shields.io/badge/Visual_Studio-MSVC-5C2D91?style=flat-square&logo=visualstudio)
Use g++(`MinGW-w64`) or MSVC(`Visual Studio`) on __`Windows`__ platform. Download MinGW-w64 [__HERE__](https://www.mingw-w64.org/downloads/)(Visual Studio also has this).
Use g++(`MinGW-w64`) or MSVC(`Visual Studio`) on __`Windows`__ platform. Download MinGW-w64 [__HERE__](https://www.mingw-w64.org/downloads/)(Visual Studio also has this), and use g++/clang++ on __`linux/macOS/Unix`__ platform (we suggest `clang`).
> $(CXX) -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
We could build the interpreter using `makefile`.
Or use g++/clang++ on __`linux/macOS/Unix`__ platform (we suggest clang).
> $(CXX) -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
Or using makefile,`mingw32-make` is __`Windows(MinGW-w64)`__ platform's `make`:
`mingw32-make` is __`Windows(MinGW-w64)`__ platform's `make`:
> mingw32-make nasal.exe
>
@ -140,13 +136,13 @@ on __`linux/macOS/Unix`__:
> make nasal
You could choose which compiler you want to use by add this after the command:
You could choose which compiler you want to use:
> CXX=clang++
> make nasal CXX=clang++
>
> CXX=g++
> make nasal CXX=g++
>
> CXX=...
> make nasal CXX=...
If you think `-O3` isn't that safe and stable, you could choose:
@ -167,55 +163,10 @@ Use these commands to get version of interpreter:
> ./nasal -v | --version
```bash
__ _
/\ \ \__ _ ___ __ _| |
/ \/ / _` / __|/ _` | |
/ /\ / (_| \__ \ (_| | |
\_\ \/ \__,_|___/\__,_|_|
nasal ver : 10.0
c++ std : 201103
thanks to : https://github.com/andyross/nasal
code repo : https://github.com/ValKmjolnir/Nasal-Interpreter
code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter
lang info : http://wiki.flightgear.org/Nasal_scripting_language
input <nasal -h> to get help .
```
Use these commands to get help(see more debug commands in help):
> ./nasal -h | --help
```bash
,--#-,
<3 / \____\ <3
|_|__A_|
nasal <option>
option:
-h, --help | get help.
-v, --version | get version of nasal interpreter.
nasal <file>
file:
input file name to execute script file.
nasal [options...] <file>
option:
-l, --lex | view token info.
-a, --ast | view abstract syntax tree.
-c, --code | view bytecode.
-e, --exec | execute.
-t, --time | execute and get the running time.
-o, --opcnt | execute and count used operands.
-d, --detail | execute and get detail crash info.
| get garbage collector info if did not crash.
-op, --optimize| use optimizer(beta).
| if want to use -op and run, please use -op -e/-t/-o/-d.
-dbg, --debug | debug mode (this will ignore -t -o -d).
file:
input file name to execute script file.
```
If your system is __`Windows`__ and you want to output unicode,please use this command before running nasal interpreter:
> chcp 65001
@ -267,18 +218,9 @@ var s=`c`;
# some special characters is allowed in this language:
'\a';
'\b';
'\e';
'\f';
'\n';
'\r';
'\t';
'\v';
'\0';
'\\';
'\?';
'\'';
'\a'; '\b'; '\e'; '\f';
'\n'; '\r'; '\t'; '\v';
'\0'; '\\'; '\?'; '\'';
'\"';
```
@ -301,9 +243,8 @@ __`vm_hash`__ is a hashmap(or like a dict in `python`) that stores values with s
```javascript
var hash={
member1:nil,
member2:'str',
member2:"str",
'member3':'member\'s name can also be a string constant',
"member4":"also this",
function:func(){
var a=me.member2~me.member3;
return a;
@ -341,10 +282,10 @@ so this type is often created by native-function that programmed in C/C++ by lib
You could see how to write your own native-functions below.
```javascript
var my_new_obj=func(){
var new_obj=func(){
return __my_obj();
}
var obj=my_new_obj();
var obj=new_obj();
```
### __operators__
@ -1814,9 +1755,7 @@ global(0x7ffff42f3808<sp+0>):
...
0x00000049 | num | 57.2958
0x0000004a | func | <0x18e6490> entry:0x489
0x0000004b | func | <0x18e6530> entry:0x49c
0x0000004c | func | <0x18e65d0> entry:0x4a8
0x0000004d | func | <0x18e6670> entry:0x4b5
...
0x0000004e | func | <0x18e6710> entry:0x4c2
0x0000004f | hash | <0x191f8b0> {5 val}
local(0x7ffff42f3d68<sp+86>):
@ -1826,7 +1765,7 @@ local(0x7ffff42f3d68<sp+86>):
## __Debugger__
In nasal v8.0 we added a debugger.
In nasal `v8.0` we added a debugger.
Now we could see both source code and bytecode when testing program.
Use command `./nasal -dbg xxx.nas` to use the debugger,
@ -1861,20 +1800,7 @@ vm stack(0x7fffe05e3190<sp+79>, limit 5, total 0)
If want help, input `h` to get help.
```bash
<option>
h, help | get help
bt, backtrace | get function call trace
c, continue | run program until break point or exit
f, file | see all the compiled files
g, global | see global values
l, local | see local values
u, upval | see upvalue
r, register | show vm register detail
a, all | show global,local and upvalue
n, next | execute next bytecode
q, exit | exit debugger
<option> <filename> <line>
bk, break | set break point
>> h
```
When running the debugger, you could see what is on stack.

View File

@ -106,14 +106,11 @@ __注意__: 如果你想直接下载发行版提供的zip/tar.gz压缩包来构
![vs](https://img.shields.io/badge/Visual_Studio-MSVC-5C2D91?style=flat-square&logo=visualstudio)
__`Windows`__ 用户通过g++(`MinGW-w64`)使用以下命令或者使用MSVC(`Visual Studio`)来进行编译. 没有编译环境的请在[__这里__](https://www.mingw-w64.org/downloads/)下载MinGW-w64。(VS同样也有MinGW-w64)
__`linux/macOS/Unix`__ 用户可以使用g++或者clang++替代下面命令中中括号的部分来进行编译(我们建议您使用`clang`)。
> $(CXX) -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
使用makefile我们就可以编译这个解释器。
__`linux/macOS/Unix`__ 用户可以使用g++或者clang++替代下面命令中中括号的部分来进行编译(我们建议您使用clang)。
> $(CXX) -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
当然也可以使用makefile`mingw32-make`是 __`Windows(MinGW-w64)`__ 平台的`make`:
`mingw32-make`__`Windows(MinGW-w64)`__ 平台的`make`:
> mingw32-make nasal.exe
>
@ -123,13 +120,13 @@ __`linux/macOS/Unix`__ 平台直接使用make即可:
> make nasal
你也可以通过在命令后面添加如下的其中一行来指定你想要使用的编译器:
你也可以通过如下的其中一行命令来指定你想要使用的编译器:
> CXX=clang++
> make nasal CXX=clang++
>
> CXX=g++
> make nasal CXX=g++
>
> CXX=...
> make nasal CXX=...
如果你觉得`-O3`编译的版本不是那么安全和稳定,你也可以选择生成稳定的版本:
@ -151,57 +148,12 @@ __`linux/macOS/Unix`__ 平台直接使用make即可:
>
> ./nasal --version
```bash
__ _
/\ \ \__ _ ___ __ _| |
/ \/ / _` / __|/ _` | |
/ /\ / (_| \__ \ (_| | |
\_\ \/ \__,_|___/\__,_|_|
nasal ver : 10.0
c++ std : 201103
thanks to : https://github.com/andyross/nasal
code repo : https://github.com/ValKmjolnir/Nasal-Interpreter
code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter
lang info : http://wiki.flightgear.org/Nasal_scripting_language
input <nasal -h> to get help .
```
下面两个命令可以用于查看帮助(调试器的使用方法可以进入调试模式之后根据提示来查询):
> ./nasal -h
>
> ./nasal --help
```bash
,--#-,
<3 / \____\ <3
|_|__A_|
nasal <option>
option:
-h, --help | get help.
-v, --version | get version of nasal interpreter.
nasal <file>
file:
input file name to execute script file.
nasal [options...] <file>
option:
-l, --lex | view token info.
-a, --ast | view abstract syntax tree.
-c, --code | view bytecode.
-e, --exec | execute.
-t, --time | execute and get the running time.
-o, --opcnt | execute and count used operands.
-d, --detail | execute and get detail crash info.
| get garbage collector info if did not crash.
-op, --optimize| use optimizer(beta).
| if want to use -op and run, please use -op -e/-t/-o/-d.
-dbg, --debug | debug mode (this will ignore -t -o -d).
file:
input file name to execute script file.
```
如果你的操作系统是 __`Windows`__ 并且你想输出unicode请保证你的控制台程序的代码页支持utf-8若不支持使用下面这个命令启用代码页:
> chcp 65001
@ -250,18 +202,9 @@ var s=`c`;
# 该语言也支持一些特别的转义字符:
'\a';
'\b';
'\e';
'\f';
'\n';
'\r';
'\t';
'\v';
'\0';
'\\';
'\?';
'\'';
'\a'; '\b'; '\e'; '\f';
'\n'; '\r'; '\t'; '\v';
'\0'; '\\'; '\?'; '\'';
'\"';
```
@ -284,9 +227,8 @@ __`vm_hash`__ 使用哈希表(类似于`python`中的字典),通过键值对
```javascript
var hash={
member1:nil,
member2:'str',
member2:"str",
'member3':'member\'s name can also be a string constant',
"member4":"also this",
function:func(){
var a=me.member2~me.member3;
return a;
@ -319,10 +261,10 @@ __`vm_upval`__ 是用于存储闭包数据的特殊类型。这种类型只在`n
__`vm_obj`__ 是一种用来存储用户自定义数据的特别类型。这意味着你可以在nasal中使用C/C++的一些复杂数据结构。如果你想为nasal添加一种新的数据结构那么就可以使用这个类型的数据。这种类型的数据一般由内置函数或者库开发者提供的模块函数生成。
```javascript
var my_new_obj=func(){
var new_obj=func(){
return __my_obj();
}
var obj=my_new_obj();
var obj=new_obj();
```
### __运算符__
@ -1675,9 +1617,7 @@ global(0x7ffff42f3808<sp+0>):
...
0x00000049 | num | 57.2958
0x0000004a | func | <0x18e6490> entry:0x489
0x0000004b | func | <0x18e6530> entry:0x49c
0x0000004c | func | <0x18e65d0> entry:0x4a8
0x0000004d | func | <0x18e6670> entry:0x4b5
...
0x0000004e | func | <0x18e6710> entry:0x4c2
0x0000004f | hash | <0x191f8b0> {5 val}
local(0x7ffff42f3d68<sp+86>):
@ -1687,7 +1627,7 @@ local(0x7ffff42f3d68<sp+86>):
## __调试器__
在v8.0版本中我们为nasal添加了调试器。现在我们可以在测试程序的时候同时看到源代码和生成的字节码并且单步执行。
`v8.0`版本中我们为nasal添加了调试器。现在我们可以在测试程序的时候同时看到源代码和生成的字节码并且单步执行。
使用这个命令`./nasal -dbg xxx.nas`来启用调试器,接下来调试器会打开文件并输出以下内容:
@ -1720,20 +1660,7 @@ vm stack(0x7fffe05e3190<sp+79>, limit 5, total 0)
如果需要查看命令的使用方法,可以输入`h`获取帮助信息。
```bash
<option>
h, help | get help
bt, backtrace | get function call trace
c, continue | run program until break point or exit
f, file | see all the compiled files
g, global | see global values
l, local | see local values
u, upval | see upvalue
r, register | show vm register detail
a, all | show global,local and upvalue
n, next | execute next bytecode
q, exit | exit debugger
<option> <filename> <line>
bk, break | set break point
>> h
```
当运行调试器的时候,你可以看到现在的操作数栈上到底有些什么数据。

View File

@ -226,19 +226,15 @@ inline void print_core(std::vector<nasal_ref>& elems)
}
nasal_ref builtin_print(nasal_ref* local,nasal_gc& gc)
{
// get arguments
// local[0] is reserved for 'me'
nasal_ref vec=local[1];
// main process
print_core(vec.vec().elems);
// get arguments,local[0] is reserved for 'me'
print_core(local[1].vec().elems);
std::cout<<std::flush;
// generate return value
return nil;
}
nasal_ref builtin_println(nasal_ref* local,nasal_gc& gc)
{
nasal_ref vec=local[1];
print_core(vec.vec().elems);
print_core(local[1].vec().elems);
std::cout<<std::endl;
return nil;
}

View File

@ -320,7 +320,6 @@ void nasal_vm::opcallsort(const uint64_t* arr)
for(uint32_t i=0;i<op_ret+1;++i)
{
total+=arr[i];
if(arr[i])
opcall.push_back({i,arr[i]});
}
std::sort(opcall.begin(),opcall.end(),
@ -958,9 +957,8 @@ inline void nasal_vm::opr_ret()
auto& upval=up.upval();
auto size=func.func().lsize;
upval.onstk=false;
upval.elems.resize(size);
for(uint32_t i=0;i<size;++i)
upval.elems[i]=local[i];
upval.elems.push_back(local[i]);
}
// cannot use gc.coroutine to judge,
// because there maybe another function call inside