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

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