add scratch
This commit is contained in:
parent
13eb47046e
commit
6b9a7788e1
|
@ -0,0 +1,19 @@
|
||||||
|
# readline
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/contrib/10.readline/cmake/")
|
||||||
|
|
||||||
|
find_package(Libedit)
|
||||||
|
|
||||||
|
find_package(Libedit)
|
||||||
|
if (Libedit_FOUND)
|
||||||
|
add_definitions(${Libedit_DEFINITIONS} -DPIC_READLINE_FOUND=1)
|
||||||
|
include_directories(${Libedit_INCLUDE_DIR})
|
||||||
|
|
||||||
|
file(GLOB PICRIN_READLINE_SOURCES ${PROJECT_SOURCE_DIR}/contrib/10.readline/src/*.c)
|
||||||
|
|
||||||
|
list(APPEND PICRIN_CONTRIB_INITS readline)
|
||||||
|
list(APPEND PICRIN_CONTRIB_LIBRARIES ${Libedit_LIBRARIES})
|
||||||
|
list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_READLINE_SOURCES})
|
||||||
|
# add_custom_target(test-readline for test in ${PROJECT_SOURCE_DIR}/contrib/10.regexp/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
|
||||||
|
# set(CONTRIB_TESTS ${CONTRIB_TESTS} test-readline)
|
||||||
|
endif()
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
cc -g test.c -o test -ledit -ltermcap
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This will include all our libedit functions. If you use C++ don't
|
||||||
|
forget to use the C++ extern "C" to get it to compile.
|
||||||
|
*/
|
||||||
|
#include <editline/readline.h>
|
||||||
|
#include <editline/history.h>
|
||||||
|
#include <histedit.h>
|
||||||
|
#include "picrin.h"
|
||||||
|
#include "picrin/string.h"
|
||||||
|
#include "picrin/port.h"
|
||||||
|
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_rl_readline(pic_state *pic)
|
||||||
|
{
|
||||||
|
char *prompt, *result;
|
||||||
|
|
||||||
|
pic_get_args(pic, "z", &prompt);
|
||||||
|
|
||||||
|
result = readline(prompt);
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return pic_obj_value(pic_str_new_cstr(pic, result));
|
||||||
|
else
|
||||||
|
return pic_eof_object();
|
||||||
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_rl_add_history(pic_state *pic)
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
pic_get_args(pic, "z", &line);
|
||||||
|
|
||||||
|
add_history(line);
|
||||||
|
|
||||||
|
return pic_undef_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_rl_clear_history(pic_state *pic)
|
||||||
|
{
|
||||||
|
pic_get_args(pic, "");
|
||||||
|
|
||||||
|
clear_history();
|
||||||
|
|
||||||
|
return pic_undef_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_rl_remove_history(pic_state *pic)
|
||||||
|
{
|
||||||
|
int line;
|
||||||
|
|
||||||
|
pic_get_args(pic, "i", &line);
|
||||||
|
|
||||||
|
remove_history(line);
|
||||||
|
|
||||||
|
return pic_undef_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pic_init_readline(pic_state *pic){
|
||||||
|
using_history();
|
||||||
|
pic_deflibrary (pic, "(picrin readline)") {
|
||||||
|
pic_defun(pic, "readline", pic_rl_readline);
|
||||||
|
pic_defun(pic, "add-history", pic_rl_add_history);
|
||||||
|
pic_defun(pic, "clear-history", pic_rl_clear_history);
|
||||||
|
pic_defun(pic, "remove-history", pic_rl_remove_history);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
(import (scheme base)
|
||||||
|
(scheme read)
|
||||||
|
(scheme eval)
|
||||||
|
(scheme write)
|
||||||
|
(picrin readline))
|
||||||
|
|
||||||
|
(let loop ((n 1))
|
||||||
|
(let ((input (readline "> ")))
|
||||||
|
(if (eof-object? input)
|
||||||
|
(newline)
|
||||||
|
(begin
|
||||||
|
(add-history input)
|
||||||
|
(write (eval (read (open-input-string input)) '(picrin user)))
|
||||||
|
(newline)
|
||||||
|
(loop 1)))))
|
|
@ -1,12 +1,5 @@
|
||||||
list(APPEND REPL_LIBRARIES picrin)
|
list(APPEND REPL_LIBRARIES picrin)
|
||||||
|
|
||||||
find_package(Libedit)
|
|
||||||
if (Libedit_FOUND)
|
|
||||||
include_directories(${Libedit_INCLUDE_DIRS})
|
|
||||||
add_definitions(${Libedit_DEFINITIONS} -DPIC_READLINE_FOUND=1)
|
|
||||||
list(APPEND REPL_LIBRARIES ${Libedit_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# build
|
# build
|
||||||
add_executable(repl tools/main.c)
|
add_executable(repl tools/main.c)
|
||||||
set_target_properties(repl PROPERTIES OUTPUT_NAME picrin)
|
set_target_properties(repl PROPERTIES OUTPUT_NAME picrin)
|
||||||
|
|
Loading…
Reference in New Issue