diff --git a/src/memory/types.rs b/src/memory/types.rs index de0f585..77ffd67 100644 --- a/src/memory/types.rs +++ b/src/memory/types.rs @@ -1,12 +1,12 @@ +use serde::{Deserialize, Serialize}; use std::fmt; - pub type ID = String; pub type StackPage = Vec; pub type FilePage = (String, Vec); /// Entry is an enum that can be either a String or a Json Value. /// It is used for I/O operations in the memory module. -#[derive(Debug, serde::Deserialize, PartialEq)] +#[derive(Debug, Serialize, serde::Deserialize, PartialEq)] pub enum Entry { String(String), Json(serde_json::Value), @@ -39,7 +39,7 @@ impl Clone for Entry { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum MemoryReturnType { //<'a> //EntryRef(Option<&'a Entry>), @@ -55,6 +55,10 @@ impl MemoryReturnType { MemoryReturnType::EntryVec(entry_vec) => entry_vec.is_none(), } } + + pub fn to_json(&self) -> serde_json::Result { + serde_json::to_string(&self) + } } impl fmt::Display for MemoryReturnType { diff --git a/src/program/executor.rs b/src/program/executor.rs index f088170..70fd21d 100644 --- a/src/program/executor.rs +++ b/src/program/executor.rs @@ -206,6 +206,13 @@ impl Executor { }; } } + + if rv.to_json.is_some() && rv.to_json.unwrap() { + let res = return_value.to_json(); + if res.is_ok() { + return_string = res.unwrap(); + } + } return_string }