25 template <
typename TYPE>
using IndexTypeOf =
typename std::vector<TYPE>::size_type;
50 const std::vector<int64_t>
60 bool endline = true) const;
64 decompiled_at(int64_t bytecode_position, const std::
string& indent=
"") const;
67 const std::vector<std::
string>
105 return stack_depth_ < stack_max_depth_;
111 return stack_depth_ > 0;
117 stack_buffer_[stack_depth_] = value;
125 return stack_buffer_[stack_depth_];
133 const std::map<std::
string, T>
137 const std::vector<std::
string>
165 const std::vector<std::
string>
275 is_nbit(const std::
string& word, I& value) const;
294 return recursion_target_depth_.empty();
300 return !(bytecodes_pointer_where() < (
301 bytecodes_offsets_[(IndexTypeOf<int64_t>)bytecodes_pointer_which() + 1] -
302 bytecodes_offsets_[(IndexTypeOf<int64_t>)bytecodes_pointer_which()]
309 segment_nonempty(int64_t segment_position)
const;
313 bytecodes_per_instruction(int64_t bytecode_position)
const;
317 err_linecol(
const std::vector<std::pair<int64_t, int64_t>>& linecol,
320 const std::string& message)
const;
324 tokenize(std::vector<std::string>& tokenized,
325 std::vector<std::pair<int64_t, int64_t>>& linecol);
329 compile(
const std::vector<std::string>& tokenized,
330 const std::vector<std::pair<int64_t, int64_t>>& linecol);
334 parse(
const std::string& defn,
335 const std::vector<std::string>& tokenized,
336 const std::vector<std::pair<int64_t, int64_t>>& linecol,
339 std::vector<I>& bytecodes,
340 std::vector<std::vector<I>>& dictionary,
346 internal_run(
bool single_step, int64_t recursion_target_depth_top);
350 write_from_stack(int64_t num, T* top)
noexcept;
354 write_add_from_stack(int64_t num, T* top)
noexcept;
358 print_number(T num)
noexcept;
362 stack_cannot_push() const noexcept {
363 return stack_depth_ == stack_max_depth_;
368 stack_cannot_pop() const noexcept {
369 return stack_depth_ == 0;
374 stack_cannot_pop2() const noexcept {
375 return stack_depth_ < 2;
380 stack_cannot_pop3() const noexcept {
381 return stack_depth_ < 3;
386 stack_pop2() noexcept {
388 return &stack_buffer_[stack_depth_];
393 stack_pop2_before_pushing1() noexcept {
395 return &stack_buffer_[stack_depth_ - 1];
400 stack_peek() const noexcept {
401 return &stack_buffer_[stack_depth_ - 1];
406 bytecode_get() const noexcept {
407 int64_t start = bytecodes_offsets_[(IndexTypeOf<int64_t>)bytecodes_pointer_which()];
408 return bytecodes_[(IndexTypeOf<I>)(start + bytecodes_pointer_where())];
413 bytecodes_pointer_push(int64_t which)
noexcept {
414 current_which_[recursion_current_depth_] = which;
415 current_where_[recursion_current_depth_] = 0;
416 recursion_current_depth_++;
421 bytecodes_pointer_pop() noexcept {
422 recursion_current_depth_--;
427 bytecodes_pointer_which() const noexcept {
428 return current_which_[recursion_current_depth_ - 1];
433 bytecodes_pointer_where() const noexcept {
434 return current_where_[recursion_current_depth_ - 1];
439 do_loop_push(int64_t start, int64_t stop)
noexcept {
440 do_recursion_depth_[do_current_depth_] = recursion_current_depth_;
441 do_stop_[do_current_depth_] = stop;
442 do_i_[do_current_depth_] = start;
448 do_steploop_push(int64_t start, int64_t stop)
noexcept {
449 do_recursion_depth_[do_current_depth_] = ~recursion_current_depth_;
450 do_stop_[do_current_depth_] = stop;
451 do_i_[do_current_depth_] = start;
457 do_recursion_depth() const noexcept {
458 return do_recursion_depth_[do_current_depth_ - 1];
463 do_abs_recursion_depth() const noexcept {
464 int64_t out = do_recursion_depth_[do_current_depth_ - 1];
475 do_loop_is_step() const noexcept {
476 return do_recursion_depth_[do_current_depth_ - 1] < 0;
481 do_stop() const noexcept {
482 return do_stop_[do_current_depth_ - 1];
487 do_i() const noexcept {
488 return do_i_[do_current_depth_ - 1];
493 do_j() const noexcept {
494 return do_i_[do_current_depth_ - 2];
499 do_k() const noexcept {
500 return do_i_[do_current_depth_ - 3];
504 int64_t output_initial_size_;
505 double output_resize_factor_;
507 std::unique_ptr<T[]> stack_buffer_;
508 int64_t stack_depth_;
509 int64_t stack_max_depth_;
511 std::vector<std::string> variable_names_;
512 std::vector<T> variables_;
514 std::vector<std::string> input_names_;
515 std::vector<bool> input_must_be_writable_;
516 std::vector<std::string> output_names_;
517 std::vector<util::dtype> output_dtypes_;
519 std::vector<std::string> strings_;
520 std::vector<std::string> dictionary_names_;
521 std::vector<I> dictionary_bytecodes_;
522 std::vector<int64_t> bytecodes_offsets_;
523 std::vector<I> bytecodes_;
525 std::unique_ptr<char[]> string_buffer_;
526 int64_t string_buffer_size_;
528 std::vector<std::shared_ptr<ForthInputBuffer>> current_inputs_;
529 std::vector<std::shared_ptr<ForthOutputBuffer>> current_outputs_;
532 std::unique_ptr<int64_t[]> current_which_;
533 std::unique_ptr<int64_t[]> current_where_;
534 int64_t recursion_current_depth_;
535 std::stack<int64_t> recursion_target_depth_;
536 int64_t recursion_max_depth_;
538 std::unique_ptr<int64_t[]> do_recursion_depth_;
539 std::unique_ptr<int64_t[]> do_stop_;
540 std::unique_ptr<int64_t[]> do_i_;
541 int64_t do_current_depth_;
543 util::ForthError current_error_;
545 int64_t count_instructions_;
546 int64_t count_reads_;
547 int64_t count_writes_;
548 int64_t count_nanoseconds_;