Raise KeyboardInterrupt on ^C
This commit is contained in:
parent
3f66b85757
commit
3735b9c16b
2
Makefile
2
Makefile
@ -31,5 +31,5 @@ tags: $(wildcard *.c) $(wildcard *.h)
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@for i in test/*.krk; do echo $$i; ./kuroko $$i > $$i.expect; done
|
@for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 ./kuroko $$i > $$i.expect; done
|
||||||
@git diff test/*.expect
|
@git diff test/*.expect
|
||||||
|
12
kuroko.c
12
kuroko.c
@ -9,6 +9,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#ifdef __toaru__
|
#ifdef __toaru__
|
||||||
#include <toaru/rline.h>
|
#include <toaru/rline.h>
|
||||||
@ -213,6 +214,14 @@ static void tab_complete_func(rline_context_t * c) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void handleSigint(int sigNum) {
|
||||||
|
if (vm.frameCount) {
|
||||||
|
krk_runtimeError(vm.exceptions.keyboardInterrupt, "Keyboard interrupt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
signal(sigNum, handleSigint);
|
||||||
|
}
|
||||||
|
|
||||||
/* Runs the interpreter to get the version information. */
|
/* Runs the interpreter to get the version information. */
|
||||||
static int version(void) {
|
static int version(void) {
|
||||||
krk_initVM(0);
|
krk_initVM(0);
|
||||||
@ -296,6 +305,9 @@ int main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
krk_initVM(flags);
|
krk_initVM(flags);
|
||||||
|
|
||||||
|
/* Bind interrupt signal */
|
||||||
|
signal(SIGINT, handleSigint);
|
||||||
|
|
||||||
#ifdef STATIC_ONLY
|
#ifdef STATIC_ONLY
|
||||||
/* Add any other modules you want to include that are normally built as shared objects. */
|
/* Add any other modules you want to include that are normally built as shared objects. */
|
||||||
STATIC_MODULE(fileio);
|
STATIC_MODULE(fileio);
|
||||||
|
20
test/testKeyboardInterrupt.krk
Normal file
20
test/testKeyboardInterrupt.krk
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
if 'KUROKO_TEST_ENV' in os.environ:
|
||||||
|
print('(This test is skipped by the test suite.)')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print("This while loop should handle a ^C.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
print("Tick.")
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
print("Caught an exception:", exception.__class__.__name__)
|
||||||
|
|
||||||
|
print("This loop will not...")
|
||||||
|
while True:
|
||||||
|
print("Tick.")
|
||||||
|
time.sleep(1)
|
1
test/testKeyboardInterrupt.krk.expect
Normal file
1
test/testKeyboardInterrupt.krk.expect
Normal file
@ -0,0 +1 @@
|
|||||||
|
(This test is skipped by the test suite.)
|
1
vm.c
1
vm.c
@ -2622,6 +2622,7 @@ void krk_initVM(int flags) {
|
|||||||
ADD_EXCEPTION_CLASS(vm.exceptions.importError, "ImportError", vm.exceptions.baseException);
|
ADD_EXCEPTION_CLASS(vm.exceptions.importError, "ImportError", vm.exceptions.baseException);
|
||||||
ADD_EXCEPTION_CLASS(vm.exceptions.ioError, "IOError", vm.exceptions.baseException);
|
ADD_EXCEPTION_CLASS(vm.exceptions.ioError, "IOError", vm.exceptions.baseException);
|
||||||
ADD_EXCEPTION_CLASS(vm.exceptions.valueError, "ValueError", vm.exceptions.baseException);
|
ADD_EXCEPTION_CLASS(vm.exceptions.valueError, "ValueError", vm.exceptions.baseException);
|
||||||
|
ADD_EXCEPTION_CLASS(vm.exceptions.keyboardInterrupt, "KeyboardInterrupt", vm.exceptions.baseException);
|
||||||
|
|
||||||
/* Build classes for basic types */
|
/* Build classes for basic types */
|
||||||
ADD_BASE_CLASS(vm.baseClasses.typeClass, "type", vm.objectClass);
|
ADD_BASE_CLASS(vm.baseClasses.typeClass, "type", vm.objectClass);
|
||||||
|
Loading…
Reference in New Issue
Block a user