From 11e36ba29f591c30d7126deb6e4f3010e0d02ee9 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Thu, 6 Feb 2020 19:06:27 +0800 Subject: [PATCH] update --- version2.0/lib/bits.nas | 14 +++++++ version2.0/lib/io.nas | 14 ++++++- version2.0/lib/math.nas | 78 +++---------------------------------- version2.0/lib/readline.nas | 12 ++++++ version2.0/lib/regex.nas | 12 ++++++ version2.0/lib/sqlite.nas | 15 +++++++ version2.0/lib/thread.nas | 20 +++++++--- version2.0/lib/unix.nas | 22 +++++++++++ version2.0/lib/utf8.nas | 15 +++++++ version2.0/nasal_lexer.h | 5 ++- 10 files changed, 127 insertions(+), 80 deletions(-) create mode 100644 version2.0/lib/bits.nas create mode 100644 version2.0/lib/readline.nas create mode 100644 version2.0/lib/regex.nas create mode 100644 version2.0/lib/sqlite.nas create mode 100644 version2.0/lib/unix.nas create mode 100644 version2.0/lib/utf8.nas diff --git a/version2.0/lib/bits.nas b/version2.0/lib/bits.nas new file mode 100644 index 0000000..7df07b8 --- /dev/null +++ b/version2.0/lib/bits.nas @@ -0,0 +1,14 @@ +# nasal lib bits.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +var bits= +{ + fld:func(){}, + sfld:func(){}, + setfld:func(){}, + buf:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/io.nas b/version2.0/lib/io.nas index f4678d1..7d7d151 100644 --- a/version2.0/lib/io.nas +++ b/version2.0/lib/io.nas @@ -1,10 +1,22 @@ # nasal lib io.nas -# 2020/2/4 +# 2020/2/6 # this file is used to avoid name confliction # and is used to avoid name undefined # before running this file will be translated to abstract syntax tree # and this ast will be linked before main ast as main-ast's beginning +var io= +{ + open:func(){}, + close:func(){}, + read:func(){}, + write:func(){}, + seek:func(){}, + tell:func(){}, + readln:func(){}, + stat:func(){}, +}; + var input=func(filename="") { if(filename=="") diff --git a/version2.0/lib/math.nas b/version2.0/lib/math.nas index 1480f2e..e3b7e9f 100644 --- a/version2.0/lib/math.nas +++ b/version2.0/lib/math.nas @@ -1,5 +1,5 @@ # nasal lib math.nas -# 2020/2/4 +# 2020/2/6 # this file is used to avoid name confliction # and is used to avoid name undefined # before running this file will be translated to abstract syntax tree @@ -24,74 +24,8 @@ var math= { var call_inline_pow=func(num,x){}; return call_inline_pow(me.e,x); - } -}; -var __e=2.7182818284590452354; -var __pi=3.14159265358979323846; -var __ln_2=0.69314718055994530942; -var __ln_10=2.30258509299404568402; - -var abs=func(number) -{ - if(number>0) - return number; - else - return -1*number; -} - -var sin=func(number) -{ - return number; -} - -var cos=func(number) -{ - return number; -} - -var tan=func(number) -{ - return sin(number)/cos(number); -} - -var cot=func(number) -{ - return cos(number)/sin(number); -} - -var exp=func(number) -{ - var int_num=int(number); - var f_num=number-int_num; - var __res_exp=exp(int_num); - var pw=1; - for(var i=1;i<6;i+=1) - { - __res_exp+=pw/i; - pw*=f_num; - } - return __res_exp; -} - -var ln=func(number) -{ - return number; -} - -var sqrt=func(number) -{ - var temp = number/8 + 0.5 + 2*number/(4+number); - var cnt = 10; - while(cnt!=0) - { - cnt-=1; - temp = (temp+number/temp)/2; - } - return temp; -} - -var atan2=func(x,y) -{ - return y/x; -} - + }, + ln:func(){}, + sqrt:func(){}, + atan2:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/readline.nas b/version2.0/lib/readline.nas new file mode 100644 index 0000000..875d086 --- /dev/null +++ b/version2.0/lib/readline.nas @@ -0,0 +1,12 @@ +# nasal lib readline.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +# GNU Readline Library +var readline=func(prompt="> ") +{ + return; +} \ No newline at end of file diff --git a/version2.0/lib/regex.nas b/version2.0/lib/regex.nas new file mode 100644 index 0000000..f7642fd --- /dev/null +++ b/version2.0/lib/regex.nas @@ -0,0 +1,12 @@ +# nasal lib regex.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +var regex= +{ + comp:func(){}, + exec:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/sqlite.nas b/version2.0/lib/sqlite.nas new file mode 100644 index 0000000..838e612 --- /dev/null +++ b/version2.0/lib/sqlite.nas @@ -0,0 +1,15 @@ +# nasal lib sqlite.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +var sqlite= +{ + open:func(){}, + close:func(){}, + prepare:func(){}, + exec:func(){}, + finalize:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/thread.nas b/version2.0/lib/thread.nas index 596fb8e..1cb52f9 100644 --- a/version2.0/lib/thread.nas +++ b/version2.0/lib/thread.nas @@ -1,7 +1,17 @@ -#nasal-strict-lib thread +# nasal lib thread.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning -var thread=func(__function) +var thread= { - __system_call_cpp_new_thread(__function); - return 0; -} \ No newline at end of file + newthread:func(){}, + newlock:func(){}, + lock:func(){}, + unlock:func(){}, + newsem:func(){}, + semdown:func(){}, + semup:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/unix.nas b/version2.0/lib/unix.nas new file mode 100644 index 0000000..6237a2c --- /dev/null +++ b/version2.0/lib/unix.nas @@ -0,0 +1,22 @@ +# nasal lib unix.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +var unix= +{ + pipe:func(){}, + fork:func(){}, + dup2:func(){}, + exec:func(){}, + waitpid:func(){}, + opendir:func(){}, + readdir:func(){}, + closedir:func(){}, + time:func(){}, + chdir:func(){}, + environ:func(){}, + sleep:func(){}, +}; \ No newline at end of file diff --git a/version2.0/lib/utf8.nas b/version2.0/lib/utf8.nas new file mode 100644 index 0000000..1bd2e82 --- /dev/null +++ b/version2.0/lib/utf8.nas @@ -0,0 +1,15 @@ +# nasal lib utf8.nas +# 2020/2/6 +# this file is used to avoid name confliction +# and is used to avoid name undefined +# before running this file will be translated to abstract syntax tree +# and this ast will be linked before main ast as main-ast's beginning + +var utf8= +{ + chstr:func(){}, + strc:func(){}, + substr:func(){}, + size:func(){}, + validate:func(){}, +}; \ No newline at end of file diff --git a/version2.0/nasal_lexer.h b/version2.0/nasal_lexer.h index 0a4944e..e1b298b 100644 --- a/version2.0/nasal_lexer.h +++ b/version2.0/nasal_lexer.h @@ -32,13 +32,14 @@ others: __unknown_operator */ -const std::string lib_filename[9]= +const std::string lib_filename[10]= { "lib/base.nas", "lib/bits.nas", "lib/io.nas", "lib/math.nas", "lib/readline.nas", + "lib/regex.nas", "lib/sqlite.nas", "lib/thread.nas", "lib/unix.nas", @@ -112,7 +113,7 @@ class resource_file void load_lib_file() { resource.clear(); - for(int i=0;i<9;++i) + for(int i=0;i<10;++i) { std::ifstream fin(lib_filename[i],std::ios::binary); if(fin.fail())