diff --git a/docs/language.js b/docs/language.js index 4492524d..b36b6778 100644 --- a/docs/language.js +++ b/docs/language.js @@ -1074,7 +1074,7 @@ var data = [ "parameter" : "mutate * node [number mutation_rate] [assoc mutation_weights] [assoc operation_type]", "output" : "*", "new value" : "new", - "description" : "Evaluates to a mutated version of the input node. The value specified in mutation_rate, from 0.0 to 1.0 and defaulting to 0.00001, indicates the probability that any node will experience a mutation. The parameter mutation_weights is an assoc where the keys are the allowed opcode names and the values are the probabilities that each opcode would be chosen; if null or unspecified, it defaults to all opcodes each with their own default probability. The operation_type is an assoc where the keys are mutation operations and the values are the probabilities that the operations will be performed. The operations can consist of the strings change_type, delete, insert, swap_elements, deep_copy_elements, delete, and change_label.", + "description" : "Evaluates to a mutated version of the input node. The value specified in mutation_rate, from 0.0 to 1.0 and defaulting to 0.00001, indicates the probability that any node will experience a mutation. The parameter mutation_weights is an assoc where the keys are the allowed opcode names and the values are the probabilities that each opcode would be chosen; if null or unspecified, it defaults to all opcodes each with their own default probability. The operation_type is an assoc where the keys are mutation operations and the values are the probabilities that the operations will be performed. The operations can consist of the strings change_type, delete, insert, swap_elements, deep_copy_elements, delete_elements, and change_label.", "example" : "(print (mutate\n (lambda (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (assoc \"a\" 1 \"b\" 2)))\n0.4))\n" }, @@ -1156,7 +1156,7 @@ var data = [ "output" : "id", "permissions" : "e", "new value" : "new", - "description" : "Creates a mutated version of the entity specified by entity1 like mutate. Returns the id of a new entity created contained by the entity that ran it. The value specified in mutation_rate, from 0.0 to 1.0 and defaulting to 0.00001, indicates the probability that any node will experience a mutation. Uses entity2 as the optional destination via an internal call to create_contained_entity. The parameter mutation_weights is an assoc where the keys are the allowed opcode names and the values are the probabilities that each opcode would be chosen; if null or unspecified, it defaults to all opcodes each with their own default probability. The operation_type is an assoc where the keys are mutation operations and the values are the probabilities that the operations will be performed. The operations can consist of the strings change_type, delete, insert, swap_elements, deep_copy_elements, delete, and change_label.", + "description" : "Creates a mutated version of the entity specified by entity1 like mutate. Returns the id of a new entity created contained by the entity that ran it. The value specified in mutation_rate, from 0.0 to 1.0 and defaulting to 0.00001, indicates the probability that any node will experience a mutation. Uses entity2 as the optional destination via an internal call to create_contained_entity. The parameter mutation_weights is an assoc where the keys are the allowed opcode names and the values are the probabilities that each opcode would be chosen; if null or unspecified, it defaults to all opcodes each with their own default probability. The operation_type is an assoc where the keys are mutation operations and the values are the probabilities that the operations will be performed. The operations can consist of the strings change_type, delete, insert, swap_elements, deep_copy_elements, delete_elements, and change_label.", "example" : "(create_entities\n \"MutateEntity\"\n (lambda (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (assoc \"a\" 1 \"b\" 2)))\n)\n(mutate_entity \"MutateEntity\" 0.4 \"MutatedEntity\")\n(print (retrieve_entity_root \"MutatedEntity\"))" }, diff --git a/src/Amalgam/importexport/FileSupportJSON.cpp b/src/Amalgam/importexport/FileSupportJSON.cpp index 65e81ed9..f894e63b 100644 --- a/src/Amalgam/importexport/FileSupportJSON.cpp +++ b/src/Amalgam/importexport/FileSupportJSON.cpp @@ -58,10 +58,12 @@ EvaluableNode *JsonToEvaluableNodeRecurse(EvaluableNodeManager *enm, simdjson::o } case simdjson::ondemand::json_type::boolean: + { if(element.get_bool()) return enm->AllocNode(ENT_TRUE); else return enm->AllocNode(ENT_FALSE); + } case simdjson::ondemand::json_type::null: return nullptr; @@ -277,6 +279,34 @@ EvaluableNode *EvaluableNodeJSONTranslation::JsonToEvaluableNode(EvaluableNodeMa auto json_padded = simdjson::padded_string(json_str); auto json_top_element = json_parser.iterate(json_padded); + //simdjson needs special handling if the top element is a scalar + if(json_top_element.is_scalar()) + { + switch(json_top_element.type()) + { + case simdjson::ondemand::json_type::number: + return enm->AllocNode(json_top_element.get_double()); + + case simdjson::ondemand::json_type::string: + { + std::string_view str_view = json_top_element.get_string(); + std::string str(str_view); + return enm->AllocNode(ENT_STRING, str); + } + + case simdjson::ondemand::json_type::boolean: + { + if(json_top_element.get_bool()) + return enm->AllocNode(ENT_TRUE); + else + return enm->AllocNode(ENT_FALSE); + } + + default: + return nullptr; + } + } + try { return JsonToEvaluableNodeRecurse(enm, json_top_element);