Skip to content

Commit

Permalink
feat: make 0 false value
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed May 31, 2023
1 parent 1cc04b1 commit 2befef0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions ena/compiler.lua
Expand Up @@ -350,9 +350,16 @@ function Compiler:collectFunctions(ast)
for i = 1, #ast do
local functionDeclaration = ast[i]
if not self.functions[functionDeclaration.name] then
self.functions[functionDeclaration.name] = {code = {}, params = functionDeclaration.params, defaultArgument = functionDeclaration.defaultArgument}
self.functions[functionDeclaration.name] = {
code = {},
params = functionDeclaration.params,
defaultArgument = functionDeclaration.defaultArgument
}
else
error("Duplicate function name '" .. functionDeclaration.name .. "()'")
error(
(self.translate and translator.err.compileErrDuplicateFunctionName or "Duplicate function name") ..
' "' .. functionDeclaration.name .. '()"'
)
end
end
end
Expand All @@ -364,7 +371,7 @@ function Compiler:compile(ast)
self:codeFunction(ast[i])
end

local entryPoint;
local entryPoint
if self.functions[literals.entryPointName] then
entryPoint = self.functions[literals.entryPointName]
elseif self.functions[literals.entryPointNameGeo] then
Expand Down
6 changes: 3 additions & 3 deletions ena/interpreter.lua
Expand Up @@ -258,22 +258,22 @@ function Interpreter:run(code)
elseif code[pc] == "jumpIfFalse" then
self:traceTwoCodesAndStack(code, pc)
pc = pc + 1
if not self.stack[self.top] then
if self.stack[self.top] == false or self.stack[self.top] == nil or self.stack[self.top] == 0 then
pc = pc + code[pc]
end
self:popStack(1)
elseif code[pc] == "jumpIfFalseJumpNoPop" then
self:traceTwoCodesAndStack(code, pc)
pc = pc + 1
if not self.stack[self.top] then
if self.stack[self.top] == false or self.stack[self.top] == nil or self.stack[self.top] == 0 then
pc = pc + code[pc]
else
self:popStack(1)
end
elseif code[pc] == "jumpIfTrueJumpNoPop" then
self:traceTwoCodesAndStack(code, pc)
pc = pc + 1
if self.stack[self.top] then
if self.stack[self.top] and self.stack[self.top] ~= 0 then
pc = pc + code[pc]
else
self:popStack(1)
Expand Down
2 changes: 1 addition & 1 deletion ena/spec/e2e.lua
Expand Up @@ -376,7 +376,7 @@ function module:testArrays()
function main() {
array = new [2][2] 1;
array[1][1] = 0;
test = 0;
test = 1;
test = test && array[1][2];
test = test && array[2][1];
test = test && array[2][2];
Expand Down

0 comments on commit 2befef0

Please sign in to comment.