diff options
author | chai <chaifix@163.com> | 2018-06-03 09:51:47 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-06-03 09:51:47 +0800 |
commit | 24cce4c24a155b726dc3b2c120defef6a94638fa (patch) | |
tree | f758703a407c2dbd0c34a59aa336849285d175ca | |
parent | 6a4f1a224273118a5429094ddd83420b7d69b28d (diff) |
更新示例
-rw-r--r-- | lls/lls.c | 5 | ||||
-rw-r--r-- | lls/lls.h | 14 | ||||
-rw-r--r-- | llsc.c | 2 | ||||
-rw-r--r-- | test/hello.lls | 147 |
4 files changed, 136 insertions, 32 deletions
@@ -37,8 +37,7 @@ typedef struct void* operant; } lls_Ins; - -int lls_bindfunction(lls_Context* C, const char* fname, lls_Func func) +int lls_bindfunction(lls_Env* env, const char* fname, lls_Func func) { -} +}
\ No newline at end of file @@ -13,17 +13,15 @@ typedef struct { int top; lls_FuncMap* funcMap; -} lls_Context; +} lls_Env; -lls_Context* lls_newcontext(); +lls_Env* lls_newenv(); -int lls_bindfunction(lls_Context* C, const char* fname, lls_Func func); -int lls_bindvariable(lls_Context* C, const char* vname, void* variable); +int lls_bindfunction(lls_Env* env, const char* fname, lls_Func func); +int lls_bindvariable(lls_Env* env, 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); - - +int lls_executefile(lls_Env* env, const char* file); +int lls_executesource(lls_Env* env, const void* buffer, int size); #endif
\ No newline at end of file @@ -1,3 +1 @@ // llsԴΪbytecode - - diff --git a/test/hello.lls b/test/hello.lls index 05c8183..8ca0886 100644 --- a/test/hello.lls +++ b/test/hello.lls @@ -1,12 +1,83 @@ -// global -// -// -// - /* +基于栈的虚拟机 +lls本身并不提供除了 + * include(<filepath>) + * typeof(<variable>) + +的函数,全部需要用户手动绑定。官方提供std包,包含一些常用的功能 + +数据类型: + real 实数 + string 字符串 + boolean 布尔值 + function 函数 + set 集合 + array 数组 + +包含其他文件,使用include函数: +加载文件时会判断文件是否加载过,加载过则不加载. + local something = include("another.lls") + +运算符: + 关系 + == + != + > + < + >= + <= + 逻辑 + ! + && + || + 赋值 + = + 算数 + + + - + * + / + ^ + % + += + -= + *= + /= + ^= + %= + 位 + & 按位与 + | 按位或 + ~ 按位非 + &= + |= + ~= + >> + << + >>= + <<= + 取set\array大小 + # + 关键字 -null -true false + null + true false + local global + new + +数字表示方式 +可以加任意个_方便阅读 + 十进制 [1~9][0~9]...[0~9] 12306 + 二进制 0 0_00_00_00_00 + 十六进制 0x 0xFA + +原生字符串 + local rawString = "" + this is a + raw + string test + ""; + */ /* 可以成为语句: @@ -15,19 +86,19 @@ true false 不可成为语句: <variable>; */ -// 声明一个变量时必须赋值,如 -foo = null; +local too; +local foo = null; -a = 10; +local a = 10; global b = 12; /* 类(首字母大写的set)*/ -Monster = { +global Monster = { health = 100, strength = 0.4, speed = 20, - - attack = func(self, other) + name = null, + attack = func(self, other) { other.health -= self.strength; }, @@ -47,6 +118,12 @@ Bat = new Monster; Bat += { fly = 20, wings = true, + create = func(_name, _speed, _wings) + { + local a = new Bat; + a:init(_name, _speed, _wings); + return a; + } }; /* @@ -61,9 +138,9 @@ Bat = new Monster + { fly = 20, wings = true, - init = func() + init = func(self, _name, _speed, _wings) { - + //... } }; */ @@ -73,6 +150,16 @@ bat = new Bat; // 语法糖,把调用者作为第一个参数压入栈 bat:init(1, 2, 3); +func newBat(_name, _speed, _wings) +{ + local a = new Bat; + a:init(_name, _speed, _wings); + return a; +} + +local bat1 = newBat(1, 2, 3); +local bat2 = Bat.create(1, 2, 3); + func test() { a = 13; @@ -98,15 +185,37 @@ func test() /* 如果第一个数据没有key,则set成为array */ /* array从0开始索引 */ arr = {1, 2, 2, 3, 5, 2}; + /* set 和 array 不可以用+拼接 */ /* 字符串拼接 */ - str = "hello " + "world"; + str = "hello " + "world"; f = {}; - } func main() { - + local image = gl.createTexture(); + global canvas = gl.createCanvas(); +} + +main() + +func instanceof(Class, obj) +{ + return obj._class == Class._class } -main()
\ No newline at end of file +Object = +{ + _class = "Object", + +}; + +Box = new Object + +{ + _class += "|Box", + +}; + + + + |