mirror of https://github.com/japl-lang/japl.git
The REPL no longer shows the last pop value if an error occurs
This commit is contained in:
parent
b9b5301ad4
commit
408d8cbeaa
|
@ -52,6 +52,7 @@ proc repl(vmObj: Option[VM]) =
|
||||||
var source = ""
|
var source = ""
|
||||||
let lineEditor = getLineEditor()
|
let lineEditor = getLineEditor()
|
||||||
var keep = true
|
var keep = true
|
||||||
|
var result: InterpretResult
|
||||||
lineEditor.bindEvent(jeQuit):
|
lineEditor.bindEvent(jeQuit):
|
||||||
keep = false
|
keep = false
|
||||||
while keep:
|
while keep:
|
||||||
|
@ -64,8 +65,8 @@ proc repl(vmObj: Option[VM]) =
|
||||||
echo "Goodbye!"
|
echo "Goodbye!"
|
||||||
break
|
break
|
||||||
elif source != "":
|
elif source != "":
|
||||||
discard bytecodeVM.interpret(source, "stdin")
|
result = bytecodeVM.interpret(source, "stdin")
|
||||||
if not bytecodeVM.lastPop.isJaplNil():
|
if not bytecodeVM.lastPop.isJaplNil() and result notin {CompileError, RuntimeError}:
|
||||||
echo stringify(bytecodeVM.lastPop)
|
echo stringify(bytecodeVM.lastPop)
|
||||||
bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2])
|
bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2])
|
||||||
bytecodeVM.freeVM()
|
bytecodeVM.freeVM()
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
# Copyright 2020 Mattia Giambirtone
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
## Implements closures
|
|
||||||
|
|
||||||
import baseObject
|
|
||||||
import function
|
|
||||||
import ../memory
|
|
||||||
|
|
||||||
|
|
||||||
type Closure* = object of Obj
|
|
||||||
## Represents a function
|
|
||||||
## closing over values outside
|
|
||||||
## of its lexical scope
|
|
||||||
function*: ptr Function
|
|
||||||
|
|
||||||
|
|
||||||
proc newClosure(function: ptr Function): ptr Closure =
|
|
||||||
## Initializes a new closure from a function
|
|
||||||
## object
|
|
||||||
result = allocateObject(Closure, ObjectType.Closure)
|
|
||||||
result.function = function
|
|
||||||
|
|
||||||
|
|
||||||
proc typeName*(self: ptr Closure): string =
|
|
||||||
result = "function"
|
|
||||||
|
|
||||||
|
|
||||||
proc stringify*(self: ptr Closure): string =
|
|
||||||
if self.function.name != nil:
|
|
||||||
if self.function.name.toStr() == "<lambda function>":
|
|
||||||
result = self.function.name.toStr()
|
|
||||||
else:
|
|
||||||
result = "<function '" & self.function.name.toStr() & "'>"
|
|
||||||
else:
|
|
||||||
result = "<code object>"
|
|
||||||
|
|
||||||
|
|
||||||
proc isFalsey*(self: ptr Closure): bool =
|
|
||||||
result = false
|
|
||||||
|
|
||||||
|
|
||||||
proc hash*(self: ptr Closure): uint64 =
|
|
||||||
result = uint64(393027534) # Arbitrary hash because ¯\_(ツ)_/¯
|
|
||||||
|
|
||||||
|
|
||||||
proc eq*(self, other: ptr Closure): bool =
|
|
||||||
result = self.function == other.function # Pointer equality
|
|
||||||
|
|
||||||
|
|
||||||
proc eq*(self: ptr Closure, other: ptr Function): bool =
|
|
||||||
result = self.function == other
|
|
|
@ -1,17 +1,3 @@
|
||||||
# Copyright 2020 Mattia Giambirtone
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
import baseObject
|
import baseObject
|
||||||
import ../meta/opcode
|
import ../meta/opcode
|
||||||
import japlString
|
import japlString
|
||||||
|
|
|
@ -46,7 +46,7 @@ when DEBUG_TRACE_VM:
|
||||||
type
|
type
|
||||||
KeyboardInterrupt* = object of CatchableError
|
KeyboardInterrupt* = object of CatchableError
|
||||||
## Custom exception to handle Ctrl+C
|
## Custom exception to handle Ctrl+C
|
||||||
InterpretResult = enum
|
InterpretResult* = enum
|
||||||
## All possible interpretation results
|
## All possible interpretation results
|
||||||
Ok,
|
Ok,
|
||||||
CompileError,
|
CompileError,
|
||||||
|
|
Loading…
Reference in New Issue