Add >= and <= operators

master
Joachim Stolberg 2022-08-06 14:36:00 +02:00
parent 8122b2be43
commit 97c66d7e23
3 changed files with 25 additions and 11 deletions

View File

@ -13,7 +13,7 @@
--]]
vm16.Comp = {}
vm16.Comp.version = "1.8"
vm16.Comp.version = "1.09"
local function error_msg(err)
local t = string.split(err, "\001")

View File

@ -573,7 +573,7 @@ condition:
| and_condition '||' condition
]]--
function BPars:condition(lbl_then, lbl_else)
local opnd1 = self:and_condition(lbl_else)
local opnd1 = self:and_condition(lbl_then, lbl_else)
local val = self:tk_peek().val
if val == "or" then
self:tk_match()
@ -595,17 +595,17 @@ and_condition:
| comparison 'and' and_condition
| comparison '&&' and_condition
]]--
function BPars:and_condition(lbl)
local opnd1 = self:comparison()
function BPars:and_condition(lbl_then, lbl_else)
local opnd1 = self:comparison(lbl_then)
local val = self:tk_peek().val
if val == "and" then
self:tk_match()
self:add_instr("jump", lbl)
self:add_instr("jump", lbl_else)
self:and_condition(lbl)
elseif val == "&&" then
self:tk_match()
self:add_instr("jump", lbl)
self:and_condition(lbl)
self:add_instr("jump", lbl_else)
self:and_condition(lbl_then)
end
end
@ -621,7 +621,7 @@ comparison:
| expression '!=' expression
| expression
]]--
function BPars:comparison()
function BPars:comparison(lbl_then)
local val = self:tk_peek().val
if val == "true" then
self:tk_match("true")
@ -648,6 +648,18 @@ function BPars:comparison()
self:tk_match(">")
local right = self:expression()
self:add_instr("skgt", left, right)
elseif val == "<=" then
self:tk_match("<=")
local right = self:expression()
left = self:add_instr("sklt", left, right)
self:add_instr("skne", left, right)
self:add_instr("jump", lbl_then)
elseif val == ">=" then
self:tk_match(">=")
local right = self:expression()
left = self:add_instr("skgt", left, right)
self:add_instr("skne", left, right)
self:add_instr("jump", lbl_then)
elseif val == "==" then
self:tk_match("==")
local right = self:expression()

View File

@ -6,8 +6,6 @@ compiler, assembler and debugger.
It enables simulation of computers in the game Minetest and is capable of
executing real binary code at a remarkable speed.
**The mod is currently under construction. Not all files and documents are always updated !!!**
![screenshot](https://github.com/joe7575/vm16/blob/master/screenshot.png)
Browse on: [GitHub](https://github.com/joe7575/vm16)
@ -23,7 +21,7 @@ This mod consists of several parts:
- C files to be compiled and installed as LuaRocks package (the core VM)
- Lua files as API to the VM (low level interface)
- Programmer and server blocks as development environment to be used to be used
- Programmer and server blocks as development environment to be used
by other Minetest mods (high level interface)
- Some demo blocks showing the usage of programmer and server. These blocks have
to be enabled via `vm16_testblocks_enabled` (see `settingtypes.txt`)
@ -122,6 +120,10 @@ Licensed under the GNU GPLv3 (See LICENSE.txt)
## History
### API v3.5 / Core v2.7.4 / ASM v2.5 / Compiler v1.09 / Debugger v1.3 (2022-08-06)
- Compiler: Add >= and <= operators
### API v3.5 / Core v2.7.4 / ASM v2.5 / Compiler v1.8 / Debugger v1.3 (2022-07-08)
- Compiler: Add constant expressions