From a558be5f3d72775bd06c3814e002d355402a7acd Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 31 May 2018 23:23:28 +0800 Subject: *init --- lls/lls.c | 30 ++++++++++++++++ lls/lls.h | 22 ++++++++++++ llsVM.c | 0 llsc.c | 3 ++ test/hello.lls | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 lls/lls.c create mode 100644 lls/lls.h create mode 100644 llsVM.c create mode 100644 llsc.c create mode 100644 test/hello.lls diff --git a/lls/lls.c b/lls/lls.c new file mode 100644 index 0000000..e8f26ea --- /dev/null +++ b/lls/lls.c @@ -0,0 +1,30 @@ +#include "lls.h" + +/* value type */ +enum +{ + VT_UNKNOWN = 0, + VT_NULL, // null | | + VT_NUMBER, // number | float | + VT_STRING, // string | char* | + VT_BOOLEAN, // boolean | char | + VT_SET, // set | struct | + VT_FUNCTION, // function | void* | 内存中同样的函数不会存两份 +}; + +typedef struct +{ + int type; + union + { + float _number; + char* _string; + char _bool; + void* _struct; + } value; +} lls_Value; + +enum +{ + +}; diff --git a/lls/lls.h b/lls/lls.h new file mode 100644 index 0000000..5f190a2 --- /dev/null +++ b/lls/lls.h @@ -0,0 +1,22 @@ +#ifndef __LLS_H +#define __LLS_H + +typedef struct +{ + int top; +} lls_Context; + +lls_Context* lls_newcontext(); + +typedef int (*lls_Function)(); + +int lls_bindfunction(lls_Context* C, const char* fname, lls_Function func); +int lls_bindvariable(lls_Context* C, const char* vname, void* variable); +int lls_bindset(); + +int lls_executefile(lls_Context* C, const char* file); +int lls_executesource(lls_Context* C, const void* buffer, int size); + + + +#endif \ No newline at end of file diff --git a/llsVM.c b/llsVM.c new file mode 100644 index 0000000..e69de29 diff --git a/llsc.c b/llsc.c new file mode 100644 index 0000000..6347da9 --- /dev/null +++ b/llsc.c @@ -0,0 +1,3 @@ +// 将lls源代码编译为bytecode + + diff --git a/test/hello.lls b/test/hello.lls new file mode 100644 index 0000000..86e6a6b --- /dev/null +++ b/test/hello.lls @@ -0,0 +1,110 @@ +// global +// +// +// + +/* +鍏抽敭瀛 +null +true false +*/ +/* +鍙互鎴愪负璇彞: + 璧嬪笺 + +涓嶅彲鎴愪负璇彞锛 + ; +*/ +// 澹版槑涓涓彉閲忔椂蹇呴』璧嬪硷紝濡 +foo = null; + +a = 10; +global b = 12; + +/* 绫伙紙棣栧瓧姣嶅ぇ鍐欑殑set锛*/ +Monster = { + health = 100, + strength = 0.4, + speed = 20, + + attack = func(self, other) + { + other.health -= self.strength; + }, + ['escape'] = func(self) + { + speed -= 10; + }, + ["init"] = func(self, _health, _speed, _strength) + { + self.speed = _speed; + self.health = _health; + }, +}; + +/* 缁ф壙 */ +Bat = new Monster; +Bat += { + fly = 20, + wings = true, +}; + +/* +鎴栬呬笅闈㈣繖鏍凤紝鍙互瀹炵幇澶氶噸缁ф壙 +Bat = new Monster + { + fly = 20, + wings = true, +} + new Foo; + +Bat = new Monster + + new Foo + +{ + fly = 20, + wings = true, + init = func() + { + + } +}; +*/ + +bat = new Bat; + +// 璇硶绯栵紝鎶婅皟鐢ㄨ呬綔涓虹涓涓弬鏁板帇鍏ユ爤 +bat:init(1, 2, 3); + +func test() +{ + a = 13; + c = { + c_1 = 12, + c_2 = 13, + c_3 = func() { + + }, + ['c_4'] = func(obj){ + obj.c_1 = 12 + }, + ["c_5"] = func(msg){ + print(msg) + } + }; + d = new c; + e = c; + d["c_4"] = "d_c_4"; + d["c_5"]("function test"); + d.c_5("function test"); + /* 鏁扮粍锛岄粯璁ゆ棤key鐨剆et */ + /* 濡傛灉绗竴涓暟鎹病鏈塳ey锛屽垯set鎴愪负array */ + /* array浠0寮濮嬬储寮 */ + arr = {1, 2, 2, 3, 5, 2}; + /* 瀛楃涓叉嫾鎺 */ + str = "hello " + "world"; +} + +func main() +{ + +} + +main() \ No newline at end of file -- cgit v1.1-26-g67d0