diff --git a/client/main.c b/client/main.c index 92894bfb..d2b80f12 100644 --- a/client/main.c +++ b/client/main.c @@ -38,6 +38,7 @@ int debug_compile_and_run(Gst *vm, GstValue ast, GstValue env) { /* Try to compile generated AST */ gst_compiler(&c, vm); gst_compiler_usemodule(&c, "std"); + gst_compiler_usemodule(&c, "std.io"); gst_compiler_globals(&c, env); func = gst_wrap_function(gst_compiler_compile(&c, ast)); /* Check for compilation errors */ diff --git a/core/cache.h b/core/cache.h index b9ca4f9a..2c80210b 100644 --- a/core/cache.h +++ b/core/cache.h @@ -28,6 +28,5 @@ void gst_cache_remove_string(Gst *vm, char *strmem); void gst_cache_remove_tuple(Gst *vm, char *tuplemem); void gst_cache_remove_struct(Gst *vm, char *structmem); -void gst_cache_remove_userdata(Gst *vm, char *usermem); #endif /* end of include guard: CACHE_H_LVYZMBLR */ diff --git a/core/stl.c b/core/stl.c index a3415cb0..79640c99 100644 --- a/core/stl.c +++ b/core/stl.c @@ -601,6 +601,30 @@ int gst_stl_close(Gst *vm) { gst_c_return(vm, gst_wrap_nil()); } +/* Functions in the io module */ +static const GstModuleItem const io_dat[] = { + {"open", gst_stl_open}, + {"slurp", gst_stl_slurp}, + {"read", gst_stl_read}, + {"write", gst_stl_write}, + {NULL, NULL} +}; + +/* Load the io module */ +void gst_stlio_load(Gst *vm) { + /* Load the normal c functions */ + GstValue module = gst_cmodule_table(vm, io_dat); + GstTable *tab = module.data.table; + /* Wrap stdin and stdout */ + FILE **inp = gst_userdata(vm, sizeof(FILE *), &gst_stl_filetype); + FILE **outp = gst_userdata(vm, sizeof(FILE *), &gst_stl_filetype); + *inp = stdin; + *outp = stdout; + gst_table_put(vm, tab, gst_string_cv(vm, "stdin"), gst_wrap_userdata(inp)); + gst_table_put(vm, tab, gst_string_cv(vm, "stdout"), gst_wrap_userdata(outp)); + gst_module_put(vm, "std.io", module); +} + /****/ /* Temporary */ /****/ @@ -674,5 +698,6 @@ static const GstModuleItem const std_module[] = { /* Load all libraries */ void gst_stl_load(Gst *vm) { + gst_stlio_load(vm); gst_module_put(vm, "std", gst_cmodule_struct(vm, std_module)); } diff --git a/libs/parse.gst b/libs/parse.gst new file mode 100644 index 00000000..e6e9478c --- /dev/null +++ b/libs/parse.gst @@ -0,0 +1,8 @@ +# Make parser + +(: parser (fn [in] { + 'in in + 'line 0 + 'index 0 + 'states [] +}))