implement BLCK naively
[openc2e.git] / caosVM.h
blob0e5ba109f911deddd9deb23409ad3bf2db439821
1 /*
2 * caosVM.h
3 * openc2e
5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #ifndef _CAOSVM_H
21 #define _CAOSVM_H
23 #include "openc2e.h"
24 #include <map>
25 #include <istream>
26 #include <ostream>
27 #include "AgentRef.h"
28 #include "caosVar.h"
30 #include <boost/variant.hpp>
31 #include <boost/weak_ptr.hpp>
32 using boost::weak_ptr;
34 class script;
36 //#define CAOSDEBUG
37 //#define CAOSDEBUGDETAIL
39 // caosVM_agent.cpp:
40 unsigned int calculateScriptId(unsigned int message_id);
42 #define LVAL 1
43 #define RVAL 2
44 #define BYTESTR 4
46 class badParamException : public caosException {
47 public:
48 badParamException() : caosException("parameter type mismatch") {}
51 class vmStackItem {
52 protected:
53 struct visit_dump : public boost::static_visitor<std::string> {
54 std::string operator()(const caosVar &i) const {
55 return i.dump();
58 std::string operator()(caosVar *i) const {
59 return std::string("ptr ") + i->dump();
62 std::string operator()(const bytestring_t &bs) const {
63 std::ostringstream oss;
64 oss << "[ ";
65 for (bytestring_t::const_iterator i = bs.begin(); i != bs.end(); i++) {
66 oss << (int)*i << " ";
68 oss << "]";
69 return oss.str();
73 struct visit_lval : public boost::static_visitor<const caosVar &> {
75 const caosVar &operator()(const caosVar &i) const {
76 return i;
79 const caosVar &operator()(caosVar *i) const {
80 return *i;
83 const caosVar &operator()(const bytestring_t &) const {
84 throw badParamException();
89 struct visit_bs : public boost::static_visitor<bytestring_t> {
90 bytestring_t operator()(const bytestring_t &i) const {
91 return i;
93 bytestring_t operator()(caosVar *i) const {
94 throw badParamException();
96 bytestring_t operator()(const caosVar &i) const {
97 throw badParamException();
101 boost::variant<caosVar, bytestring_t> value;
103 public:
105 vmStackItem(const caosVar &v) {
106 value = v;
109 vmStackItem(bytestring_t bs) {
110 value = bs;
113 vmStackItem(const vmStackItem &orig) {
114 value = orig.value;
117 const caosVar &getRVal() const {
118 try {
119 return boost::apply_visitor(visit_lval(), value);
120 } catch (boost::bad_visit &e) {
121 throw badParamException();
125 bytestring_t getByteStr() const {
126 try {
127 return boost::apply_visitor(visit_bs(), value);
128 } catch (boost::bad_visit &e) {
129 throw badParamException();
133 std::string dump() const {
134 try {
135 return boost::apply_visitor(visit_dump(), value);
136 } catch (boost::bad_visit &e) {
137 return std::string("ERR::bad_visit");
142 struct callStackItem {
143 std::vector<vmStackItem> valueStack;
144 int nip;
147 typedef class caosVM *caosVM_p;
149 class blockCond {
150 // XXX NOT SERIALIZABLE FIXME
151 public:
152 virtual bool operator()() = 0;
153 virtual ~blockCond() {}
156 class caosVM {
157 public:
158 int trace;
160 blockCond *blocking;
162 void startBlocking(blockCond *whileWhat);
163 bool isBlocking();
165 // nb, ptr is immutable, class is mutable
166 // This is so the stack manipulation macros work in the op classes as well
167 const caosVM_p vm; // == this
169 // script state...
170 shared_ptr<script> currentscript;
171 int nip, cip, runops;
173 bool inst, lock, stop_loop;
174 int timeslice;
176 std::vector<vmStackItem> valueStack;
177 std::vector<vmStackItem> auxStack;
178 std::vector<callStackItem> callStack;
180 std::istream *inputstream;
181 std::ostream *outputstream;
183 // ...which includes variables accessible to script
184 caosVar var[100]; // might want to make this a map, for memory efficiency
185 caosVar _p_[2]; // might want to add this onto the end of above map, if done
186 AgentRef targ, owner, _it_;
187 caosVar from;
188 int part;
189 weak_ptr<class Camera> camera;
190 class Camera *getCamera();
192 void resetScriptState(); // resets everything except OWNR
194 private:
195 void resetCore();
196 public:
198 caosVar result;
200 public:
201 void setTarg(const AgentRef &a) { targ = a; }
202 void setVariables(caosVar &one, caosVar &two) { _p_[0] = one; _p_[1] = two; }
203 void setOwner(Agent *a) { owner = a; }
204 void setOutputStream(std::ostream &o) { outputstream = &o; }
206 class CreatureAgent *getTargCreatureAgent();
207 class Creature *getTargCreature();
208 class SpritePart *getCurrentSpritePart();
209 class AnimatablePart *getCurrentAnimatablePart();
211 void dummy_cmd();
213 // map
214 void v_ADDM();
215 void c_ADDB();
216 void c_BRMI();
217 void c_MAPD();
218 void c_MAPK();
219 void v_ADDR();
220 void c_RTYP();
221 void v_RTYP();
222 void v_RTYP_c2();
223 void c_SETV_RTYP();
224 void c_DOOR();
225 void v_DOOR();
226 void c_RATE();
227 void v_ROOM();
228 void v_LEFT();
229 void v_RGHT();
230 void v_UP();
231 void v_DOWN();
232 void c_PROP();
233 void v_PROP();
234 void c_PERM();
235 void v_PERM();
236 void v_GRAP();
237 void v_GMAP();
238 void c_LINK();
239 void v_LINK();
240 void v_GRID();
241 void c_EMIT();
242 void v_WALL();
243 void c_ALTR();
244 void v_MAPW();
245 void v_MAPH();
246 void v_BKDS();
247 void v_RLOC();
248 void c_DMAP();
249 void v_ERID();
250 void c_DELR();
251 void c_DELM();
252 void v_MLOC();
253 void v_HIRP();
254 void v_LORP();
255 void v_TORX();
256 void v_TORY();
257 void c_CACL();
258 void v_WIND();
259 void v_TEMP();
260 void s_TEMP();
261 void v_LITE();
262 void s_LITE();
263 void v_RADN();
264 void s_RADN();
265 void v_ONTR();
266 void s_ONTR();
267 void v_INTR();
268 void s_INTR();
269 void v_PRES();
270 void s_PRES();
271 void v_HSRC();
272 void s_HSRC();
273 void v_LSRC();
274 void s_LSRC();
275 void v_RSRC();
276 void s_RSRC();
277 void v_PSRC();
278 void s_PSRC();
279 void v_WNDX();
280 void v_WNDY();
281 void c_DOCA();
282 void c_SETV_DOOR();
283 void v_FLOR();
284 void c_SYS_DMAP();
285 void v_GNDW();
286 void v_GRND();
287 void c_ROOM();
288 void v_ROOM_c1();
290 // camera
291 void v_VISI();
292 void v_ONTV();
293 void c_CMRT();
294 void c_META();
295 void v_META();
296 void c_CMRA();
297 void c_CMRP();
298 void v_CMRX();
299 void v_CMRY();
300 void v_WNDW();
301 void v_WNDH();
302 void v_WNDB();
303 void v_WNDL();
304 void v_WNDR();
305 void v_WNDT();
306 void c_WDOW();
307 void v_WDOW();
308 void c_TRCK();
309 void v_TRCK();
310 void c_LINE();
311 void v_SNAX();
312 void c_SCAM();
313 void c_ZOOM();
314 void c_SNAP();
315 void v_LOFT();
316 void c_BKGD();
317 void v_BKGD();
318 void c_FRSH();
319 void c_SYS_CMRP();
320 void c_SYS_CMRA();
321 void c_SYS_CAMT();
322 void c_SYS_WTOP();
324 // world
325 void c_LOAD();
326 void c_SAVE();
327 void c_QUIT();
328 void v_WNAM();
329 void v_WUID();
330 void c_WTNT();
331 void v_NWLD();
332 void c_WRLD();
333 void v_WRLD();
334 void c_PSWD();
335 void v_PSWD();
336 void v_WNTI();
337 void c_DELW();
339 // core
340 void v_GAME();
341 void s_GAME();
342 void v_EAME();
343 void s_EAME();
344 void c_DELG();
345 void c_OUTX();
346 void c_OUTS();
347 void c_OUTV();
348 void c_SCRP(); // dummy
349 void c_RSCR(); // dummy
350 void c_ISCR(); // dummy
351 void c_ENDM();
352 void v_VMNR();
353 void v_VMJR();
354 void v_WOLF();
355 void v_LANG();
356 void v_TOKN();
357 void v_GAME_c2();
358 void s_GAME_c2();
359 void c_VRSN();
360 void v_VRSN();
361 void v_OC2E_DDIR();
362 void c_SYS_CMND();
364 // variables
365 void c_SETV();
366 void v_RAND();
367 void c_REAF();
368 void v_VAxx();
369 void v_OVxx();
370 void v_MVxx();
371 void s_VAxx();
372 void s_OVxx();
373 void s_MVxx();
374 void c_MODV();
375 void c_SUBV();
376 void c_NEGV();
377 void c_MULV();
378 void c_ADDV();
379 void c_SETA();
380 void c_DIVV();
381 void c_SETS();
382 void v_UFOS();
383 void v_MODU();
384 void v_GNAM();
385 void c_ABSV();
386 void v_ACOS();
387 void v_ASIN();
388 void v_ATAN();
389 void v_COS_();
390 void v_SIN_();
391 void v_TAN_();
392 void v_SQRT();
393 void v_P1();
394 void s_P1();
395 void v_P2();
396 void s_P2();
397 void c_ANDV();
398 void c_ORRV();
399 void c_ADDS();
400 void v_VTOS();
401 void v_AVAR();
402 void s_AVAR();
403 void v_CHAR();
404 void c_CHAR();
405 void v_TYPE();
406 void v_ITOF();
407 void v_FTOI();
408 void v_STRL();
409 void v_READ();
410 void v_CATI();
411 void v_CATA();
412 void v_CATX();
413 void c_CATO();
414 void v_WILD();
415 void v_NAME();
416 void s_NAME();
417 void v_MAME();
418 void s_MAME();
419 void v_SUBS();
420 void v_STOI();
421 void v_STOF();
422 void v_LOWA();
423 void v_UPPA();
424 void v_SINS();
425 void v_REAQ();
426 void c_DELN();
427 void v_REAN();
428 void c_NAMN();
429 void v_GAMN();
430 void c_POWV();
431 void c_RNDV();
432 void v_EGGL();
433 void v_HATL();
435 // flow
436 void c_DOIF();
437 void c_ENDI();
438 void c_REPS();
439 void c_REPE();
440 void c_ELSE();
441 void c_ELIF();
442 void c_LOOP();
443 void c_EVER();
444 void c_UNTL();
445 void c_GSUB();
446 void c_SUBR();
447 void c_RETN();
448 void c_ENUM();
449 void c_ESEE();
450 void c_ETCH();
451 void c_EPAS();
452 void c_ECON();
453 void c_NEXT();
454 void c_CALL();
455 void v_CAOS();
457 // debug
458 void c_DBG_ASRT();
459 void c_DBG_OUTS();
460 void c_DBG_OUTV();
461 void c_DBUG();
462 void c_DBG_MALLOC();
463 void c_DBG_DUMP();
464 void c_DBG_TRACE();
465 void c_MANN();
466 void c_DBG_DISA();
467 void v_UNID();
468 void v_UNID_c2();
469 void v_AGNT();
470 void v_DBG_IDNT();
471 void c_DBG_PROF();
472 void c_DBG_CPRO();
473 void v_DBG_STOK();
474 void c_DBG_TSLC();
475 void v_DBG_TSLC();
477 // agent
478 void c_NEW_COMP();
479 void c_NEW_COMP_c1();
480 void c_NEW_SIMP();
481 void c_NEW_SIMP_c2();
482 void c_NEW_VHCL();
483 void c_NEW_VHCL_c1();
484 void c_NEW_BKBD();
485 void c_NEW_CBUB();
486 void v_NULL();
487 void c_POSE();
488 void c_RTAR();
489 void c_TTAR();
490 void c_STAR();
491 void v_TARG();
492 void c_ATTR();
493 void c_TICK();
494 void c_BHVR();
495 void c_TARG();
496 void v_FROM();
497 void v_FROM_ds();
498 void s_FROM();
499 void s_FROM_ds();
500 void v_POSE();
501 void c_KILL();
502 void c_SCRX();
503 void c_ANIM();
504 void c_ANIM_c2();
505 void c_ANMS();
506 void v_ATTR();
507 void s_ATTR();
508 void v_ABBA();
509 void c_BASE();
510 void v_BASE();
511 void v_BHVR();
512 void v_CARR();
513 void v_CARR_c1();
514 void v_FMLY();
515 void v_GNUS();
516 void v_SPCS();
517 void v_PNTR();
518 void v_OWNR();
519 void c_MESG_WRIT();
520 void c_MESG_WRT();
521 void v_TOTL();
522 void c_SHOW();
523 void v_SHOW();
524 void v_POSX();
525 void v_POSY();
526 void c_FRAT();
527 void c_OVER();
528 void c_PUHL();
529 void c_SETV_PUHL();
530 void v_PUHL();
531 void v_POSL();
532 void v_POST();
533 void v_POSB();
534 void v_POSR();
535 void v_PLNE();
536 void c_PLNE();
537 void v_WDTH();
538 void c_TINT();
539 void c_RNGE();
540 void v_RNGE();
541 void v_RNGE_c2();
542 void s_RNGE();
543 void s_RNGE_c2();
544 void v_TRAN();
545 void c_TRAN();
546 void v_HGHT();
547 void c_HAND();
548 void v_HAND();
549 void v_TOUC();
550 void v_TICK();
551 void c_PUPT();
552 void c_SETV_PUPT();
553 void c_STPT();
554 void c_DCOR();
555 void c_MIRA();
556 void v_MIRA();
557 void v_DISQ();
558 void c_ALPH();
559 void v_HELD();
560 void c_GALL();
561 void v_GALL();
562 void v_SEEE();
563 void v_TINT();
564 void c_TINO();
565 void c_DROP();
566 void v_NCLS();
567 void v_PCLS();
568 void v_TCOR();
569 void c_CORE();
570 void v_TWIN();
571 void v_ACTV();
572 void s_ACTV();
573 void v_THRT();
574 void s_THRT();
575 void v_SIZE();
576 void s_SIZE();
577 void v_GRAV();
578 void s_GRAV();
579 void c_SETV_CLS2();
580 void c_SETV_CLAS();
581 void c_SLIM();
582 void c_BHVR_c2();
583 void v_LIML();
584 void v_LIMT();
585 void v_LIMR();
586 void v_LIMB_c1();
587 void v_OBJP();
588 void s_OBJP();
589 void v_XIST();
590 void c_SCLE();
591 void c_IMGE();
592 void c_TNTW();
593 void c_PRNT();
594 void v_TCAR();
595 void c_EDIT();
596 void v_FRZN();
597 void s_FRZN();
598 void c_BLCK();
600 // motion
601 void c_ELAS();
602 void v_ELAS();
603 void c_MVTO();
604 void v_VELX();
605 void v_VELY();
606 void s_VELX();
607 void s_VELY();
608 void v_OBST();
609 void v_OBST_c2();
610 void v_TMVB();
611 void v_TMVT();
612 void v_TMVF();
613 void v_RELX();
614 void v_RELY();
615 void v_RELX_c2();
616 void v_RELY_c2();
617 void c_VELO();
618 void c_ACCG();
619 void v_ACCG();
620 void s_ACCG();
621 void v_ACCG_c2();
622 void s_ACCG_c2();
623 void c_AERO();
624 void v_AERO();
625 void v_AERO_c2();
626 void s_AERO();
627 void s_AERO_c2();
628 void c_MVSF();
629 void c_FRIC();
630 void v_FRIC();
631 void v_FALL();
632 void v_MOVS();
633 void s_MOVS();
634 void c_MVBY();
635 void c_FLTO();
636 void c_FREL();
637 void v_FLTX();
638 void v_FLTY();
639 void c_MCRT();
640 void v_REST();
641 void s_REST();
643 // scripts
644 void c_INST();
645 void c_SLOW();
646 void c_LOCK();
647 void c_UNLK();
648 void c_WAIT();
649 void c_STOP();
650 void v_CODE();
651 void v_CODF();
652 void v_CODG();
653 void v_CODS();
654 void c_JECT();
655 void v_SORQ();
657 void c_RGAM();
658 void v_MOWS();
660 // compound
661 void c_PART();
662 void v_PART();
663 void c_NEW_PART();
664 void c_PAT_DULL();
665 void c_PAT_BUTT();
666 void c_PAT_FIXD();
667 void c_PAT_TEXT();
668 void c_PAT_CMRA();
669 void c_PAT_KILL();
670 void c_PAT_MOVE();
671 void c_PAT_GRPH();
672 void c_FCUS();
673 void c_FRMT();
674 void c_PTXT();
675 void v_PTXT();
676 void v_PNXT();
677 void c_PAGE();
678 void v_PAGE();
679 void v_NPGS();
680 void c_GRPV();
681 void c_GRPL();
682 void c_BBD_WORD();
683 void c_BBD_SHOW();
684 void c_BBD_EMIT();
685 void c_BBD_EDIT();
686 void c_BBD_VOCB();
687 void c_NEW_BBTX();
688 void c_BBTX();
689 void c_SPOT();
690 void c_KNOB();
691 void c_KMSG();
692 void c_BBLE();
693 void c_BBFD();
695 // creatures
696 void c_STM_SHOU();
697 void c_STM_SIGN();
698 void c_STM_TACT();
699 void c_STM_WRIT();
700 void c_STIM_SHOU();
701 void c_STIM_SIGN();
702 void c_STIM_TACT();
703 void c_STIM_WRIT();
704 void c_STIM_FROM_c1();
705 void c_STIM_SHOU_c2();
706 void c_STIM_SIGN_c2();
707 void c_STIM_TACT_c2();
708 void c_STIM_WRIT_c2();
709 void c_SWAY_SHOU();
710 void c_SWAY_SIGN();
711 void c_SWAY_TACT();
712 void c_SWAY_WRIT();
713 void c_ZOMB();
714 void c_DIRN();
715 void c_NOHH();
716 void v_HHLD();
717 void c_MVFT();
718 void v_CREA();
719 void c_VOCB();
720 void c_DEAD();
721 void c_NORN();
722 void v_NORN();
723 void s_NORN();
724 void v_ZOMB();
725 void v_DEAD();
726 void c_URGE_SHOU();
727 void c_URGE_SIGN();
728 void c_URGE_TACT();
729 void c_URGE_WRIT();
730 void c_DRIV();
731 void v_DRIV();
732 void c_CHEM();
733 void c_CHEM_c1();
734 void v_CHEM();
735 void v_CHEM_c1();
736 void c_ASLP();
737 void v_ASLP();
738 void c_APPR();
739 void c_UNCS();
740 void v_UNCS();
741 void v_FACE_STRING();
742 void v_FACE_INT();
743 void c_LIKE();
744 void v_LIMB();
745 void c_ORDR_SHOU();
746 void c_ORDR_SIGN();
747 void c_ORDR_TACT();
748 void c_ORDR_WRIT();
749 void c_DREA();
750 void v_DREA();
751 void c_BORN();
752 void v_CAGE();
753 void v_BYIT();
754 void v_IT();
755 void c_NEWC();
756 void c_NEW_CREA();
757 void c_NEW_CREA_c1();
758 void c_NEW_CREA_c2();
759 void c_LTCY();
760 void c_MATE();
761 void v_DRV();
762 void v_IITT();
763 void c_AGES();
764 void c_LOCI();
765 void v_LOCI();
766 void v_TAGE();
767 void v_ORGN();
768 void v_ORGF();
769 void v_ORGI();
770 void c_SOUL();
771 void v_SOUL();
772 void v_DECN();
773 void v_ATTN();
774 void v_DIRN();
775 void c_TOUC();
776 void c_FORF();
777 void c_WALK();
778 void c_FACE();
779 void c_DONE();
780 void c_SAYN();
781 void c_IMPT();
782 void c_AIM();
783 void v_BABY();
784 void s_BABY();
785 void c_SNEZ();
786 void v_DRIV_c1();
787 void c_DREA_c1();
788 void c_FK();
789 void v_BRED();
790 void v_BVAR();
791 void c_EXPR();
792 void v_EXPR();
793 void c_TNTC();
794 void c_INJR();
795 void c_SAY();
796 void c_TRIG();
797 void v_MONK();
798 // (clothes)
799 void c_BODY();
800 void v_BODY();
801 void c_DYED();
802 void c_HAIR();
803 void c_NUDE();
804 void c_RSET();
805 void c_STRE();
806 void c_SWAP();
807 void c_WEAR();
808 void v_WEAR();
809 void c_TNTO();
810 // (attachment locations)
811 void v_DFTX();
812 void v_DFTY();
813 void v_UFTX();
814 void v_UFTY();
815 void v_HEDX();
816 void v_HEDY();
817 void v_MTHX();
818 void v_MTHY();
820 // sounds
821 void c_SNDE();
822 void c_SNDC();
823 void c_MMSC();
824 void v_MMSC();
825 void c_RMSC();
826 void v_RMSC();
827 void c_SNDL();
828 void c_FADE();
829 void c_STPC();
830 void c_STRK();
831 void c_VOLM();
832 void v_VOLM();
833 void v_MUTE();
834 void c_SEZZ();
835 void c_VOIS();
836 void c_MIDI();
837 void c_PLDS();
839 // time
840 void v_PACE();
841 void c_BUZZ();
842 void v_BUZZ();
843 void v_HIST_DATE();
844 void v_DATE();
845 void v_HIST_SEAN();
846 void v_SEAN();
847 void v_HIST_TIME();
848 void v_TIME();
849 void v_HIST_YEAR();
850 void v_YEAR();
851 void v_MSEC();
852 void c_PAUS();
853 void v_PAUS();
854 void c_WPAU();
855 void v_WPAU();
856 void v_RTIF();
857 void v_RTIM();
858 void v_WTIK();
859 void v_RACE();
860 void v_ETIK();
861 void v_SEAV();
862 void c_ASEA();
863 void v_TMOD();
864 void v_DAYT();
865 void v_MONT();
867 // resources
868 void v_PRAY_AGTI();
869 void v_PRAY_AGTS();
870 void v_PRAY_BACK();
871 void v_PRAY_COUN();
872 void v_PRAY_DEPS();
873 void v_PRAY_EXPO();
874 void v_PRAY_FILE();
875 void v_PRAY_FORE();
876 void c_PRAY_GARB();
877 void v_PRAY_IMPO();
878 void v_PRAY_INJT();
879 void v_PRAY_KILL();
880 void v_PRAY_MAKE();
881 void v_PRAY_NEXT();
882 void v_PRAY_PREV();
883 void c_PRAY_REFR();
884 void v_PRAY_TEST();
885 void v_NET_MAKE();
887 // input
888 void c_CLAC();
889 void c_CLIK();
890 void c_IMSK();
891 void v_IMSK();
892 void v_KEYD();
893 void v_HOTS();
894 void v_HOTP();
895 void c_PURE();
896 void v_PURE();
897 void v_MOPX();
898 void v_MOPY();
899 void v_SCOL();
900 void v_CLAC();
901 void v_CLIK();
902 void c_SCRL();
903 void c_MOUS();
905 // vehicles
906 void c_CABN();
907 void c_CABW();
908 void c_SPAS();
909 void c_GPAS();
910 void c_GPAS_c2();
911 void c_DPAS();
912 void c_DPAS_c2();
913 void c_CABP();
914 void c_RPAS();
915 void c_CABV();
916 void v_CABV();
917 void v_XVEC();
918 void s_XVEC();
919 void v_YVEC();
920 void s_YVEC();
921 void v_BUMP();
922 void c_TELE();
923 void c_DPS2();
925 // ports
926 void c_PRT_BANG();
927 void v_PRT_FRMA();
928 void v_PRT_FROM();
929 void c_PRT_INEW();
930 void v_PRT_ITOT();
931 void c_PRT_IZAP();
932 void c_PRT_JOIN();
933 void c_PRT_KRAK();
934 void v_PRT_NAME();
935 void c_PRT_ONEW();
936 void v_PRT_OTOT();
937 void c_PRT_OZAP();
938 void c_PRT_SEND();
940 // files
941 void c_FILE_GLOB();
942 void c_FILE_ICLO();
943 void c_FILE_IOPE();
944 void c_FILE_JDEL();
945 void c_FILE_OCLO();
946 void c_FILE_OFLU();
947 void c_FILE_OOPE();
948 void v_FVWM();
949 void v_INNF();
950 void v_INNI();
951 void v_INNL();
952 void v_INOK();
953 void c_WEBB();
955 // net
956 void v_NET_ERRA();
957 void v_NET_EXPO();
958 void v_NET_FROM();
959 void c_NET_HEAD();
960 void c_NET_HEAR();
961 void v_NET_HOST();
962 void c_NET_LINE();
963 void v_NET_LINE();
964 void c_NET_PASS();
965 void v_NET_PASS();
966 void v_NET_RAWE();
967 void c_NET_RUSO();
968 void c_NET_STAT();
969 void v_NET_ULIN();
970 void c_NET_UNIK();
971 void v_NET_USER();
972 void v_NET_WHAT();
973 void c_NET_WHOD();
974 void c_NET_WHOF();
975 void c_NET_WHON();
976 void c_NET_WHOZ();
977 void c_NET_WRIT();
979 // genetics
980 void c_GENE_CLON();
981 void c_GENE_CROS();
982 void c_GENE_KILL();
983 void c_GENE_LOAD();
984 void c_GENE_MOVE();
985 void v_GTOS();
986 void v_MTOA();
987 void v_MTOC();
988 void c_NEW_GENE();
990 // history
991 void v_HIST_CAGE();
992 void v_HIST_COUN();
993 void v_HIST_CROS();
994 void c_HIST_EVNT();
995 void v_HIST_FIND();
996 void v_HIST_FINR();
997 void v_HIST_FOTO();
998 void c_HIST_FOTO();
999 void v_HIST_GEND();
1000 void v_HIST_GNUS();
1001 void v_HIST_MON1();
1002 void v_HIST_MON2();
1003 void v_HIST_MUTE();
1004 void v_HIST_NAME();
1005 void c_HIST_NAME();
1006 void v_HIST_NETU();
1007 void v_HIST_NEXT();
1008 void v_HIST_PREV();
1009 void v_HIST_RTIM();
1010 void v_HIST_TAGE();
1011 void v_HIST_TYPE();
1012 void c_HIST_UTXT();
1013 void v_HIST_UTXT();
1014 void v_HIST_VARI();
1015 void c_HIST_WIPE();
1016 void v_HIST_WNAM();
1017 void v_HIST_WTIK();
1018 void v_HIST_WUID();
1019 void v_HIST_WVET();
1020 void v_OOWW();
1021 void c_EVNT();
1022 void c_RMEV();
1023 void c_DDE_NEGG();
1024 void c_DDE_DIED();
1025 void c_DDE_LIVE();
1027 // Vector ops
1028 void v_VEC_MAKE();
1029 void c_VEC_GETC();
1030 void v_VEC_ANGL();
1031 void c_VEC_SUBV();
1032 void c_VEC_ADDV();
1033 void c_VEC_MULV();
1034 void v_VEC_UNIT();
1035 void v_VEC_NULL();
1036 void v_VEC_MAGN();
1037 void c_VEC_SETV();
1040 // serialization test functions
1041 void c_SERS_MAPP();
1042 void c_SERL_MAPP();
1043 void c_SERS_SCRP();
1044 void c_SERL_SCRP();
1046 void safeJMP(int nip);
1047 void invoke_cmd(script *s, bool is_saver, int opidx);
1048 void runOpCore(script *s, struct caosOp op);
1049 void runOp();
1050 void runEntirely(shared_ptr<script> s);
1052 void tick();
1053 void stop();
1054 bool fireScript(shared_ptr<script> s, bool nointerrupt, Agent *frm = 0);
1056 caosVM(const AgentRef &o);
1057 ~caosVM();
1059 bool stopped() { return !currentscript; }
1061 friend void setupCommandPointers();
1064 typedef void (caosVM::*caosVMmethod)();
1066 class notEnoughParamsException : public caosException {
1067 public:
1068 notEnoughParamsException() : caosException("Not enough parameters") {}
1071 class invalidAgentException : public caosException {
1072 public:
1073 invalidAgentException() : caosException("Invalid agent handle") {}
1074 invalidAgentException(const char *s) : caosException(s) {}
1075 invalidAgentException(const std::string &s) : caosException(s) {}
1078 #define VM_VERIFY_SIZE(n) // no-op, we assert in the pops. orig: if (params.size() != n) { throw notEnoughParamsException(); }
1079 static inline void VM_STACK_CHECK(const caosVM *vm) {
1080 if (!vm->valueStack.size())
1081 throw notEnoughParamsException();
1084 class caosVM__lval {
1085 protected:
1086 caosVM *owner;
1087 public:
1088 caosVar value;
1089 caosVM__lval(caosVM *vm) : owner(vm) {
1090 VM_STACK_CHECK(vm);
1091 value = owner->valueStack.back().getRVal();
1092 owner->valueStack.pop_back();
1094 ~caosVM__lval() {
1095 owner->valueStack.push_back(value);
1099 #define VM_PARAM_VALUE(name) caosVar name; { VM_STACK_CHECK(vm); \
1100 vmStackItem __x = vm->valueStack.back(); \
1101 name = __x.getRVal(); } vm->valueStack.pop_back();
1102 #define VM_PARAM_STRING(name) std::string name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1103 name = __x.getRVal().getString(); } vm->valueStack.pop_back();
1104 #define VM_PARAM_INTEGER(name) int name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1105 name = __x.getRVal().getInt(); } vm->valueStack.pop_back();
1106 #define VM_PARAM_FLOAT(name) float name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1107 name = __x.getRVal().getFloat(); } vm->valueStack.pop_back();
1108 #define VM_PARAM_VECTOR(name) Vector<float> name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1109 name = __x.getRVal().getVector(); } vm->valueStack.pop_back();
1110 #define VM_PARAM_AGENT(name) boost::shared_ptr<Agent> name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1111 name = __x.getRVal().getAgent(); } vm->valueStack.pop_back();
1112 // TODO: is usage of valid_agent correct here, or should we be caos_asserting?
1113 #define VM_PARAM_VALIDAGENT(name) VM_PARAM_AGENT(name) valid_agent(name);
1114 #define VM_PARAM_VARIABLE(name) caosVM__lval vm__lval_##name(this); caosVar * const name = &vm__lval_##name.value;
1115 #define VM_PARAM_DECIMAL(name) caosVar name; { VM_STACK_CHECK(vm); vmStackItem __x = vm->valueStack.back(); \
1116 name = __x.getRVal(); } vm->valueStack.pop_back();
1117 #define VM_PARAM_BYTESTR(name) bytestring_t name; { \
1118 VM_STACK_CHECK(vm); \
1119 vmStackItem __x = vm->valueStack.back(); \
1120 name = __x.getByteStr(); } vm->valueStack.pop_back();
1122 #define CAOS_LVALUE(name, check, get, set) \
1123 void caosVM::v_##name() { \
1124 check; \
1125 valueStack.push_back((get)); \
1127 void caosVM::s_##name() { \
1128 check; \
1129 VM_PARAM_VALUE(newvalue) \
1130 set; \
1133 #define CAOS_LVALUE_WITH(name, agent, check, get, set) \
1134 CAOS_LVALUE(name, valid_agent(agent); check, get, set)
1136 #define CAOS_LVALUE_TARG(name, check, get, set) \
1137 CAOS_LVALUE_WITH(name, targ, check, get, set)
1139 #define CAOS_LVALUE_WITH_SIMPLE(name, agent, exp) \
1140 CAOS_LVALUE(name, valid_agent(agent), exp, exp = newvalue)
1142 #define CAOS_LVALUE_SIMPLE(name, exp) \
1143 CAOS_LVALUE(name, (void)0, exp, exp = newvalue)
1145 #define CAOS_LVALUE_TARG_SIMPLE(name, exp) \
1146 CAOS_LVALUE_TARG(name, (void)0, exp, exp = newvalue)
1147 #define STUB throw caosException("stub in " __FILE__)
1149 // FIXME: use do { ... } while (0)
1150 #define valid_agent(x) do { if (!(x)) throw invalidAgentException(boost::str(boost::format("Invalid agent handle: %s thrown from %s:%d") % #x % __FILE__ % __LINE__)); } while(0)
1152 #endif
1153 /* vim: set noet: */