3#ifndef AWKWARD_LayoutBuilder_H_
4#define AWKWARD_LayoutBuilder_H_
23 enum class state : std::int32_t {
48 using utype = std::underlying_type<state>::type;
61 template <
typename T,
typename I>
72 const int64_t initial,
99 const std::shared_ptr<ForthMachineOf<T, I>>
200 template <
typename D>
203 auto const& outputs = vm_.get()->outputs();
204 auto search = outputs.find(vm_output_data);
205 if (search != outputs.end()) {
206 auto data = std::static_pointer_cast<D>(search->second.get()->ptr());
207 auto size = search->second.get()->len();
208 for (int64_t i = 0; i < size; i++) {
209 if (data.get()[i] == x) {
266 form_builder_from_json(
const std::string& json_form);
269 template <
typename JSON>
271 from_json(
const JSON& json_doc);
275 initialise_builder(
const std::string& json_form);
282 template <
typename D>
287 const std::string json_form_;
296 std::shared_ptr<ForthMachineOf<T, I>> vm_;
299 std::map<std::string, std::shared_ptr<ForthInputBuffer>> vm_inputs_map_;
302 std::string vm_input_data_;
305 std::string vm_source_;
308 std::set<util::ForthError> ignore_;
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition: Builder.h:20
Definition: ForthMachine.h:25
User interface to the FormBuilder system: the LayoutBuilder is a fixed reference while the FormBuilde...
Definition: LayoutBuilder.h:62
const std::string vm_source() const
Returns an AwkwardForth source code generated from the 'Form' and passed to the 'ForthMachine' virtua...
void begin_list()
Begins building a nested list.
void pre_snapshot() const
void boolean(bool x)
Adds a boolean value x to the accumulated data.
void index(int64_t x)
Issues an 'index' vm command. The value 'x' is pushed to the VM stack, it is not added to the accumul...
void complex(std::complex< double > x)
Adds a complex value x to the accumulated data.
const std::shared_ptr< ForthMachineOf< T, I > > vm() const
void bytestring(const std::string &x)
Adds an unencoded bytestring x in STL format to the accumulated data.
const std::string & json_form() const
Definition: LayoutBuilder.h:76
void float64(double x)
Adds a real value x to the accumulated data.
const FormBuilderPtr< T, I > builder() const
Definition: LayoutBuilder.h:251
static int64_t next_id()
Generates next unique ID.
LayoutBuilder(const std::string &json_form, const int64_t initial, bool vm_init=true)
Creates an LayoutBuilder from a full set of parameters.
void connect(const std::shared_ptr< ForthMachineOf< T, I > > &vm)
Connects a Virtual Machine if it was not initialized before.
void tag(int8_t tag)
Sets the pointer to a given tag tag; the next command will fill that slot.
void add_bool(bool x)
Adds a boolean value x to the accumulated data.
static int64_t error_id
An error ID to be used to generate a user 'halt' message.
Definition: LayoutBuilder.h:261
void string(const char *x)
Adds a UTF-8 encoded, null-terminated bytestring value x to the accumulated data.
void add_double(double x)
Adds a double value x to the accumulated data.
void add_end_list()
Ends a nested list.
void end_list()
Ends a nested list.
void resume() const
Resume Virtual machine run.
void add_complex(std::complex< double > x)
Adds a complex value x to the accumulated data.
void add_begin_list()
Begins building a nested list.
static int64_t next_error_id()
Generates a user-defined error ID.
static int64_t next_node_id
A unique ID to use when Form nodes do not have Form key defined.
Definition: LayoutBuilder.h:257
bool find_index_of(D x, const std::string &vm_output_data)
Finds an index of a data in a VM output buffer. This is used to build a 'categorical' array.
Definition: LayoutBuilder.h:202
void int64(int64_t x)
Adds an integer value x to the accumulated data.
void null()
Adds a null value to the accumulated data.
void add_string(const std::string &x)
Adds a string value x to the accumulated data.
void string(const std::string &x)
Adds a UTF-8 encoded bytestring x in STL format to the accumulated data.
void add_int64(int64_t x)
Adds an int64_t value x to the accumulated data.
void string(const char *x, int64_t length)
Adds a UTF-8 encoded bytestring value x with a given length to the accumulated data.
void debug_step() const
Prints debug information from the Virtual Machine stack.
int64_t length() const
Current length of the accumulated array.
void bytestring(const char *x)
Adds an unencoded, null-terminated bytestring value x to the accumulated data.
const std::string to_buffers(BuffersContainer &container) const
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
void bytestring(const char *x, int64_t length)
Adds an unencoded bytestring value x with a given length to the accumulated data.
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
Definition: BitMaskedArray.h:15
const std::string primitive_to_state(const std::string &name)
const std::string index_form_to_vm_format(const std::string &form_index)
std::map< std::string, std::shared_ptr< ForthOutputBuffer > > ForthOutputBufferMap
Definition: FormBuilder.h:16
const std::string primitive_to_vm_format(const std::string &name)
const std::string index_form_to_name(const std::string &form_index)
state
Definition: LayoutBuilder.h:23
std::shared_ptr< FormBuilder< T, I > > FormBuilderPtr
Definition: FormBuilder.h:177
std::underlying_type< state >::type utype
Definition: LayoutBuilder.h:48