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 20KB

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