Open duangsuse opened 6 years ago
我们来整理一下,顺便彻底解释所有指令语义和 stack-based 化指令(只使用堆栈传参)
LV 拥有 call-stack
(带有 ret_addr
和 lazy 的 locals HashMap
、catch ArrayMap
)、stack
(LinkedList
LV 是 基于堆栈 的虚拟机,LV 只有全局表要求线程安全
LV 支持自己的 exception
系统
LV 支持 block
,会在创建 block
时自动打包 block
的所有符号本地变量引用
LV 使用可扩展的 指令系统,支持指令插件
LV 支持的字面量有 boolean/null/number ( byte, short, int, long, float, double, BigInteger, BigDecimal )/char/string/symbol/range
LV 支持 注释 和 动态链接(允许在需要的时候创建新数组来容纳更多指令并注册函数符号表)、调试信息 (file name, line number)
LV 暂时使用 代码文本表示
LV 支持 循环和分支逻辑、子过程调用、赋值运算
;
到行末尾是注释,除非是在字符串出现这个
true
是真 false
是假
null
是空
支持 0x 0b 0o
数字(Hex 数位字符只支持小写),自动删除下划线,类型依次以 B S I L F D N P
结尾,默认类型为 I
'c'
单字符的 single-quoted string 为 char
"str" 'str'
非单字符的为 string
,其中 ""
会处理 escape \b\t\n\r\"\\
ssss
是 symbol
0..9
是 range
,不过这不是在词法扫描的时候创建的...
\t\f\r\13\v\u000C
是空格
\n
是换行符
单纯的汇编指令式,一行为一条指令,可能是 symbol
或 Object
,如果是 Object
,向堆栈上压入这个对象,如果是 symbol
则尝试执行 OpCode
啥都不做
向堆栈上压入一个对象
向堆栈上压入 null
向堆栈上压入 true
向堆栈上压入 false
向堆栈上压入当前 LV 虚拟机引用
弹出栈顶的值,转换为 Integer,创建指定大小的新的 Array
弹出栈顶的两个值,转换为 Integer,创建 range v2..v1
对象并压入堆栈
弹出栈顶的三个值,转换为 Integer,创建 range v3..v2
(step v1) 对象并压入堆栈
弹出栈顶的值,检查其是否是 String 的实例,如果不是,抛出内部错误,否则创建新 Symbol 对象并压入堆栈
弹出栈顶的值,检查其是否是 Range 的实例,如果不是,抛出内部错误,否则创建新 Block 对象并压入堆栈
new
send
初始化当前调用栈帧的本地表
将当前调用栈帧的本地表引用置为 null
弹出一个 String 参数 v0,将本地变量或 null
入栈
弹出一个 String 参数 v0,弹出一个参数 v1,设置本地变量 v0 = v1
get
put
弹出一个 String 参数 v0,在下一个 IP 处添加函数符号 v0
弹出一个 String 参数 funame,然后调用指定函数,如果没有找到,则设置 expect_fun
弹出调用栈帧并重置 pc
到 ret_addr
弹出一个 Block,调用它
duangsues.is_a? SaltedFish, [05.07.18 22:39] 指令列表:
nop 啥都不做
push [object] 往栈上放置一个对象
pushnull 放置 null
pushtrue 放置 true
pushfalse 放置 false
pushlv 往栈上放置虚拟机引用
scope 进入作用域
leave 离开作用域
sget 读取本地变量
sput 设置本地变量
fun [sym] 定义函数符号
call [sym] 调用函数
ret 返回
jump [ip] 跳转到 ip 处执行
branchif [ip] if
branchunless [ip] unless
get 读取全局变量
put 设置全局变量
newary [n] 创建 n 维度的数组
index []
newindex []=
file [fname] 在文件中
line [line] 在行中
send 调用对象方法和类方法
new 创建对象
block [range] 创建块对象,它打包所有引用到的本地变量的绑定
yield 调用块对象
or
in?
and
op<
op>
op<=
op>=
noteq
eq
fulleq
shl
newrange
add
sub
mul
div
mod
pwr
cast
not
inc
dec
len
duangsues.is_a? SaltedFish, [05.07.18 22:41] [In reply to duangsues.is_a? SaltedFish]
throw
catch
top
topn
swap
pop
dup
dupn
tostring
duangsues.is_a? SaltedFish, [05.07.18 22:39] 指令列表:
nop 啥都不做
push [object] 往栈上放置一个对象
pushnull 放置 null
pushtrue 放置 true
pushfalse 放置 false
pushlv 往栈上放置虚拟机引用
scope 进入作用域
leave 离开作用域
sget 读取本地变量
sput 设置本地变量
fun [sym] 定义函数符号
call [sym] 调用函数
ret 返回
jump [ip] 跳转到 ip 处执行
branchif [ip] if
branchunless [ip] unless
get 读取全局变量
put 设置全局变量
newary [n] 创建 n 维度的数组
index []
newindex []=
file [fname] 在文件中
line [line] 在行中
send 调用对象方法和类方法
new 创建对象
block [range] 创建块对象,它打包所有引用到的本地变量的绑定
yield 调用块对象
or
in?
and
op<
op>
op<=
op>=
noteq
eq
fulleq
shl
newrange
add
sub
mul
div
mod
pwr
cast
not
inc
dec
len
duangsues.is_a? SaltedFish, [05.07.18 22:41] [In reply to duangsues.is_a? SaltedFish]
throw
catch
top
topn
swap
pop
dup
dupn
tostring
+
and-
operatorsscope
statementblock
andnesting lexical scoping