Browse Source

Sol Part 29: Whitespace is a Character Too!

master
Graham Northup 7 years ago
parent
commit
77d2337ecb
  1. 1
      .gitignore
  2. 31
      astprint.c
  3. 820
      builtins.c
  4. 441
      cdata.c
  5. 2
      dsl
  6. 6
      gc.c
  7. 2395
      lex.yy.c
  8. 172
      object.c
  9. 4072
      parser.tab.c
  10. 963
      runtime.c
  11. 68
      solrun.c
  12. 124
      state.c
  13. 54
      util.c

1
.gitignore

@ -2,3 +2,4 @@ sol
*.o
stdout
.submodule_stamp
*.orig

31
astprint.c

@ -8,7 +8,10 @@ void prlev(sol_state_t *state, int lev, const char *fmt, ...) {
va_list vl;
int i;
for(i = 0; i < lev; i++) { sol_putchar(state, '|'); sol_putchar(state, ' '); }
for(i = 0; i < lev; i++) {
sol_putchar(state, '|');
sol_putchar(state, ' ');
}
va_start(vl, fmt);
sol_vprintf(state, fmt, vl);
va_end(vl);
@ -67,18 +70,18 @@ void prst(sol_state_t *state, stmt_node *node, int lev) {
}
break;
case ST_RET:
prlev(state, lev, "Stmt<Ret>:");
prex(state, node->ret->ret, lev+1);
break;
case ST_RET:
prlev(state, lev, "Stmt<Ret>:");
prex(state, node->ret->ret, lev+1);
break;
case ST_CONT:
prlev(state, lev, "Stmt<Continue>");
break;
case ST_CONT:
prlev(state, lev, "Stmt<Continue>");
break;
case ST_BREAK:
prlev(state, lev, "Stmt<Break>");
break;
case ST_BREAK:
prlev(state, lev, "Stmt<Break>");
break;
}
}
@ -155,7 +158,7 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
prlev(state, lev, "Op: /");
break;
case OP_MOD:
case OP_MOD:
prlev(state, lev, "Op: %");
break;
@ -303,11 +306,11 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
}
void st_print(sol_state_t *state, stmt_node *stmt) {
prst(state, stmt, 0);
prst(state, stmt, 0);
}
void ex_print(sol_state_t *state, expr_node *expr) {
prex(state, expr, 0);
prex(state, expr, 0);
}
/*int main(int argc, char **argv) {

820
builtins.c
File diff suppressed because it is too large
View File

441
cdata.c

@ -14,257 +14,260 @@ sol_ops_t sol_cstruct_spec_ops;
sol_ops_t sol_cstruct_ops;
void sol_cstruct_init(void) {
sol_ops_init(&sol_cstruct_spec_ops);
sol_ops_init(&sol_cstruct_ops);
sol_ops_init(&sol_cstruct_spec_ops);
sol_ops_init(&sol_cstruct_ops);
sol_cstruct_ops.index = sol_f_cstruct_index;
sol_cstruct_ops.setindex = sol_f_cstruct_setindex;
sol_cstruct_is_init = 1;
sol_cstruct_ops.index = sol_f_cstruct_index;
sol_cstruct_ops.setindex = sol_f_cstruct_setindex;
sol_cstruct_is_init = 1;
}
sol_object_t *sol_new_cstruct_specs(sol_state_t *state) {
return sol_new_map(state);
return sol_new_map(state);
}
sol_object_t *sol_new_cstruct_spec(sol_state_t *state, sol_spec_t type) {
ENSURE();
sol_object_t *res = sol_new_cdata(state, NEW(sol_memspec_t), &sol_cstruct_spec_ops);
AS(res->cdata, sol_memspec_t)->type = type;
return res;
ENSURE();
sol_object_t *res = sol_new_cdata(state, NEW(sol_memspec_t), &sol_cstruct_spec_ops);
AS(res->cdata, sol_memspec_t)->type = type;
return res;
}
void sol_cstruct_add_member(sol_state_t *state, sol_object_t *specs, sol_object_t *key, sol_memtype_t memtype, int offset) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = memtype;
AS(spec->cdata, sol_memspec_t)->offset = offset;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = memtype;
AS(spec->cdata, sol_memspec_t)->offset = offset;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
}
void sol_cstruct_add_member_name(sol_state_t *state, sol_object_t *specs, char *name, sol_memtype_t memtype, int offset) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = memtype;
AS(spec->cdata, sol_memspec_t)->offset = offset;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = memtype;
AS(spec->cdata, sol_memspec_t)->offset = offset;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
}
void sol_cstruct_add_pointer(sol_state_t *state, sol_object_t *pspecs, sol_object_t *key, sol_object_t *specs, int offset) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = SOL_MT_PTR;
AS(spec->cdata, sol_memspec_t)->offset = offset;
AS(spec->cdata, sol_memspec_t)->specs = pspecs;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = SOL_MT_PTR;
AS(spec->cdata, sol_memspec_t)->offset = offset;
AS(spec->cdata, sol_memspec_t)->specs = pspecs;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
}
void sol_cstruct_add_pointer_name(sol_state_t *state, sol_object_t *pspecs, char *name, sol_object_t *specs, int offset) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = SOL_MT_PTR;
AS(spec->cdata, sol_memspec_t)->offset = offset;
AS(spec->cdata, sol_memspec_t)->specs = pspecs;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_MEMBER);
AS(spec->cdata, sol_memspec_t)->memtype = SOL_MT_PTR;
AS(spec->cdata, sol_memspec_t)->offset = offset;
AS(spec->cdata, sol_memspec_t)->specs = pspecs;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
}
void sol_cstruct_add_func(sol_state_t *state, sol_object_t *specs, sol_object_t *key, sol_cfunc_t cfunc) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_CFUNC);
AS(spec->cdata, sol_memspec_t)->cfunc = cfunc;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_CFUNC);
AS(spec->cdata, sol_memspec_t)->cfunc = cfunc;
sol_map_set(state, specs, key, spec);
sol_obj_free(spec);
}
void sol_cstruct_add_func_name(sol_state_t *state, sol_object_t *specs, char *name, sol_cfunc_t cfunc) {
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_CFUNC);
AS(spec->cdata, sol_memspec_t)->cfunc = cfunc;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
sol_object_t *spec = sol_new_cstruct_spec(state, SOL_CS_CFUNC);
AS(spec->cdata, sol_memspec_t)->cfunc = cfunc;
sol_map_set_name(state, specs, name, spec);
sol_obj_free(spec);
}
sol_object_t *sol_new_cstruct(sol_state_t *state, void *data, sol_object_t *specs) {
sol_object_t *res = sol_new_cdata(state, NEW(sol_cstruct_t), &sol_cstruct_ops);
AS(res->cdata, sol_cstruct_t)->data = data;
AS(res->cdata, sol_cstruct_t)->specs = sol_incref(specs);
return res;
sol_object_t *res = sol_new_cdata(state, NEW(sol_cstruct_t), &sol_cstruct_ops);
AS(res->cdata, sol_cstruct_t)->data = data;
AS(res->cdata, sol_cstruct_t)->specs = sol_incref(specs);
return res;
}
sol_object_t *sol_f_cstruct_index(sol_state_t *state, sol_object_t *args) {
sol_object_t *cstructobj = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1);
sol_cstruct_t *cstruct = cstructobj->cdata;
sol_object_t *specobj = sol_map_get(state, cstruct->specs, idx), *res = NULL;
sol_memspec_t *spec;
char cbuf[2] = {0, 0};
if(sol_is_none(state, specobj)) {
sol_obj_free(specobj);
sol_obj_free(idx);
sol_obj_free(cstructobj);
return sol_set_error_string(state, "No such CStruct index");
}
spec = specobj->cdata;
switch(spec->type) {
case SOL_CS_MEMBER:
switch(spec->memtype) {
case SOL_MT_INT:
res = sol_new_int(state, AT(cstruct->data, int, spec->offset));
break;
case SOL_MT_INT8:
res = sol_new_int(state, AT(cstruct->data, int8_t, spec->offset));
break;
case SOL_MT_INT16:
res = sol_new_int(state, AT(cstruct->data, int16_t, spec->offset));
break;
case SOL_MT_INT32:
res = sol_new_int(state, AT(cstruct->data, int32_t, spec->offset));
break;
case SOL_MT_INT64:
res = sol_new_int(state, AT(cstruct->data, int64_t, spec->offset));
break;
case SOL_MT_UINT:
res = sol_new_int(state, AT(cstruct->data, unsigned int, spec->offset));
break;
case SOL_MT_UINT8:
res = sol_new_int(state, AT(cstruct->data, uint8_t, spec->offset));
break;
case SOL_MT_UINT16:
res = sol_new_int(state, AT(cstruct->data, uint16_t, spec->offset));
break;
case SOL_MT_UINT32:
res = sol_new_int(state, AT(cstruct->data, uint32_t, spec->offset));
break;
/*case SOL_MT_UINT64:
res = sol_new_int(state, AT(cstruct->data, uint64_t, spec->offset));
break;*/
case SOL_MT_FLOAT:
res = sol_new_float(state, AT(cstruct->data, float, spec->offset));
break;
case SOL_MT_DOUBLE:
res = sol_new_float(state, AT(cstruct->data, double, spec->offset));
break;
case SOL_MT_CHAR:
cbuf[0] = AT(cstruct->data, char, spec->offset);
res = sol_new_string(state, cbuf);
break;
case SOL_MT_CSTR:
res = sol_new_string(state, AT(cstruct->data, char *, spec->offset));
break;
case SOL_MT_CFUNC:
res = sol_new_cfunc(state, AT(cstruct->data, sol_cfunc_t, spec->offset));
break;
case SOL_MT_PTR:
res = sol_new_cstruct(state, AT(cstruct->data, void *, spec->offset), spec->specs);
break;
}
break;
case SOL_CS_CFUNC:
res = sol_new_cfunc(state, spec->cfunc);
break;
}
if(!res) res = sol_incref(state->None);
return res;
sol_object_t *cstructobj = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1);
sol_cstruct_t *cstruct = cstructobj->cdata;
sol_object_t *specobj = sol_map_get(state, cstruct->specs, idx), *res = NULL;
sol_memspec_t *spec;
char cbuf[2] = {0, 0};
if(sol_is_none(state, specobj)) {
sol_obj_free(specobj);
sol_obj_free(idx);
sol_obj_free(cstructobj);
return sol_set_error_string(state, "No such CStruct index");
}
spec = specobj->cdata;
switch(spec->type) {
case SOL_CS_MEMBER:
switch(spec->memtype) {
case SOL_MT_INT:
res = sol_new_int(state, AT(cstruct->data, int, spec->offset));
break;
case SOL_MT_INT8:
res = sol_new_int(state, AT(cstruct->data, int8_t, spec->offset));
break;
case SOL_MT_INT16:
res = sol_new_int(state, AT(cstruct->data, int16_t, spec->offset));
break;
case SOL_MT_INT32:
res = sol_new_int(state, AT(cstruct->data, int32_t, spec->offset));
break;
case SOL_MT_INT64:
res = sol_new_int(state, AT(cstruct->data, int64_t, spec->offset));
break;
case SOL_MT_UINT:
res = sol_new_int(state, AT(cstruct->data, unsigned int, spec->offset));
break;
case SOL_MT_UINT8:
res = sol_new_int(state, AT(cstruct->data, uint8_t, spec->offset));
break;
case SOL_MT_UINT16:
res = sol_new_int(state, AT(cstruct->data, uint16_t, spec->offset));
break;
case SOL_MT_UINT32:
res = sol_new_int(state, AT(cstruct->data, uint32_t, spec->offset));
break;
/*case SOL_MT_UINT64:
res = sol_new_int(state, AT(cstruct->data, uint64_t, spec->offset));
break;*/
case SOL_MT_FLOAT:
res = sol_new_float(state, AT(cstruct->data, float, spec->offset));
break;
case SOL_MT_DOUBLE:
res = sol_new_float(state, AT(cstruct->data, double, spec->offset));
break;
case SOL_MT_CHAR:
cbuf[0] = AT(cstruct->data, char, spec->offset);
res = sol_new_string(state, cbuf);
break;
case SOL_MT_CSTR:
res = sol_new_string(state, AT(cstruct->data, char *, spec->offset));
break;
case SOL_MT_CFUNC:
res = sol_new_cfunc(state, AT(cstruct->data, sol_cfunc_t, spec->offset));
break;
case SOL_MT_PTR:
res = sol_new_cstruct(state, AT(cstruct->data, void *, spec->offset), spec->specs);
break;
}
break;
case SOL_CS_CFUNC:
res = sol_new_cfunc(state, spec->cfunc);
break;
}
if(!res) {
res = sol_incref(state->None);
}
return res;
}
sol_object_t *sol_f_cstruct_setindex(sol_state_t *state, sol_object_t *args) {
sol_object_t *cstructobj = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1), *val = sol_list_get_index(state, args, 2);
sol_cstruct_t *cstruct = cstructobj->cdata;
sol_object_t *specobj = sol_map_get(state, cstruct->specs, idx);
sol_memspec_t *spec;
char cbuf[2] = {0, 0};
if(sol_is_none(state, specobj)) {
sol_obj_free(specobj);
sol_obj_free(idx);
sol_obj_free(cstructobj);
return sol_set_error_string(state, "No such CStruct index");
}
spec = specobj->cdata;
switch(spec->type) {
case SOL_CS_MEMBER:
switch(spec->memtype) {
case SOL_MT_INT:
AT(cstruct->data, int, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT8:
AT(cstruct->data, int8_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT16:
AT(cstruct->data, int16_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT32:
AT(cstruct->data, int32_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT64:
AT(cstruct->data, int64_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT:
AT(cstruct->data, unsigned int, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT8:
AT(cstruct->data, uint8_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT16:
AT(cstruct->data, uint16_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT32:
AT(cstruct->data, uint32_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
/*case SOL_MT_UINT64:
AT(cstruct->data, uint64_t, spec->offset) = sol_cast_int(state, val)->ival;
break;*/
case SOL_MT_FLOAT:
AT(cstruct->data, float, spec->offset) = sol_cast_float(state, val)->fval;
break;
case SOL_MT_DOUBLE:
AT(cstruct->data, double, spec->offset) = sol_cast_float(state, val)->fval;
break;
case SOL_MT_CHAR:
AT(cstruct->data, char, spec->offset) = sol_cast_string(state, val)->str[0];
break;
case SOL_MT_CSTR:
AT(cstruct->data, char *, spec->offset) = strdup(sol_cast_string(state, val)->str);
break;
case SOL_MT_CFUNC:
return sol_set_error_string(state, "Can't assign CFunc members");
break;
case SOL_MT_PTR:
if(!sol_is_cdata(val) || spec->specs != AS(val->cdata, sol_cstruct_t)->specs)
return sol_set_error_string(state, "Invalid type for PTR assignment");
AT(cstruct->data, void *, spec->offset) = AS(val->cdata, sol_cstruct_t)->data;
}
break;
case SOL_CS_CFUNC:
return sol_set_error_string(state, "Can't assign CFunc members");
break;
}
return sol_incref(state->None);
sol_object_t *cstructobj = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1), *val = sol_list_get_index(state, args, 2);
sol_cstruct_t *cstruct = cstructobj->cdata;
sol_object_t *specobj = sol_map_get(state, cstruct->specs, idx);
sol_memspec_t *spec;
char cbuf[2] = {0, 0};
if(sol_is_none(state, specobj)) {
sol_obj_free(specobj);
sol_obj_free(idx);
sol_obj_free(cstructobj);
return sol_set_error_string(state, "No such CStruct index");
}
spec = specobj->cdata;
switch(spec->type) {
case SOL_CS_MEMBER:
switch(spec->memtype) {
case SOL_MT_INT:
AT(cstruct->data, int, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT8:
AT(cstruct->data, int8_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT16:
AT(cstruct->data, int16_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT32:
AT(cstruct->data, int32_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_INT64:
AT(cstruct->data, int64_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT:
AT(cstruct->data, unsigned int, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT8:
AT(cstruct->data, uint8_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT16:
AT(cstruct->data, uint16_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
case SOL_MT_UINT32:
AT(cstruct->data, uint32_t, spec->offset) = sol_cast_int(state, val)->ival;
break;
/*case SOL_MT_UINT64:
AT(cstruct->data, uint64_t, spec->offset) = sol_cast_int(state, val)->ival;
break;*/
case SOL_MT_FLOAT:
AT(cstruct->data, float, spec->offset) = sol_cast_float(state, val)->fval;
break;
case SOL_MT_DOUBLE:
AT(cstruct->data, double, spec->offset) = sol_cast_float(state, val)->fval;
break;
case SOL_MT_CHAR:
AT(cstruct->data, char, spec->offset) = sol_cast_string(state, val)->str[0];
break;
case SOL_MT_CSTR:
AT(cstruct->data, char *, spec->offset) = strdup(sol_cast_string(state, val)->str);
break;
case SOL_MT_CFUNC:
return sol_set_error_string(state, "Can't assign CFunc members");
break;
case SOL_MT_PTR:
if(!sol_is_cdata(val) || spec->specs != AS(val->cdata, sol_cstruct_t)->specs) {
return sol_set_error_string(state, "Invalid type for PTR assignment");
}
AT(cstruct->data, void *, spec->offset) = AS(val->cdata, sol_cstruct_t)->data;
}
break;
case SOL_CS_CFUNC:
return sol_set_error_string(state, "Can't assign CFunc members");
break;
}
return sol_incref(state->None);
}

2
dsl

@ -1 +1 @@
Subproject commit 10976abb77cee1f9beb6514a80e38e950bca9a0d
Subproject commit aff43d13d92bc83038bf675afbcaf5304be5acf5

6
gc.c

@ -35,8 +35,10 @@ void sol_obj_free(sol_object_t *obj) {
}
void sol_obj_release(sol_object_t *obj) {
if(obj->ops->free) obj->ops->free(NULL, obj);
free(obj);
if(obj->ops->free) {
obj->ops->free(NULL, obj);
}
free(obj);
}
#endif

2395
lex.yy.c
File diff suppressed because it is too large
View File

172
object.c

@ -9,7 +9,9 @@
sol_object_t *sol_cast_int(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_int(obj)) return sol_incref(obj);
if(sol_is_int(obj)) {
return sol_incref(obj);
}
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->toint(state, ls);
@ -19,7 +21,9 @@ sol_object_t *sol_cast_int(sol_state_t *state, sol_object_t *obj) {
sol_object_t *sol_cast_float(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_float(obj)) return sol_incref(obj);
if(sol_is_float(obj)) {
return sol_incref(obj);
}
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->tofloat(state, ls);
@ -29,7 +33,9 @@ sol_object_t *sol_cast_float(sol_state_t *state, sol_object_t *obj) {
sol_object_t *sol_cast_string(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_string(obj)) return sol_incref(obj);
if(sol_is_string(obj)) {
return sol_incref(obj);
}
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->tostring(state, ls);
@ -61,7 +67,9 @@ sol_object_t *sol_new_singlet(sol_state_t *state, const char *name) {
// And, now, for the rest of the checked stuff...
void sol_init_object(sol_state_t *state, sol_object_t *obj) {
if(obj->ops->init) obj->ops->init(state, obj);
if(obj->ops->init) {
obj->ops->init(state, obj);
}
}
sol_object_t *sol_new_int(sol_state_t *state, long i) {
@ -159,22 +167,30 @@ sol_object_t *sol_list_sublist(sol_state_t *state, sol_object_t *list, int idx)
}
sol_object_t *sol_list_get_index(sol_state_t *state, sol_object_t *list, int idx) {
if(idx<0 || idx>=dsl_seq_len(list->seq)) return sol_incref(state->None);
if(idx<0 || idx>=dsl_seq_len(list->seq)) {
return sol_incref(state->None);
}
return sol_incref(AS_OBJ(dsl_seq_get(list->seq, idx)));
}
void sol_list_set_index(sol_state_t *state, sol_object_t *list, int idx, sol_object_t *obj) {
if(idx<0 || idx>=dsl_seq_len(list->seq)) return;
if(idx<0 || idx>=dsl_seq_len(list->seq)) {
return;
}
dsl_seq_set(list->seq, idx, obj);
}
void sol_list_insert(sol_state_t *state, sol_object_t *list, int idx, sol_object_t *obj) {
if(idx<0 || idx>dsl_seq_len(list->seq)) return;
if(idx<0 || idx>dsl_seq_len(list->seq)) {
return;
}
dsl_seq_insert(list->seq, idx, obj);
}
sol_object_t *sol_list_remove(sol_state_t *state, sol_object_t *list, int idx) {
if(idx<0 || idx>=dsl_seq_len(list->seq)) return sol_incref(state->None);
if(idx<0 || idx>=dsl_seq_len(list->seq)) {
return sol_incref(state->None);
}
return dsl_seq_remove(list->seq, idx);
}
@ -198,13 +214,13 @@ sol_object_t *sol_list_truncate(sol_state_t *state, sol_object_t *list, int len)
}
void sol_list_append(sol_state_t *state, sol_object_t *dest, sol_object_t *src) {
dsl_seq *oldseq = dest->seq;
dsl_seq *oldseq = dest->seq;
dest->seq = dsl_seq_append(dest->seq, src->seq);
dsl_free_seq(oldseq);
}
sol_object_t *sol_f_list_free(sol_state_t *state, sol_object_t *list) {
dsl_free_seq(list->seq);
dsl_free_seq(list->seq);
return list;
}
@ -254,29 +270,31 @@ int sol_validate_list(sol_state_t *state, sol_object_t *list) {
}*/
sol_object_t *sol_new_map(sol_state_t *state) {
sol_object_t *map = sol_alloc_object(state);
map->type = SOL_MAP;
map->ops = &(state->MapOps);
map->seq = dsl_seq_new_array(NULL, &(state->obfuncs));
sol_object_t *map = sol_alloc_object(state);
map->type = SOL_MAP;
map->ops = &(state->MapOps);
map->seq = dsl_seq_new_array(NULL, &(state->obfuncs));
sol_init_object(state, map);
return map;
return map;
}
sol_object_t *sol_map_from_seq(sol_state_t *state, dsl_seq *seq) {
sol_object_t *map = sol_alloc_object(state);
if(sol_has_error(state)) return sol_incref(state->None);
map->type = SOL_MAP;
map->ops = &(state->MapOps);
map->seq = seq;
return map;
sol_object_t *map = sol_alloc_object(state);
if(sol_has_error(state)) {
return sol_incref(state->None);
}
map->type = SOL_MAP;
map->ops = &(state->MapOps);
map->seq = seq;
return map;
}
int sol_map_len(sol_state_t *state, sol_object_t *map) {
return dsl_seq_len(map->seq);
return dsl_seq_len(map->seq);
}
sol_object_t *sol_map_mcell(sol_state_t *state, sol_object_t *map, sol_object_t *key) {
sol_object_t *list, *cmp, *icmp, *res = NULL;
sol_object_t *list, *cmp, *icmp, *res = NULL;
dsl_seq_iter *iter;
if(!sol_is_map(map)) {
printf("WARNING: Attempt to index non-map as map\n");
@ -289,24 +307,24 @@ sol_object_t *sol_map_mcell(sol_state_t *state, sol_object_t *map, sol_object_t
sol_obj_free(list);
return sol_incref(state->None);
}
sol_list_insert(state, list, 0, key);
sol_list_insert(state, list, 0, key);
sol_list_insert(state, list, 1, state->None);
if(!dsl_seq_iter_is_invalid(iter)) do {
sol_list_set_index(state, list, 1, AS_OBJ(dsl_seq_iter_at(iter))->key);
cmp = key->ops->cmp(state, list);
icmp = sol_cast_int(state, cmp);
sol_obj_free(cmp);
if(icmp->ival == 0) {
res = AS_OBJ(dsl_seq_iter_at(iter));
}
sol_obj_free(icmp);
} while(dsl_seq_iter_next(iter));
if(!dsl_seq_iter_is_invalid(iter)) do {
sol_list_set_index(state, list, 1, AS_OBJ(dsl_seq_iter_at(iter))->key);
cmp = key->ops->cmp(state, list);
icmp = sol_cast_int(state, cmp);
sol_obj_free(cmp);
if(icmp->ival == 0) {
res = AS_OBJ(dsl_seq_iter_at(iter));
}
sol_obj_free(icmp);
} while(dsl_seq_iter_next(iter));
dsl_free_seq_iter(iter);
sol_obj_free(list);
if(res) {
return res;
}
return sol_incref(state->None);
return sol_incref(state->None);
}
int sol_map_has(sol_state_t *state, sol_object_t *map, sol_object_t *key) {
@ -317,8 +335,8 @@ int sol_map_has(sol_state_t *state, sol_object_t *map, sol_object_t *key) {
}
sol_object_t *sol_map_get(sol_state_t *state, sol_object_t *map, sol_object_t *key) {
sol_object_t *mcell = sol_map_mcell(state, map, key);
if(sol_is_none(state, mcell)) {
sol_object_t *mcell = sol_map_mcell(state, map, key);
if(sol_is_none(state, mcell)) {
return mcell;
}
return sol_incref(mcell->val);
@ -332,7 +350,7 @@ sol_object_t *sol_map_get_name(sol_state_t *state, sol_object_t *map, char *name
}
void sol_map_set(sol_state_t *state, sol_object_t *map, sol_object_t *key, sol_object_t *val) {
sol_object_t *mcell =sol_map_mcell(state, map, key), *newcell, *temp;
sol_object_t *mcell =sol_map_mcell(state, map, key), *newcell, *temp;
if(sol_is_none(state, mcell)) {
newcell = sol_alloc_object(state);
newcell->type = SOL_MCELL;
@ -355,7 +373,7 @@ void sol_map_set_name(sol_state_t *state, sol_object_t *map, char *name, sol_obj
}
void sol_map_set_existing(sol_state_t *state, sol_object_t *map, sol_object_t *key, sol_object_t *val) {
sol_object_t *mcell =sol_map_mcell(state, map, key), *temp;
sol_object_t *mcell =sol_map_mcell(state, map, key), *temp;
if(!sol_is_none(state, mcell)) {
temp = mcell->val;
mcell->val = sol_incref(val);
@ -364,22 +382,22 @@ void sol_map_set_existing(sol_state_t *state, sol_object_t *map, sol_object_t *k
}
sol_object_t *sol_map_copy(sol_state_t *state, sol_object_t *map) {
return sol_map_from_seq(state, dsl_seq_copy(map->seq));
return sol_map_from_seq(state, dsl_seq_copy(map->seq));
}
void sol_map_merge(sol_state_t *state, sol_object_t *dest, sol_object_t *src) {
dsl_seq_iter *iter = dsl_new_seq_iter(src->seq);
dsl_seq_iter *iter = dsl_new_seq_iter(src->seq);
if(!dsl_seq_iter_is_invalid(iter)) do {
sol_map_set(state, dest, AS_OBJ(dsl_seq_iter_at(iter))->key, AS_OBJ(dsl_seq_iter_at(iter))->val);
} while(dsl_seq_iter_next(iter));
sol_map_set(state, dest, AS_OBJ(dsl_seq_iter_at(iter))->key, AS_OBJ(dsl_seq_iter_at(iter))->val);
} while(dsl_seq_iter_next(iter));
dsl_free_seq_iter(iter);
}
void sol_map_merge_existing(sol_state_t *state, sol_object_t *dest, sol_object_t *src) {
dsl_seq_iter *iter = dsl_new_seq_iter(src->seq);
dsl_seq_iter *iter = dsl_new_seq_iter(src->seq);
if(!dsl_seq_iter_is_invalid(iter)) do {
sol_map_set_existing(state, dest, AS_OBJ(dsl_seq_iter_at(iter))->key, AS_OBJ(dsl_seq_iter_at(iter))->val);
} while(dsl_seq_iter_next(iter));
sol_map_set_existing(state, dest, AS_OBJ(dsl_seq_iter_at(iter))->key, AS_OBJ(dsl_seq_iter_at(iter))->val);
} while(dsl_seq_iter_next(iter));
dsl_free_seq_iter(iter);
}
@ -397,13 +415,17 @@ void sol_map_invert(sol_state_t *state, sol_object_t *map) {
}
sol_object_t *sol_f_map_free(sol_state_t *state, sol_object_t *map) {
dsl_free_seq(map->seq);
return map;
dsl_free_seq(map->seq);
return map;
}
sol_object_t *sol_f_mcell_free(sol_state_t *state, sol_object_t *mcell) {
if(mcell->key) sol_obj_free(mcell->key);
if(mcell->val) sol_obj_free(mcell->val);
if(mcell->key) {
sol_obj_free(mcell->key);
}
if(mcell->val) {
sol_obj_free(mcell->val);
}
return mcell;
}
@ -429,21 +451,21 @@ sol_object_t *sol_f_mcell_free(sol_state_t *state, sol_object_t *mcell) {
}*/
sol_object_t *sol_new_cfunc(sol_state_t *state, sol_cfunc_t cfunc) {
sol_object_t *res = sol_alloc_object(state);
res->type = SOL_CFUNCTION;
res->ops = &(state->CFuncOps);
res->cfunc = cfunc;
sol_object_t *res = sol_alloc_object(state);
res->type = SOL_CFUNCTION;
res->ops = &(state->CFuncOps);
res->cfunc = cfunc;
sol_init_object(state, res);
return res;
return res;
}
sol_object_t *sol_new_cdata(sol_state_t *state, void *cdata, sol_ops_t *ops) {
sol_object_t *res = sol_alloc_object(state);
res->type = SOL_CDATA;
res->ops = ops;
res->cdata = cdata;
sol_object_t *res = sol_alloc_object(state);
res->type = SOL_CDATA;
res->ops = ops;
res->cdata = cdata;
sol_init_object(state, res);
return res;
return res;
}
sol_object_t *sol_new_buffer(sol_state_t *state, void *buffer, ssize_t sz, sol_owntype_t own, sol_freefunc_t freef, sol_movefunc_t movef) {
@ -464,7 +486,7 @@ sol_object_t *sol_f_buffer_free(sol_state_t *state, sol_object_t *buf) {
case OWN_FREE:
free(buf->buffer);
break;
case OWN_CALLF:
buf->freef(buf->buffer, buf->sz);
break;
@ -515,7 +537,9 @@ size_t sol_stream_printf(sol_state_t *state, sol_object_t *stream, const char *f
va_list va;
size_t res;
if(!(stream->modes & MODE_WRITE)) {
if(state) sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
}
return 0;
}
va_start(va, fmt);
@ -526,7 +550,9 @@ size_t sol_stream_printf(sol_state_t *state, sol_object_t *stream, const char *f
size_t sol_stream_vprintf(sol_state_t *state, sol_object_t *stream, const char *fmt, va_list va) {
if(!(stream->modes & MODE_WRITE)) {
if(state) sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
}
return 0;
}
return vfprintf(stream->stream, fmt, va);
@ -536,7 +562,9 @@ size_t sol_stream_scanf(sol_state_t *state, sol_object_t *stream, const char *fm
va_list va;
size_t res;
if(!(stream->modes & MODE_READ)) {
if(state) sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
}
return 0;
}
va_start(va, fmt);
@ -547,7 +575,9 @@ size_t sol_stream_scanf(sol_state_t *state, sol_object_t *stream, const char *fm
size_t sol_stream_fread(sol_state_t *state, sol_object_t *stream, char *buffer, size_t sz, size_t memb) {
if(!(stream->modes & MODE_READ)) {
if(state) sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
}
return 0;
}
return fread(buffer, sz, memb, stream->stream);
@ -555,7 +585,9 @@ size_t sol_stream_fread(sol_state_t *state, sol_object_t *stream, char *buffer,
size_t sol_stream_fwrite(sol_state_t *state, sol_object_t *stream, char *buffer, size_t sz, size_t memb) {
if(!(stream->modes & MODE_WRITE)) {
if(state) sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
}
return 0;
}
return fwrite(buffer, sz, memb, stream->stream);
@ -563,7 +595,9 @@ size_t sol_stream_fwrite(sol_state_t *state, sol_object_t *stream, char *buffer,
char *sol_stream_fgets(sol_state_t *state, sol_object_t *stream, char *buffer, size_t sz) {
if(!(stream->modes & MODE_READ)) {
if(state) sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Read from non-readable stream"));
}
return NULL;
}
return fgets(buffer, sz, stream->stream);
@ -571,7 +605,9 @@ char *sol_stream_fgets(sol_state_t *state, sol_object_t *stream, char *buffer, s
int sol_stream_fputc(sol_state_t *state, sol_object_t *stream, int ch) {
if(!(stream->modes & MODE_WRITE)) {
if(state) sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
if(state) {
sol_obj_free(sol_set_error_string(state, "Write to non-writable stream"));
}
return 0;
}
return fputc(ch, stream->stream);

4072
parser.tab.c
File diff suppressed because it is too large
View File

963
runtime.c
File diff suppressed because it is too large
View File

68
solrun.c

@ -3,49 +3,53 @@
#include "parser.tab.h"
int main(int argc, char **argv) {
stmt_node *program;
sol_state_t state;
char *c;
int printtree = 0;
stmt_node *program;
sol_state_t state;
char *c;
int printtree = 0;
FILE *prgstream = stdin;
if(argc>1) {
c = argv[1];
while(*c) {
switch(*c) {
case 'd':
yydebug = 1;
break;
case 't':
printtree = 1;
break;
if(argc>1) {
c = argv[1];
while(*c) {
switch(*c) {
case 'd':
yydebug = 1;
break;
case 't':
printtree = 1;
break;
case 'r':
if(argc<2) {
printf("r option requires file\n");
return 1;
}
prgstream = fopen(argv[2], "r");
}
c++;
}
}
if(!prgstream) {
}
c++;
}
}
if(!prgstream) {
printf("No input program (check filenames)\n");
return 1;
}
program = sol_compile_file(prgstream);
if(prgstream!=stdin) fclose(prgstream);
program = sol_compile_file(prgstream);
if(prgstream!=stdin) {
fclose(prgstream);
}
sol_state_init(&state);
if(printtree) st_print(&state, program);
if(printtree) {
st_print(&state, program);
}
if(program) {
sol_exec(&state, program);
if(program) {
sol_exec(&state, program);
if(sol_has_error(&state)) {
printf("Error: ");
ob_print(state.error);
@ -53,10 +57,10 @@ int main(int argc, char **argv) {
}
//st_free(program);
sol_state_cleanup(&state);
return 0;
}
return 0;
}
printf("NULL program (probably a syntax error)\n");
printf("NULL program (probably a syntax error)\n");
return 1;
return 1;
}

124
state.c

@ -15,9 +15,15 @@ int sol_state_init(sol_state_t *state) {
state->sflag = SF_NORMAL;
// If any of the following fail, some very weird things are happening.
if(!(state->None = sol_new_singlet(state, "None"))) goto cleanup;
if(!(state->OutOfMemory = sol_new_singlet(state, "OutOfMemory"))) goto cleanup;
if(!(state->StopIteration = sol_new_singlet(state, "StopIteration"))) goto cleanup;
if(!(state->None = sol_new_singlet(state, "None"))) {
goto cleanup;
}
if(!(state->OutOfMemory = sol_new_singlet(state, "OutOfMemory"))) {
goto cleanup;
}
if(!(state->StopIteration = sol_new_singlet(state, "StopIteration"))) {
goto cleanup;
}
// We can now use the normal error reporting mechanism, now
// that errors are distinguishable. Set that up now.
@ -25,7 +31,7 @@ int sol_state_init(sol_state_t *state) {
//Initialize all of the builtin operations
//(these ones are technically already pointed to by None/OOM)
sol_ops_init(&(state->NullOps));
state->SingletOps = state->NullOps;
state->IntOps = state->NullOps;
state->FloatOps = state->NullOps;
@ -40,10 +46,10 @@ int sol_state_init(sol_state_t *state) {
state->DyLibOps = state->NullOps;
state->DySymOps = state->NullOps;
state->StreamOps = state->NullOps;
state->SingletOps.tname = "singlet";
state->SingletOps.tostring = sol_f_singlet_tostring;
state->IntOps.tname = "int";
state->IntOps.add = sol_f_int_add;
state->IntOps.sub = sol_f_int_sub;
@ -60,7 +66,7 @@ int sol_state_init(sol_state_t *state) {
state->IntOps.toint = sol_f_int_toint;
state->IntOps.tofloat = sol_f_int_tofloat;
state->IntOps.tostring = sol_f_int_tostring;
state->FloatOps.tname = "float";
state->FloatOps.add = sol_f_float_add;
state->FloatOps.sub = sol_f_float_sub;
@ -70,7 +76,7 @@ int sol_state_init(sol_state_t *state) {
state->FloatOps.toint = sol_f_float_toint;
state->FloatOps.tofloat = sol_f_float_tofloat;
state->FloatOps.tostring = sol_f_float_tostring;
state->StringOps.tname = "string";
state->StringOps.add = sol_f_str_add;
state->StringOps.mul = sol_f_str_mul;
@ -83,7 +89,7 @@ int sol_state_init(sol_state_t *state) {
state->StringOps.tostring = sol_f_str_tostring;
state->StringOps.repr = sol_f_str_repr;
state->StringOps.free = sol_f_str_free;
state->ListOps.tname = "list";
state->ListOps.add = sol_f_list_add;
state->ListOps.mul = sol_f_list_mul;
@ -94,7 +100,7 @@ int sol_state_init(sol_state_t *state) {
state->ListOps.iter = sol_f_list_iter;
state->ListOps.tostring = sol_f_list_tostring;
state->ListOps.free = sol_f_list_free;
state->MapOps.tname = "map";
state->MapOps.add = sol_f_map_add;
state->MapOps.call = sol_f_map_call;
@ -105,63 +111,69 @@ int sol_state_init(sol_state_t *state) {
state->MapOps.tostring = sol_f_map_tostring;
state->MapOps.repr = sol_f_map_repr;
state->MapOps.free = sol_f_map_free;
state->MCellOps.tname = "mcell";
state->MCellOps.tostring = sol_f_mcell_tostring;
state->MCellOps.free = sol_f_mcell_free;
state->FuncOps.tname = "function";
state->FuncOps.call = sol_f_func_call;
state->FuncOps.index = sol_f_func_index;
state->FuncOps.setindex = sol_f_func_setindex;
state->FuncOps.tostring = sol_f_func_tostring;
state->CFuncOps.tname = "cfunction";
state->CFuncOps.call = sol_f_cfunc_call;
state->CFuncOps.tostring = sol_f_cfunc_tostring;
state->ASTNodeOps.tname = "astnode";
state->ASTNodeOps.call = sol_f_astnode_call;
state->ASTNodeOps.index = sol_f_astnode_index;
state->ASTNodeOps.setindex = sol_f_astnode_setindex;
state->ASTNodeOps.tostring = sol_f_astnode_tostring;
state->BufferOps.tname = "buffer";
state->BufferOps.index = sol_f_buffer_index;
state->BufferOps.tostring = sol_f_buffer_tostring;
state->BufferOps.free = sol_f_buffer_free;
state->DyLibOps.tname = "dylib";
state->DyLibOps.index = sol_f_dylib_index;
state->DyLibOps.free = sol_f_dylib_free;
state->DyLibOps.tostring = sol_f_dylib_tostring;
state->DySymOps.tname = "dysym";
state->DySymOps.call = sol_f_dysym_call;
state->DySymOps.index = sol_f_dysym_index;
state->DySymOps.setindex = sol_f_dysym_setindex;
state->DySymOps.tostring = sol_f_dysym_tostring;
state->StreamOps.tname = "stream";
state->StreamOps.blsh = sol_f_stream_blsh;
state->StreamOps.brsh = sol_f_stream_brsh;
state->StreamOps.index = sol_f_stream_index;
state->StreamOps.free = sol_f_stream_free;
state->StreamOps.tostring = sol_f_stream_tostring;
state->obfuncs.copy = (dsl_copier) sol_obj_acquire;
state->obfuncs.destr = (dsl_destructor) sol_obj_free;
state->error = state->None;
state->scopes = sol_new_list(state);
if(sol_has_error(state)) goto cleanup;
if(sol_has_error(state)) {
goto cleanup;
}
globals = sol_new_map(state);
state->modules = sol_new_map(state);
state->methods = sol_new_map(state);
if(sol_has_error(state)) goto cleanup;
if(sol_has_error(state)) {
goto cleanup;
}
sol_list_insert(state, state->scopes, 0, globals);
sol_obj_free(globals);
if(sol_has_error(state)) goto cleanup;
if(sol_has_error(state)) {
goto cleanup;
}
// I'm going to buffer all of these together because I can.
sol_map_set_name(state, globals, "OutOfMemory", state->OutOfMemory);
sol_map_set_name(state, globals, "StopIteration", state->StopIteration);
@ -182,7 +194,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, globals, "parse", sol_new_cfunc(state, sol_f_parse));
sol_map_set_name(state, globals, "ord", sol_new_cfunc(state, sol_f_ord));
sol_map_set_name(state, globals, "chr", sol_new_cfunc(state, sol_f_chr));
mod = sol_new_map(state);
sol_map_set_name(state, mod, "getref", sol_new_cfunc(state, sol_f_debug_getref));
sol_map_set_name(state, mod, "setref", sol_new_cfunc(state, sol_f_debug_setref));
@ -194,14 +206,14 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, mod, "hexversion", sol_new_int(state, HEXVER));
sol_register_module_name(state, "debug", mod);
sol_obj_free(mod);
mod = sol_new_map(state);
sol_map_set_name(state, mod, "str", sol_new_cfunc(state, sol_f_iter_str));
sol_map_set_name(state, mod, "list", sol_new_cfunc(state, sol_f_iter_list));
sol_map_set_name(state, mod, "map", sol_new_cfunc(state, sol_f_iter_map));
sol_register_module_name(state, "iter", mod);
sol_obj_free(mod);
mod = sol_new_map(state);
sol_map_set_name(state, mod, "ST_EXPR", sol_new_int(state, ST_EXPR));
sol_map_set_name(state, mod, "ST_IFELSE", sol_new_int(state, ST_IFELSE));
@ -251,7 +263,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_invert(state, mod);
sol_map_set_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print));
sol_register_module_name(state, "ast", mod);
btype = sol_new_map(state);
sol_map_set_name(state, btype, "none", sol_new_int(state, BUF_NONE));
sol_map_set_name(state, btype, "uint8", sol_new_int(state, BUF_UINT8));
@ -273,7 +285,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, btype, "cstr", sol_new_int(state, BUF_CSTR));
sol_map_set_name(state, btype, "ptr", sol_new_int(state, BUF_PTR));
sol_map_invert(state, btype);
bsize = sol_new_map(state);
sol_map_set_name(state, bsize, "uint8", sol_new_int(state, sizeof(uint8_t)));
sol_map_set_name(state, bsize, "uint16", sol_new_int(state, sizeof(uint16_t)));
@ -293,7 +305,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, bsize, "double", sol_new_int(state, sizeof(double)));
sol_map_set_name(state, bsize, "cstr", sol_new_int(state, sizeof(char *)));
sol_map_set_name(state, bsize, "ptr", sol_new_int(state, sizeof(void *)));
bobj = sol_new_map(state);
sol_map_set_name(state, bobj, "SOL_SINGLET", sol_new_int(state, SOL_SINGLET));
sol_map_set_name(state, bobj, "SOL_INTEGER", sol_new_int(state, SOL_INTEGER));
@ -312,7 +324,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, bobj, "SOL_STREAM", sol_new_int(state, SOL_STREAM));
sol_map_set_name(state, bobj, "SOL_CDATA", sol_new_int(state, SOL_CDATA));
sol_map_invert(state, bobj);
mod = sol_new_map(state);
sol_map_set_name(state, mod, "new", sol_new_cfunc(state, sol_f_buffer_new));
sol_map_set_name(state, mod, "fromstring", sol_new_cfunc(state, sol_f_buffer_fromstring));
@ -326,7 +338,7 @@ int sol_state_init(sol_state_t *state) {
sol_obj_free(bobj);
sol_obj_free(bsize);
sol_obj_free(btype);
mod = sol_new_map(state);
sol_map_set_name(state, mod, "MODE_READ", sol_new_int(state, MODE_READ));
sol_map_set_name(state, mod, "MODE_WRITE", sol_new_int(state, MODE_WRITE));
@ -344,7 +356,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, mod, "open", sol_new_cfunc(state, sol_f_stream_open));
sol_register_module_name(state, "io", mod);
sol_obj_free(mod);
meths = sol_new_map(state);
sol_map_set_name(state, meths, "get", sol_new_cfunc(state, sol_f_buffer_get));
sol_map_set_name(state, meths, "set", sol_new_cfunc(state, sol_f_buffer_set));
@ -362,7 +374,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, meths, "filter", sol_new_cfunc(state, sol_f_list_filter));
sol_register_methods_name(state, "list", meths);
sol_obj_free(meths);
meths = sol_new_map(state);
sol_map_set_name(state, meths, "read", sol_new_cfunc(state, sol_f_stream_read));
sol_map_set_name(state, meths, "write", sol_new_cfunc(state, sol_f_stream_write));
@ -372,20 +384,22 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, meths, "eof", sol_new_cfunc(state, sol_f_stream_eof));
sol_register_methods_name(state, "stream", meths);
sol_obj_free(meths);
meths = sol_new_map(state);
sol_map_set_name(state, meths, "sub", sol_new_cfunc(state, sol_f_str_sub));
sol_map_set_name(state, meths, "split", sol_new_cfunc(state, sol_f_str_split));
sol_map_set_name(state, meths, "find", sol_new_cfunc(state, sol_f_str_find));
sol_register_methods_name(state, "string", meths);
sol_obj_free(meths);
if(sol_has_error(state)) goto cleanup;
if(sol_has_error(state)) {
goto cleanup;
}
// We're all set!
return 1;
cleanup:
cleanup:
sol_obj_free(state->None);
sol_obj_free(state->OutOfMemory);
sol_obj_free(state->StopIteration);
@ -398,7 +412,9 @@ void sol_state_cleanup(sol_state_t *state) {
sol_obj_free(state->None);
sol_obj_free(state->OutOfMemory);
sol_obj_free(state->StopIteration);
if(state->ret) sol_obj_free(state->ret);
if(state->ret) {
sol_obj_free(state->ret);
}
sol_obj_free(state->modules);
sol_obj_free(state->methods);
}
@ -422,7 +438,7 @@ sol_object_t *sol_state_resolve(sol_state_t *state, sol_object_t *key) {
}
dsl_free_seq_iter(iter);
sol_obj_free(args);
temp = sol_get_module(state, key);
if(!sol_is_none(state, temp)) {
return temp;
@ -434,7 +450,9 @@ sol_object_t *sol_state_resolve(sol_state_t *state, sol_object_t *key) {
sol_object_t *sol_state_resolve_name(sol_state_t *state, const char *name) {
sol_object_t *key = sol_new_string(state, name), *temp;
if(sol_ha