front end optimization&stack overflow prompt

change parameter type to avoid unnecessary copies of string.
change stack depth from 65536<<4 to 16+(65536<<2).
now you could know stack overflow when it happens
This commit is contained in:
Valk Richard Li
2021-06-07 23:53:43 +08:00
parent a3dbaebfd8
commit 166fe32839
10 changed files with 172 additions and 396 deletions
+30 -36
View File
@@ -1,8 +1,10 @@
# Nasal Script Language
## Introduction
[Nasal](http://wiki.flightgear.org/Nasal_scripting_language) is a script language that used in [FlightGear](https://www.flightgear.org/).
The interpreter is totally rewritten by ValKmjolnir using C++(standard c++11) without reusing the code in Andy Ross's nasal interpreter(https://github.com/andyross/nasal). But we really appreciate that Andy created this amazing programming language and his interpreter project.
The interpreter is totally rewritten by ValKmjolnir using C++(standard c++11) without reusing the code in Andy Ross's nasal interpreter(<https://github.com/andyross/nasal>). But we really appreciate that Andy created this amazing programming language and his interpreter project.
The interpreter is still in development(now it works well --2021/2/15). We really need your support!
@@ -10,9 +12,9 @@ Also,i am a member of [FGPRC](https://www.fgprc.org/), welcome to join us!
(2021/5/4) Now this project uses MIT license.Edit it if you want, use this project to learn or create more interesting things(But don't forget me XD).
# Why Writing Nasal Interpreter
## Why Writing Nasal Interpreter
Nasal is a script language first used in Flightgear, created by Andy Ross(https://github.com/andyross).
Nasal is a script language first used in Flightgear, created by Andy Ross(<https://github.com/andyross>).
But in last summer holiday, members in FGPRC told me that it is hard to debug with nasal-console in Flightgear, especially when checking syntax errors.
@@ -26,7 +28,7 @@ Also, you could use this language to write some interesting programs and run the
You could add your own built-in functions to change this interpreter to a useful tool in your own projects(such as a script in your own game).
# How to Compile
## How to Compile
Better choose the latest update of the interpreter.
@@ -34,7 +36,7 @@ MUST USE -O2 ! pragma gcc optimize(2) seems useless when using g++
> g++ -std=c++11 -O2 main.cpp -o main.exe
# Parser
## Parser
LL(k) parser.
@@ -47,7 +49,7 @@ These two expressions have the same first set,so LL(1) is useless for this langu
Maybe in the future i can refactor it to LL(1) with special checks.
## version 1.0(last update 2019/10/14)
### version 1.0(last update 2019/10/14)
First fully functional version of nasal_parser.
@@ -59,17 +61,17 @@ In version 0.17(2019/9/15) 0.18(2019/9/18) 0.19(2019/10/1)i was playing the pars
This project began at 2019/8/31.
# Abstract Syntax Tree
## Abstract Syntax Tree
## Version 1.2(last update 2019/10/31)
### Version 1.2(last update 2019/10/31)
The ast has been completed in this version.
## Version 2.0(last update 2020/8/31)
### Version 2.0(last update 2020/8/31)
A completed ast-interpreter with unfinished lib functions.
## Version 3.0(last update 2020/10/23)
### Version 3.0(last update 2020/10/23)
The ast is refactored and is now easier to read and maintain.
@@ -79,15 +81,15 @@ Now you can add your own functions as builtin-functions in this interpreter!
I decide to save the ast interpreter after releasing v4.0. Because it took me a long time to think and write...
## Version 5.0(last update 2021/3/7)
### Version 5.0(last update 2021/3/7)
I change my mind.AST interpreter leaves me too much things to do.
If i continue saving this interpreter,it will be harder for me to make the bytecode vm become more efficient.
# Byte Code Interpreter
## Byte Code Interpreter
## Version 4.0(last update 2020/12/17)
### Version 4.0(last update 2020/12/17)
I have just finished the first version of byte-code-interpreter.
@@ -120,7 +122,7 @@ for(var i=0;i<4000000;i+=1);
0x0000000b: nop 0x00000000
```
## Version 5.0(last update 2021/3/7)
### Version 5.0(last update 2021/3/7)
I decide to optimize bytecode vm in this version.
@@ -128,7 +130,7 @@ Because it takes more than 1.5s to count i from 0 to 4000000-1.This is not effic
2021/1/23 update: Now it can count from 0 to 4000000-1 in 1.5s.
## Version 6.0(last update 2021/6/1)
### Version 6.0(last update 2021/6/1)
Use loadg loadl callg calll mcallg mcalll to avoid branches.
@@ -169,7 +171,7 @@ for(var i=0;i<4000000;i+=1);
0x0000000c: nop 0x00000000
```
## Version 6.5(latest)
### Version 6.5(latest)
2021/5/31 update: Now gc can collect garbage correctly without re-collecting,which will cause fatal error.
@@ -213,9 +215,9 @@ f(1024,2048);
0x00000011: nop 0x00000000
```
# How to Use Nasal to Program
## How to Use Nasal to Program
## basic value type
### basic value type
Nasal has 6 value types.Number,string,vector,hash,function,nil.
@@ -281,7 +283,7 @@ var f=func(x,y,z,dynamic_para...)
}
```
## operators
### operators
```javascript
1+2;
@@ -311,7 +313,7 @@ a/=1;
a~='string';
```
## definition
### definition
```javascript
var a=1;
@@ -321,14 +323,14 @@ var (a,b,c)=(0,1,2);
(var a,b,c)=(0,1,2);
```
## multi-assignment
### multi-assignment
```javascript
(a,b[0],c.d)=[0,1,2];
(a,b[1],c.e)=(0,1,2);
```
## conditional expression
### conditional expression
```javascript
if(1)
@@ -349,7 +351,7 @@ else
}
```
## loop
### loop
```javascript
while(condition)
@@ -365,7 +367,7 @@ foreach(var i;elem)
print(i);
```
## subvec
### subvec
Use index to search one element in the string will get the ascii number of this character.If you want to get the character,use built-in function chr().
@@ -374,7 +376,7 @@ a[-1,1,0:2,0:,:3,:,nil:8,3:nil,nil:nil];
"hello world"[0];
```
## special function call
### special function call
This is of great use but is not very efficient(because hashmap use string as the key to compare).
@@ -382,7 +384,7 @@ This is of great use but is not very efficient(because hashmap use string as the
a(x:0,y:1,z:2);
```
## lambda
### lambda
Also functions have this kind of use:
@@ -391,7 +393,7 @@ func(x,y){return x+y}(0,1);
func(x){return 1/(1+math.exp(-x));}(0.5);
```
## closure
### closure
Use closure to OOP.
@@ -419,7 +421,7 @@ var student=func(name,age)
}
```
## built-in functions
### built-in functions
Must import lib.nas or has these functions' definitions inside your code.
@@ -522,11 +524,3 @@ nasal_val* builtin_getkeys(std::vector<nasal_val*>& local_scope,nasal_gc& gc)
return ret_addr;
}
```
# 写在最后
我要怎么才能告诉gitee的逆天管理员gitee上的ValKmjolnir和github的ValKmjolnir是一个人?
他居然告诉我,我从github同步的仓库是他人项目?
我证明我是我自己?:sweat_smile: