Browse Source

Sol Part 31: Rip In Pieces!

Graham Northup 5 years ago
parent
commit
792c057cc6
2 changed files with 48 additions and 23 deletions
  1. 24
    3
      builtins.c
  2. 24
    20
      interp.sol

+ 24
- 3
builtins.c View File

@@ -1458,6 +1458,12 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
1458 1458
 	assoclist_node *cura;
1459 1459
 	identlist_node *curi;
1460 1460
 	int i = 0;
1461
+	if(!stmt) {
1462
+		sol_obj_free(obj);
1463
+		sol_obj_free(key);
1464
+		sol_obj_free(str);
1465
+		return sol_set_error_string(state, "Access NULL AST node");
1466
+	}
1461 1467
 	if(sol_is_aststmt(obj)) {
1462 1468
 		if(sol_string_eq(state, str, "type")) {
1463 1469
 			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) {
1664 1670
 	assoclist_node *cura, *preva = NULL;
1665 1671
 	identlist_node *curi, *previ = NULL;
1666 1672
 	int i = 0, len;
1673
+	if(!stmt) {
1674
+		sol_obj_free(obj);
1675
+		sol_obj_free(key);
1676
+		sol_obj_free(str);
1677
+		sol_obj_free(val);
1678
+		return sol_set_error_string(state, "Access NULL AST node");
1679
+	}
1667 1680
 	if(sol_is_aststmt(obj)) {
1668 1681
 		if(sol_string_eq(state, str, "type")) {
1669 1682
 			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) {
1984 1997
 	sol_object_t *obj = sol_list_get_index(state, args, 0), *res;
1985 1998
 	char s[64];
1986 1999
 	if(sol_is_aststmt(obj)) {
1987
-		snprintf(s, 64, "<Stmt[%s]>", sol_StmtNames[((stmt_node *)obj->node)->type]);
2000
+		if(!obj->node) {
2001
+			snprintf(s, 64, "<NULL Stmt>");
2002
+		} else {
2003
+			snprintf(s, 64, "<Stmt[%s]>", sol_StmtNames[((stmt_node *)obj->node)->type]);
2004
+		}
1988 2005
 	} else {
1989
-		snprintf(s, 64, "<Expr[%s]>", sol_ExprNames[((expr_node *)obj->node)->type]);
2006
+		if(!obj->node) {
2007
+			snprintf(s, 64, "<NULL Expr>");
2008
+		} else {
2009
+			snprintf(s, 64, "<Expr[%s]>", sol_ExprNames[((expr_node *)obj->node)->type]);
2010
+		}
1990 2011
 	}
1991 2012
 	sol_obj_free(obj);
1992 2013
 	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) {
2492 2513
 		return sol_set_error_string(state, "File open failed");
2493 2514
 	}
2494 2515
 	return sol_new_stream(state, f, m);
2495
-}
2516
+}

+ 24
- 20
interp.sol View File

@@ -47,28 +47,32 @@ while __interp.running do
47 47
 					if !__interp.program[0] then
48 48
 						print('Syntax error')
49 49
 					else
50
-						if __interp.program[1].stmtlist[0].type == ast.ST_EXPR then
51
-							__interp.program[1] = __interp.program[1].stmtlist[0].expr
52
-							__interp.isexpr = 1
50
+						if !(try(func() __interp.program[1].stmtlist[0].type end)[0]) then
51
+							print('NULL program error')
53 52
 						else
54
-							__interp.isexpr = 0
55
-						end
56
-						__interp.result = try(__interp.program[1])
57
-						if !__interp.result[0] then
58
-							print(__interp.result[1])
59
-							print(__interp.result[2])
60
-							for ent in __interp.result[2] do
61
-								st = ent[0]
62
-								scope = ent[1]
63
-								if st.type == ast.ST_LIST then continue end
64
-								print('In', st, 'at', st.loc.line, ',', st.loc.col, ':')
65
-								ast.print(st)
66
-								print(scope)
67
-								print('---')
53
+							if __interp.program[1].stmtlist[0].type == ast.ST_EXPR then
54
+								__interp.program[1] = __interp.program[1].stmtlist[0].expr
55
+								__interp.isexpr = 1
56
+							else
57
+								__interp.isexpr = 0
68 58
 							end
69
-						else
70
-							if __interp.isexpr then
71
-								prepr(__interp.result[1])
59
+							__interp.result = try(__interp.program[1])
60
+							if !__interp.result[0] then
61
+								print(__interp.result[1])
62
+								print(__interp.result[2])
63
+								for ent in __interp.result[2] do
64
+									st = ent[0]
65
+									scope = ent[1]
66
+									if st.type == ast.ST_LIST then continue end
67
+									print('In', st, 'at', st.loc.line, ',', st.loc.col, ':')
68
+									ast.print(st)
69
+									print(scope)
70
+									print('---')
71
+								end
72
+							else
73
+								if __interp.isexpr then
74
+									prepr(__interp.result[1])
75
+								end
72 76
 							end
73 77
 						end
74 78
 					end

Loading…
Cancel
Save