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.

sol.h 19KB

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