Browse Source

Sol Part 31: Rip In Pieces!

master
Graham Northup 6 years ago
parent
commit
792c057cc6
  1. 27
      builtins.c
  2. 44
      interp.sol

27
builtins.c

@ -1458,6 +1458,12 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
assoclist_node *cura;
identlist_node *curi;
int i = 0;
if(!stmt) {
sol_obj_free(obj);
sol_obj_free(key);
sol_obj_free(str);
return sol_set_error_string(state, "Access NULL AST node");
}
if(sol_is_aststmt(obj)) {
if(sol_string_eq(state, str, "type")) {
res = sol_new_int(state, stmt->type);
@ -1664,6 +1670,13 @@ sol_object_t *sol_f_astnode_setindex(sol_state_t *state, sol_object_t *args) {
assoclist_node *cura, *preva = NULL;
identlist_node *curi, *previ = NULL;
int i = 0, len;
if(!stmt) {
sol_obj_free(obj);
sol_obj_free(key);
sol_obj_free(str);
sol_obj_free(val);
return sol_set_error_string(state, "Access NULL AST node");
}
if(sol_is_aststmt(obj)) {
if(sol_string_eq(state, str, "type")) {
ival = sol_cast_int(state, val);
@ -1984,9 +1997,17 @@ sol_object_t *sol_f_astnode_tostring(sol_state_t *state, sol_object_t *args) {
sol_object_t *obj = sol_list_get_index(state, args, 0), *res;
char s[64];
if(sol_is_aststmt(obj)) {
snprintf(s, 64, "<Stmt[%s]>", sol_StmtNames[((stmt_node *)obj->node)->type]);
if(!obj->node) {
snprintf(s, 64, "<NULL Stmt>");
} else {
snprintf(s, 64, "<Stmt[%s]>", sol_StmtNames[((stmt_node *)obj->node)->type]);
}
} else {
snprintf(s, 64, "<Expr[%s]>", sol_ExprNames[((expr_node *)obj->node)->type]);
if(!obj->node) {
snprintf(s, 64, "<NULL Expr>");
} else {
snprintf(s, 64, "<Expr[%s]>", sol_ExprNames[((expr_node *)obj->node)->type]);
}
}
sol_obj_free(obj);
return sol_new_string(state, s);
@ -2492,4 +2513,4 @@ sol_object_t *sol_f_stream_open(sol_state_t *state, sol_object_t *args) {
return sol_set_error_string(state, "File open failed");
}
return sol_new_stream(state, f, m);
}
}

44
interp.sol

@ -47,28 +47,32 @@ while __interp.running do
if !__interp.program[0] then
print('Syntax error')
else
if __interp.program[1].stmtlist[0].type == ast.ST_EXPR then
__interp.program[1] = __interp.program[1].stmtlist[0].expr
__interp.isexpr = 1
if !(try(func() __interp.program[1].stmtlist[0].type end)[0]) then
print('NULL program error')
else
__interp.isexpr = 0
end
__interp.result = try(__interp.program[1])
if !__interp.result[0] then
print(__interp.result[1])
print(__interp.result[2])
for ent in __interp.result[2] do
st = ent[0]
scope = ent[1]
if st.type == ast.ST_LIST then continue end
print('In', st, 'at', st.loc.line, ',', st.loc.col, ':')
ast.print(st)
print(scope)
print('---')
if __interp.program[1].stmtlist[0].type == ast.ST_EXPR then
__interp.program[1] = __interp.program[1].stmtlist[0].expr
__interp.isexpr = 1
else
__interp.isexpr = 0
end
else
if __interp.isexpr then
prepr(__interp.result[1])
__interp.result = try(__interp.program[1])
if !__interp.result[0] then
print(__interp.result[1])
print(__interp.result[2])
for ent in __interp.result[2] do
st = ent[0]
scope = ent[1]
if st.type == ast.ST_LIST then continue end
print('In', st, 'at', st.loc.line, ',', st.loc.col, ':')
ast.print(st)
print(scope)
print('---')
end
else
if __interp.isexpr then
prepr(__interp.result[1])
end
end
end
end

Loading…
Cancel
Save