فهرست منبع

[eval] support evaluate

Simon Krajewski 7 سال پیش
والد
کامیت
7a5b299c1d
2فایلهای تغییر یافته به همراه19 افزوده شده و 2 حذف شده
  1. 1 2
      src/macro/eval/evalDebugMisc.ml
  2. 18 0
      src/macro/eval/evalDebugSocket.ml

+ 1 - 2
src/macro/eval/evalDebugMisc.ml

@@ -68,7 +68,6 @@ let find_breakpoint ctx sid =
 	with Exit ->
 		match !found with None -> assert false | Some breakpoint -> breakpoint
 
-
 (* Helper *)
 
 exception Parse_expr_error of string
@@ -197,7 +196,7 @@ let rec expr_to_value ctx env e =
 				let v1 = loop e1 in
 				let v2 = loop e2 in
 				let p = pos e in
-				(get_binop_fun op p) v1 v2
+				(try get_binop_fun op p with _ -> raise Exit) v1 v2
 			end
 		| EUnop(op,flag,e1) ->
 			begin match op with

+ 18 - 0
src/macro/eval/evalDebugSocket.ml

@@ -517,6 +517,24 @@ let make_connection socket =
 					with Parse_expr_error e ->
 						error e
 					end
+				| "evaluate" ->
+					let s =
+						match params with
+						| Some (JObject fl) ->
+							let id = try List.find (fun (n,_) -> n = "expr") fl with Not_found -> invalid_params () in
+							(match (snd id) with JString s -> s | _ -> invalid_params ())
+						| _ -> invalid_params ()
+					in
+					begin try
+						let e = parse_expr ctx s env.env_debug.expr.epos in
+						let v = expr_to_value ctx env e in
+						Loop (var_to_json "" v (Ast.s_expr e))
+					with
+					| Parse_expr_error e ->
+						error e
+					| Exit ->
+						error "Don't know how to handle this expression"
+					end
 				| meth ->
 					let open JsonRpc in
 					raise (JsonRpc_error (Method_not_found (id, meth)))