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.

488 lines
18 KiB

  1. #ifndef SOL_H
  2. #define SOL_H
  3. #ifndef NULL
  4. #define NULL ((void *) 0)
  5. #endif
  6. #include <stdio.h>
  7. #include "dsl/dsl.h"
  8. // Forward declarations:
  9. struct sol_tag_object_t;
  10. typedef struct sol_tag_object_t sol_object_t;
  11. struct sol_tag_state_t;
  12. typedef struct sol_tag_state_t sol_state_t;
  13. typedef sol_object_t *(*sol_cfunc_t)(sol_state_t *, sol_object_t *);
  14. typedef void (*sol_printfunc_t)(sol_object_t *);
  15. typedef struct {
  16. char *tname;
  17. sol_cfunc_t add;
  18. sol_cfunc_t sub;
  19. sol_cfunc_t mul;
  20. sol_cfunc_t div;
  21. sol_cfunc_t mod;
  22. sol_cfunc_t pow;
  23. sol_cfunc_t band;
  24. sol_cfunc_t bor;
  25. sol_cfunc_t bxor;
  26. sol_cfunc_t blsh;
  27. sol_cfunc_t brsh;
  28. sol_cfunc_t bnot;
  29. sol_cfunc_t cmp;
  30. sol_cfunc_t call;
  31. sol_cfunc_t index;
  32. sol_cfunc_t setindex;
  33. sol_cfunc_t len;
  34. sol_cfunc_t iter;
  35. sol_cfunc_t toint;
  36. sol_cfunc_t tofloat;
  37. sol_cfunc_t tostring;
  38. sol_cfunc_t repr;
  39. sol_cfunc_t init;
  40. sol_cfunc_t free;
  41. } sol_ops_t;
  42. typedef enum {
  43. SOL_SINGLET,
  44. SOL_INTEGER,
  45. SOL_FLOAT,
  46. SOL_STRING,
  47. SOL_LIST,
  48. SOL_MAP,
  49. SOL_MCELL,
  50. SOL_FUNCTION,
  51. SOL_CFUNCTION,
  52. SOL_STMT,
  53. SOL_EXPR,
  54. SOL_BUFFER,
  55. SOL_DYLIB,
  56. SOL_DYSYM,
  57. SOL_STREAM,
  58. SOL_CDATA
  59. } sol_objtype_t;
  60. typedef enum {
  61. BUF_NONE,
  62. BUF_INT8,
  63. BUF_INT16,
  64. BUF_INT32,
  65. BUF_INT64,
  66. BUF_UINT8,
  67. BUF_UINT16,
  68. BUF_UINT32,
  69. BUF_UINT64,
  70. BUF_CHAR,
  71. BUF_BYTE,
  72. BUF_INT,
  73. BUF_UINT,
  74. BUF_LONG,
  75. BUF_ULONG,
  76. BUF_FLOAT,
  77. BUF_DOUBLE,
  78. BUF_CSTR,
  79. BUF_PTR
  80. } sol_buftype_t;
  81. typedef enum {
  82. OWN_NONE,
  83. OWN_FREE,
  84. OWN_CALLF
  85. } sol_owntype_t;
  86. typedef enum {
  87. MODE_READ = 1,
  88. MODE_WRITE = 2,
  89. MODE_APPEND = 4,
  90. MODE_TRUNCATE = 8,
  91. MODE_BINARY = 16
  92. } sol_modes_t;
  93. typedef void (*sol_freefunc_t)(void *, size_t);
  94. typedef void *(*sol_movefunc_t)(void *, size_t);
  95. typedef struct sol_tag_object_t {
  96. sol_objtype_t type;
  97. int refcnt;
  98. sol_ops_t *ops;
  99. union {
  100. long ival;
  101. double fval;
  102. char *str;
  103. dsl_seq *seq;
  104. struct {
  105. struct sol_tag_object_t *key;
  106. struct sol_tag_object_t *val;
  107. };
  108. struct {
  109. void *func; // Actually a stmt_node *
  110. void *args; // Actually an identlist_node *
  111. struct sol_tag_object_t *closure;
  112. struct sol_tag_object_t *udata;
  113. char *fname;
  114. };
  115. sol_cfunc_t cfunc;
  116. void *node;
  117. struct {
  118. void *buffer;
  119. ssize_t sz;
  120. sol_owntype_t own;
  121. sol_freefunc_t freef;
  122. sol_movefunc_t movef;
  123. };
  124. void *dlhandle;
  125. struct {
  126. void *dlsym;
  127. dsl_seq *argtp;
  128. sol_buftype_t rettp;
  129. };
  130. struct {
  131. FILE *stream;
  132. sol_modes_t modes;
  133. };
  134. void *cdata;
  135. };
  136. } sol_object_t;
  137. typedef enum {SF_NORMAL, SF_BREAKING, SF_CONTINUING} sol_state_flag_t;
  138. typedef struct sol_tag_state_t {
  139. sol_object_t *scopes; // A list of scope maps, innermost out, ending at the global scope
  140. sol_object_t *ret; // Return value of this function, for early return
  141. sol_state_flag_t sflag; // Used to implement break/continue
  142. sol_object_t *error; // Some arbitrary error descriptor, None if no error
  143. sol_object_t *None;
  144. sol_object_t *OutOfMemory;
  145. sol_object_t *StopIteration;
  146. sol_ops_t NullOps;
  147. sol_ops_t SingletOps;
  148. sol_ops_t IntOps;
  149. sol_ops_t FloatOps;
  150. sol_ops_t StringOps;
  151. sol_ops_t ListOps;
  152. sol_ops_t MapOps;
  153. sol_ops_t MCellOps;
  154. sol_ops_t FuncOps;
  155. sol_ops_t CFuncOps;
  156. sol_ops_t ASTNodeOps;
  157. sol_ops_t BufferOps;
  158. sol_ops_t DyLibOps;
  159. sol_ops_t DySymOps;
  160. sol_ops_t StreamOps;
  161. sol_object_t *modules;
  162. sol_object_t *methods;
  163. dsl_object_funcs obfuncs;
  164. } sol_state_t;
  165. // state.c
  166. int sol_state_init(sol_state_t *);
  167. void sol_state_cleanup(sol_state_t *);
  168. sol_object_t *sol_state_resolve(sol_state_t *, sol_object_t *);
  169. sol_object_t *sol_state_resolve_name(sol_state_t *, const char *);
  170. void sol_state_assign(sol_state_t *, sol_object_t *, sol_object_t *);
  171. void sol_state_assign_name(sol_state_t *, const char *, sol_object_t *);
  172. void sol_state_assign_l(sol_state_t *, sol_object_t *, sol_object_t *);
  173. void sol_state_assign_l_name(sol_state_t *, const char *, sol_object_t *);
  174. void sol_state_push_scope(sol_state_t *, sol_object_t *);
  175. sol_object_t *sol_state_pop_scope(sol_state_t *);
  176. sol_object_t *sol_get_error(sol_state_t *);
  177. sol_object_t *sol_set_error(sol_state_t *, sol_object_t *);
  178. sol_object_t *sol_set_error_string(sol_state_t *, const char *);
  179. void sol_clear_error(sol_state_t *);
  180. void sol_register_module(sol_state_t *, sol_object_t *, sol_object_t *);
  181. void sol_register_module_name(sol_state_t *, char *, sol_object_t *);
  182. sol_object_t *sol_get_module(sol_state_t *, sol_object_t *);
  183. sol_object_t *sol_get_module_name(sol_state_t *, char *);
  184. void sol_register_methods(sol_state_t *, sol_object_t *, sol_object_t *);
  185. void sol_register_methods_name(sol_state_t *, char *, sol_object_t *);
  186. sol_object_t *sol_get_methods(sol_state_t *, sol_object_t *);
  187. sol_object_t *sol_get_methods_name(sol_state_t *, char *);
  188. sol_object_t *sol_get_stdin(sol_state_t *);
  189. sol_object_t *sol_get_stdout(sol_state_t *);
  190. sol_object_t *sol_get_stderr(sol_state_t *);
  191. void sol_ops_init(sol_ops_t *);
  192. // builtins.c
  193. sol_object_t *sol_f_not_impl(sol_state_t *, sol_object_t *);
  194. sol_object_t *sol_f_no_op(sol_state_t *, sol_object_t *);
  195. sol_object_t *sol_f_default_cmp(sol_state_t *, sol_object_t *);
  196. sol_object_t *sol_f_default_tostring(sol_state_t *, sol_object_t *);
  197. sol_object_t *sol_f_default_repr(sol_state_t *, sol_object_t *);
  198. sol_object_t *sol_f_toint(sol_state_t *, sol_object_t *);
  199. sol_object_t *sol_f_tofloat(sol_state_t *, sol_object_t *);
  200. sol_object_t *sol_f_tostring(sol_state_t *, sol_object_t *);
  201. sol_object_t *sol_f_try(sol_state_t *, sol_object_t *);
  202. sol_object_t *sol_f_error(sol_state_t *, sol_object_t *);
  203. sol_object_t *sol_f_type(sol_state_t *, sol_object_t *);
  204. sol_object_t *sol_f_prepr(sol_state_t *, sol_object_t *);
  205. sol_object_t *sol_f_print(sol_state_t *, sol_object_t *);
  206. sol_object_t *sol_f_rawget(sol_state_t *, sol_object_t *);
  207. sol_object_t *sol_f_rawset(sol_state_t *, sol_object_t *);
  208. sol_object_t *sol_f_range(sol_state_t *, sol_object_t *);
  209. sol_object_t *sol_f_exec(sol_state_t *, sol_object_t *);
  210. sol_object_t *sol_f_eval(sol_state_t *, sol_object_t *);
  211. sol_object_t *sol_f_execfile(sol_state_t *, sol_object_t *);
  212. sol_object_t *sol_f_parse(sol_state_t *, sol_object_t *);
  213. sol_object_t *sol_f_debug_getref(sol_state_t *, sol_object_t *);
  214. sol_object_t *sol_f_debug_setref(sol_state_t *, sol_object_t *);
  215. sol_object_t *sol_f_debug_closure(sol_state_t *, sol_object_t *);
  216. sol_object_t *sol_f_debug_globals(sol_state_t *, sol_object_t *);
  217. sol_object_t *sol_f_debug_locals(sol_state_t *, sol_object_t *);
  218. sol_object_t *sol_f_debug_scopes(sol_state_t *, sol_object_t *);
  219. sol_object_t *sol_f_iter_str(sol_state_t *, sol_object_t *);
  220. sol_object_t *sol_f_iter_list(sol_state_t *, sol_object_t *);
  221. sol_object_t *sol_f_iter_map(sol_state_t *, sol_object_t *);
  222. sol_object_t *sol_f_singlet_tostring(sol_state_t *, sol_object_t *);
  223. sol_object_t *sol_f_int_add(sol_state_t *, sol_object_t *);
  224. sol_object_t *sol_f_int_sub(sol_state_t *, sol_object_t *);
  225. sol_object_t *sol_f_int_mul(sol_state_t *, sol_object_t *);
  226. sol_object_t *sol_f_int_div(sol_state_t *, sol_object_t *);
  227. sol_object_t *sol_f_int_mod(sol_state_t *, sol_object_t *);
  228. sol_object_t *sol_f_int_pow(sol_state_t *, sol_object_t *);
  229. sol_object_t *sol_f_int_band(sol_state_t *, sol_object_t *);
  230. sol_object_t *sol_f_int_bor(sol_state_t *, sol_object_t *);
  231. sol_object_t *sol_f_int_bxor(sol_state_t *, sol_object_t *);
  232. sol_object_t *sol_f_int_blsh(sol_state_t *, sol_object_t *);
  233. sol_object_t *sol_f_int_brsh(sol_state_t *, sol_object_t *);
  234. sol_object_t *sol_f_int_bnot(sol_state_t *, sol_object_t *);
  235. sol_object_t *sol_f_int_cmp(sol_state_t *, sol_object_t *);
  236. sol_object_t *sol_f_int_toint(sol_state_t *, sol_object_t *);
  237. sol_object_t *sol_f_int_tofloat(sol_state_t *, sol_object_t *);
  238. sol_object_t *sol_f_int_tostring(sol_state_t *, sol_object_t *);
  239. sol_object_t *sol_f_float_add(sol_state_t *, sol_object_t *);
  240. sol_object_t *sol_f_float_sub(sol_state_t *, sol_object_t *);
  241. sol_object_t *sol_f_float_mul(sol_state_t *, sol_object_t *);
  242. sol_object_t *sol_f_float_div(sol_state_t *, sol_object_t *);
  243. sol_object_t *sol_f_float_pow(sol_state_t *, sol_object_t *);
  244. sol_object_t *sol_f_float_cmp(sol_state_t *, sol_object_t *);
  245. sol_object_t *sol_f_float_toint(sol_state_t *, sol_object_t *);
  246. sol_object_t *sol_f_float_tofloat(sol_state_t *, sol_object_t *);
  247. sol_object_t *sol_f_float_tostring(sol_state_t *, sol_object_t *);
  248. sol_object_t *sol_f_str_add(sol_state_t *, sol_object_t *);
  249. sol_object_t *sol_f_str_mul(sol_state_t *, sol_object_t *);
  250. sol_object_t *sol_f_str_len(sol_state_t *, sol_object_t *);
  251. sol_object_t *sol_f_str_iter(sol_state_t *, sol_object_t *);
  252. sol_object_t *sol_f_str_cmp(sol_state_t *, sol_object_t *);
  253. sol_object_t *sol_f_str_index(sol_state_t *, sol_object_t *);
  254. sol_object_t *sol_f_str_toint(sol_state_t *, sol_object_t *);
  255. sol_object_t *sol_f_str_tofloat(sol_state_t *, sol_object_t *);
  256. sol_object_t *sol_f_str_tostring(sol_state_t *, sol_object_t *);
  257. sol_object_t *sol_f_str_repr(sol_state_t *, sol_object_t *);
  258. sol_object_t *sol_f_list_add(sol_state_t *, sol_object_t *);
  259. sol_object_t *sol_f_list_mul(sol_state_t *, sol_object_t *);
  260. sol_object_t *sol_f_list_index(sol_state_t *, sol_object_t *);
  261. sol_object_t *sol_f_list_setindex(sol_state_t *, sol_object_t *);
  262. sol_object_t *sol_f_list_len(sol_state_t *, sol_object_t *);
  263. sol_object_t *sol_f_list_iter(sol_state_t *, sol_object_t *);
  264. sol_object_t *sol_f_list_tostring(sol_state_t *, sol_object_t *);
  265. sol_object_t *sol_f_list_copy(sol_state_t *, sol_object_t *);
  266. sol_object_t *sol_f_list_insert(sol_state_t *, sol_object_t *);
  267. sol_object_t *sol_f_list_remove(sol_state_t *, sol_object_t *);
  268. sol_object_t *sol_f_list_truncate(sol_state_t *, sol_object_t *);
  269. sol_object_t *sol_f_list_map(sol_state_t *, sol_object_t *);
  270. sol_object_t *sol_f_list_filter(sol_state_t *, sol_object_t *);
  271. sol_object_t *sol_f_map_add(sol_state_t *, sol_object_t *);
  272. sol_object_t *sol_f_map_index(sol_state_t *, sol_object_t *);
  273. sol_object_t *sol_f_map_setindex(sol_state_t *, sol_object_t *);
  274. sol_object_t *sol_f_map_call(sol_state_t *, sol_object_t *);
  275. sol_object_t *sol_f_map_len(sol_state_t *, sol_object_t *);
  276. sol_object_t *sol_f_map_iter(sol_state_t *, sol_object_t *);
  277. sol_object_t *sol_f_map_tostring(sol_state_t *, sol_object_t *);
  278. sol_object_t *sol_f_mcell_tostring(sol_state_t *, sol_object_t *);
  279. sol_object_t *sol_f_func_call(sol_state_t *, sol_object_t *); // Defined in ast.c
  280. sol_object_t *sol_f_func_index(sol_state_t *, sol_object_t *);
  281. sol_object_t *sol_f_func_setindex(sol_state_t *, sol_object_t *);
  282. sol_object_t *sol_f_func_tostring(sol_state_t *, sol_object_t *);
  283. sol_object_t *sol_f_cfunc_call(sol_state_t *, sol_object_t *);
  284. sol_object_t *sol_f_cfunc_tostring(sol_state_t *, sol_object_t *);
  285. sol_object_t *sol_f_astnode_call(sol_state_t *, sol_object_t *);
  286. sol_object_t *sol_f_astnode_index(sol_state_t *, sol_object_t *);
  287. sol_object_t *sol_f_astnode_setindex(sol_state_t *, sol_object_t *);
  288. sol_object_t *sol_f_astnode_tostring(sol_state_t *, sol_object_t *);
  289. sol_object_t *sol_f_buffer_index(sol_state_t *, sol_object_t *);
  290. sol_object_t *sol_f_buffer_tostring(sol_state_t *, sol_object_t *);
  291. sol_object_t *sol_f_buffer_get(sol_state_t *, sol_object_t *);
  292. sol_object_t *sol_f_buffer_set(sol_state_t *, sol_object_t *);
  293. sol_object_t *sol_f_buffer_address(sol_state_t *, sol_object_t *);
  294. sol_object_t *sol_f_buffer_size(sol_state_t *, sol_object_t *);
  295. sol_object_t *sol_f_buffer_new(sol_state_t *, sol_object_t *);
  296. sol_object_t *sol_f_buffer_fromstring(sol_state_t *, sol_object_t *);
  297. sol_object_t *sol_f_buffer_fromobject(sol_state_t *, sol_object_t *);
  298. sol_object_t *sol_f_buffer_fromaddress(sol_state_t *, sol_object_t *);
  299. sol_object_t *sol_f_dylib_index(sol_state_t *, sol_object_t *);
  300. sol_object_t *sol_f_dylib_tostring(sol_state_t *, sol_object_t *);
  301. sol_object_t *sol_f_dylib_open(sol_state_t *, sol_object_t *);
  302. sol_object_t *sol_f_dysym_call(sol_state_t *, sol_object_t *);
  303. sol_object_t *sol_f_dysym_index(sol_state_t *, sol_object_t *);
  304. sol_object_t *sol_f_dysym_setindex(sol_state_t *, sol_object_t *);
  305. sol_object_t *sol_f_dysym_tostring(sol_state_t *, sol_object_t *);
  306. sol_object_t *sol_f_dysym_get(sol_state_t *, sol_object_t *);
  307. sol_object_t *sol_f_dysym_set(sol_state_t *, sol_object_t *);
  308. sol_object_t *sol_f_stream_blsh(sol_state_t *, sol_object_t *);
  309. sol_object_t *sol_f_stream_brsh(sol_state_t *, sol_object_t *);
  310. sol_object_t *sol_f_stream_index(sol_state_t *, sol_object_t *);
  311. sol_object_t *sol_f_stream_tostring(sol_state_t *, sol_object_t *);
  312. sol_object_t *sol_f_stream_write(sol_state_t *, sol_object_t *);
  313. sol_object_t *sol_f_stream_read(sol_state_t *, sol_object_t *);
  314. sol_object_t *sol_f_stream_seek(sol_state_t *, sol_object_t *);
  315. sol_object_t *sol_f_stream_tell(sol_state_t *, sol_object_t *);
  316. sol_object_t *sol_f_stream_flush(sol_state_t *, sol_object_t *);
  317. sol_object_t *sol_f_stream_open(sol_state_t *, sol_object_t *);
  318. // object.c
  319. #define sol_incref(obj) (++((obj)->refcnt), obj)
  320. #define sol_decref(obj) (--((obj)->refcnt))
  321. sol_object_t *sol_obj_acquire(sol_object_t *);
  322. void sol_obj_free(sol_object_t *);
  323. void sol_obj_release(sol_object_t *);
  324. #define sol_is_singlet(obj) ((obj)->type == SOL_SINGLET)
  325. #define sol_is_none(state, obj) ((obj) == state->None)
  326. #define sol_is_oom(state, obj) ((obj) == state->OutOfMemory)
  327. #define sol_is_int(obj) ((obj)-> type == SOL_INTEGER)
  328. #define sol_is_float(obj) ((obj)->type == SOL_FLOAT)
  329. #define sol_is_string(obj) ((obj)->type == SOL_STRING)
  330. #define sol_is_list(obj) ((obj)->type == SOL_LIST)
  331. #define sol_is_map(obj) ((obj)->type == SOL_MAP || (obj)->type == SOL_MCELL)
  332. #define sol_is_func(obj) ((obj)->type == SOL_FUNCTION)
  333. #define sol_is_cfunc(obj) ((obj)->type == SOL_CFUNCTION)
  334. #define sol_is_aststmt(obj) ((obj)->type == SOL_STMT)
  335. #define sol_is_astexpr(obj) ((obj)->type == SOL_EXPR)
  336. #define sol_is_astnode(obj) (sol_is_aststmt(obj) || sol_is_astexpr(obj))
  337. #define sol_is_buffer(obj) ((obj)->type == SOL_BUFFER)
  338. #define sol_is_cdata(obj) ((obj)->type == SOL_CDATA)
  339. #define sol_has_error(state) (!sol_is_none((state), (state)->error))
  340. sol_object_t *sol_alloc_object(sol_state_t *);
  341. sol_object_t *sol_new_singlet(sol_state_t *, const char *);
  342. sol_object_t *sol_new_int(sol_state_t *, long);
  343. sol_object_t *sol_new_float(sol_state_t *, double);
  344. sol_object_t *sol_new_string(sol_state_t *, const char *);
  345. int sol_string_cmp(sol_state_t *, sol_object_t *, const char *);
  346. #define sol_string_eq(state, string, cstr) (sol_string_cmp((state), (string), (cstr))==0)
  347. sol_object_t *sol_string_concat(sol_state_t *, sol_object_t *, sol_object_t *);
  348. sol_object_t *sol_string_concat_cstr(sol_state_t *, sol_object_t *, char *);
  349. sol_object_t *sol_new_list(sol_state_t *);
  350. sol_object_t *sol_list_from_seq(sol_state_t *, dsl_seq *);
  351. int sol_list_len(sol_state_t *, sol_object_t *);
  352. sol_object_t *sol_list_sublist(sol_state_t *, sol_object_t *, int);
  353. sol_object_t *sol_list_get_index(sol_state_t *, sol_object_t *, int);
  354. void sol_list_set_index(sol_state_t *, sol_object_t *, int, sol_object_t *);
  355. void sol_list_insert(sol_state_t *, sol_object_t *, int, sol_object_t *);
  356. sol_object_t *sol_list_remove(sol_state_t *, sol_object_t *, int);
  357. sol_object_t *sol_list_copy(sol_state_t *, sol_object_t *);
  358. sol_object_t *sol_list_truncate(sol_state_t *, sol_object_t *, int);
  359. void sol_list_append(sol_state_t *, sol_object_t *, sol_object_t *);
  360. #define sol_list_push(st, ls, obj) sol_list_insert(st, ls, 0, obj);
  361. #define sol_list_pop(st, ls) sol_list_remove(st, ls, 0);
  362. sol_object_t *sol_new_map(sol_state_t *);
  363. int sol_map_len(sol_state_t *, sol_object_t *);
  364. sol_object_t *sol_map_mcell(sol_state_t *, sol_object_t *, sol_object_t *);
  365. int sol_map_has(sol_state_t *, sol_object_t *, sol_object_t *);
  366. sol_object_t *sol_map_get(sol_state_t *, sol_object_t *, sol_object_t *);
  367. sol_object_t *sol_map_get_name(sol_state_t *, sol_object_t *, char *);
  368. void sol_map_set(sol_state_t *, sol_object_t *, sol_object_t *, sol_object_t *);
  369. void sol_map_set_name(sol_state_t *, sol_object_t *, char *, sol_object_t *);
  370. void sol_map_set_existing(sol_state_t *, sol_object_t *, sol_object_t *, sol_object_t *);
  371. sol_object_t *sol_map_copy(sol_state_t *, sol_object_t *);
  372. void sol_map_merge(sol_state_t *, sol_object_t *, sol_object_t *);
  373. void sol_map_merge_existing(sol_state_t *, sol_object_t *, sol_object_t *);
  374. void sol_map_invert(sol_state_t *, sol_object_t *);
  375. // Defined in ast.h
  376. // sol_object_t *sol_new_func(sol_state_t *, identlist_node *, stmt_node *, char *);
  377. // sol_object_t *sol_new_stmtnode(sol_state_t *, stmt_node *);
  378. // sol_object_t *sol_new_exprnode(sol_state_t *, expr_node *);
  379. sol_object_t *sol_new_cfunc(sol_state_t *, sol_cfunc_t);
  380. sol_object_t *sol_new_cdata(sol_state_t *, void *, sol_ops_t *);
  381. sol_object_t *sol_new_buffer(sol_state_t *, void *, ssize_t, sol_owntype_t, sol_freefunc_t, sol_movefunc_t);
  382. sol_object_t *sol_new_dylib(sol_state_t *, void *);
  383. sol_object_t *sol_new_dysym(sol_state_t *, void *, dsl_seq *, sol_buftype_t);
  384. sol_object_t *sol_new_stream(sol_state_t *, FILE *, sol_modes_t);
  385. size_t sol_stream_printf(sol_state_t *, sol_object_t *, const char *, ...);
  386. size_t sol_stream_scanf(sol_state_t *, sol_object_t *, const char *, ...);
  387. size_t sol_stream_fread(sol_state_t *, sol_object_t *, char *, size_t, size_t);
  388. size_t sol_stream_fwrite(sol_state_t *, sol_object_t *, char *, size_t, size_t);
  389. char *sol_stream_fgets(sol_state_t *, sol_object_t *, char *, size_t);
  390. #define sol_printf(state, ...) sol_stream_printf(state, sol_get_stdout(state), __VA_ARGS__)
  391. #define sol_scanf(state, ...) sol_stream_scanf(state, sol_get_stdin(state, __VA_ARGS__)
  392. #define sol_fread(state, ...) sol_stream_fread(state, sol_get_stdin(state), __VA_ARGS__)
  393. #define sol_fwrite(state, ...) sol_stream_fwrite(state, sol_get_stdout(state), __VA_ARGS__)
  394. int sol_stream_feof(sol_state_t *, sol_object_t *);
  395. int sol_stream_ferror(sol_state_t *, sol_object_t *);
  396. #define sol_stream_ready(state, stream) (!(sol_stream_feof((state), (stream)) || sol_stream_ferror((state), (stream))))
  397. int sol_stream_fseek(sol_state_t *, sol_object_t *, long, int);
  398. long sol_stream_ftell(sol_state_t *, sol_object_t *);
  399. int sol_stream_fflush(sol_state_t *, sol_object_t *);
  400. sol_object_t *sol_cast_int(sol_state_t *, sol_object_t *);
  401. sol_object_t *sol_cast_float(sol_state_t *, sol_object_t *);
  402. sol_object_t *sol_cast_string(sol_state_t *, sol_object_t *);
  403. sol_object_t *sol_cast_repr(sol_state_t *, sol_object_t *);
  404. sol_object_t *sol_f_str_free(sol_state_t *, sol_object_t *);
  405. sol_object_t *sol_f_list_free(sol_state_t *, sol_object_t *);
  406. sol_object_t *sol_f_map_free(sol_state_t *, sol_object_t *);
  407. sol_object_t *sol_f_mcell_free(sol_state_t *, sol_object_t *);
  408. sol_object_t *sol_f_buffer_free(sol_state_t *, sol_object_t *);
  409. sol_object_t *sol_f_dylib_free(sol_state_t *, sol_object_t *);
  410. sol_object_t *sol_f_stream_free(sol_state_t *, sol_object_t *);
  411. int sol_validate_list(sol_state_t *, sol_object_t *);
  412. int sol_validate_map(sol_state_t *, sol_object_t *);
  413. // util.c
  414. sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int *, int, ...);
  415. #define AS_OBJ(x) ((sol_object_t *) (x))
  416. #endif