Browse Source

Sol Part 39: Now with 100% more arrows!

master
Graham Northup 6 years ago
parent
commit
cd32a6ff54
  1. 3
      Makefile
  2. 31
      builtins.c
  3. 8
      interp.sol
  4. 7
      sol.h
  5. 6
      state.c

3
Makefile

@ -1,9 +1,10 @@
CFLAGS= -g
LDFLAGS= -lm -ldl -lreadline
OBJ= lex.yy.o parser.tab.o dsl/seq.o dsl/list.o dsl/array.o dsl/generic.o astprint.o runtime.o gc.o object.o state.o builtins.o solrun.o
all: $(OBJ)
git submodule init && git submodule sync && git submodule update
gcc $(CFLAGS) $? -o sol -lm -ldl
gcc $(CFLAGS) $? $(LDFLAGS) -o sol
%.o: %.c
gcc -c -o $@ $? $(CFLAGS)

31
builtins.c

@ -4,6 +4,8 @@
#include <math.h>
#include <stdint.h>
#include <dlfcn.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "ast.h"
#include "dsl/dsl.h"
@ -458,6 +460,35 @@ sol_object_t *sol_f_debug_scopes(sol_state_t *state, sol_object_t *args) {
return sol_incref(state->scopes);
}
sol_object_t *sol_f_readline_readline(sol_state_t *state, sol_object_t *args) {
sol_object_t *obj, *objstr, *res;
char *line;
if(sol_list_len(state, args) > 0) {
obj = sol_list_get_index(state, args, 0);
objstr = sol_cast_string(state, obj);
line = readline(objstr->str);
sol_obj_free(obj);
sol_obj_free(objstr);
} else {
line = readline("");
}
if(line) {
res = sol_new_string(state, line);
free(line);
} else {
res = sol_new_string(state, "");
}
return res;
}
sol_object_t *sol_f_readline_add_history(sol_state_t *state, sol_object_t *args) {
sol_object_t *line = sol_list_get_index(state, args, 0), *linestr = sol_cast_string(state, line);
add_history(linestr->str);
sol_obj_free(linestr);
sol_obj_free(line);
return sol_incref(state->None);
}
void _sol_freef_seq_iter(void *iter, size_t sz) {
dsl_free_seq_iter((dsl_seq_iter *) iter);
}

8
interp.sol

@ -19,12 +19,12 @@ quit = exit
while __interp.running do
if #__interp.buffer then
io.stdout << __interp.ps2
__interp.prompt = __interp.ps2
else
io.stdout << __interp.ps1
__interp.prompt = __interp.ps1
end
__interp.line = io.stdin:read(io.LINE)
__interp.line = __interp.line:sub(0, -1)
__interp.line = readline.readline(__interp.prompt)
if #__interp.line then readline.add_history(__interp.line) end
--prepr(__interp.line)
--prepr(__interp)
if (__interp.line:sub(-4, None)=="then") then

7
sol.h

@ -9,8 +9,8 @@
#include <stdarg.h>
#include "dsl/dsl.h"
#define VERSION "0.1a4"
#define HEXVER 0x0001A04
#define VERSION "0.1a5"
#define HEXVER 0x0001A05
#ifndef SOL_ICACHE_MIN
#define SOL_ICACHE_MIN -128
@ -282,6 +282,9 @@ sol_object_t *sol_f_iter_str(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_iter_list(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_iter_map(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_readline_readline(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_readline_add_history(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_ast_print(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_singlet_tostring(sol_state_t *, sol_object_t *);

6
state.c

@ -251,6 +251,12 @@ int sol_state_init(sol_state_t *state) {
sol_register_module_name(state, "iter", mod);
sol_obj_free(mod);
mod = sol_new_map(state);
sol_map_borrow_name(state, mod, "readline", sol_new_cfunc(state, sol_f_readline_readline));
sol_map_borrow_name(state, mod, "add_history", sol_new_cfunc(state, sol_f_readline_add_history));
sol_register_module_name(state, "readline", mod);
sol_obj_free(mod);
mod = sol_new_map(state);
sol_map_borrow_name(state, mod, "ST_EXPR", sol_new_int(state, ST_EXPR));
sol_map_borrow_name(state, mod, "ST_IFELSE", sol_new_int(state, ST_IFELSE));

Loading…
Cancel
Save