From 726fa81bf2597aa4b3d14a89915993eaa9d62908 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 6 Jun 2018 07:58:47 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lls/lls.c | 11 ++++-- test/hello.lls | 118 ++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 39 deletions(-) diff --git a/lls/lls.c b/lls/lls.c index 81d54a7..8599cfd 100644 --- a/lls/lls.c +++ b/lls/lls.c @@ -5,10 +5,11 @@ enum { VT_UNKNOWN = 0, VT_NULL, // null | | - VT_NUMBER, // number | float | + VT_REAL, // real | float | VT_STRING, // string | char* | VT_BOOLEAN, // boolean | char | - VT_SET, // set | struct | + VT_SET, // set | void* | + VT_ARRAY, // array | void* | VT_FUNCTION, // function | void* | 内存中同样的函数不会存两份 }; @@ -17,10 +18,12 @@ typedef struct int type; union { - float _number; + float _real; char* _string; char _bool; - void* _struct; + void* _set; + void* _array; + int _func; } value; } lls_Value; diff --git a/test/hello.lls b/test/hello.lls index 8ca0886..c29ff3c 100644 --- a/test/hello.lls +++ b/test/hello.lls @@ -7,12 +7,26 @@ lls鏈韩骞朵笉鎻愪緵闄や簡 鐨勫嚱鏁帮紝鍏ㄩ儴闇瑕佺敤鎴锋墜鍔ㄧ粦瀹氥傚畼鏂规彁渚泂td鍖咃紝鍖呭惈涓浜涘父鐢ㄧ殑鍔熻兘 鏁版嵁绫诲瀷: - real 瀹炴暟 - string 瀛楃涓 - boolean 甯冨皵鍊 - function 鍑芥暟 - set 闆嗗悎 - array 鏁扮粍 + real 瀹炴暟 鍊 + boolean 甯冨皵鍊 鍊 + --------------------------- + string 瀛楃涓 鍦板潃 + set 闆嗗悎 鍦板潃 + array 鏁扮粍 鍦板潃 + --------------------------- + function 鍑芥暟 鍦板潃锛堜粎锛 + +new鍏抽敭瀛椾細鎷疯礉鍐呭瓨锛屽鏋滄病鏈塶ew鍒欎細浣跨敤鍦板潃璧嬪 + +local s = "hello"; +local a = s; +a[0] = '1'; +io.print(s); +// 1ello +local b = new s; +b[0] = '1'; +io.print(s); +// hello 鍖呭惈鍏朵粬鏂囦欢锛屼娇鐢╥nclude鍑芥暟: 鍔犺浇鏂囦欢鏃朵細鍒ゆ柇鏂囦欢鏄惁鍔犺浇杩囷紝鍔犺浇杩囧垯涓嶅姞杞. @@ -20,43 +34,43 @@ lls鏈韩骞朵笉鎻愪緵闄や簡 杩愮畻绗: 鍏崇郴 - == - != - > - < - >= - <= - 閫昏緫 - ! + == + != + > + < + >= + <= + 閫昏緫 + ! && - || - 璧嬪 + || + 璧嬪 = - 绠楁暟 + 绠楁暟 + - * - / - ^ - % + / + % += -= *= - /= - ^= + /= %= - 浣 - & 鎸変綅涓 + 浣 + & 鎸変綅涓 | 鎸変綅鎴 - ~ 鎸変綅闈 - &= + ~ 鎸変綅鍙栧弽 + ^ 鎸変綅寮傛垨 + &= |= - ~= + ~= + ^= >> << >>= <<= - 鍙杝et\array澶у皬 + 鍙杝et\array\string闀垮害 # 鍏抽敭瀛 @@ -133,8 +147,8 @@ Bat = new Monster + { wings = true, } + new Foo; -Bat = new Monster + - new Foo + +Bat = Monster + + Foo + { fly = 20, wings = true, @@ -202,20 +216,54 @@ main() func instanceof(Class, obj) { return obj._class == Class._class -} +} Object = { - _class = "Object", - + _class = {"Object"}, + instanceof = func(self, Class) + { + return array.contain(self._class, Class._class); + //return string.contain(self._class, Class._class); + //return self._class == Class._class; + } }; -Box = new Object + +Box = Object + { - _class += "|Box", + _class = {"Box"}, }; +box = new Box; +if(box:instanceof(Object)) +{ + +} + +// 涓轰簡瑙e喅閲嶅鎷疯礉鍑芥暟鐨勯棶棰,閲囩敤涓涓猻et灏佽杩欎簺鍑芥暟 +// set\array鍙橀噺璧嬪肩殑鏃跺欎笉浼氭嫹璐濓紝鑰屾槸寮曠敤鍚屼竴涓湴鍧 +Bird = { + _method = { + fly = func(self) + { + // .... + } + } +} + +bird = new Bird; + +bird._method.fly(bird); +// 鑰冭檻寮曞叆unique鍏抽敭瀛楋紝澹版槑鍙橀噺鐨勬椂鍊欙紝涓嶄細鎷疯礉鍓湰锛岃屾槸鎷疯礉鍦板潃 +Bird = { + unique fly = func(self){ + // .... + } +} +bird = new Bird; +bird:fly(); +// 鎴栬呴檺鍒跺嚱鏁板彧鑳芥嫹璐濆湴鍧 -- cgit v1.1-26-g67d0