|
@@ -157,6 +157,7 @@ int sol_state_init(sol_state_t *state) {
|
157
|
157
|
state->CFuncOps.tname = "cfunction";
|
158
|
158
|
state->CFuncOps.call = sol_f_cfunc_call;
|
159
|
159
|
state->CFuncOps.tostring = sol_f_cfunc_tostring;
|
|
160
|
+ state->CFuncOps.free = sol_f_cfunc_free;
|
160
|
161
|
|
161
|
162
|
state->ASTNodeOps.tname = "astnode";
|
162
|
163
|
state->ASTNodeOps.call = sol_f_astnode_call;
|
|
@@ -233,35 +234,37 @@ int sol_state_init(sol_state_t *state) {
|
233
|
234
|
|
234
|
235
|
// NB: None is actually a keyword in the language--it doesn't need to be a
|
235
|
236
|
// global (see parser.y)
|
236
|
|
- sol_map_borrow_name(state, globals, "OutOfMemory", state->OutOfMemory);
|
237
|
|
- sol_map_borrow_name(state, globals, "toint", sol_new_cfunc(state, sol_f_toint));
|
238
|
|
- sol_map_borrow_name(state, globals, "tofloat", sol_new_cfunc(state, sol_f_tofloat));
|
239
|
|
- sol_map_borrow_name(state, globals, "tostring", sol_new_cfunc(state, sol_f_tostring));
|
240
|
|
- sol_map_borrow_name(state, globals, "try", sol_new_cfunc(state, sol_f_try));
|
241
|
|
- sol_map_borrow_name(state, globals, "apply", sol_new_cfunc(state, sol_f_apply));
|
242
|
|
- sol_map_borrow_name(state, globals, "error", sol_new_cfunc(state, sol_f_error));
|
243
|
|
- sol_map_borrow_name(state, globals, "type", sol_new_cfunc(state, sol_f_type));
|
244
|
|
- sol_map_borrow_name(state, globals, "prepr", sol_new_cfunc(state, sol_f_prepr));
|
245
|
|
- sol_map_borrow_name(state, globals, "print", sol_new_cfunc(state, sol_f_print));
|
246
|
|
- sol_map_borrow_name(state, globals, "rawget", sol_new_cfunc(state, sol_f_rawget));
|
247
|
|
- sol_map_borrow_name(state, globals, "rawset", sol_new_cfunc(state, sol_f_rawset));
|
248
|
|
- sol_map_borrow_name(state, globals, "range", sol_new_cfunc(state, sol_f_range));
|
249
|
|
- sol_map_borrow_name(state, globals, "exec", sol_new_cfunc(state, sol_f_exec));
|
250
|
|
- sol_map_borrow_name(state, globals, "eval", sol_new_cfunc(state, sol_f_eval));
|
251
|
|
- sol_map_borrow_name(state, globals, "execfile", sol_new_cfunc(state, sol_f_execfile));
|
252
|
|
- sol_map_borrow_name(state, globals, "parse", sol_new_cfunc(state, sol_f_parse));
|
253
|
|
- sol_map_borrow_name(state, globals, "ord", sol_new_cfunc(state, sol_f_ord));
|
254
|
|
- sol_map_borrow_name(state, globals, "chr", sol_new_cfunc(state, sol_f_chr));
|
|
237
|
+ // OutOfMemory (and other important singlets) are set, not borrowed,
|
|
238
|
+ // because the state still holds a reference to them
|
|
239
|
+ sol_map_set_name(state, globals, "OutOfMemory", state->OutOfMemory);
|
|
240
|
+ sol_map_borrow_name(state, globals, "toint", sol_new_cfunc(state, sol_f_toint, "toint"));
|
|
241
|
+ sol_map_borrow_name(state, globals, "tofloat", sol_new_cfunc(state, sol_f_tofloat, "tofloat"));
|
|
242
|
+ sol_map_borrow_name(state, globals, "tostring", sol_new_cfunc(state, sol_f_tostring, "tostring"));
|
|
243
|
+ sol_map_borrow_name(state, globals, "try", sol_new_cfunc(state, sol_f_try, "try"));
|
|
244
|
+ sol_map_borrow_name(state, globals, "apply", sol_new_cfunc(state, sol_f_apply, "apply"));
|
|
245
|
+ sol_map_borrow_name(state, globals, "error", sol_new_cfunc(state, sol_f_error, "error"));
|
|
246
|
+ sol_map_borrow_name(state, globals, "type", sol_new_cfunc(state, sol_f_type, "type"));
|
|
247
|
+ sol_map_borrow_name(state, globals, "prepr", sol_new_cfunc(state, sol_f_prepr, "prepr"));
|
|
248
|
+ sol_map_borrow_name(state, globals, "print", sol_new_cfunc(state, sol_f_print, "print"));
|
|
249
|
+ sol_map_borrow_name(state, globals, "rawget", sol_new_cfunc(state, sol_f_rawget, "rawget"));
|
|
250
|
+ sol_map_borrow_name(state, globals, "rawset", sol_new_cfunc(state, sol_f_rawset, "rawset"));
|
|
251
|
+ sol_map_borrow_name(state, globals, "range", sol_new_cfunc(state, sol_f_range, "range"));
|
|
252
|
+ sol_map_borrow_name(state, globals, "exec", sol_new_cfunc(state, sol_f_exec, "exec"));
|
|
253
|
+ sol_map_borrow_name(state, globals, "eval", sol_new_cfunc(state, sol_f_eval, "eval"));
|
|
254
|
+ sol_map_borrow_name(state, globals, "execfile", sol_new_cfunc(state, sol_f_execfile, "execfile"));
|
|
255
|
+ sol_map_borrow_name(state, globals, "parse", sol_new_cfunc(state, sol_f_parse, "parse"));
|
|
256
|
+ sol_map_borrow_name(state, globals, "ord", sol_new_cfunc(state, sol_f_ord, "ord"));
|
|
257
|
+ sol_map_borrow_name(state, globals, "chr", sol_new_cfunc(state, sol_f_chr, "chr"));
|
255
|
258
|
|
256
|
259
|
mod = sol_new_map(state);
|
257
|
|
- sol_map_borrow_name(state, mod, "getref", sol_new_cfunc(state, sol_f_debug_getref));
|
258
|
|
- sol_map_borrow_name(state, mod, "setref", sol_new_cfunc(state, sol_f_debug_setref));
|
259
|
|
- sol_map_borrow_name(state, mod, "closure", sol_new_cfunc(state, sol_f_debug_closure));
|
260
|
|
- sol_map_borrow_name(state, mod, "globals", sol_new_cfunc(state, sol_f_debug_globals));
|
261
|
|
- sol_map_borrow_name(state, mod, "locals", sol_new_cfunc(state, sol_f_debug_locals));
|
262
|
|
- sol_map_borrow_name(state, mod, "scopes", sol_new_cfunc(state, sol_f_debug_scopes));
|
263
|
|
- sol_map_borrow_name(state, mod, "version", sol_new_string(state, VERSION));
|
264
|
|
- sol_map_borrow_name(state, mod, "hexversion", sol_new_int(state, HEXVER));
|
|
260
|
+ sol_map_borrow_name(state, mod, "getref", sol_new_cfunc(state, sol_f_debug_getref, "debug.getref"));
|
|
261
|
+ sol_map_borrow_name(state, mod, "setref", sol_new_cfunc(state, sol_f_debug_setref, "debug.setref"));
|
|
262
|
+ sol_map_borrow_name(state, mod, "closure", sol_new_cfunc(state, sol_f_debug_closure, "debug.closure"));
|
|
263
|
+ sol_map_borrow_name(state, mod, "globals", sol_new_cfunc(state, sol_f_debug_globals, "debug.globals"));
|
|
264
|
+ sol_map_borrow_name(state, mod, "locals", sol_new_cfunc(state, sol_f_debug_locals, "debug.locals"));
|
|
265
|
+ sol_map_borrow_name(state, mod, "scopes", sol_new_cfunc(state, sol_f_debug_scopes, "debug.scopes"));
|
|
266
|
+ sol_map_borrow_name(state, mod, "version", sol_new_string(state, SOL_VERSION));
|
|
267
|
+ sol_map_borrow_name(state, mod, "hexversion", sol_new_int(state, SOL_HEXVER));
|
265
|
268
|
#ifdef SOL_ICACHE
|
266
|
269
|
sol_map_borrow_name(state, mod, "icache_min", sol_new_int(state, SOL_ICACHE_MIN));
|
267
|
270
|
sol_map_borrow_name(state, mod, "icache_max", sol_new_int(state, SOL_ICACHE_MAX));
|
|
@@ -270,15 +273,15 @@ int sol_state_init(sol_state_t *state) {
|
270
|
273
|
sol_obj_free(mod);
|
271
|
274
|
|
272
|
275
|
mod = sol_new_map(state);
|
273
|
|
- sol_map_borrow_name(state, mod, "str", sol_new_cfunc(state, sol_f_iter_str));
|
274
|
|
- sol_map_borrow_name(state, mod, "list", sol_new_cfunc(state, sol_f_iter_list));
|
275
|
|
- sol_map_borrow_name(state, mod, "map", sol_new_cfunc(state, sol_f_iter_map));
|
|
276
|
+ sol_map_borrow_name(state, mod, "str", sol_new_cfunc(state, sol_f_iter_str, "iter.str"));
|
|
277
|
+ sol_map_borrow_name(state, mod, "list", sol_new_cfunc(state, sol_f_iter_list, "iter.list"));
|
|
278
|
+ sol_map_borrow_name(state, mod, "map", sol_new_cfunc(state, sol_f_iter_map, "iter.map"));
|
276
|
279
|
sol_register_module_name(state, "iter", mod);
|
277
|
280
|
sol_obj_free(mod);
|
278
|
281
|
|
279
|
282
|
mod = sol_new_map(state);
|
280
|
|
- sol_map_borrow_name(state, mod, "readline", sol_new_cfunc(state, sol_f_readline_readline));
|
281
|
|
- sol_map_borrow_name(state, mod, "add_history", sol_new_cfunc(state, sol_f_readline_add_history));
|
|
283
|
+ sol_map_borrow_name(state, mod, "readline", sol_new_cfunc(state, sol_f_readline_readline, "readline.readline"));
|
|
284
|
+ sol_map_borrow_name(state, mod, "add_history", sol_new_cfunc(state, sol_f_readline_add_history, "readline.add_history"));
|
282
|
285
|
sol_register_module_name(state, "readline", mod);
|
283
|
286
|
sol_obj_free(mod);
|
284
|
287
|
|
|
@@ -332,7 +335,7 @@ int sol_state_init(sol_state_t *state) {
|
332
|
335
|
sol_map_borrow_name(state, mod, "KIND_STMT", sol_new_int(state, -1));
|
333
|
336
|
sol_map_borrow_name(state, mod, "KIND_EXPR", sol_new_int(state, -2));
|
334
|
337
|
sol_map_invert(state, mod);
|
335
|
|
- sol_map_borrow_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print));
|
|
338
|
+ sol_map_borrow_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print, "ast.print"));
|
336
|
339
|
sol_register_module_name(state, "ast", mod);
|
337
|
340
|
|
338
|
341
|
btype = sol_new_map(state);
|
|
@@ -397,10 +400,10 @@ int sol_state_init(sol_state_t *state) {
|
397
|
400
|
sol_map_invert(state, bobj);
|
398
|
401
|
|
399
|
402
|
mod = sol_new_map(state);
|
400
|
|
- sol_map_borrow_name(state, mod, "new", sol_new_cfunc(state, sol_f_buffer_new));
|
401
|
|
- sol_map_borrow_name(state, mod, "fromstring", sol_new_cfunc(state, sol_f_buffer_fromstring));
|
402
|
|
- sol_map_borrow_name(state, mod, "fromobject", sol_new_cfunc(state, sol_f_buffer_fromobject));
|
403
|
|
- sol_map_borrow_name(state, mod, "fromaddress", sol_new_cfunc(state, sol_f_buffer_fromaddress));
|
|
403
|
+ sol_map_borrow_name(state, mod, "new", sol_new_cfunc(state, sol_f_buffer_new, "buffer.new"));
|
|
404
|
+ sol_map_borrow_name(state, mod, "fromstring", sol_new_cfunc(state, sol_f_buffer_fromstring, "buffer.fromstring"));
|
|
405
|
+ sol_map_borrow_name(state, mod, "fromobject", sol_new_cfunc(state, sol_f_buffer_fromobject, "buffer.fromobject"));
|
|
406
|
+ sol_map_borrow_name(state, mod, "fromaddress", sol_new_cfunc(state, sol_f_buffer_fromaddress, "buffer.fromaddress"));
|
404
|
407
|
sol_map_set_name(state, mod, "type", btype);
|
405
|
408
|
sol_map_set_name(state, mod, "sizeof", bsize);
|
406
|
409
|
sol_map_set_name(state, mod, "objtype", bobj);
|
|
@@ -421,44 +424,44 @@ int sol_state_init(sol_state_t *state) {
|
421
|
424
|
sol_map_borrow_name(state, mod, "SEEK_END", sol_new_int(state, SEEK_END));
|
422
|
425
|
sol_map_borrow_name(state, mod, "ALL", sol_new_string(state, "ALL"));
|
423
|
426
|
sol_map_borrow_name(state, mod, "LINE", sol_new_string(state, "LINE"));
|
424
|
|
- sol_map_borrow_name(state, mod, "open", sol_new_cfunc(state, sol_f_stream_open));
|
425
|
|
- sol_map_borrow_name(state, mod, "__setindex", sol_new_cfunc(state, sol_f_io_setindex));
|
426
|
|
- sol_map_borrow_name(state, mod, "__index", sol_new_cfunc(state, sol_f_io_index));
|
|
427
|
+ sol_map_borrow_name(state, mod, "open", sol_new_cfunc(state, sol_f_stream_open, "io.open"));
|
|
428
|
+ sol_map_borrow_name(state, mod, "__setindex", sol_new_cfunc(state, sol_f_io_setindex, "io.__setindex"));
|
|
429
|
+ sol_map_borrow_name(state, mod, "__index", sol_new_cfunc(state, sol_f_io_index, "io.__index"));
|
427
|
430
|
sol_register_module_name(state, "io", mod);
|
428
|
431
|
sol_obj_free(mod);
|
429
|
432
|
|
430
|
433
|
meths = sol_new_map(state);
|
431
|
|
- sol_map_borrow_name(state, meths, "get", sol_new_cfunc(state, sol_f_buffer_get));
|
432
|
|
- sol_map_borrow_name(state, meths, "set", sol_new_cfunc(state, sol_f_buffer_set));
|
433
|
|
- sol_map_borrow_name(state, meths, "address", sol_new_cfunc(state, sol_f_buffer_address));
|
434
|
|
- sol_map_borrow_name(state, meths, "size", sol_new_cfunc(state, sol_f_buffer_size));
|
|
434
|
+ sol_map_borrow_name(state, meths, "get", sol_new_cfunc(state, sol_f_buffer_get, "buffer.get"));
|
|
435
|
+ sol_map_borrow_name(state, meths, "set", sol_new_cfunc(state, sol_f_buffer_set, "buffer.set"));
|
|
436
|
+ sol_map_borrow_name(state, meths, "address", sol_new_cfunc(state, sol_f_buffer_address, "buffer.address"));
|
|
437
|
+ sol_map_borrow_name(state, meths, "size", sol_new_cfunc(state, sol_f_buffer_size, "buffer.size"));
|
435
|
438
|
sol_register_methods_name(state, "buffer", meths);
|
436
|
439
|
sol_obj_free(meths);
|
437
|
440
|
|
438
|
441
|
meths = sol_new_map(state);
|
439
|
|
- sol_map_borrow_name(state, meths, "copy", sol_new_cfunc(state, sol_f_list_copy));
|
440
|
|
- sol_map_borrow_name(state, meths, "insert", sol_new_cfunc(state, sol_f_list_insert));
|
441
|
|
- sol_map_borrow_name(state, meths, "remove", sol_new_cfunc(state, sol_f_list_remove));
|
442
|
|
- sol_map_borrow_name(state, meths, "truncate", sol_new_cfunc(state, sol_f_list_truncate));
|
443
|
|
- sol_map_borrow_name(state, meths, "map", sol_new_cfunc(state, sol_f_list_map));
|
444
|
|
- sol_map_borrow_name(state, meths, "filter", sol_new_cfunc(state, sol_f_list_filter));
|
|
442
|
+ sol_map_borrow_name(state, meths, "copy", sol_new_cfunc(state, sol_f_list_copy, "list.copy"));
|
|
443
|
+ sol_map_borrow_name(state, meths, "insert", sol_new_cfunc(state, sol_f_list_insert, "list.insert"));
|
|
444
|
+ sol_map_borrow_name(state, meths, "remove", sol_new_cfunc(state, sol_f_list_remove, "list.remove"));
|
|
445
|
+ sol_map_borrow_name(state, meths, "truncate", sol_new_cfunc(state, sol_f_list_truncate, "list.truncate"));
|
|
446
|
+ sol_map_borrow_name(state, meths, "map", sol_new_cfunc(state, sol_f_list_map, "list.map"));
|
|
447
|
+ sol_map_borrow_name(state, meths, "filter", sol_new_cfunc(state, sol_f_list_filter, "list.filter"));
|
445
|
448
|
sol_register_methods_name(state, "list", meths);
|
446
|
449
|
sol_obj_free(meths);
|
447
|
450
|
|
448
|
451
|
meths = sol_new_map(state);
|
449
|
|
- sol_map_borrow_name(state, meths, "read", sol_new_cfunc(state, sol_f_stream_read));
|
450
|
|
- sol_map_borrow_name(state, meths, "write", sol_new_cfunc(state, sol_f_stream_write));
|
451
|
|
- sol_map_borrow_name(state, meths, "seek", sol_new_cfunc(state, sol_f_stream_seek));
|
452
|
|
- sol_map_borrow_name(state, meths, "tell", sol_new_cfunc(state, sol_f_stream_tell));
|
453
|
|
- sol_map_borrow_name(state, meths, "flush", sol_new_cfunc(state, sol_f_stream_flush));
|
454
|
|
- sol_map_borrow_name(state, meths, "eof", sol_new_cfunc(state, sol_f_stream_eof));
|
|
452
|
+ sol_map_borrow_name(state, meths, "read", sol_new_cfunc(state, sol_f_stream_read, "stream.read"));
|
|
453
|
+ sol_map_borrow_name(state, meths, "write", sol_new_cfunc(state, sol_f_stream_write, "stream.write"));
|
|
454
|
+ sol_map_borrow_name(state, meths, "seek", sol_new_cfunc(state, sol_f_stream_seek, "stream.seek"));
|
|
455
|
+ sol_map_borrow_name(state, meths, "tell", sol_new_cfunc(state, sol_f_stream_tell, "stream.tell"));
|
|
456
|
+ sol_map_borrow_name(state, meths, "flush", sol_new_cfunc(state, sol_f_stream_flush, "stream.flush"));
|
|
457
|
+ sol_map_borrow_name(state, meths, "eof", sol_new_cfunc(state, sol_f_stream_eof, "stream.eof"));
|
455
|
458
|
sol_register_methods_name(state, "stream", meths);
|
456
|
459
|
sol_obj_free(meths);
|
457
|
460
|
|
458
|
461
|
meths = sol_new_map(state);
|
459
|
|
- sol_map_borrow_name(state, meths, "sub", sol_new_cfunc(state, sol_f_str_sub));
|
460
|
|
- sol_map_borrow_name(state, meths, "split", sol_new_cfunc(state, sol_f_str_split));
|
461
|
|
- sol_map_borrow_name(state, meths, "find", sol_new_cfunc(state, sol_f_str_find));
|
|
462
|
+ sol_map_borrow_name(state, meths, "sub", sol_new_cfunc(state, sol_f_str_sub, "str.sub"));
|
|
463
|
+ sol_map_borrow_name(state, meths, "split", sol_new_cfunc(state, sol_f_str_split, "str.split"));
|
|
464
|
+ sol_map_borrow_name(state, meths, "find", sol_new_cfunc(state, sol_f_str_find, "str.find"));
|
462
|
465
|
sol_register_methods_name(state, "string", meths);
|
463
|
466
|
sol_obj_free(meths);
|
464
|
467
|
|
|
@@ -469,23 +472,9 @@ int sol_state_init(sol_state_t *state) {
|
469
|
472
|
// Perform initialization based on the user profile, if so requested.
|
470
|
473
|
// TODO: Make this switchable at runtime.
|
471
|
474
|
|
472
|
|
- for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {
|
473
|
|
- fp = fopen(sol_AbsInitPaths[i], "r");
|
474
|
|
- if(fp) {
|
475
|
|
- stmt = sol_compile_file(fp);
|
476
|
|
- sol_exec(state, stmt);
|
477
|
|
- st_free(stmt);
|
478
|
|
- fclose(fp);
|
479
|
|
- }
|
480
|
|
- }
|
481
|
|
-
|
482
|
|
- suffix = getenv("HOME");
|
483
|
|
- if(suffix) {
|
484
|
|
- strncpy(sol_TempPath, suffix, TMP_PATH_SZ);
|
485
|
|
- suffix = sol_TempPath + strlen(sol_TempPath);
|
486
|
|
- for(i = 0; i < LENGTH(sol_HomeInitPaths); i++) {
|
487
|
|
- strncpy(suffix, sol_HomeInitPaths[i], TMP_PATH_SZ - (suffix - sol_TempPath));
|
488
|
|
- fp = fopen(sol_TempPath, "r");
|
|
475
|
+ if(!(state->features & SOL_FT_NO_USR_INIT)) {
|
|
476
|
+ for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {
|
|
477
|
+ fp = fopen(sol_AbsInitPaths[i], "r");
|
489
|
478
|
if(fp) {
|
490
|
479
|
stmt = sol_compile_file(fp);
|
491
|
480
|
sol_exec(state, stmt);
|
|
@@ -493,10 +482,26 @@ int sol_state_init(sol_state_t *state) {
|
493
|
482
|
fclose(fp);
|
494
|
483
|
}
|
495
|
484
|
}
|
496
|
|
- }
|
497
|
|
-
|
498
|
|
- if(sol_has_error(state)) {
|
499
|
|
- goto cleanup;
|
|
485
|
+
|
|
486
|
+ suffix = getenv("HOME");
|
|
487
|
+ if(suffix) {
|
|
488
|
+ strncpy(sol_TempPath, suffix, TMP_PATH_SZ);
|
|
489
|
+ suffix = sol_TempPath + strlen(sol_TempPath);
|
|
490
|
+ for(i = 0; i < LENGTH(sol_HomeInitPaths); i++) {
|
|
491
|
+ strncpy(suffix, sol_HomeInitPaths[i], TMP_PATH_SZ - (suffix - sol_TempPath));
|
|
492
|
+ fp = fopen(sol_TempPath, "r");
|
|
493
|
+ if(fp) {
|
|
494
|
+ stmt = sol_compile_file(fp);
|
|
495
|
+ sol_exec(state, stmt);
|
|
496
|
+ st_free(stmt);
|
|
497
|
+ fclose(fp);
|
|
498
|
+ }
|
|
499
|
+ }
|
|
500
|
+ }
|
|
501
|
+
|
|
502
|
+ if(sol_has_error(state)) {
|
|
503
|
+ goto cleanup;
|
|
504
|
+ }
|
500
|
505
|
}
|
501
|
506
|
|
502
|
507
|
// We're all set!
|