The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

893 lines
35 KiB

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <termios.h>
  6. #include <sys/ioctl.h>
  7. #include "ast.h"
  8. #define TMP_PATH_SZ 256
  9. char *sol_AbsInitPaths[] = {
  10. "/etc/sol/init.sol",
  11. "/opt/sol/init.sol",
  12. };
  13. char *sol_HomeInitPaths[] = {
  14. "/.config/sol/init.sol",
  15. };
  16. char sol_TempPath[TMP_PATH_SZ];
  17. #define LENGTH(array) (sizeof(array) / sizeof(array[0]))
  18. int sol_state_init(sol_state_t *state) {
  19. sol_object_t *globals, *mod, *meths;
  20. sol_object_t *btype, *bsize, *bobj;
  21. unsigned long i;
  22. FILE *fp;
  23. stmt_node *stmt;
  24. char *suffix;
  25. sol_mm_initialize(state);
  26. state->None = NULL;
  27. state->OutOfMemory = NULL;
  28. state->scopes = NULL;
  29. state->error = NULL;
  30. state->traceback = NULL;
  31. state->ret = NULL;
  32. state->sflag = SF_NORMAL;
  33. state->lastvalue = NULL;
  34. state->loopvalue = NULL;
  35. #ifdef DEBUG_GC
  36. // This is necessary for DEBUG_GC's early allocation; it gets overwritten,
  37. // unfortunately, during sol_ops_init below, so it's duplicated.
  38. state->SingletOps.tname = "singlet";
  39. #endif
  40. // If any of the following fail, some very weird things are happening.
  41. if(!(state->None = sol_new_singlet(state, "None"))) {
  42. goto cleanup;
  43. }
  44. if(!(state->OutOfMemory = sol_new_singlet(state, "OutOfMemory"))) {
  45. goto cleanup;
  46. }
  47. // We can now use the normal error reporting mechanism, now
  48. // that errors are distinguishable. Set that up now.
  49. //Initialize all of the builtin operations
  50. //(these ones are technically already pointed to by None/OOM)
  51. sol_ops_init(&(state->NullOps));
  52. state->SingletOps = state->NullOps;
  53. state->IntOps = state->NullOps;
  54. state->FloatOps = state->NullOps;
  55. state->StringOps = state->NullOps;
  56. state->ListOps = state->NullOps;
  57. state->MapOps = state->NullOps;
  58. state->MCellOps = state->NullOps;
  59. state->FuncOps = state->NullOps;
  60. state->CFuncOps = state->NullOps;
  61. state->ASTNodeOps = state->NullOps;
  62. state->BufferOps = state->NullOps;
  63. state->DyLibOps = state->NullOps;
  64. state->DySymOps = state->NullOps;
  65. state->StreamOps = state->NullOps;
  66. state->SingletOps.tname = "singlet";
  67. state->SingletOps.tostring = sol_f_singlet_tostring;
  68. state->SingletOps.tobuffer = sol_f_singlet_tobuffer;
  69. state->SingletOps.free = sol_f_singlet_free;
  70. state->IntOps.tname = "int";
  71. state->IntOps.add = sol_f_int_add;
  72. state->IntOps.sub = sol_f_int_sub;
  73. state->IntOps.mul = sol_f_int_mul;
  74. state->IntOps.div = sol_f_int_div;
  75. state->IntOps.mod = sol_f_int_mod;
  76. state->IntOps.pow = sol_f_int_pow;
  77. state->IntOps.band = sol_f_int_band;
  78. state->IntOps.bor = sol_f_int_bor;
  79. state->IntOps.bxor = sol_f_int_bxor;
  80. state->IntOps.blsh = sol_f_int_blsh;
  81. state->IntOps.brsh = sol_f_int_brsh;
  82. state->IntOps.bnot = sol_f_int_bnot;
  83. state->IntOps.cmp = sol_f_int_cmp;
  84. state->IntOps.toint = sol_f_int_toint;
  85. state->IntOps.tofloat = sol_f_int_tofloat;
  86. state->IntOps.tostring = sol_f_int_tostring;
  87. state->FloatOps.tname = "float";
  88. state->FloatOps.add = sol_f_float_add;
  89. state->FloatOps.sub = sol_f_float_sub;
  90. state->FloatOps.mul = sol_f_float_mul;
  91. state->FloatOps.div = sol_f_float_div;
  92. state->FloatOps.cmp = sol_f_float_cmp;
  93. state->FloatOps.toint = sol_f_float_toint;
  94. state->FloatOps.tofloat = sol_f_float_tofloat;
  95. state->FloatOps.tostring = sol_f_float_tostring;
  96. state->StringOps.tname = "string";
  97. state->StringOps.add = sol_f_str_add;
  98. state->StringOps.mul = sol_f_str_mul;
  99. state->StringOps.cmp = sol_f_str_cmp;
  100. state->StringOps.index = sol_f_str_index;
  101. state->StringOps.len = sol_f_str_len;
  102. state->StringOps.iter = sol_f_str_iter;
  103. state->StringOps.toint = sol_f_str_toint;
  104. state->StringOps.tofloat = sol_f_str_tofloat;
  105. state->StringOps.tostring = sol_f_str_tostring;
  106. state->StringOps.tobuffer = sol_f_str_tobuffer;
  107. state->StringOps.repr = sol_f_str_repr;
  108. state->StringOps.free = sol_f_str_free;
  109. state->ListOps.tname = "list";
  110. state->ListOps.add = sol_f_list_add;
  111. state->ListOps.mul = sol_f_list_mul;
  112. state->ListOps.cmp = sol_f_list_cmp;
  113. state->ListOps.call = sol_f_not_impl;
  114. state->ListOps.index = sol_f_list_index;
  115. state->ListOps.setindex = sol_f_list_setindex;
  116. state->ListOps.len = sol_f_list_len;
  117. state->ListOps.iter = sol_f_list_iter;
  118. state->ListOps.tostring = sol_f_list_tostring;
  119. state->ListOps.free = sol_f_list_free;
  120. state->MapOps.tname = "map";
  121. state->MapOps.add = sol_f_map_add;
  122. state->MapOps.call = sol_f_map_call;
  123. state->MapOps.index = sol_f_map_index;
  124. state->MapOps.setindex = sol_f_map_setindex;
  125. state->MapOps.len = sol_f_map_len;
  126. state->MapOps.iter = sol_f_map_iter;
  127. state->MapOps.tostring = sol_f_map_tostring;
  128. state->MapOps.repr = sol_f_map_repr;
  129. state->MapOps.free = sol_f_map_free;
  130. state->MCellOps.tname = "mcell";
  131. state->MCellOps.tostring = sol_f_mcell_tostring;
  132. state->MCellOps.free = sol_f_mcell_free;
  133. state->FuncOps.tname = "function";
  134. state->FuncOps.call = sol_f_func_call;
  135. state->FuncOps.index = sol_f_func_index;
  136. state->FuncOps.setindex = sol_f_func_setindex;
  137. state->FuncOps.tostring = sol_f_func_tostring;
  138. state->FuncOps.free = sol_f_func_free;
  139. state->CFuncOps.tname = "cfunction";
  140. state->CFuncOps.call = sol_f_cfunc_call;
  141. state->CFuncOps.tostring = sol_f_cfunc_tostring;
  142. state->CFuncOps.free = sol_f_cfunc_free;
  143. state->ASTNodeOps.tname = "astnode";
  144. state->ASTNodeOps.call = sol_f_astnode_call;
  145. state->ASTNodeOps.index = sol_f_astnode_index;
  146. state->ASTNodeOps.setindex = sol_f_astnode_setindex;
  147. state->ASTNodeOps.tostring = sol_f_astnode_tostring;
  148. state->ASTNodeOps.free = sol_f_astnode_free;
  149. state->BufferOps.tname = "buffer";
  150. state->BufferOps.add = sol_f_buffer_add;
  151. state->BufferOps.mul = sol_f_buffer_mul;
  152. state->BufferOps.cmp = sol_f_buffer_cmp;
  153. state->BufferOps.len = sol_f_buffer_len;
  154. state->BufferOps.iter = sol_f_buffer_iter;
  155. state->BufferOps.index = sol_f_buffer_index;
  156. state->BufferOps.tostring = sol_f_buffer_tostring;
  157. state->BufferOps.repr = sol_f_buffer_repr;
  158. state->BufferOps.toint = sol_f_buffer_toint;
  159. state->BufferOps.tofloat = sol_f_buffer_tofloat;
  160. state->BufferOps.tobuffer = sol_f_buffer_tobuffer;
  161. state->BufferOps.free = sol_f_buffer_free;
  162. state->DyLibOps.tname = "dylib";
  163. state->DyLibOps.index = sol_f_dylib_index;
  164. state->DyLibOps.free = sol_f_dylib_free;
  165. state->DyLibOps.tostring = sol_f_dylib_tostring;
  166. state->DySymOps.tname = "dysym";
  167. state->DySymOps.call = sol_f_dysym_call;
  168. state->DySymOps.index = sol_f_dysym_index;
  169. state->DySymOps.setindex = sol_f_dysym_setindex;
  170. state->DySymOps.tostring = sol_f_dysym_tostring;
  171. state->StreamOps.tname = "stream";
  172. state->StreamOps.blsh = sol_f_stream_blsh;
  173. state->StreamOps.brsh = sol_f_stream_brsh;
  174. state->StreamOps.index = sol_f_stream_index;
  175. state->StreamOps.free = sol_f_stream_free;
  176. state->StreamOps.tostring = sol_f_stream_tostring;
  177. #ifdef DEBUG_GC
  178. state->obfuncs.copy = (dsl_copier) _sol_gc_dsl_copier;
  179. state->obfuncs.destr = (dsl_destructor) _sol_gc_dsl_destructor;
  180. #else
  181. state->obfuncs.copy = (dsl_copier) sol_obj_acquire;
  182. state->obfuncs.destr = (dsl_destructor) sol_obj_free;
  183. #endif
  184. #ifdef SOL_ICACHE
  185. state->icache_bypass = 1;
  186. for(i = 0; i <= (SOL_ICACHE_MAX - SOL_ICACHE_MIN); i++) {
  187. state->icache[i] = sol_new_int(state, ((long) i) + SOL_ICACHE_MIN);
  188. }
  189. state->icache_bypass = 0;
  190. #endif
  191. state->calling_type = "(none)";
  192. state->calling_meth = "(none)";
  193. state->lastvalue = sol_incref(state->None);
  194. state->loopvalue = sol_incref(state->None);
  195. state->error = state->None;
  196. state->scopes = sol_new_list(state);
  197. if(sol_has_error(state)) {
  198. goto cleanup;
  199. }
  200. globals = sol_new_map(state);
  201. state->modules = sol_new_map(state);
  202. state->methods = sol_new_map(state);
  203. if(sol_has_error(state)) {
  204. goto cleanup;
  205. }
  206. sol_list_insert(state, state->scopes, 0, globals);
  207. sol_obj_free(globals);
  208. if(sol_has_error(state)) {
  209. goto cleanup;
  210. }
  211. state->_stdin = sol_new_stream(state, stdin, MODE_READ);
  212. state->_stdout = sol_new_stream(state, stdout, MODE_WRITE);
  213. state->_stderr = sol_new_stream(state, stderr, MODE_WRITE);
  214. // NB: None is actually a keyword in the language--it doesn't need to be a
  215. // global (see parser.y)
  216. // OutOfMemory (and other important singlets) are set, not borrowed,
  217. // because the state still holds a reference to them
  218. sol_map_set_name(state, globals, "OutOfMemory", state->OutOfMemory);
  219. sol_map_borrow_name(state, globals, "toint", sol_new_cfunc(state, sol_f_toint, "toint"));
  220. sol_map_borrow_name(state, globals, "tofloat", sol_new_cfunc(state, sol_f_tofloat, "tofloat"));
  221. sol_map_borrow_name(state, globals, "tostring", sol_new_cfunc(state, sol_f_tostring, "tostring"));
  222. sol_map_borrow_name(state, globals, "tobuffer", sol_new_cfunc(state, sol_f_tobuffer, "tobuffer"));
  223. sol_map_borrow_name(state, globals, "try", sol_new_cfunc(state, sol_f_try, "try"));
  224. sol_map_borrow_name(state, globals, "apply", sol_new_cfunc(state, sol_f_apply, "apply"));
  225. sol_map_borrow_name(state, globals, "error", sol_new_cfunc(state, sol_f_error, "error"));
  226. sol_map_borrow_name(state, globals, "type", sol_new_cfunc(state, sol_f_type, "type"));
  227. sol_map_borrow_name(state, globals, "prepr", sol_new_cfunc(state, sol_f_prepr, "prepr"));
  228. sol_map_borrow_name(state, globals, "print", sol_new_cfunc(state, sol_f_print, "print"));
  229. sol_map_borrow_name(state, globals, "rawget", sol_new_cfunc(state, sol_f_rawget, "rawget"));
  230. sol_map_borrow_name(state, globals, "rawset", sol_new_cfunc(state, sol_f_rawset, "rawset"));
  231. sol_map_borrow_name(state, globals, "range", sol_new_cfunc(state, sol_f_range, "range"));
  232. //sol_map_borrow_name(state, globals, "exec", sol_new_cfunc(state, sol_f_exec, "exec"));
  233. //sol_map_borrow_name(state, globals, "eval", sol_new_cfunc(state, sol_f_eval, "eval"));
  234. sol_map_borrow_name(state, globals, "execfile", sol_new_cfunc(state, sol_f_execfile, "execfile"));
  235. sol_map_borrow_name(state, globals, "parse", sol_new_cfunc(state, sol_f_parse, "parse"));
  236. sol_map_borrow_name(state, globals, "ord", sol_new_cfunc(state, sol_f_ord, "ord"));
  237. sol_map_borrow_name(state, globals, "chr", sol_new_cfunc(state, sol_f_chr, "chr"));
  238. mod = sol_new_map(state);
  239. sol_map_borrow_name(state, mod, "getref", sol_new_cfunc(state, sol_f_debug_getref, "debug.getref"));
  240. sol_map_borrow_name(state, mod, "setref", sol_new_cfunc(state, sol_f_debug_setref, "debug.setref"));
  241. sol_map_borrow_name(state, mod, "closure", sol_new_cfunc(state, sol_f_debug_closure, "debug.closure"));
  242. sol_map_borrow_name(state, mod, "globals", sol_new_cfunc(state, sol_f_debug_globals, "debug.globals"));
  243. sol_map_borrow_name(state, mod, "locals", sol_new_cfunc(state, sol_f_debug_locals, "debug.locals"));
  244. sol_map_borrow_name(state, mod, "scopes", sol_new_cfunc(state, sol_f_debug_scopes, "debug.scopes"));
  245. sol_map_borrow_name(state, mod, "version", sol_new_buffer(state, SOL_VERSION, strlen(SOL_VERSION), OWN_NONE, NULL, NULL));
  246. sol_map_borrow_name(state, mod, "hexversion", sol_new_int(state, SOL_HEXVER));
  247. #ifdef SOL_ICACHE
  248. sol_map_borrow_name(state, mod, "icache_min", sol_new_int(state, SOL_ICACHE_MIN));
  249. sol_map_borrow_name(state, mod, "icache_max", sol_new_int(state, SOL_ICACHE_MAX));
  250. #endif
  251. sol_map_borrow_name(state, mod, "modules", state->modules);
  252. sol_map_borrow_name(state, mod, "methods", state->methods);
  253. sol_map_borrow_name(state, mod, "getops", sol_new_cfunc(state, sol_f_debug_getops, "debug.getops"));
  254. sol_register_module_name(state, "debug", mod);
  255. sol_obj_free(mod);
  256. mod = sol_new_map(state);
  257. sol_map_borrow_name(state, mod, "str", sol_new_cfunc(state, sol_f_iter_str, "iter.str"));
  258. sol_map_borrow_name(state, mod, "buffer", sol_new_cfunc(state, sol_f_iter_buffer, "iter.buffer"));
  259. sol_map_borrow_name(state, mod, "list", sol_new_cfunc(state, sol_f_iter_list, "iter.list"));
  260. sol_map_borrow_name(state, mod, "map", sol_new_cfunc(state, sol_f_iter_map, "iter.map"));
  261. sol_register_module_name(state, "iter", mod);
  262. sol_obj_free(mod);
  263. #ifndef NO_READLINE
  264. mod = sol_new_map(state);
  265. sol_map_borrow_name(state, mod, "readline", sol_new_cfunc(state, sol_f_readline_readline, "readline.readline"));
  266. sol_map_borrow_name(state, mod, "add_history", sol_new_cfunc(state, sol_f_readline_add_history, "readline.add_history"));
  267. sol_register_module_name(state, "readline", mod);
  268. sol_obj_free(mod);
  269. #endif
  270. mod = sol_new_map(state);
  271. sol_map_borrow_name(state, mod, "ST_EXPR", sol_new_int(state, ST_EXPR));
  272. sol_map_borrow_name(state, mod, "ST_LIST", sol_new_int(state, ST_LIST));
  273. sol_map_borrow_name(state, mod, "ST_RET", sol_new_int(state, ST_RET));
  274. sol_map_borrow_name(state, mod, "ST_CONT", sol_new_int(state, ST_CONT));
  275. sol_map_borrow_name(state, mod, "ST_BREAK", sol_new_int(state, ST_BREAK));
  276. sol_map_borrow_name(state, mod, "EX_LIT", sol_new_int(state, EX_LIT));
  277. sol_map_borrow_name(state, mod, "EX_LISTGEN", sol_new_int(state, EX_LISTGEN));
  278. sol_map_borrow_name(state, mod, "EX_MAPGEN", sol_new_int(state, EX_MAPGEN));
  279. sol_map_borrow_name(state, mod, "EX_BINOP", sol_new_int(state, EX_BINOP));
  280. sol_map_borrow_name(state, mod, "EX_UNOP", sol_new_int(state, EX_UNOP));
  281. sol_map_borrow_name(state, mod, "EX_INDEX", sol_new_int(state, EX_INDEX));
  282. sol_map_borrow_name(state, mod, "EX_SETINDEX", sol_new_int(state, EX_SETINDEX));
  283. sol_map_borrow_name(state, mod, "EX_ASSIGN", sol_new_int(state, EX_ASSIGN));
  284. sol_map_borrow_name(state, mod, "EX_REF", sol_new_int(state, EX_REF));
  285. sol_map_borrow_name(state, mod, "EX_CALL", sol_new_int(state, EX_CALL));
  286. sol_map_borrow_name(state, mod, "EX_FUNCDECL", sol_new_int(state, EX_FUNCDECL));
  287. sol_map_borrow_name(state, mod, "EX_IFELSE", sol_new_int(state, EX_IFELSE));
  288. sol_map_borrow_name(state, mod, "EX_LOOP", sol_new_int(state, EX_LOOP));
  289. sol_map_borrow_name(state, mod, "EX_ITER", sol_new_int(state, EX_ITER));
  290. sol_map_borrow_name(state, mod, "OP_ADD", sol_new_int(state, OP_ADD));
  291. sol_map_borrow_name(state, mod, "OP_SUB", sol_new_int(state, OP_SUB));
  292. sol_map_borrow_name(state, mod, "OP_MUL", sol_new_int(state, OP_MUL));
  293. sol_map_borrow_name(state, mod, "OP_DIV", sol_new_int(state, OP_DIV));
  294. sol_map_borrow_name(state, mod, "OP_MOD", sol_new_int(state, OP_MOD));
  295. sol_map_borrow_name(state, mod, "OP_POW", sol_new_int(state, OP_POW));
  296. sol_map_borrow_name(state, mod, "OP_BAND", sol_new_int(state, OP_BAND));
  297. sol_map_borrow_name(state, mod, "OP_BOR", sol_new_int(state, OP_BOR));
  298. sol_map_borrow_name(state, mod, "OP_BXOR", sol_new_int(state, OP_BXOR));
  299. sol_map_borrow_name(state, mod, "OP_LAND", sol_new_int(state, OP_LAND));
  300. sol_map_borrow_name(state, mod, "OP_LOR", sol_new_int(state, OP_LOR));
  301. sol_map_borrow_name(state, mod, "OP_EQUAL", sol_new_int(state, OP_EQUAL));
  302. sol_map_borrow_name(state, mod, "OP_NEQUAL", sol_new_int(state, OP_NEQUAL));
  303. sol_map_borrow_name(state, mod, "OP_LESS", sol_new_int(state, OP_LESS));
  304. sol_map_borrow_name(state, mod, "OP_GREATER", sol_new_int(state, OP_GREATER));
  305. sol_map_borrow_name(state, mod, "OP_LESSEQ", sol_new_int(state, OP_LESSEQ));
  306. sol_map_borrow_name(state, mod, "OP_GREATEREQ", sol_new_int(state, OP_GREATEREQ));
  307. sol_map_borrow_name(state, mod, "OP_LSHIFT", sol_new_int(state, OP_LSHIFT));
  308. sol_map_borrow_name(state, mod, "OP_RSHIFT", sol_new_int(state, OP_RSHIFT));
  309. sol_map_borrow_name(state, mod, "OP_NEG", sol_new_int(state, OP_NEG));
  310. sol_map_borrow_name(state, mod, "OP_BNOT", sol_new_int(state, OP_BNOT));
  311. sol_map_borrow_name(state, mod, "OP_LNOT", sol_new_int(state, OP_LNOT));
  312. sol_map_borrow_name(state, mod, "OP_LEN", sol_new_int(state, OP_LEN));
  313. sol_map_borrow_name(state, mod, "LIT_INT", sol_new_int(state, LIT_INT));
  314. sol_map_borrow_name(state, mod, "LIT_FLOAT", sol_new_int(state, LIT_FLOAT));
  315. sol_map_borrow_name(state, mod, "LIT_STRING", sol_new_int(state, LIT_STRING));
  316. sol_map_borrow_name(state, mod, "LIT_NONE", sol_new_int(state, LIT_NONE));
  317. sol_map_borrow_name(state, mod, "KIND_STMT", sol_new_int(state, -1));
  318. sol_map_borrow_name(state, mod, "KIND_EXPR", sol_new_int(state, -2));
  319. sol_map_invert(state, mod);
  320. sol_map_borrow_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print, "ast.print"));
  321. sol_register_module_name(state, "ast", mod);
  322. btype = sol_new_map(state);
  323. sol_map_borrow_name(state, btype, "none", sol_new_int(state, BUF_NONE));
  324. sol_map_borrow_name(state, btype, "uint8", sol_new_int(state, BUF_UINT8));
  325. sol_map_borrow_name(state, btype, "uint16", sol_new_int(state, BUF_UINT16));
  326. sol_map_borrow_name(state, btype, "uint32", sol_new_int(state, BUF_UINT32));
  327. sol_map_borrow_name(state, btype, "uint64", sol_new_int(state, BUF_UINT64));
  328. sol_map_borrow_name(state, btype, "int8", sol_new_int(state, BUF_INT8));
  329. sol_map_borrow_name(state, btype, "int16", sol_new_int(state, BUF_INT16));
  330. sol_map_borrow_name(state, btype, "int32", sol_new_int(state, BUF_INT32));
  331. sol_map_borrow_name(state, btype, "int64", sol_new_int(state, BUF_INT64));
  332. sol_map_borrow_name(state, btype, "char", sol_new_int(state, BUF_CHAR));
  333. sol_map_borrow_name(state, btype, "byte", sol_new_int(state, BUF_BYTE));
  334. sol_map_borrow_name(state, btype, "int", sol_new_int(state, BUF_INT));
  335. sol_map_borrow_name(state, btype, "uint", sol_new_int(state, BUF_UINT));
  336. sol_map_borrow_name(state, btype, "long", sol_new_int(state, BUF_LONG));
  337. sol_map_borrow_name(state, btype, "ulong", sol_new_int(state, BUF_ULONG));
  338. sol_map_borrow_name(state, btype, "float", sol_new_int(state, BUF_FLOAT));
  339. sol_map_borrow_name(state, btype, "double", sol_new_int(state, BUF_DOUBLE));
  340. sol_map_borrow_name(state, btype, "cstr", sol_new_int(state, BUF_CSTR));
  341. sol_map_borrow_name(state, btype, "ptr", sol_new_int(state, BUF_PTR));
  342. sol_map_invert(state, btype);
  343. bsize = sol_new_map(state);
  344. sol_map_borrow_name(state, bsize, "uint8", sol_new_int(state, sizeof(uint8_t)));
  345. sol_map_borrow_name(state, bsize, "uint16", sol_new_int(state, sizeof(uint16_t)));
  346. sol_map_borrow_name(state, bsize, "uint32", sol_new_int(state, sizeof(uint32_t)));
  347. sol_map_borrow_name(state, bsize, "uint64", sol_new_int(state, sizeof(uint64_t)));
  348. sol_map_borrow_name(state, bsize, "int8", sol_new_int(state, sizeof(int8_t)));
  349. sol_map_borrow_name(state, bsize, "int16", sol_new_int(state, sizeof(int16_t)));
  350. sol_map_borrow_name(state, bsize, "int32", sol_new_int(state, sizeof(int32_t)));
  351. sol_map_borrow_name(state, bsize, "int64", sol_new_int(state, sizeof(int64_t)));
  352. sol_map_borrow_name(state, bsize, "char", sol_new_int(state, sizeof(char)));
  353. sol_map_borrow_name(state, bsize, "byte", sol_new_int(state, sizeof(unsigned char)));
  354. sol_map_borrow_name(state, bsize, "int", sol_new_int(state, sizeof(int)));
  355. sol_map_borrow_name(state, bsize, "uint", sol_new_int(state, sizeof(unsigned int)));
  356. sol_map_borrow_name(state, bsize, "long", sol_new_int(state, sizeof(long)));
  357. sol_map_borrow_name(state, bsize, "ulong", sol_new_int(state, sizeof(unsigned long)));
  358. sol_map_borrow_name(state, bsize, "float", sol_new_int(state, sizeof(float)));
  359. sol_map_borrow_name(state, bsize, "double", sol_new_int(state, sizeof(double)));
  360. sol_map_borrow_name(state, bsize, "cstr", sol_new_int(state, sizeof(char *)));
  361. sol_map_borrow_name(state, bsize, "ptr", sol_new_int(state, sizeof(void *)));
  362. bobj = sol_new_map(state);
  363. sol_map_borrow_name(state, bobj, "SOL_SINGLET", sol_new_int(state, SOL_SINGLET));
  364. sol_map_borrow_name(state, bobj, "SOL_INTEGER", sol_new_int(state, SOL_INTEGER));
  365. sol_map_borrow_name(state, bobj, "SOL_FLOAT", sol_new_int(state, SOL_FLOAT));
  366. sol_map_borrow_name(state, bobj, "SOL_STRING", sol_new_int(state, SOL_STRING));
  367. sol_map_borrow_name(state, bobj, "SOL_LIST", sol_new_int(state, SOL_LIST));
  368. sol_map_borrow_name(state, bobj, "SOL_MAP", sol_new_int(state, SOL_MAP));
  369. sol_map_borrow_name(state, bobj, "SOL_MCELL", sol_new_int(state, SOL_MCELL));
  370. sol_map_borrow_name(state, bobj, "SOL_FUNCTION", sol_new_int(state, SOL_FUNCTION));
  371. sol_map_borrow_name(state, bobj, "SOL_CFUNCTION", sol_new_int(state, SOL_CFUNCTION));
  372. sol_map_borrow_name(state, bobj, "SOL_STMT", sol_new_int(state, SOL_STMT));
  373. sol_map_borrow_name(state, bobj, "SOL_EXPR", sol_new_int(state, SOL_EXPR));
  374. sol_map_borrow_name(state, bobj, "SOL_BUFFER", sol_new_int(state, SOL_BUFFER));
  375. sol_map_borrow_name(state, bobj, "SOL_DYLIB", sol_new_int(state, SOL_DYLIB));
  376. sol_map_borrow_name(state, bobj, "SOL_DYSYM", sol_new_int(state, SOL_DYSYM));
  377. sol_map_borrow_name(state, bobj, "SOL_STREAM", sol_new_int(state, SOL_STREAM));
  378. sol_map_borrow_name(state, bobj, "SOL_CDATA", sol_new_int(state, SOL_CDATA));
  379. sol_map_invert(state, bobj);
  380. mod = sol_new_map(state);
  381. sol_map_borrow_name(state, mod, "new", sol_new_cfunc(state, sol_f_buffer_new, "buffer.new"));
  382. sol_map_borrow_name(state, mod, "fromstring", sol_new_cfunc(state, sol_f_buffer_fromstring, "buffer.fromstring"));
  383. sol_map_borrow_name(state, mod, "fromobject", sol_new_cfunc(state, sol_f_buffer_fromobject, "buffer.fromobject"));
  384. sol_map_borrow_name(state, mod, "fromaddress", sol_new_cfunc(state, sol_f_buffer_fromaddress, "buffer.fromaddress"));
  385. sol_map_set_name(state, mod, "type", btype);
  386. sol_map_set_name(state, mod, "sizeof", bsize);
  387. sol_map_set_name(state, mod, "objtype", bobj);
  388. sol_register_module_name(state, "buffer", mod);
  389. sol_obj_free(mod);
  390. sol_obj_free(bobj);
  391. sol_obj_free(bsize);
  392. sol_obj_free(btype);
  393. mod = sol_new_map(state);
  394. sol_map_borrow_name(state, mod, "MODE_READ", sol_new_int(state, MODE_READ));
  395. sol_map_borrow_name(state, mod, "MODE_WRITE", sol_new_int(state, MODE_WRITE));
  396. sol_map_borrow_name(state, mod, "MODE_APPEND", sol_new_int(state, MODE_APPEND));
  397. sol_map_borrow_name(state, mod, "MODE_TRUNCATE", sol_new_int(state, MODE_TRUNCATE));
  398. sol_map_borrow_name(state, mod, "MODE_BINARY", sol_new_int(state, MODE_BINARY));
  399. sol_map_borrow_name(state, mod, "SEEK_SET", sol_new_int(state, SEEK_SET));
  400. sol_map_borrow_name(state, mod, "SEEK_CUR", sol_new_int(state, SEEK_CUR));
  401. sol_map_borrow_name(state, mod, "SEEK_END", sol_new_int(state, SEEK_END));
  402. sol_map_borrow_name(state, mod, "ALL", sol_new_buffer(state, "ALL", 3, OWN_NONE, NULL, NULL));
  403. sol_map_borrow_name(state, mod, "LINE", sol_new_buffer(state, "LINE", 4, OWN_NONE, NULL, NULL));
  404. sol_map_borrow_name(state, mod, "TIOCGWINSZ", sol_new_int(state, TIOCGWINSZ));
  405. sol_map_borrow_name(state, mod, "TIOCSWINSZ", sol_new_int(state, TIOCSWINSZ));
  406. sol_map_borrow_name(state, mod, "open", sol_new_cfunc(state, sol_f_stream_open, "io.open"));
  407. sol_map_borrow_name(state, mod, "__setindex", sol_new_cfunc(state, sol_f_io_setindex, "io.__setindex"));
  408. sol_map_borrow_name(state, mod, "__index", sol_new_cfunc(state, sol_f_io_index, "io.__index"));
  409. sol_register_module_name(state, "io", mod);
  410. sol_obj_free(mod);
  411. meths = sol_new_map(state);
  412. sol_map_borrow_name(state, meths, "get", sol_new_cfunc(state, sol_f_buffer_get, "buffer.get"));
  413. sol_map_borrow_name(state, meths, "set", sol_new_cfunc(state, sol_f_buffer_set, "buffer.set"));
  414. sol_map_borrow_name(state, meths, "address", sol_new_cfunc(state, sol_f_buffer_address, "buffer.address"));
  415. sol_map_borrow_name(state, meths, "size", sol_new_cfunc(state, sol_f_buffer_size, "buffer.size"));
  416. sol_map_borrow_name(state, meths, "sub", sol_new_cfunc(state, sol_f_buffer_sub, "buffer.sub"));
  417. sol_map_borrow_name(state, meths, "split", sol_new_cfunc(state, sol_f_buffer_split, "buffer.split"));
  418. sol_map_borrow_name(state, meths, "find", sol_new_cfunc(state, sol_f_buffer_find, "buffer.find"));
  419. sol_register_methods_name(state, "buffer", meths);
  420. sol_obj_free(meths);
  421. meths = sol_new_map(state);
  422. sol_map_borrow_name(state, meths, "copy", sol_new_cfunc(state, sol_f_list_copy, "list.copy"));
  423. sol_map_borrow_name(state, meths, "insert", sol_new_cfunc(state, sol_f_list_insert, "list.insert"));
  424. sol_map_borrow_name(state, meths, "remove", sol_new_cfunc(state, sol_f_list_remove, "list.remove"));
  425. sol_map_borrow_name(state, meths, "truncate", sol_new_cfunc(state, sol_f_list_truncate, "list.truncate"));
  426. sol_map_borrow_name(state, meths, "map", sol_new_cfunc(state, sol_f_list_map, "list.map"));
  427. sol_map_borrow_name(state, meths, "filter", sol_new_cfunc(state, sol_f_list_filter, "list.filter"));
  428. sol_map_borrow_name(state, meths, "reduce", sol_new_cfunc(state, sol_f_list_reduce, "list.reduce"));
  429. sol_register_methods_name(state, "list", meths);
  430. sol_obj_free(meths);
  431. meths = sol_new_map(state);
  432. sol_map_borrow_name(state, meths, "read", sol_new_cfunc(state, sol_f_stream_read_buffer, "stream.read_buffer"));
  433. sol_map_borrow_name(state, meths, "read_buffer", sol_new_cfunc(state, sol_f_stream_read_buffer, "stream.read_buffer"));
  434. sol_map_borrow_name(state, meths, "write", sol_new_cfunc(state, sol_f_stream_write, "stream.write"));
  435. sol_map_borrow_name(state, meths, "seek", sol_new_cfunc(state, sol_f_stream_seek, "stream.seek"));
  436. sol_map_borrow_name(state, meths, "tell", sol_new_cfunc(state, sol_f_stream_tell, "stream.tell"));
  437. sol_map_borrow_name(state, meths, "flush", sol_new_cfunc(state, sol_f_stream_flush, "stream.flush"));
  438. sol_map_borrow_name(state, meths, "eof", sol_new_cfunc(state, sol_f_stream_eof, "stream.eof"));
  439. sol_map_borrow_name(state, meths, "ioctl", sol_new_cfunc(state, sol_f_stream_ioctl, "stream.ioctl"));
  440. sol_register_methods_name(state, "stream", meths);
  441. sol_obj_free(meths);
  442. meths = sol_new_map(state);
  443. sol_map_borrow_name(state, meths, "sub", sol_new_cfunc(state, sol_f_str_sub, "str.sub"));
  444. sol_map_borrow_name(state, meths, "split", sol_new_cfunc(state, sol_f_str_split, "str.split"));
  445. sol_map_borrow_name(state, meths, "find", sol_new_cfunc(state, sol_f_str_find, "str.find"));
  446. sol_register_methods_name(state, "string", meths);
  447. sol_obj_free(meths);
  448. state->fnstack = sol_new_list(state);
  449. if(sol_has_error(state)) {
  450. goto cleanup;
  451. }
  452. // Perform initialization based on the user profile, if so requested.
  453. if(!(state->features & SOL_FT_NO_USR_INIT)) {
  454. for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {
  455. fp = fopen(sol_AbsInitPaths[i], "r");
  456. if(state->features & SOL_FT_DEBUG) {
  457. printf("state init: loading abs %s: ", sol_AbsInitPaths[i]);
  458. }
  459. if(fp) {
  460. if(state->features & SOL_FT_DEBUG) {
  461. printf("found");
  462. }
  463. stmt = sol_compile_file(fp);
  464. sol_exec(state, stmt);
  465. st_free(stmt);
  466. fclose(fp);
  467. } else {
  468. if(state->features & SOL_FT_DEBUG) {
  469. printf("not found");
  470. }
  471. }
  472. if(state->features & SOL_FT_DEBUG) {
  473. printf("\n");
  474. }
  475. }
  476. suffix = getenv("HOME");
  477. if(state->features & SOL_FT_DEBUG) {
  478. printf("state init: loading relative to %s\n", suffix);
  479. }
  480. if(suffix) {
  481. strncpy(sol_TempPath, suffix, TMP_PATH_SZ);
  482. suffix = sol_TempPath + strlen(sol_TempPath);
  483. for(i = 0; i < LENGTH(sol_HomeInitPaths); i++) {
  484. strncpy(suffix, sol_HomeInitPaths[i], TMP_PATH_SZ - (suffix - sol_TempPath));
  485. if(state->features & SOL_FT_DEBUG) {
  486. printf("state init: loading rel %s: ", sol_TempPath);
  487. }
  488. fp = fopen(sol_TempPath, "r");
  489. if(fp) {
  490. if(state->features & SOL_FT_DEBUG) {
  491. printf("found");
  492. }
  493. stmt = sol_compile_file(fp);
  494. sol_exec(state, stmt);
  495. st_free(stmt);
  496. fclose(fp);
  497. } else {
  498. if(state->features & SOL_FT_DEBUG) {
  499. printf("not found");
  500. }
  501. }
  502. if(state->features & SOL_FT_DEBUG) {
  503. printf("\n");
  504. }
  505. }
  506. }
  507. if(sol_has_error(state)) {
  508. goto cleanup;
  509. }
  510. }
  511. // We're all set!
  512. return 1;
  513. cleanup:
  514. sol_obj_free(state->None);
  515. sol_obj_free(state->OutOfMemory);
  516. return 0;
  517. }
  518. void sol_state_cleanup(sol_state_t *state) {
  519. long i;
  520. sol_obj_free(state->scopes);
  521. sol_obj_free(state->error);
  522. sol_obj_free(state->None);
  523. sol_obj_free(state->OutOfMemory);
  524. sol_obj_free(state->_stdin);
  525. sol_obj_free(state->_stdout);
  526. sol_obj_free(state->_stderr);
  527. if(state->ret) {
  528. sol_obj_free(state->ret);
  529. }
  530. #ifdef SOL_ICACHE
  531. for(i = 0; i <= (SOL_ICACHE_MAX - SOL_ICACHE_MIN); i++) {
  532. sol_obj_free(state->icache[i]);
  533. }
  534. #endif
  535. sol_obj_free(state->modules);
  536. sol_obj_free(state->methods);
  537. sol_mm_finalize(state);
  538. }
  539. sol_object_t *sol_state_resolve(sol_state_t *state, sol_object_t *key) {
  540. sol_object_t *temp, *args;
  541. dsl_seq_iter *iter = dsl_new_seq_iter(state->scopes->seq);
  542. args = sol_new_list(state);
  543. sol_list_insert(state, args, 0, state->None);
  544. sol_list_insert(state, args, 1, key);
  545. while(!dsl_seq_iter_is_invalid(iter)) {
  546. sol_list_set_index(state, args, 0, dsl_seq_iter_at(iter));
  547. temp = CALL_METHOD(state, ((sol_object_t *) dsl_seq_iter_at(iter)), index, args);
  548. if(!sol_is_none(state, temp)) {
  549. dsl_free_seq_iter(iter);
  550. sol_obj_free(args);
  551. return temp;
  552. }
  553. sol_obj_free(temp);
  554. dsl_seq_iter_next(iter);
  555. }
  556. dsl_free_seq_iter(iter);
  557. sol_obj_free(args);
  558. temp = sol_get_module(state, key);
  559. if(!sol_is_none(state, temp)) {
  560. return temp;
  561. }
  562. sol_obj_free(temp);
  563. return sol_incref(state->None);
  564. }
  565. sol_object_t *sol_state_resolve_name(sol_state_t *state, const char *name) {
  566. sol_object_t *key = sol_new_buffer(state, (char *) name, strlen(name), OWN_NONE, NULL, NULL), *temp;
  567. if(sol_has_error(state)) {
  568. return sol_incref(state->None);
  569. }
  570. temp = sol_state_resolve(state, key);
  571. sol_obj_free(key);
  572. return temp;
  573. }
  574. void sol_state_assign(sol_state_t *state, sol_object_t *key, sol_object_t *val) {
  575. sol_object_t *cur = state->scopes, *next, *active = NULL, *args;
  576. if(!cur) {
  577. sol_set_error_string(state, "Global state does not exist");
  578. return;
  579. }
  580. active = sol_list_get_index(state, state->scopes, sol_list_len(state, state->scopes) - 1);
  581. if(!active || sol_is_none(state, cur)) {
  582. sol_set_error_string(state, "No scopes exist");
  583. return;
  584. }
  585. args = sol_new_list(state);
  586. sol_list_insert(state, args, 0, active);
  587. sol_list_insert(state, args, 1, key);
  588. sol_list_insert(state, args, 2, val);
  589. sol_obj_free(CALL_METHOD(state, active, setindex, args));
  590. sol_obj_free(args);
  591. }
  592. void sol_state_assign_name(sol_state_t *state, const char *name, sol_object_t *val) {
  593. sol_object_t *key = sol_new_buffer(state, (char *) name, strlen(name), OWN_NONE, NULL, NULL);
  594. if(sol_has_error(state)) {
  595. return;
  596. }
  597. sol_state_assign(state, key, val);
  598. sol_obj_free(key);
  599. }
  600. void sol_state_assign_l(sol_state_t *state, sol_object_t *key, sol_object_t *val) {
  601. sol_object_t *cur = state->scopes, *args;
  602. cur = sol_list_get_index(state, state->scopes, 0);
  603. if(!cur || sol_is_none(state, cur)) {
  604. sol_set_error_string(state, "Local state does not exist");
  605. return;
  606. }
  607. args = sol_new_list(state);
  608. sol_list_insert(state, args, 0, cur);
  609. sol_list_insert(state, args, 1, key);
  610. sol_list_insert(state, args, 2, val);
  611. sol_obj_free(CALL_METHOD(state, cur, setindex, args));
  612. sol_obj_free(args);
  613. }
  614. void sol_state_assign_l_name(sol_state_t *state, const char *name, sol_object_t *val) {
  615. sol_object_t *key = sol_new_buffer(state, (char *) name, strlen(name), OWN_NONE, NULL, NULL);
  616. if(sol_has_error(state)) {
  617. return;
  618. }
  619. sol_state_assign_l(state, key, val);
  620. sol_obj_free(key);
  621. }
  622. void sol_state_push_scope(sol_state_t *state, sol_object_t *scope) {
  623. sol_list_push(state, state->scopes, scope);
  624. }
  625. sol_object_t *sol_state_pop_scope(sol_state_t *state) {
  626. return sol_list_pop(state, state->scopes);
  627. }
  628. sol_object_t *sol_get_error(sol_state_t *state) {
  629. return sol_incref(state->error);
  630. }
  631. sol_object_t *sol_set_error(sol_state_t *state, sol_object_t *err) {
  632. state->error = sol_incref(err);
  633. sol_init_traceback(state);
  634. return sol_incref(state->None);
  635. }
  636. sol_object_t *sol_set_error_string(sol_state_t *state, const char *serr) {
  637. sol_object_t *err = sol_new_buffer(state, strdup(serr), strlen(serr), OWN_FREE, NULL, NULL), *res;
  638. if(sol_has_error(state)) {
  639. sol_obj_free(err);
  640. return sol_incref(state->None);
  641. }
  642. res = sol_set_error(state, err);
  643. sol_obj_free(err);
  644. return res;
  645. }
  646. void sol_clear_error(sol_state_t *state) {
  647. // This silliness ensures we don't accidentally free None.
  648. sol_object_t *olderr = state->error;
  649. state->error = sol_incref(state->None);
  650. sol_obj_free(olderr);
  651. }
  652. void sol_init_traceback(sol_state_t *state) {
  653. if(state->traceback) {
  654. sol_obj_free(state->traceback);
  655. }
  656. state->traceback = sol_new_list(state);
  657. }
  658. void sol_add_traceback(sol_state_t *state, sol_object_t *node) {
  659. sol_object_t *pair = sol_new_list(state), *scope = sol_list_get_index(state, state->scopes, 0);
  660. sol_list_insert(state, pair, 0, node);
  661. sol_list_insert(state, pair, 1, scope);
  662. sol_obj_free(scope);
  663. if(sol_list_len(state, state->fnstack) > 0) {
  664. scope = sol_list_get_index(state, state->fnstack, 0);
  665. sol_list_insert(state, pair, 2, scope);
  666. sol_obj_free(scope);
  667. } else {
  668. sol_list_insert(state, pair, 2, state->None);
  669. }
  670. sol_list_insert(state, state->traceback, 0, pair);
  671. sol_obj_free(pair);
  672. }
  673. sol_object_t *sol_traceback(sol_state_t *state) {
  674. if(state->traceback) {
  675. return sol_incref(state->traceback);
  676. }
  677. return sol_incref(state->None);
  678. }
  679. void sol_register_module(sol_state_t *state, sol_object_t *key, sol_object_t *val) {
  680. sol_map_set(state, state->modules, key, val);
  681. }
  682. void sol_register_module_name(sol_state_t *state, char *name, sol_object_t *val) {
  683. sol_map_set_name(state, state->modules, name, val);
  684. }
  685. sol_object_t *sol_get_module(sol_state_t *state, sol_object_t *key) {
  686. return sol_map_get(state, state->modules, key);
  687. }
  688. sol_object_t *sol_get_module_name(sol_state_t *state, char *name) {
  689. return sol_map_get_name(state, state->modules, name);
  690. }
  691. void sol_register_methods(sol_state_t *state, sol_object_t *key, sol_object_t *val) {
  692. sol_map_set(state, state->methods, key, val);
  693. }
  694. void sol_register_methods_name(sol_state_t *state, char *name, sol_object_t *val) {
  695. sol_map_set_name(state, state->methods, name, val);
  696. }
  697. sol_object_t *sol_get_methods(sol_state_t *state, sol_object_t *key) {
  698. return sol_map_get(state, state->methods, key);
  699. }
  700. sol_object_t *sol_get_methods_name(sol_state_t *state, char *name) {
  701. return sol_map_get_name(state, state->methods, name);
  702. }
  703. sol_object_t *sol_f_io_index(sol_state_t *state, sol_object_t *args) {
  704. sol_object_t *self = sol_list_get_index(state, args, 0), *name = sol_list_get_index(state, args, 1), *namestr = sol_cast_string(state, name), *res;
  705. if(sol_string_eq(state, namestr, "stdin")) {
  706. sol_obj_free(name);
  707. sol_obj_free(namestr);
  708. return sol_incref(state->_stdin);
  709. }
  710. if(sol_string_eq(state, namestr, "stdout")) {
  711. sol_obj_free(name);
  712. sol_obj_free(namestr);
  713. return sol_incref(state->_stdout);
  714. }
  715. if(sol_string_eq(state, namestr, "stderr")) {
  716. sol_obj_free(name);
  717. sol_obj_free(namestr);
  718. return sol_incref(state->_stderr);
  719. }
  720. sol_obj_free(namestr);
  721. res = sol_map_get(state, self, name);
  722. sol_obj_free(self);
  723. sol_obj_free(name);
  724. return res;
  725. }
  726. sol_object_t *sol_f_io_setindex(sol_state_t *state, sol_object_t *args) {
  727. sol_object_t *name = sol_list_get_index(state, args, 1), *value = sol_list_get_index(state, args, 2);
  728. sol_object_t *namestr = sol_cast_string(state, name), *io;
  729. if(sol_string_eq(state, namestr, "stdin")) {
  730. sol_obj_free(state->_stdin);
  731. state->_stdin = sol_incref(value);
  732. goto done;
  733. }
  734. if(sol_string_eq(state, namestr, "stdout")) {
  735. sol_obj_free(state->_stdout);
  736. state->_stdout = sol_incref(value);
  737. goto done;
  738. }
  739. if(sol_string_eq(state, namestr, "stderr")) {
  740. sol_obj_free(state->_stderr);
  741. state->_stderr = sol_incref(value);
  742. goto done;
  743. }
  744. io = sol_list_get_index(state, args, 0);
  745. sol_map_set(state, io, name, value);
  746. sol_obj_free(io);
  747. done:
  748. sol_obj_free(namestr);
  749. sol_obj_free(value);
  750. sol_obj_free(name);
  751. return sol_incref(state->None);
  752. }
  753. sol_object_t *sol_get_stdin(sol_state_t *state) {
  754. return sol_incref(state->_stdin);
  755. }
  756. sol_object_t *sol_get_stdout(sol_state_t *state) {
  757. return sol_incref(state->_stdout);
  758. }
  759. sol_object_t *sol_get_stderr(sol_state_t *state) {
  760. return sol_incref(state->_stderr);
  761. }
  762. void sol_ops_init(sol_ops_t *ops) {
  763. ops->tname = "unknown";
  764. ops->add = sol_f_not_impl;
  765. ops->sub = sol_f_not_impl;
  766. ops->mul = sol_f_not_impl;
  767. ops->div = sol_f_not_impl;
  768. ops->mod = sol_f_not_impl;
  769. ops->pow = sol_f_not_impl;
  770. ops->tbang = sol_f_tbang;
  771. ops->band = sol_f_not_impl;
  772. ops->bor = sol_f_not_impl;
  773. ops->bxor = sol_f_not_impl;
  774. ops->blsh = sol_f_not_impl;
  775. ops->brsh = sol_f_not_impl;
  776. ops->bnot = sol_f_not_impl;
  777. ops->cmp = sol_f_default_cmp;
  778. ops->call = sol_f_not_impl;
  779. ops->index = sol_f_not_impl;
  780. ops->setindex = sol_f_not_impl;
  781. ops->len = sol_f_not_impl;
  782. ops->iter = sol_f_not_impl;
  783. ops->toint = sol_f_not_impl;
  784. ops->tofloat = sol_f_not_impl;
  785. ops->tostring = sol_f_default_tostring;
  786. ops->tobuffer = sol_f_default_tobuffer;
  787. ops->repr = sol_f_default_repr;
  788. ops->init = sol_f_no_op;
  789. ops->free = sol_f_no_op;
  790. }