39 #include "../base/ver.h"
43 #include "../base/str.h"
46 #ifndef CHECK_INCLUDED
47 #include "../base/check.h"
50 #ifndef MPOOL_INCLUDED
51 #include "../mem/mpool.h"
54 #ifndef FLEXARR_INCLUDED
55 #include "../bds/flexarr.h"
58 #ifndef STACK_INCLUDED
59 #include "../bds/stack.h"
62 #ifndef STRMEM_INCLUDED
63 #include "../dom/strmem.h"
66 #ifndef LIST_2_INCLUDED
67 #include "../rel/list_2.h"
70 #ifndef CUR_2_INCLUDED
71 #include "../rel/cur_2.h"
74 #ifndef SET_2_INCLUDED
75 #include "../rel/set_2.h"
78 #ifndef SET_TT_INCLUDED
79 #include "../rel/set_tt.h"
82 #ifndef REL_N_N_INCLUDED
83 #include "../rel/rel_n_n.h"
86 #ifndef CUR_N_N_INCLUDED
87 #include "../rel/cur_n_n.h"
103 static const int BAM_NULL_ADDR = 0;
114 static const long BAM_MAGIC = 0x41424D0AL;
120 static const int BAM_CODE_AREA_SIZE = 1024;
126 static const int BAM_MAX_VARS = 256;
132 static const int BAM_STACK_SIZE = 1024;
138 static const int BAM_MAX_LIST_2 = 10;
144 static const int BAM_MAX_CUR_2 = 10;
150 static const int BAM_MAX_SET_2 = 10;
156 static const int BAM_MAX_SET_2B = 10;
162 static const int BAM_MAX_MMAP_1_1 = 10;
168 static const int BAM_MAX_CUR_1_1 = 10;
252 void vars(
int num_vars);
342 int cur_2(
int list_id);
387 store_inst(INST_NULL);
402 store_inst(INST_HALT);
420 CHECK(addr >= 0,
"bam_c::call: addr is negative");
421 CHECK(addr < BAM_CODE_AREA_SIZE,
422 "bam_c::call: addr too large");
423 CHECK(addr < NextCodeAddr,
424 "bam_c::call: addr not used");
427 store_inst_16(INST_CALL, addr);
445 store_inst_16(INST_CALL, 0);
462 CHECK(inst_addr >= 0,
463 "bam_c::call_patch: inst_addr is negative");
464 CHECK(inst_addr < BAM_CODE_AREA_SIZE,
465 "bam_c::call_patch: inst_addr too large");
466 CHECK(Code[inst_addr] == INST_CALL,
467 "bam_c::call_patch: no CALL instruction");
468 CHECK(proc_addr >= 0,
469 "bam_c::call_patch: proc_addr is negative");
470 CHECK(proc_addr < BAM_CODE_AREA_SIZE,
471 "bam_c::call_patch: proc_addr too large");
472 CHECK(proc_addr <= NextCodeAddr,
473 "bam_c::call_patch: addr not used");
476 if(proc_addr == NextCodeAddr)
481 Code[inst_addr++] =
static_cast<char>((proc_addr>>8) & 0xFF);
482 Code[inst_addr] =
static_cast<char>(proc_addr & 0xFF);
497 store_inst(INST_RETURN);
522 "bam_c::dupcheck_2: set_id is negative");
523 CHECK(set_id < NumRelSet2,
524 "bam_c::dupcheck_2: set_id too large");
526 "bam_c::dupcheck_2: var_id is negative");
527 CHECK(var_id < NumVars,
528 "bam_c::dupcheck_2: var_id too large");
531 store_inst_8_8(INST_DUPCHECK_2, set_id, var_id);
557 "bam_c::dupcheck_2b: set_id is negative");
558 CHECK(set_id < NumRelSet2B,
559 "bam_c::dupcheck_2b: set_id too large");
561 "bam_c::dupcheck_2b: var1_id is negative");
562 CHECK(var1_id < NumVars,
563 "bam_c::dupcheck_2b: var1_id too large");
565 "bam_c::dupcheck_2b: var2_id is negative");
566 CHECK(var2_id < NumVars,
567 "bam_c::dupcheck_2b: var2_id too large");
570 store_inst_8_8_8(INST_DUPCHECK_2B, set_id, var1_id, var2_id);
592 "bam_c::save_var: var_id is negative");
593 CHECK(var_id < NumVars,
594 "bam_c::save_var: var_id too large");
597 store_inst_8(INST_SAVE_VAR, var_id);
619 "bam_c::restore_var: var_id is negative");
620 CHECK(var_id < NumVars,
621 "bam_c::restore_var: var_id too large");
624 store_inst_8(INST_RESTORE_VAR, var_id);
643 "bam_c::save_mmap_1_1_cur: cur_id is negative");
644 CHECK(cur_id < NumCurMMap11,
645 "bam_c::save_mmap_1_1_cur: cur_id too large");
648 store_inst_8(INST_SAVE_MMAP_1_1_CUR, cur_id);
667 "bam_c::restore_mmap_1_1_cur: cur_id is negative");
668 CHECK(cur_id < NumCurMMap11,
669 "bam_c::restore_mmap_1_1_cur: cur_id too large");
672 store_inst_8(INST_RESTORE_MMAP_1_1_CUR, cur_id);
690 CHECK(cur_id >= 0,
"bam_c::loop_list_2: cur_id is negative");
691 CHECK(cur_id < NumCurList2,
692 "bam_c::loop_list_2: cur_id too large");
695 store_inst_8_16(INST_LOOP_LIST_2, cur_id, 0);
713 CHECK(inst_addr >= 0,
714 "bam_c::loop_patch: inst_addr is negative");
715 CHECK(inst_addr < BAM_CODE_AREA_SIZE,
716 "bam_c::loop_patch: inst_addr too large");
717 CHECK(inst_addr < NextCodeAddr,
718 "bam_c::loop_patch: inst_addr not used");
719 CHECK(Code[inst_addr] == INST_LOOP_LIST ||
720 Code[inst_addr] == INST_LOOP_LIST_2 ||
721 Code[inst_addr] == INST_LOOP_MMAP ||
722 Code[inst_addr] == INST_LOOP_MMAP_1_1,
723 "bam_c::loop_patch: no LOOP instruction");
724 CHECK(loop_done_addr >= 0,
725 "bam_c::loop_patch: loop_done_addr is negative");
726 CHECK(loop_done_addr < BAM_CODE_AREA_SIZE,
727 "bam_c::loop_patch: loop_done_addr too large");
728 CHECK(loop_done_addr <= NextCodeAddr,
729 "bam_c::loop_patch: loop_done_addr not used");
732 if(loop_done_addr == NextCodeAddr)
738 Code[inst_addr++] =
static_cast<char>((loop_done_addr>>8)&0xFF);
739 Code[inst_addr] =
static_cast<char>(loop_done_addr & 0xFF);
769 "bam_c::loop_mmap_1_1: cur_id is negative");
770 CHECK(cur_id < NumCurMMap11,
771 "bam_c::loop_mmap_1_1: cur_id too large");
772 CHECK(loop_done_addr == BAM_NULL_ADDR ||
774 "bam_c::loop_mmap_1_1: loop_done_addr is negative");
775 CHECK(loop_done_addr == BAM_NULL_ADDR ||
776 loop_done_addr < BAM_CODE_AREA_SIZE,
777 "bam_c::loop_mmap_1_1: loop_done_addr too large");
778 CHECK(loop_done_addr == BAM_NULL_ADDR ||
779 loop_done_addr <= NextCodeAddr,
780 "bam_c::loop_mmap_1_1: loop_done_addr not used");
782 "bam_c::loop_mmap_1_1: var_id is negative");
783 CHECK(var_id < NumVars,
784 "bam_c::loop_mmap_1_1: var_id too large");
787 store_inst_8_16_8(INST_LOOP_MMAP_1_1, cur_id, loop_done_addr,
806 "bam_c::get_list_2_col_1: cur_id is negative");
807 CHECK(cur_id < NumCurList2,
808 "bam_c::get_list_2_col_1: cur_id too large");
810 "bam_c::get_list_2_col_1: var_id is negative");
811 CHECK(var_id < NumVars,
812 "bam_c::get_list_2_col_1: var_id too large");
815 store_inst_8_8(INST_GET_LIST_2_COL_1, cur_id, var_id);
834 "bam_c::get_list_2_col_2: cur_id is negative");
835 CHECK(cur_id < NumCurList2,
836 "bam_c::get_list_2_col_2: cur_id too large");
838 "bam_c::get_list_2_col_2: var_id is negative");
839 CHECK(var_id < NumVars,
840 "bam_c::get_list_2_col_2: var_id too large");
843 store_inst_8_8(INST_GET_LIST_2_COL_2, cur_id, var_id);
862 "bam_c::get_mmap_1_1_out_1: cur_id is negative");
863 CHECK(cur_id < NumCurMMap11,
864 "bam_c::get_mmap_1_1_out_1: cur_id too large");
866 "bam_c::get_mmap_1_1_out_1: var_id is negative");
867 CHECK(var_id < NumVars,
868 "bam_c::get_mmap_1_1_out_1: var_id too large");
871 store_inst_8_8(INST_GET_MMAP_1_1_OUT_1, cur_id, var_id);
901 "bam_c::end_loop_list_2: cur_id is negative");
902 CHECK(cur_id < NumCurList2,
903 "bam_c::end_loop_list_2: cur_id too large");
904 CHECK(loop_body_addr >= 0,
905 "bam_c::end_loop_list_2: loop_body_addr is negative");
906 CHECK(loop_body_addr < BAM_CODE_AREA_SIZE,
907 "bam_c::end_loop_list_2: loop_body_addr too large");
908 CHECK(loop_body_addr < NextCodeAddr,
909 "bam_c::end_loop_list_2: loop_body_addr not used");
912 store_inst_8_16(INST_END_LOOP_LIST_2, cur_id, loop_body_addr);
942 "bam_c::end_loop_mmap_1_1: cur_id is negative");
943 CHECK(cur_id < NumCurMMap11,
944 "bam_c::end_loop_mmap_1_1: cur_id too large");
945 CHECK(loop_body_addr >= 0,
946 "bam_c::end_loop_mmap_1_1: loop_body_addr is negative");
947 CHECK(loop_body_addr < BAM_CODE_AREA_SIZE,
948 "bam_c::end_loop_mmap_1_1: loop_body_addr too large");
949 CHECK(loop_body_addr < NextCodeAddr,
950 "bam_c::end_loop_mmap_1_1: loop_body_addr not used");
953 store_inst_8_16(INST_END_LOOP_MMAP_1_1, cur_id, loop_body_addr);
980 "bam_c::insert_list_2: rel_id is negative");
981 CHECK(rel_id < NumRelList2,
982 "bam_c::insert_list_2: rel_id too large");
984 "bam_c::insert_list_2: var1_id is negative");
985 CHECK(var1_id < NumVars,
986 "bam_c::insert_list_2: var1_id too large");
988 "bam_c::insert_list_2: var2_id is negative");
989 CHECK(var2_id < NumVars,
990 "bam_c::insert_list_2: var2_id too large");
993 store_inst_8_8_8(INST_INSERT_LIST_2, rel_id, var1_id, var2_id);
1012 "bam_c::insert_list_2_v: rel_id is negative");
1013 CHECK(rel_id < NumRelList2,
1014 "bam_c::insert_list_2_v: rel_id too large");
1016 "bam_c::insert_list_2_v: var_id is negative");
1017 CHECK(var_id < NumVars,
1018 "bam_c::insert_list_2_v: var_id too large");
1021 store_inst_8_8(INST_INSERT_LIST_2_V, rel_id, var_id);
1048 "bam_c::insert_mmap_1_1: set_id is negative");
1049 CHECK(set_id < NumRelMMap11,
1050 "bam_c::insert_mmap_1_1: set_id too large");
1052 "bam_c::insert_mmap_1_1: var1_id is negative");
1053 CHECK(var1_id < NumVars,
1054 "bam_c::insert_mmap_1_1: var1_id too large");
1056 "bam_c::insert_mmap_1_1: var2_id is negative");
1057 CHECK(var2_id < NumVars,
1058 "bam_c::insert_mmap_1_1: var2_id too large");
1061 store_inst_8_8_8(INST_INSERT_MMAP_1_1,
1062 set_id, var1_id, var2_id);
1089 "bam_c::trace_call_2: str_id is negative");
1090 CHECK(str_id < Strings.length(),
1091 "bam_c::trace_call_2: str_id too large");
1093 "bam_c::trace_call_2: str_id not 8 bit");
1095 "bam_c::trace_call_2: var1_id is negative");
1096 CHECK(var1_id < NumVars,
1097 "bam_c::trace_call_2: var1_id too large");
1099 "bam_c::trace_call_2: var2_id is negative");
1100 CHECK(var2_id < NumVars,
1101 "bam_c::trace_call_2: var2_id too large");
1104 store_inst_8_8_8(INST_TRACE_CALL_2,
1105 str_id, var1_id, var2_id);
1117 bool run(
int start_addr);
1136 str_t check()
const;
1171 void store_inst(
inst_t inst);
1182 void store_inst_8(
inst_t inst,
int arg);
1193 void store_inst_16(
inst_t inst,
int arg);
1204 void store_inst_8_8(
inst_t inst,
int arg1,
int arg2);
1215 void store_inst_8_8_8(
inst_t inst,
int arg1,
int arg2,
int arg3);
1226 void store_inst_8_16(
inst_t inst,
int arg1,
int arg2);
1237 void store_inst_8_16_8(
inst_t inst,
int arg1,
int arg2,
int arg3);
1256 void store_tmp_halt();
1278 unsigned char Code[BAM_CODE_AREA_SIZE];
1284 int Vars[BAM_MAX_VARS];
1302 cur_2_t CurList2[BAM_MAX_CUR_2];
1306 set_2_t RelSet2[BAM_MAX_SET_2];
1346 #define BAM_NULL (static_cast<bam_t>(0))
void get_list_2_col_2(int cur_id, int var_id)
Definition: bam.h:827
void save_mmap_1_1_cur(int cur_id)
Definition: bam.h:636
void end_loop_mmap_1_1(int cur_id, int loop_body_addr)
Definition: bam.h:935
void get_list_2_col_1(int cur_id, int var_id)
Definition: bam.h:799
void dump(str_t headline=STR_NULL) const
Definition: bam.cpp:1235
int cur_1_1(int mmap_id)
Definition: bam.cpp:316
int list_2(list_2_t list)
Definition: bam.cpp:160
void end_loop_list_2(int cur_id, int loop_body_addr)
Definition: bam.h:894
void call_forward()
Definition: bam.h:439
void loop_patch(int inst_addr, int loop_done_addr)
Definition: bam.h:707
void dupcheck_2b(int set_id, int var1_id, int var2_id)
Definition: bam.h:550
void restore_mmap_1_1_cur(int cur_id)
Definition: bam.h:660
int next_code_addr()
Definition: bam.h:366
void insert_list_2(int rel_id, int var1_id, int var2_id)
Definition: bam.h:973
void dupcheck_2(int set_id, int var_id)
Definition: bam.h:515
void loop_list_2(int cur_id)
Definition: bam.h:684
int string(str_t str)
Definition: bam.cpp:127
bam_c(str_t name)
Definition: bam.cpp:55
void vars(int num_vars)
Definition: bam.cpp:104
#define CHECK_VALID(EX)
Definition: check.h:85
void null()
Definition: bam.h:384
const char * str_t
Definition: str.h:41
void loop_mmap_1_1(int cur_id, int loop_done_addr, int var_id)
Definition: bam.h:762
int cur_2(int list_id)
Definition: bam.cpp:263
void insert_mmap_1_1(int set_id, int var1_id, int var2_id)
Definition: bam.h:1041
void get_mmap_1_1_out_1(int cur_id, int var_id)
Definition: bam.h:855
void trace_call_2(int str_id, int var1_id, int var2_id)
Definition: bam.h:1082
void call(int addr)
Definition: bam.h:414
int mmap_1_1(rel_n_n_t mmap)
Definition: bam.cpp:238
#define STR_NULL
Definition: str.h:52
void halt()
Definition: bam.h:399
void restore_var(int var_id)
Definition: bam.h:612
bam_c * bam_t
Definition: bam.h:1336
void insert_list_2_v(int rel_id, int var_id)
Definition: bam.h:1005
int set_2(set_2_t set)
Definition: bam.cpp:186
int set_2b(set_tt_t set)
Definition: bam.cpp:212
void ret()
Definition: bam.h:494
bool run(int start_addr)
Definition: bam.cpp:370
bool error()
Definition: bam.h:234
#define CHECK(EX, MSG)
Definition: check.h:69
void call_patch(int inst_addr, int proc_addr)
Definition: bam.h:456
Enumeration type for Abstract Machine Instructions (OpCodes)
void save_var(int var_id)
Definition: bam.h:585