*** empty log message ***
[chuck-blob.git] / exile / v1 / src / chuck_instr.cpp
blobd8de4eadaf4615c4519d920a9ba2c307b2964acd
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_instr.cpp
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #include <math.h>
34 #include <limits.h>
35 #include <typeinfo>
36 using namespace std;
38 #include "chuck_instr.h"
39 #include "chuck_vm.h"
40 #include "chuck_ugen.h"
41 #include "chuck_bbq.h"
42 #include "chuck_dl.h"
43 #include "chuck_type.h"
48 // define SP offset
49 #define push_( sp, val ) *(sp) = (val); (sp)++
50 #define push_uint( sp, val ) *((uint*&)sp) = val; ((uint*&)sp)++
51 #define pop_( sp, n ) sp -= (n)
52 #define val_( sp ) *(sp)
57 //-----------------------------------------------------------------------------
58 // name: name()
59 // desc: ...
60 //-----------------------------------------------------------------------------
61 const char * Chuck_Instr::name() const
63 return typeid(*this).name();
69 //-----------------------------------------------------------------------------
70 // name: execute()
71 // desc: ...
72 //-----------------------------------------------------------------------------
73 void Chuck_Instr_Add_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
75 sint *& sp = (sint *&)shred->reg->sp;
76 pop_( sp, 2 );
77 push_( sp, val_(sp) + val_(sp+1) );
83 //-----------------------------------------------------------------------------
84 // name: execute()
85 // desc: ...
86 //-----------------------------------------------------------------------------
87 void Chuck_Instr_Inc_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
89 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
90 sint *& reg_sp = (sint *&)shred->reg->sp;
92 // pop word from reg stack
93 pop_( reg_sp, 1 );
94 // increment value
95 (*(reg_sp-1))++;
96 // copy value into mem stack
97 *( (sint *)(mem_sp + *(reg_sp)) ) = *(reg_sp-1);
104 //-----------------------------------------------------------------------------
105 // name: class Chuck_Instr_Dec_int
106 // desc: ...
107 //-----------------------------------------------------------------------------
108 void Chuck_Instr_Dec_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
110 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
111 sint *& reg_sp = (sint *&)shred->reg->sp;
113 // pop word from reg stack
114 pop_( reg_sp, 1 );
115 // decrement value
116 (*(reg_sp-1))--;
117 // copy value into mem stack
118 *( (sint *)(mem_sp + *(reg_sp)) ) = *(reg_sp-1);
124 //-----------------------------------------------------------------------------
125 // name: exexute()
126 // desc: ...
127 //-----------------------------------------------------------------------------
128 void Chuck_Instr_Complement_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
130 sint *& sp = (sint *&)shred->reg->sp;
131 (*(sp-1)) = ~(*(sp-1));
137 //-----------------------------------------------------------------------------
138 // name: execute()
139 // desc: ...
140 //-----------------------------------------------------------------------------
141 void Chuck_Instr_Mod_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
143 sint *& sp = (sint *&)shred->reg->sp;
144 pop_( sp, 2 );
145 push_( sp, val_(sp) % val_(sp+1) );
151 //-----------------------------------------------------------------------------
152 // name: execute()
153 // desc: ...
154 //-----------------------------------------------------------------------------
155 void Chuck_Instr_Minus_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
157 sint *& sp = (sint *&)shred->reg->sp;
158 pop_( sp, 2 );
159 push_( sp, val_(sp) - val_(sp+1) );
165 //-----------------------------------------------------------------------------
166 // name: execute()
167 // desc: ...
168 //-----------------------------------------------------------------------------
169 void Chuck_Instr_Times_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
171 sint *& sp = (sint *&)shred->reg->sp;
172 pop_( sp, 2 );
173 push_( sp, val_(sp) * val_(sp+1) );
179 //-----------------------------------------------------------------------------
180 // name: execute()
181 // desc: ...
182 //-----------------------------------------------------------------------------
183 void Chuck_Instr_Divide_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
185 sint *& sp = (sint *&)shred->reg->sp;
186 pop_( sp, 2 );
187 push_( sp, val_(sp) / val_(sp+1) );
194 //-----------------------------------------------------------------------------
195 // name: execute()
196 // desc: ...
197 //-----------------------------------------------------------------------------
198 void Chuck_Instr_Add_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
200 uint *& sp = (uint *&)shred->reg->sp;
201 pop_( sp, 2 );
202 push_( sp, val_(sp) + val_(sp+1) );
208 //-----------------------------------------------------------------------------
209 // name: execute()
210 // desc: ...
211 //-----------------------------------------------------------------------------
212 void Chuck_Instr_Inc_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
214 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
215 uint *& reg_sp = (uint *&)shred->reg->sp;
217 // pop word from reg stack
218 pop_( reg_sp, 1 );
219 // increment value
220 (*(reg_sp-1))++;
221 // copy value into mem stack
222 *( (uint *)(mem_sp + *(reg_sp)) ) = *(reg_sp-1);
229 //-----------------------------------------------------------------------------
230 // name: execute()
231 // desc: ...
232 //-----------------------------------------------------------------------------
233 void Chuck_Instr_Dec_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
235 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
236 uint *& reg_sp = (uint *&)shred->reg->sp;
238 // pop word from reg stack
239 pop_( reg_sp, 1 );
240 // decrement value
241 (*(reg_sp-1))--;
242 // copy value into mem stack
243 *( (uint *)(mem_sp + *(reg_sp)) ) = *(reg_sp-1);
249 //-----------------------------------------------------------------------------
250 // name: exexute()
251 // desc: ...
252 //-----------------------------------------------------------------------------
253 void Chuck_Instr_Complement_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
255 uint *& sp = (uint *&)shred->reg->sp;
256 (*sp) = ~(*sp);
262 //-----------------------------------------------------------------------------
263 // name: execute()
264 // desc: ...
265 //-----------------------------------------------------------------------------
266 void Chuck_Instr_Mod_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
268 uint *& sp = (uint *&)shred->reg->sp;
269 pop_( sp, 2 );
270 push_( sp, val_(sp) % val_(sp+1) );
276 //-----------------------------------------------------------------------------
277 // name: execute()
278 // desc: ...
279 //-----------------------------------------------------------------------------
280 void Chuck_Instr_Minus_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
282 uint *& sp = (uint *&)shred->reg->sp;
283 pop_( sp, 2 );
284 push_( sp, val_(sp) - val_(sp+1) );
290 //-----------------------------------------------------------------------------
291 // name: execute()
292 // desc: ...
293 //-----------------------------------------------------------------------------
294 void Chuck_Instr_Times_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
296 uint *& sp = (uint *&)shred->reg->sp;
297 pop_( sp, 2 );
298 push_( sp, val_(sp) * val_(sp+1) );
304 //-----------------------------------------------------------------------------
305 // name: execute()
306 // desc: ...
307 //-----------------------------------------------------------------------------
308 void Chuck_Instr_Divide_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
310 uint *& sp = (uint *&)shred->reg->sp;
311 pop_( sp, 2 );
312 push_( sp, val_(sp) / val_(sp+1) );
319 //-----------------------------------------------------------------------------
320 // name: execute()
321 // desc: ...
322 //-----------------------------------------------------------------------------
323 void Chuck_Instr_Add_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
325 float *& sp = (float *&)shred->reg->sp;
326 pop_( sp, 2 );
327 push_( sp, val_(sp) + val_(sp+1) );
333 //-----------------------------------------------------------------------------
334 // name: execute()
335 // desc: ...
336 //-----------------------------------------------------------------------------
337 void Chuck_Instr_Minus_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
339 float *& sp = (float *&)shred->reg->sp;
340 pop_( sp, 2 );
341 push_( sp, val_(sp) - val_(sp+1) );
347 //-----------------------------------------------------------------------------
348 // name: execute()
349 // desc: ...
350 //-----------------------------------------------------------------------------
351 void Chuck_Instr_Times_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
353 float *& sp = (float *&)shred->reg->sp;
354 pop_( sp, 2 );
355 push_( sp, val_(sp) * val_(sp+1) );
361 //-----------------------------------------------------------------------------
362 // name: execute()
363 // desc: ...
364 //-----------------------------------------------------------------------------
365 void Chuck_Instr_Divide_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
367 float *& sp = (float *&)shred->reg->sp;
368 pop_( sp, 2 );
369 push_( sp, val_(sp) / val_(sp+1) );
376 //-----------------------------------------------------------------------------
377 // name: execute()
378 // desc: ...
379 //-----------------------------------------------------------------------------
380 void Chuck_Instr_Mod_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
382 float *& sp = (float *&)shred->reg->sp;
383 pop_( sp, 2 );
384 push_( sp, (float)fmod( val_(sp), val_(sp+1) ) );
390 //-----------------------------------------------------------------------------
391 // name: execute()
392 // desc: ...
393 //-----------------------------------------------------------------------------
394 void Chuck_Instr_Add_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
396 double *& sp = (double *&)shred->reg->sp;
397 pop_( sp, 2 );
398 push_( sp, val_(sp) + val_(sp+1) );
404 //-----------------------------------------------------------------------------
405 // name: execute()
406 // desc: ...
407 //-----------------------------------------------------------------------------
408 void Chuck_Instr_Minus_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
410 double *& sp = (double *&)shred->reg->sp;
411 pop_( sp, 2 );
412 push_( sp, val_(sp) - val_(sp+1) );
418 //-----------------------------------------------------------------------------
419 // name: execute()
420 // desc: ...
421 //-----------------------------------------------------------------------------
422 void Chuck_Instr_Times_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
424 double *& sp = (double *&)shred->reg->sp;
425 pop_( sp, 2 );
426 push_( sp, val_(sp) * val_(sp+1) );
432 //-----------------------------------------------------------------------------
433 // name: execute()
434 // desc: ...
435 //-----------------------------------------------------------------------------
436 void Chuck_Instr_Divide_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
438 double *& sp = (double *&)shred->reg->sp;
439 pop_( sp, 2 );
440 push_( sp, val_(sp) / val_(sp+1) );
447 //-----------------------------------------------------------------------------
448 // name: execute()
449 // desc: ...
450 //-----------------------------------------------------------------------------
451 void Chuck_Instr_Mod_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
453 double *& sp = (double *&)shred->reg->sp;
454 pop_( sp, 2 );
455 push_( sp, fmod( val_(sp), val_(sp+1) ) );
461 //-----------------------------------------------------------------------------
462 // name: execute()
463 // desc: ...
464 //-----------------------------------------------------------------------------
465 void Chuck_Instr_Reg_Push_Imm::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
467 uint *& reg_sp = (uint *&)shred->reg->sp;
469 // push val into reg stack
470 push_( reg_sp, m_val );
476 //-----------------------------------------------------------------------------
477 // name: execute()
478 // desc: ...
479 //-----------------------------------------------------------------------------
480 void Chuck_Instr_Reg_Push_Imm2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
482 double *& reg_sp = (double *&)shred->reg->sp;
484 // push val into reg stack
485 push_( reg_sp, m_val );
491 //-----------------------------------------------------------------------------
492 // name: execute()
493 // desc: ...
494 //-----------------------------------------------------------------------------
495 void Chuck_Instr_Reg_Push_Now::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
497 t_CKTIME *& reg_sp = (t_CKTIME *&)shred->reg->sp;
499 // push val into reg stack
500 push_( reg_sp, shred->now );
506 //-----------------------------------------------------------------------------
507 // name: execute()
508 // desc: ...
509 //-----------------------------------------------------------------------------
510 void Chuck_Instr_Reg_Push_Start::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
512 t_CKTIME *& reg_sp = (t_CKTIME *&)shred->reg->sp;
514 // push val into reg stack
515 push_( reg_sp, shred->start );
521 //-----------------------------------------------------------------------------
522 // name: execute()
523 // desc: ...
524 //-----------------------------------------------------------------------------
525 void Chuck_Instr_Reg_Push_Maybe::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
527 t_CKINT *& reg_sp = (t_CKINT *&)shred->reg->sp;
529 // push val into reg stack
530 float num = (float)rand() / (float)RAND_MAX;
531 push_( reg_sp, num > .5 );
537 //-----------------------------------------------------------------------------
538 // name: execute()
539 // desc: ...
540 //-----------------------------------------------------------------------------
541 void Chuck_Instr_Reg_Push_Deref::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
543 if( m_size == 4 )
545 uint *& reg_sp = (uint *&)shred->reg->sp;
546 push_( reg_sp, *((uint *)m_val) );
548 else
550 double *& reg_sp = (double *&)shred->reg->sp;
551 push_( reg_sp, *((double *)m_val) );
558 //-----------------------------------------------------------------------------
559 // name: execute()
560 // desc: ...
561 //-----------------------------------------------------------------------------
562 void Chuck_Instr_Reg_Push_Mem::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
564 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
565 uint *& reg_sp = (uint *&)shred->reg->sp;
567 // push mem stack content into reg stack
568 push_( reg_sp, *((uint *)(mem_sp + m_val)) );
574 //-----------------------------------------------------------------------------
575 // name: execute()
576 // desc: ...
577 //-----------------------------------------------------------------------------
578 void Chuck_Instr_Reg_Push_Mem2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
580 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
581 double *& reg_sp = (double *&)shred->reg->sp;
583 // push mem stack content into reg stack
584 push_( reg_sp, *((double *)(mem_sp + m_val)) );
590 //-----------------------------------------------------------------------------
591 // name: execute()
592 // desc: ...
593 //-----------------------------------------------------------------------------
594 void Chuck_Instr_Reg_Pop_Mem::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
596 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
597 uint *& reg_sp = (uint *&)shred->reg->sp;
599 // pop word from reg stack
600 pop_( reg_sp, 2 );
601 // copy popped value into mem stack
602 *((uint *)(mem_sp + *(reg_sp+1) )) = *reg_sp;
608 //-----------------------------------------------------------------------------
609 // name: execute()
610 // desc: ...
611 //-----------------------------------------------------------------------------
612 void Chuck_Instr_Reg_Pop_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
614 uint *& reg_sp = (uint *&)shred->reg->sp;
616 // pop word from reg stack
617 pop_( reg_sp, 1 );
623 //-----------------------------------------------------------------------------
624 // name: execute()
625 // desc: ...
626 //-----------------------------------------------------------------------------
627 void Chuck_Instr_Reg_Pop_Word2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
629 double *& reg_sp = (double *&)shred->reg->sp;
631 // pop word from reg stack
632 pop_( reg_sp, 1 );
638 //-----------------------------------------------------------------------------
639 // name: execute()
640 // desc: ...
641 //-----------------------------------------------------------------------------
642 void Chuck_Instr_Mem_Push_Imm::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
644 uint *& mem_sp = (uint *&)shred->mem->sp;
646 // pop word from reg stack
647 push_( mem_sp, m_val );
653 //-----------------------------------------------------------------------------
654 // name: execute()
655 // desc: ...
656 //-----------------------------------------------------------------------------
657 void Chuck_Instr_Mem_Push_Imm2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
659 double *& mem_sp = (double *&)shred->mem->sp;
661 // pop word from reg stack
662 push_( mem_sp, m_val );
668 //-----------------------------------------------------------------------------
669 // name: execute()
670 // desc: ...
671 //-----------------------------------------------------------------------------
672 void Chuck_Instr_Mem_Pop_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
674 uint *& mem_sp = (uint *&)shred->mem->sp;
676 // pop word from reg stack
677 pop_( mem_sp, 1 );
683 //-----------------------------------------------------------------------------
684 // name: execute()
685 // desc: ...
686 //-----------------------------------------------------------------------------
687 void Chuck_Instr_Mem_Pop_Word2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
689 double *& mem_sp = (double *&)shred->mem->sp;
691 // pop word from reg stack
692 pop_( mem_sp, 1 );
698 //-----------------------------------------------------------------------------
699 // name: execute()
700 // desc: ...
701 //-----------------------------------------------------------------------------
702 void Chuck_Instr_Branch_Lt_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
704 sint *& sp = (sint *&)shred->reg->sp;
705 pop_( sp, 2 );
706 if( val_(sp) < val_(sp+1) )
707 shred->next_pc = m_jmp;
713 //-----------------------------------------------------------------------------
714 // name: execute()
715 // desc: ...
716 //-----------------------------------------------------------------------------
717 void Chuck_Instr_Branch_Gt_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
719 sint *& sp = (sint *&)shred->reg->sp;
720 pop_( sp, 2 );
721 if( val_(sp) > val_(sp+1) )
722 shred->next_pc = m_jmp;
728 //-----------------------------------------------------------------------------
729 // name: execute()
730 // desc: ...
731 //-----------------------------------------------------------------------------
732 void Chuck_Instr_Branch_Le_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
734 sint *& sp = (sint *&)shred->reg->sp;
735 pop_( sp, 2 );
736 if( val_(sp) <= val_(sp+1) )
737 shred->next_pc = m_jmp;
743 //-----------------------------------------------------------------------------
744 // name: execute()
745 // desc: ...
746 //-----------------------------------------------------------------------------
747 void Chuck_Instr_Branch_Ge_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
749 sint *& sp = (sint *&)shred->reg->sp;
750 pop_( sp, 2 );
751 if( val_(sp) >= val_(sp+1) )
752 shred->next_pc = m_jmp;
758 //-----------------------------------------------------------------------------
759 // name: execute()
760 // desc: ...
761 //-----------------------------------------------------------------------------
762 void Chuck_Instr_Branch_Eq_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
764 sint *& sp = (sint *&)shred->reg->sp;
765 pop_( sp, 2 );
766 if( val_(sp) == val_(sp+1) )
767 shred->next_pc = m_jmp;
773 //-----------------------------------------------------------------------------
774 // name: execute()
775 // desc: ...
776 //-----------------------------------------------------------------------------
777 void Chuck_Instr_Branch_Neq_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
779 sint *& sp = (sint *&)shred->reg->sp;
780 pop_( sp, 2 );
781 if( val_(sp) != val_(sp+1) )
782 shred->next_pc = m_jmp;
788 //-----------------------------------------------------------------------------
789 // name: execute()
790 // desc: ...
791 //-----------------------------------------------------------------------------
792 void Chuck_Instr_Not_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
794 sint *& sp = (sint *&)shred->reg->sp;
795 (*(sp-1)) = !(*(sp-1));
801 //-----------------------------------------------------------------------------
802 // name: execute()
803 // desc: ...
804 //-----------------------------------------------------------------------------
805 void Chuck_Instr_Negate_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
807 sint *& sp = (sint *&)shred->reg->sp;
808 (*(sp-1)) = -(*(sp-1));
814 //-----------------------------------------------------------------------------
815 // name: execute()
816 // desc: ...
817 //-----------------------------------------------------------------------------
818 void Chuck_Instr_Negate_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
820 uint *& sp = (uint *&)shred->reg->sp;
821 sint *& sp_int = (sint *&)shred->reg->sp;
822 (*(sp_int-1)) = -((sint)(*(sp-1)));
828 //-----------------------------------------------------------------------------
829 // name: execute()
830 // desc: ...
831 //-----------------------------------------------------------------------------
832 void Chuck_Instr_Negate_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
834 float *& sp = (float *&)shred->reg->sp;
835 (*(sp-1)) = -(*(sp-1));
841 //-----------------------------------------------------------------------------
842 // name: execute()
843 // desc: ...
844 //-----------------------------------------------------------------------------
845 void Chuck_Instr_Negate_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
847 double *& sp = (double *&)shred->reg->sp;
848 (*(sp-1)) = -(*(sp-1));
854 //-----------------------------------------------------------------------------
855 // name: execute()
856 // desc: ...
857 //-----------------------------------------------------------------------------
858 void Chuck_Instr_Branch_Lt_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
860 uint *& sp = (uint *&)shred->reg->sp;
861 pop_( sp, 2 );
862 if( val_(sp) < val_(sp+1) )
863 shred->next_pc = m_jmp;
869 //-----------------------------------------------------------------------------
870 // name: execute()
871 // desc: ...
872 //-----------------------------------------------------------------------------
873 void Chuck_Instr_Branch_Gt_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
875 uint *& sp = (uint *&)shred->reg->sp;
876 pop_( sp, 2 );
877 if( val_(sp) > val_(sp+1) )
878 shred->next_pc = m_jmp;
884 //-----------------------------------------------------------------------------
885 // name: execute()
886 // desc: ...
887 //-----------------------------------------------------------------------------
888 void Chuck_Instr_Branch_Le_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
890 uint *& sp = (uint *&)shred->reg->sp;
891 pop_( sp, 2 );
892 if( val_(sp) <= val_(sp+1) )
893 shred->next_pc = m_jmp;
899 //-----------------------------------------------------------------------------
900 // name: execute()
901 // desc: ...
902 //-----------------------------------------------------------------------------
903 void Chuck_Instr_Branch_Ge_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
905 uint *& sp = (uint *&)shred->reg->sp;
906 pop_( sp, 2 );
907 if( val_(sp) >= val_(sp+1) )
908 shred->next_pc = m_jmp;
914 //-----------------------------------------------------------------------------
915 // name: execute()
916 // desc: ...
917 //-----------------------------------------------------------------------------
918 void Chuck_Instr_Branch_Eq_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
920 uint *& sp = (uint *&)shred->reg->sp;
921 pop_( sp, 2 );
922 if( val_(sp) == val_(sp+1) )
923 shred->next_pc = m_jmp;
929 //-----------------------------------------------------------------------------
930 // name: execute()
931 // desc: ...
932 //-----------------------------------------------------------------------------
933 void Chuck_Instr_Branch_Neq_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
935 uint *& sp = (uint *&)shred->reg->sp;
936 pop_( sp, 2 );
937 if( val_(sp) != val_(sp+1) )
938 shred->next_pc = m_jmp;
944 //-----------------------------------------------------------------------------
945 // name: execute()
946 // desc: ...
947 //-----------------------------------------------------------------------------
948 void Chuck_Instr_Branch_Lt_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
950 float *& sp = (float *&)shred->reg->sp;
951 pop_( sp, 2 );
952 if( val_(sp) < val_(sp+1) )
953 shred->next_pc = m_jmp;
959 //-----------------------------------------------------------------------------
960 // name: execute()
961 // desc: ...
962 //-----------------------------------------------------------------------------
963 void Chuck_Instr_Branch_Gt_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
965 float *& sp = (float *&)shred->reg->sp;
966 pop_( sp, 2 );
967 if( val_(sp) > val_(sp+1) )
968 shred->next_pc = m_jmp;
974 //-----------------------------------------------------------------------------
975 // name: execute()
976 // desc: ...
977 //-----------------------------------------------------------------------------
978 void Chuck_Instr_Branch_Le_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
980 float *& sp = (float *&)shred->reg->sp;
981 pop_( sp, 2 );
982 if( val_(sp) <= val_(sp+1) )
983 shred->next_pc = m_jmp;
989 //-----------------------------------------------------------------------------
990 // name: execute()
991 // desc: ...
992 //-----------------------------------------------------------------------------
993 void Chuck_Instr_Branch_Ge_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
995 float *& sp = (float *&)shred->reg->sp;
996 pop_( sp, 2 );
997 if( val_(sp) >= val_(sp+1) )
998 shred->next_pc = m_jmp;
1004 //-----------------------------------------------------------------------------
1005 // name: execute()
1006 // desc: ...
1007 //-----------------------------------------------------------------------------
1008 void Chuck_Instr_Branch_Eq_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1010 float *& sp = (float *&)shred->reg->sp;
1011 pop_( sp, 2 );
1012 if( val_(sp) == val_(sp+1) )
1013 shred->next_pc = m_jmp;
1019 //-----------------------------------------------------------------------------
1020 // name: execute()
1021 // desc: ...
1022 //-----------------------------------------------------------------------------
1023 void Chuck_Instr_Branch_Neq_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1025 float *& sp = (float *&)shred->reg->sp;
1026 pop_( sp, 2 );
1027 if( val_(sp) != val_(sp+1) )
1028 shred->next_pc = m_jmp;
1034 //-----------------------------------------------------------------------------
1035 // name: execute()
1036 // desc: ...
1037 //-----------------------------------------------------------------------------
1038 void Chuck_Instr_Branch_Lt_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1040 double *& sp = (double *&)shred->reg->sp;
1041 pop_( sp, 2 );
1042 if( val_(sp) < val_(sp+1) )
1043 shred->next_pc = m_jmp;
1049 //-----------------------------------------------------------------------------
1050 // name: execute()
1051 // desc: ...
1052 //-----------------------------------------------------------------------------
1053 void Chuck_Instr_Branch_Gt_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1055 double *& sp = (double *&)shred->reg->sp;
1056 pop_( sp, 2 );
1057 if( val_(sp) > val_(sp+1) )
1058 shred->next_pc = m_jmp;
1064 //-----------------------------------------------------------------------------
1065 // name: execute()
1066 // desc: ...
1067 //-----------------------------------------------------------------------------
1068 void Chuck_Instr_Branch_Le_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1070 double *& sp = (double *&)shred->reg->sp;
1071 pop_( sp, 2 );
1072 if( val_(sp) <= val_(sp+1) )
1073 shred->next_pc = m_jmp;
1079 //-----------------------------------------------------------------------------
1080 // name: execute()
1081 // desc: ...
1082 //-----------------------------------------------------------------------------
1083 void Chuck_Instr_Branch_Ge_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1085 double *& sp = (double *&)shred->reg->sp;
1086 pop_( sp, 2 );
1087 if( val_(sp) >= val_(sp+1) )
1088 shred->next_pc = m_jmp;
1094 //-----------------------------------------------------------------------------
1095 // name: execute()
1096 // desc: ...
1097 //-----------------------------------------------------------------------------
1098 void Chuck_Instr_Branch_Eq_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1100 double *& sp = (double *&)shred->reg->sp;
1101 pop_( sp, 2 );
1102 if( val_(sp) == val_(sp+1) )
1103 shred->next_pc = m_jmp;
1109 //-----------------------------------------------------------------------------
1110 // name: execute()
1111 // desc: ...
1112 //-----------------------------------------------------------------------------
1113 void Chuck_Instr_Branch_Neq_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1115 double *& sp = (double *&)shred->reg->sp;
1116 pop_( sp, 2 );
1117 if( val_(sp) != val_(sp+1) )
1118 shred->next_pc = m_jmp;
1124 //-----------------------------------------------------------------------------
1125 // name: execute()
1126 // desc: ...
1127 //-----------------------------------------------------------------------------
1128 void Chuck_Instr_Binary_And::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1130 uint *& sp = (uint *&)shred->reg->sp;
1131 pop_( sp, 2 );
1132 push_( sp, val_(sp) & val_(sp+1) );
1138 //-----------------------------------------------------------------------------
1139 // name: execute()
1140 // desc: ...
1141 //-----------------------------------------------------------------------------
1142 void Chuck_Instr_Binary_Or::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1144 uint *& sp = (uint *&)shred->reg->sp;
1145 pop_( sp, 2 );
1146 push_( sp, val_(sp) | val_(sp+1) );
1152 //-----------------------------------------------------------------------------
1153 // name: execute()
1154 // desc: ...
1155 //-----------------------------------------------------------------------------
1156 void Chuck_Instr_Binary_Xor::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1158 uint *& sp = (uint *&)shred->reg->sp;
1159 pop_( sp, 2 );
1160 push_( sp, val_(sp) ^ val_(sp+1) );
1166 //-----------------------------------------------------------------------------
1167 // name: execute()
1168 // desc: ...
1169 //-----------------------------------------------------------------------------
1170 void Chuck_Instr_Binary_Shift_Right::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1172 uint *& sp = (uint *&)shred->reg->sp;
1173 pop_( sp, 2 );
1174 push_( sp, val_(sp) >> val_(sp+1) );
1180 //-----------------------------------------------------------------------------
1181 // name: execute()
1182 // desc: ...
1183 //-----------------------------------------------------------------------------
1184 void Chuck_Instr_Binary_Shift_Left::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1186 uint *& sp = (uint *&)shred->reg->sp;
1187 pop_( sp, 2 );
1188 push_( sp, val_(sp) << val_(sp+1) );
1194 //-----------------------------------------------------------------------------
1195 // name: execute()
1196 // desc: ...
1197 //-----------------------------------------------------------------------------
1198 void Chuck_Instr_Lt_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1200 sint *& sp = (sint *&)shred->reg->sp;
1201 pop_( sp, 2 );
1202 push_( sp, val_(sp) < val_(sp+1) );
1208 //-----------------------------------------------------------------------------
1209 // name: execute()
1210 // desc: ...
1211 //-----------------------------------------------------------------------------
1212 void Chuck_Instr_Gt_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1214 sint *& sp = (sint *&)shred->reg->sp;
1215 pop_( sp, 2 );
1216 push_( sp, val_(sp) > val_(sp+1) );
1222 //-----------------------------------------------------------------------------
1223 // name: execute()
1224 // desc: ...
1225 //-----------------------------------------------------------------------------
1226 void Chuck_Instr_Le_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1228 sint *& sp = (sint *&)shred->reg->sp;
1229 pop_( sp, 2 );
1230 push_( sp, val_(sp) <= val_(sp+1) );
1236 //-----------------------------------------------------------------------------
1237 // name: execute()
1238 // desc: ...
1239 //-----------------------------------------------------------------------------
1240 void Chuck_Instr_Ge_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1242 sint *& sp = (sint *&)shred->reg->sp;
1243 pop_( sp, 2 );
1244 push_( sp, val_(sp) >= val_(sp+1) );
1250 //-----------------------------------------------------------------------------
1251 // name: execute()
1252 // desc: ...
1253 //-----------------------------------------------------------------------------
1254 void Chuck_Instr_Eq_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1256 sint *& sp = (sint *&)shred->reg->sp;
1257 pop_( sp, 2 );
1258 push_( sp, val_(sp) == val_(sp+1) );
1264 //-----------------------------------------------------------------------------
1265 // name: execute()
1266 // desc: ...
1267 //-----------------------------------------------------------------------------
1268 void Chuck_Instr_Neq_int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1270 sint *& sp = (sint *&)shred->reg->sp;
1271 pop_( sp, 2 );
1272 push_( sp, val_(sp) != val_(sp+1) );
1278 //-----------------------------------------------------------------------------
1279 // name: execute()
1280 // desc: ...
1281 //-----------------------------------------------------------------------------
1282 void Chuck_Instr_Lt_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1284 uint *& sp = (uint *&)shred->reg->sp;
1285 pop_( sp, 2 );
1286 push_( sp, val_(sp) < val_(sp+1) );
1292 //-----------------------------------------------------------------------------
1293 // name: execute()
1294 // desc: ...
1295 //-----------------------------------------------------------------------------
1296 void Chuck_Instr_Gt_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1298 uint *& sp = (uint *&)shred->reg->sp;
1299 pop_( sp, 2 );
1300 push_( sp, val_(sp) > val_(sp+1) );
1306 //-----------------------------------------------------------------------------
1307 // name: execute()
1308 // desc: ...
1309 //-----------------------------------------------------------------------------
1310 void Chuck_Instr_Le_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1312 uint *& sp = (uint *&)shred->reg->sp;
1313 pop_( sp, 2 );
1314 push_( sp, val_(sp) <= val_(sp+1) );
1320 //-----------------------------------------------------------------------------
1321 // name: execute()
1322 // desc: ...
1323 //-----------------------------------------------------------------------------
1324 void Chuck_Instr_Ge_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1326 uint *& sp = (uint *&)shred->reg->sp;
1327 pop_( sp, 2 );
1328 push_( sp, val_(sp) >= val_(sp+1) );
1333 //-----------------------------------------------------------------------------
1334 // name: execute()
1335 // desc: ...
1336 //-----------------------------------------------------------------------------
1337 void Chuck_Instr_Eq_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1339 uint *& sp = (uint *&)shred->reg->sp;
1340 pop_( sp, 2 );
1341 push_( sp, val_(sp) == val_(sp+1) );
1347 //-----------------------------------------------------------------------------
1348 // name: execute()
1349 // desc: ...
1350 //-----------------------------------------------------------------------------
1351 void Chuck_Instr_Neq_uint::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1353 uint *& sp = (uint *&)shred->reg->sp;
1354 pop_( sp, 2 );
1355 push_( sp, val_(sp) != val_(sp+1) );
1361 //-----------------------------------------------------------------------------
1362 // name: execute()
1363 // desc: ...
1364 //-----------------------------------------------------------------------------
1365 void Chuck_Instr_Lt_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1367 float *& sp = (float *&)shred->reg->sp;
1368 pop_( sp, 2 );
1369 push_uint( sp, val_(sp) < val_(sp+1) );
1375 //-----------------------------------------------------------------------------
1376 // name: execute()
1377 // desc: ...
1378 //-----------------------------------------------------------------------------
1379 void Chuck_Instr_Gt_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1381 float *& sp = (float *&)shred->reg->sp;
1382 pop_( sp, 2 );
1383 push_uint( sp, val_(sp) > val_(sp+1) );
1389 //-----------------------------------------------------------------------------
1390 // name: execute()
1391 // desc: ...
1392 //-----------------------------------------------------------------------------
1393 void Chuck_Instr_Le_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1395 float *& sp = (float *&)shred->reg->sp;
1396 pop_( sp, 2 );
1397 push_uint( sp, val_(sp) <= val_(sp+1) );
1403 //-----------------------------------------------------------------------------
1404 // name: execute()
1405 // desc: ...
1406 //-----------------------------------------------------------------------------
1407 void Chuck_Instr_Ge_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1409 float *& sp = (float *&)shred->reg->sp;
1410 pop_( sp, 2 );
1411 push_uint( sp, val_(sp) >= val_(sp+1) );
1416 //-----------------------------------------------------------------------------
1417 // name: execute()
1418 // desc: ...
1419 //-----------------------------------------------------------------------------
1420 void Chuck_Instr_Eq_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1422 float *& sp = (float *&)shred->reg->sp;
1423 pop_( sp, 2 );
1424 push_uint( sp, val_(sp) == val_(sp+1) );
1430 //-----------------------------------------------------------------------------
1431 // name: execute()
1432 // desc: ...
1433 //-----------------------------------------------------------------------------
1434 void Chuck_Instr_Neq_single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1436 float *& sp = (float *&)shred->reg->sp;
1437 pop_( sp, 2 );
1438 push_uint( sp, val_(sp) != val_(sp+1) );
1444 //-----------------------------------------------------------------------------
1445 // name: execute()
1446 // desc: ...
1447 //-----------------------------------------------------------------------------
1448 void Chuck_Instr_Lt_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1450 double *& sp = (double *&)shred->reg->sp;
1451 pop_( sp, 2 );
1452 push_uint( sp, val_(sp) < val_(sp+1) );
1458 //-----------------------------------------------------------------------------
1459 // name: execute()
1460 // desc: ...
1461 //-----------------------------------------------------------------------------
1462 void Chuck_Instr_Gt_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1464 double *& sp = (double *&)shred->reg->sp;
1465 pop_( sp, 2 );
1466 push_uint( sp, val_(sp) > val_(sp+1) );
1472 //-----------------------------------------------------------------------------
1473 // name: execute()
1474 // desc: ...
1475 //-----------------------------------------------------------------------------
1476 void Chuck_Instr_Le_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1478 double *& sp = (double *&)shred->reg->sp;
1479 pop_( sp, 2 );
1480 push_uint( sp, val_(sp) <= val_(sp+1) );
1486 //-----------------------------------------------------------------------------
1487 // name: execute()
1488 // desc: ...
1489 //-----------------------------------------------------------------------------
1490 void Chuck_Instr_Ge_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1492 double *& sp = (double *&)shred->reg->sp;
1493 pop_( sp, 2 );
1494 push_uint( sp, val_(sp) >= val_(sp+1) );
1499 //-----------------------------------------------------------------------------
1500 // name: execute()
1501 // desc: ...
1502 //-----------------------------------------------------------------------------
1503 void Chuck_Instr_Eq_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1505 double *& sp = (double *&)shred->reg->sp;
1506 pop_( sp, 2 );
1507 push_uint( sp, val_(sp) == val_(sp+1) );
1513 //-----------------------------------------------------------------------------
1514 // name: execute()
1515 // desc: ...
1516 //-----------------------------------------------------------------------------
1517 void Chuck_Instr_Neq_double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1519 double *& sp = (double *&)shred->reg->sp;
1520 pop_( sp, 2 );
1521 push_uint( sp, val_(sp) != val_(sp+1) );
1527 //-----------------------------------------------------------------------------
1528 // name: execute()
1529 // desc: ...
1530 //-----------------------------------------------------------------------------
1531 void Chuck_Instr_And::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1533 uint *& sp = (uint *&)shred->reg->sp;
1534 pop_( sp, 2 );
1535 push_( sp, val_(sp) && val_(sp+1) );
1541 //-----------------------------------------------------------------------------
1542 // name: execute()
1543 // desc: ...
1544 //-----------------------------------------------------------------------------
1545 void Chuck_Instr_Or::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1547 uint *& sp = (uint *&)shred->reg->sp;
1548 pop_( sp, 2 );
1549 push_( sp, val_(sp) || val_(sp+1) );
1555 //-----------------------------------------------------------------------------
1556 // name: execute()
1557 // desc: ...
1558 //-----------------------------------------------------------------------------
1559 void Chuck_Instr_Goto::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1561 shred->next_pc = m_jmp;
1567 //-----------------------------------------------------------------------------
1568 // name: execute()
1569 // desc: ...
1570 //-----------------------------------------------------------------------------
1571 void Chuck_Instr_Nop::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1573 // no op
1579 //-----------------------------------------------------------------------------
1580 // name: execute()
1581 // desc: ...
1582 //-----------------------------------------------------------------------------
1583 void Chuck_Instr_EOC::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1585 // end the shred
1586 shred->is_done = TRUE;
1587 shred->is_running = FALSE;
1593 //-----------------------------------------------------------------------------
1594 // name: execute()
1595 // desc: ...
1596 //-----------------------------------------------------------------------------
1597 void Chuck_Instr_Chuck_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1599 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
1600 uint *& reg_sp = (uint *&)shred->reg->sp;
1602 // pop word from reg stack
1603 pop_( reg_sp, 2 );
1604 // copy popped value into mem stack
1605 *( (uint *)(mem_sp + *(reg_sp+1)) ) = *reg_sp;
1607 push_( reg_sp, *reg_sp );
1613 //-----------------------------------------------------------------------------
1614 // name: execute()
1615 // desc: ...
1616 //-----------------------------------------------------------------------------
1617 void Chuck_Instr_Chuck_Assign2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1619 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
1620 uint *& reg_sp = (uint *&)shred->reg->sp;
1622 // pop word from reg stack
1623 pop_( reg_sp, 3 );
1624 // copy popped value into mem stack
1625 *( (double *)(mem_sp + *(reg_sp+2)) ) = *(double *)reg_sp;
1627 double *& sp_double = (double *&)reg_sp;
1628 push_( sp_double, *sp_double );
1634 //-----------------------------------------------------------------------------
1635 // name: execute()
1636 // desc: ...
1637 //-----------------------------------------------------------------------------
1638 void Chuck_Instr_Chuck_Assign_Deref::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1640 uint *& reg_sp = (uint *&)shred->reg->sp;
1642 // pop word from reg stack
1643 pop_( reg_sp, 2 );
1644 // copy popped value into mem stack
1645 *( (uint *)(*(reg_sp+1)) ) = *reg_sp;
1647 push_( reg_sp, *reg_sp );
1653 //-----------------------------------------------------------------------------
1654 // name: execute()
1655 // desc: ...
1656 //-----------------------------------------------------------------------------
1657 void Chuck_Instr_Chuck_Assign_Deref2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1659 uint *& reg_sp = (uint *&)shred->reg->sp;
1661 // pop word from reg stack
1662 pop_( reg_sp, 3 );
1663 // copy popped value into mem stack
1664 *( (double *)(*(reg_sp+2)) ) = *(double *)reg_sp;
1666 double *& sp_double = (double *&)reg_sp;
1667 push_( sp_double, *sp_double );
1673 //-----------------------------------------------------------------------------
1674 // name: execute()
1675 // desc: ...
1676 //-----------------------------------------------------------------------------
1677 void Chuck_Instr_Chuck_Assign_Object::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1679 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
1680 uint *& reg_sp = (uint *&)shred->reg->sp;
1682 // pop word from reg stack
1683 pop_( reg_sp, 2 );
1684 // release any previous reference
1685 Chuck_VM_Object ** obj = (Chuck_VM_Object **)(mem_sp + *(reg_sp+1));
1686 // if( *obj ) (*obj)->release();
1687 // copy popped value into mem stack
1688 *obj = *(Chuck_VM_Object **)reg_sp;
1689 // add reference
1690 (*(Chuck_VM_Object **)reg_sp)->add_ref();
1692 push_( reg_sp, *reg_sp );
1698 //-----------------------------------------------------------------------------
1699 // name: execute()
1700 // desc: ...
1701 //-----------------------------------------------------------------------------
1702 void Chuck_Instr_Chuck_Release_Object::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1704 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
1705 uint *& reg_sp = (uint *&)shred->reg->sp;
1706 Chuck_VM_Object * obj = NULL;
1708 // pop word from reg stack
1709 pop_( reg_sp, 1 );
1710 // copy popped value into mem stack
1711 obj = *( (Chuck_VM_Object **)(mem_sp + *(reg_sp)) );
1712 // release
1713 obj->release();
1719 //-----------------------------------------------------------------------------
1720 // name: execute()
1721 // desc: ...
1722 //-----------------------------------------------------------------------------
1723 void Chuck_Instr_Chuck_Assign_Object_Deref::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1725 uint *& reg_sp = (uint *&)shred->reg->sp;
1727 // pop word from reg stack
1728 pop_( reg_sp, 2 );
1729 // copy popped value into mem stack
1730 *( (uint *)(*(reg_sp+1)) ) = *reg_sp;
1731 // add reference
1732 ( *((Chuck_VM_Object **)reg_sp) )->add_ref();
1734 push_( reg_sp, *reg_sp );
1740 //-----------------------------------------------------------------------------
1741 // name: execute()
1742 // desc: ...
1743 //-----------------------------------------------------------------------------
1744 void Chuck_Instr_Chuck_Assign_Object2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1746 BYTE__ *& mem_sp = (BYTE__ *&)shred->mem->sp;
1747 uint *& reg_sp = (uint *&)shred->reg->sp;
1749 // pop word from reg stack
1750 pop_( reg_sp, 2 );
1751 // copy popped value into mem stack
1752 *( (uint *)(mem_sp + *reg_sp) ) = *(reg_sp+1);
1753 // add reference
1754 ( *((Chuck_VM_Object **)(reg_sp+1)) )->add_ref();
1756 push_( reg_sp, *(reg_sp+1) );
1762 //-----------------------------------------------------------------------------
1763 // name: execute()
1764 // desc: ...
1765 //-----------------------------------------------------------------------------
1766 void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1768 uint *& mem_sp = (uint *&)shred->mem->sp;
1769 uint *& reg_sp = (uint *&)shred->reg->sp;
1771 // pop word
1772 pop_( reg_sp, 2 );
1773 Chuck_VM_Code * func = (Chuck_VM_Code *)*reg_sp;
1774 uint local_depth = *(reg_sp+1);
1775 local_depth = ( local_depth >> 2 ) + ( local_depth & 0x3 ? 1 : 0 );
1776 uint stack_depth = ( func->stack_depth >> 2 ) + ( func->stack_depth & 0x3 ? 1 : 0 );
1777 uint prev_stack = ( *(mem_sp-1) >> 2 ) + ( *(mem_sp-1) & 0x3 ? 1 : 0 );
1779 // jump the sp
1780 mem_sp += prev_stack + local_depth;
1781 // push the prev stack
1782 push_( mem_sp, prev_stack + local_depth );
1783 // push the current function
1784 push_( mem_sp, (uint)shred->code );
1785 // push the pc
1786 push_( mem_sp, (uint)(shred->pc + 1) );
1787 // push the stack depth
1788 push_( mem_sp, stack_depth );
1789 // set the pc to 0
1790 shred->next_pc = 0;
1791 // set the code
1792 shred->code = func;
1793 shred->instr = func->instr;
1795 if( stack_depth )
1797 BYTE__ *& mem_sp2 = (BYTE__ *&)mem_sp;
1798 BYTE__ *& reg_sp2 = (BYTE__ *&)reg_sp;
1800 // pop the arguments
1801 pop_( reg_sp2, stack_depth << 2 );
1802 // push the arguments
1803 memcpy( mem_sp2, reg_sp2, stack_depth << 2 );
1810 //-----------------------------------------------------------------------------
1811 // name: execute()
1812 // desc: ...
1813 //-----------------------------------------------------------------------------
1814 void Chuck_Instr_Func_Call2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1816 uint *& mem_sp = (uint *&)shred->mem->sp;
1817 uint *& reg_sp = (uint *&)shred->reg->sp;
1818 Chuck_DL_Return retval;
1820 pop_( reg_sp, 3 );
1821 f_ck_func f = (f_ck_func)(*(reg_sp+1));
1822 uint stack_size = ((*reg_sp) >> 2) + ( *reg_sp & 0x3 ? 1 : 0 );
1823 uint local_depth = *(reg_sp+2) + *(mem_sp-1);
1824 uint push = ((local_depth) >> 2) + ( local_depth & 0x3 ? 1 : 0 );
1825 reg_sp -= stack_size;
1826 mem_sp += push;
1827 uint * sp = reg_sp;
1828 uint * mem = mem_sp;
1829 // copy to args
1830 for( uint i = 0; i < stack_size; i++ )
1831 *mem++ = *sp++;
1832 // call the function
1833 f( mem_sp, &retval );
1834 mem_sp -= push;
1835 // push the return args
1836 push_( reg_sp, retval.v_uint );
1842 //-----------------------------------------------------------------------------
1843 // name: execute()
1844 // desc: ...
1845 //-----------------------------------------------------------------------------
1846 void Chuck_Instr_Func_Call3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1848 uint *& mem_sp = (uint *&)shred->mem->sp;
1849 uint *& reg_sp = (uint *&)shred->reg->sp;
1850 Chuck_DL_Return retval;
1852 pop_( reg_sp, 3 );
1853 f_ck_func f = (f_ck_func)(*(reg_sp+1));
1854 uint stack_size = ((*reg_sp) >> 2) + ( *reg_sp & 0x3 ? 1 : 0 );
1855 uint local_depth = *(reg_sp+2) + *(mem_sp-1);
1856 uint push = (local_depth >> 2) + ( local_depth & 0x3 ? 1 : 0 );
1857 reg_sp -= stack_size;
1858 mem_sp += push;
1859 uint * sp = reg_sp;
1860 uint * mem = mem_sp;
1861 // copy to args
1862 for( uint i = 0; i < stack_size; i++ )
1863 *mem++ = *sp++;
1864 // call the function
1865 f( mem_sp, &retval );
1866 mem_sp -= push;
1867 // push the return args
1868 double *& sp_double = (double *&)reg_sp;
1869 push_( sp_double, retval.v_float );
1875 //-----------------------------------------------------------------------------
1876 // name: execute()
1877 // desc: ...
1878 //-----------------------------------------------------------------------------
1879 void Chuck_Instr_Func_Call0::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1881 uint *& mem_sp = (uint *&)shred->mem->sp;
1882 uint *& reg_sp = (uint *&)shred->reg->sp;
1883 Chuck_DL_Return retval;
1885 pop_( reg_sp, 3 );
1886 f_ck_func f = (f_ck_func)(*(reg_sp+1));
1887 uint stack_size = ((*reg_sp) >> 2) + ( *reg_sp & 0x3 ? 1 : 0 );
1888 uint local_depth = *(reg_sp+2) + *(mem_sp-1);
1889 uint push = (local_depth >> 2) + ( local_depth & 0x3 ? 1 : 0 );
1890 reg_sp -= stack_size;
1891 mem_sp += push;
1892 uint * sp = reg_sp;
1893 uint * mem = mem_sp;
1894 // copy to args
1895 for( uint i = 0; i < stack_size; i++ )
1896 *mem++ = *sp++;
1897 // call the function
1898 f( mem_sp, &retval );
1899 mem_sp -= push;
1900 // push the return args
1901 // push_( reg_sp, retval.v_uint );
1907 //-----------------------------------------------------------------------------
1908 // name: execute()
1909 // desc: ...
1910 //-----------------------------------------------------------------------------
1911 void Chuck_Instr_Func_Return::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1913 uint *& mem_sp = (uint *&)shred->mem->sp;
1914 uint *& reg_sp = (uint *&)shred->reg->sp;
1916 // pop pc
1917 pop_( mem_sp, 2 );
1918 shred->next_pc = *mem_sp;
1919 // pop the code
1920 pop_( mem_sp, 1 );
1921 Chuck_VM_Code * func = (Chuck_VM_Code *)*mem_sp;
1922 // pop the prev_stack
1923 pop_( mem_sp, 1 );
1924 // jump the prev stack
1925 mem_sp -= *(mem_sp);
1927 // set the shred
1928 shred->code = func;
1929 shred->instr = func->instr;
1935 //-----------------------------------------------------------------------------
1936 // name: execute()
1937 // desc: ...
1938 //-----------------------------------------------------------------------------
1939 void Chuck_Instr_Spork::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1941 uint *& reg_sp = (uint *&)shred->reg->sp;
1943 // pop the stack
1944 pop_( reg_sp, 1 );
1945 // get the code
1946 Chuck_VM_Code * code = *(Chuck_VM_Code **)reg_sp;
1947 // spork it
1948 Chuck_VM_Shred * sh = vm->spork( code, shred );
1949 // copy args
1950 if( m_val )
1952 pop_( shred->reg->sp, m_val );
1953 memcpy( sh->reg->sp, shred->reg->sp, m_val );
1954 sh->reg->sp += m_val;
1956 // push the stack
1957 push_( reg_sp, sh->id );
1963 //-----------------------------------------------------------------------------
1964 // name: execute()
1965 // desc: ...
1966 //-----------------------------------------------------------------------------
1967 void Chuck_Instr_Time_Advance::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
1969 t_CKTIME *& sp = (t_CKTIME *&)shred->reg->sp;
1971 // pop word from reg stack
1972 pop_( sp, 1 );
1974 if( *sp < shred->now )
1976 // we have a problem
1977 fprintf( stderr,
1978 "[chuck](VM): Exception DestTimeNegative: '%.6f'\n", *sp );
1979 // do something!
1980 shred->is_running = FALSE;
1982 return;
1985 // shredule the shred
1986 vm->shreduler()->shredule( shred, *sp );
1987 // suspend
1988 shred->is_running = FALSE;
1990 push_( sp, *sp );
1996 //-----------------------------------------------------------------------------
1997 // name: execute()
1998 // desc: ...
1999 //-----------------------------------------------------------------------------
2000 void Chuck_Instr_Add_dur_time::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2002 t_CKTIME *& p = (t_CKTIME *&)shred->reg->sp;
2003 pop_( p, 1 );
2004 t_CKTIME t = *p;
2006 t_CKDUR *& sp = (t_CKDUR *&)shred->reg->sp;
2007 pop_( sp, 1 );
2008 t_CKDUR d = *sp;
2010 push_( sp, (t_CKTIME)( d + (t_CKDUR)t ) );
2015 //-----------------------------------------------------------------------------
2016 // name: execute()
2017 // desc: ...
2018 //-----------------------------------------------------------------------------
2019 void Chuck_Instr_Midi_Out::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2021 uint *& sp = (uint *&)shred->reg->sp;
2023 // pop word
2024 pop_( sp, m_val ? 1 : 0 );
2026 // send the word as midi msg
2027 MidiOut * out = vm->bbq()->midi_out( m_val ? *(sp) : 0 );
2028 if( !out && vm->bbq()->out_count( m_val ? *(sp) : 0 ) < 2 )
2029 fprintf( stderr, "[chuck](VM): cannot open MIDI output device # '%i'...\n",
2030 m_val ? *(sp) : 0 );
2032 // push anything?
2033 push_( sp, (uint)out );
2039 //-----------------------------------------------------------------------------
2040 // name: execute()
2041 // desc: ...
2042 //-----------------------------------------------------------------------------
2043 void Chuck_Instr_Midi_Out_Go::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2045 MidiMsg msg;
2046 uint *& sp = (uint *&)shred->reg->sp;
2048 // pop word
2049 pop_( sp, 2 );
2051 uint v = *( m_val ? sp+1 : sp );
2052 msg.data[0] = (v >> 16) & 0xff;
2053 msg.data[1] = (v >> 8) & 0xff;
2054 msg.data[2] = (v) & 0xff;
2056 // send the word as midi msg
2057 MidiOut * out = *(MidiOut **)( m_val ? (sp) : sp+1 );
2058 if( out ) out->send( &msg );
2060 // push anything?
2061 push_( sp, (uint)out );
2067 //-----------------------------------------------------------------------------
2068 // name: execute()
2069 // desc: ...
2070 //-----------------------------------------------------------------------------
2071 void Chuck_Instr_Midi_In::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2073 uint *& sp = (uint *&)shred->reg->sp;
2075 if( m_val ) pop_( sp, 1 );
2076 MidiIn * in = vm->bbq()->midi_in( m_val ? *(sp) : 0 );
2077 if( !in && vm->bbq()->in_count( m_val ? *(sp) : 0 ) < 2 )
2079 fprintf( stderr, "[chuck](VM): cannot open MIDI input device '%i'...\n",
2080 m_val ? *(sp) : 0 );
2083 push_( sp, (uint)in );
2089 //-----------------------------------------------------------------------------
2090 // name: execute()
2091 // desc: ...
2092 //-----------------------------------------------------------------------------
2093 void Chuck_Instr_Midi_In_Go::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2095 MidiMsg msg;
2096 uint *& sp = (uint *&)shred->reg->sp;
2098 pop_( sp, 1 );
2099 MidiIn * in = *(MidiIn **)sp;
2100 if( !in )
2102 push_( sp, 0 );
2103 return;
2106 if( in->recv( &msg ) )
2108 // msg2.data[0] = msg.data[3];
2109 // msg2.data[1] = msg.data[2];
2110 // msg2.data[2] = msg.data[1];
2111 // msg2.data[3] = msg.data[0];
2112 push_( sp, *((uint *)&msg) );
2114 else
2116 push_( sp, 0 );
2123 //-----------------------------------------------------------------------------
2124 // name: execute()
2125 // desc: ...
2126 //-----------------------------------------------------------------------------
2127 void Chuck_Instr_ADC::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2129 uint *& reg_sp = (uint *&)shred->reg->sp;
2130 push_( reg_sp, (uint)vm->m_adc );
2136 //-----------------------------------------------------------------------------
2137 // name: execute()
2138 // desc: ...
2139 //-----------------------------------------------------------------------------
2140 void Chuck_Instr_DAC::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2142 uint *& reg_sp = (uint *&)shred->reg->sp;
2143 push_( reg_sp, (uint)vm->m_dac );
2149 //-----------------------------------------------------------------------------
2150 // name: execute()
2151 // desc: ...
2152 //-----------------------------------------------------------------------------
2153 void Chuck_Instr_Bunghole::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2155 uint *& reg_sp = (uint *&)shred->reg->sp;
2156 push_( reg_sp, (uint)vm->m_bunghole );
2162 //-----------------------------------------------------------------------------
2163 // name: execute()
2164 // desc: ...
2165 //-----------------------------------------------------------------------------
2166 void Chuck_Instr_UGen_Link::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2168 Chuck_UGen **& sp = (Chuck_UGen **&)shred->reg->sp;
2170 pop_( sp, 2 );
2171 (*(sp + 1))->add( *sp );
2172 push_( sp, *(sp + 1) );
2178 //-----------------------------------------------------------------------------
2179 // name: execute()
2180 // desc: ...
2181 //-----------------------------------------------------------------------------
2182 void Chuck_Instr_UGen_UnLink::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2184 Chuck_UGen **& sp = (Chuck_UGen **&)shred->reg->sp;
2186 pop_( sp, 2 );
2187 (*(sp+1))->remove( *sp );
2188 push_( sp, *(sp + 1) );
2194 //-----------------------------------------------------------------------------
2195 // name: execute()
2196 // desc: ...
2197 //-----------------------------------------------------------------------------
2198 void Chuck_Instr_UGen_Alloc::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2200 uint *& sp = (uint *&)shred->reg->sp;
2201 Chuck_UGen_Info * info = NULL;
2202 Chuck_UGen * ugen = NULL;
2204 pop_( sp, 1 );
2205 info = (Chuck_UGen_Info *)*(sp);
2206 ugen = new Chuck_UGen;
2207 // copy the info over
2208 ugen->ctor = info->ctor;
2209 ugen->dtor = info->dtor;
2210 ugen->tick = info->tick;
2211 ugen->pmsg = info->pmsg;
2212 ugen->m_max_src = info->max_src;
2213 // call the constructor
2214 ugen->state = ugen->ctor ? ugen->ctor( shred->now ) : NULL ;
2216 // setup the reference with the shred
2217 ugen->shred = shred;
2218 shred->add( ugen );
2219 push_( sp, (uint)ugen );
2225 //-----------------------------------------------------------------------------
2226 // name: execute()
2227 // desc: ...
2228 //-----------------------------------------------------------------------------
2229 void Chuck_Instr_UGen_DeAlloc::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2236 //-----------------------------------------------------------------------------
2237 // name: execute()
2238 // desc: ...
2239 //-----------------------------------------------------------------------------
2240 void Chuck_Instr_UGen_Ctrl::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2242 uint *& sp = (uint *&)shred->reg->sp;
2244 pop_( sp, 4 );
2245 Chuck_UGen * ugen = (Chuck_UGen *)*(sp+1);
2246 f_ctrl ctrl = (f_ctrl)*(sp+2);
2247 f_cget cget = (f_cget)*(sp+3);
2248 // call ctrl
2249 ctrl( shred->now, ugen->state, (void *)sp );
2250 if( cget ) cget( shred->now, ugen->state, (void *)sp );
2251 // push the new value
2252 push_( sp, *sp);
2258 //-----------------------------------------------------------------------------
2259 // name: execute()
2260 // desc: ...
2261 //-----------------------------------------------------------------------------
2262 void Chuck_Instr_UGen_CGet::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2264 uint *& sp = (uint *&)shred->reg->sp;
2266 pop_( sp, 2 );
2267 Chuck_UGen * ugen = (Chuck_UGen *)*(sp);
2268 f_cget cget = (f_cget)*(sp+1);
2269 // call cget
2270 cget( shred->now, ugen->state, (void *)sp );
2271 // push the new value
2272 push_( sp, *sp);
2278 //-----------------------------------------------------------------------------
2279 // name: execute()
2280 // desc: ...
2281 //-----------------------------------------------------------------------------
2282 void Chuck_Instr_UGen_Ctrl2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2284 uint *& sp = (uint *&)shred->reg->sp;
2286 pop_( sp, 4 );
2287 Chuck_UGen * ugen = (Chuck_UGen *)*(sp+1);
2288 f_ctrl ctrl = (f_ctrl)*(sp+2);
2289 f_cget cget = (f_cget)*(sp+3);
2290 // call ctrl
2291 pop_( sp, 1 );
2292 ctrl( shred->now, ugen->state, (void *)sp );
2293 if( cget ) cget( shred->now, ugen->state, (void *)sp );
2294 // push the new value
2295 ((double *&)shred->reg->sp)++;
2301 //-----------------------------------------------------------------------------
2302 // name: execute()
2303 // desc: ...
2304 //-----------------------------------------------------------------------------
2305 void Chuck_Instr_UGen_CGet2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2307 uint *& sp = (uint *&)shred->reg->sp;
2309 pop_( sp, 2 );
2310 Chuck_UGen * ugen = (Chuck_UGen *)*(sp);
2311 f_cget cget = (f_cget)*(sp+1);
2312 // call cget
2313 cget( shred->now, ugen->state, (void *)sp );
2314 // push the new value
2315 ((double *&)shred->reg->sp)++;
2321 //-----------------------------------------------------------------------------
2322 // name: execute()
2323 // desc: ...
2324 //-----------------------------------------------------------------------------
2325 void Chuck_Instr_UGen_PMsg::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2327 Chuck_UGen **& sp = (Chuck_UGen **&)shred->reg->sp;
2329 pop_( sp, 2 );
2331 // (*(sp + 1))->pmsg( shred->now, *sp );
2333 push_( sp, *(sp + 1) );
2339 //-----------------------------------------------------------------------------
2340 // name: execute()
2341 // desc: ...
2342 //-----------------------------------------------------------------------------
2343 void Chuck_Instr_UGen_Ctrl_Op::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2345 uint *& sp = (uint *&)shred->reg->sp;
2347 pop_( sp, 4 );
2348 Chuck_UGen * ugen = (Chuck_UGen *)*(sp+1);
2349 ugen->m_op = *(sint *)sp;
2350 // push the new value
2351 push_( sp, *sp);
2357 //-----------------------------------------------------------------------------
2358 // name: execute()
2359 // desc: ...
2360 //-----------------------------------------------------------------------------
2361 void Chuck_Instr_UGen_CGet_Op::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2363 uint *& sp = (uint *&)shred->reg->sp;
2365 pop_( sp, 2 );
2366 Chuck_UGen * ugen = (Chuck_UGen *)*(sp);
2367 // push the new value
2368 push_( sp, ugen->m_op );
2374 //-----------------------------------------------------------------------------
2375 // name: execute()
2376 // desc: ...
2377 //-----------------------------------------------------------------------------
2378 void Chuck_Instr_UGen_Ctrl_Gain::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2380 uint *& sp = (uint *&)shred->reg->sp;
2382 // HACK: this won't work for 64-bit long
2383 ((Chuck_UGen *)*(sp-3))->m_gain = (float)*(double *)(sp-5);
2384 pop_( sp, 5 );
2386 // push the new value
2387 ((double *&)shred->reg->sp)++;
2393 //-----------------------------------------------------------------------------
2394 // name: execute()
2395 // desc: ...
2396 //-----------------------------------------------------------------------------
2397 void Chuck_Instr_UGen_CGet_Gain::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2399 uint *& sp = (uint *&)shred->reg->sp;
2401 pop_( sp, 2 );
2402 Chuck_UGen * ugen = (Chuck_UGen *)*(sp);
2403 // push the new value
2404 double *& sp_double = (double *&)shred->reg->sp;
2405 push_( sp_double, (double)ugen->m_gain );
2411 //-----------------------------------------------------------------------------
2412 // name: execute()
2413 // desc: ...
2414 //-----------------------------------------------------------------------------
2415 void Chuck_Instr_UGen_CGet_Last::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2417 uint *& sp = (uint *&)shred->reg->sp;
2419 pop_( sp, 2 );
2420 Chuck_UGen * ugen = (Chuck_UGen *)*(sp);
2421 // push the new value
2422 double *& sp_double = (double *&)shred->reg->sp;
2423 push_( sp_double, (double)ugen->m_current );
2429 //-----------------------------------------------------------------------------
2430 // name: execute()
2431 // desc: ...
2432 //-----------------------------------------------------------------------------
2433 void Chuck_Instr_DLL_Load::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2435 uint *& sp = (uint *&)shred->reg->sp;
2436 sint retval = FALSE;
2437 Chuck_DLL * dll = NULL;
2438 pop_( sp, 2 );
2440 // load the DLL into the vm
2441 dll = vm->dll_load( (const char *)(*sp) );
2442 // load the DLL into the namespace
2443 if( dll ) retval = type_engine_add_dll( (t_Env)vm->get_env(), dll,
2444 (const char *)(*(sp+1)) );
2446 // push the result
2447 push_( sp, (uint)dll );
2453 //-----------------------------------------------------------------------------
2454 // name: execute()
2455 // desc: ...
2456 //-----------------------------------------------------------------------------
2457 void Chuck_Instr_DLL_Unload::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2459 uint *& sp = (uint *&)shred->reg->sp;
2460 sint retval = FALSE;
2461 Chuck_DLL * dll = NULL;
2462 pop_( sp, 1 );
2464 // unload the dll
2465 dll = (Chuck_DLL *)(*sp);
2466 if( dll ) retval = vm->dll_unload( dll );
2468 // push the result
2469 push_( sp, retval );
2475 //-----------------------------------------------------------------------------
2476 // name: execute()
2477 // desc: ...
2478 //-----------------------------------------------------------------------------
2479 void Chuck_Instr_Cast_single2int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2481 sint *& sp = (sint *&)shred->reg->sp;
2482 pop_( sp, 1 );
2483 push_( sp, (sint)*(float *)sp );
2489 //-----------------------------------------------------------------------------
2490 // name: execute()
2491 // desc: ...
2492 //-----------------------------------------------------------------------------
2493 void Chuck_Instr_Cast_int2single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2495 float *& sp = (float *&)shred->reg->sp;
2496 pop_( sp, 1 );
2497 push_( sp, (float)*(sint *)sp );
2503 //-----------------------------------------------------------------------------
2504 // name: execute()
2505 // desc: ...
2506 //-----------------------------------------------------------------------------
2507 void Chuck_Instr_Cast_double2int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2509 double *& sp = (double *&)shred->reg->sp;
2510 sint *& sp_int = (sint *&)sp;
2511 pop_( sp, 1 );
2512 push_( sp_int, (sint)(*sp) );
2518 //-----------------------------------------------------------------------------
2519 // name: execute()
2520 // desc: ...
2521 //-----------------------------------------------------------------------------
2522 void Chuck_Instr_Cast_int2double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2524 sint *& sp = (sint *&)shred->reg->sp;
2525 double *& sp_double = (double *&)sp;
2526 pop_( sp, 1 );
2527 push_( sp_double, (double)(*sp) );
2533 //-----------------------------------------------------------------------------
2534 // name: execute()
2535 // desc: ...
2536 //-----------------------------------------------------------------------------
2537 void Chuck_Instr_Cast_double2single::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2539 double *& sp = (double *&)shred->reg->sp;
2540 float *& sp_float = (float *&)sp;
2541 pop_( sp, 1 );
2542 push_( sp_float, (float)(*sp) );
2548 //-----------------------------------------------------------------------------
2549 // name: execute()
2550 // desc: ...
2551 //-----------------------------------------------------------------------------
2552 void Chuck_Instr_Cast_single2double::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2554 float *& sp = (float *&)shred->reg->sp;
2555 double *& sp_double = (double *&)sp;
2556 pop_( sp, 1 );
2557 push_( sp_double, (double)(*sp) );
2563 //-----------------------------------------------------------------------------
2564 // name: execute()
2565 // desc: ...
2566 //-----------------------------------------------------------------------------
2567 void Chuck_Instr_Print_Console::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2569 uint *& sp = (uint *&)shred->reg->sp;
2570 uint type;
2571 uint w = 0;
2573 // pop word from reg stack
2574 pop_( sp, 1 );
2575 type = *sp;
2577 switch( type )
2579 case cip_int:
2580 case cip_uint:
2581 case cip_string:
2582 pop_( sp, 2 );
2583 break;
2585 case cip_double:
2586 case cip_float:
2587 case cip_dur:
2588 case cip_time:
2589 w = 1;
2590 pop_( sp, 3 );
2591 break;
2593 default:
2594 fprintf( stderr,
2595 "[chuck virtual machine]: Exception UnknownTypeToStdout '%u'\n",
2596 type );
2597 return;
2600 switch( type )
2602 case cip_int:
2603 fprintf( stdout, "%i\n", *((sint*)sp) );
2604 break;
2605 case cip_uint:
2606 fprintf( stdout, "%u\n", *((uint *)sp) );
2607 break;
2608 case cip_float:
2609 fprintf( stdout, "%.6f\n", *((double *)sp) );
2610 break;
2611 case cip_double:
2612 fprintf( stdout, "%.6f\n", *((double *)sp) );
2613 break;
2614 case cip_string:
2615 fprintf( stdout, "%s\n", *((char **)sp) );
2616 break;
2617 case cip_dur:
2618 fprintf( stdout, "dur=%.4fs\n", *((t_CKDUR *)sp) / (double)Digitalio::sampling_rate() );
2619 break;
2620 case cip_time:
2621 fprintf( stdout, "time=%.4fs\n", *((t_CKTIME *)sp) / (double)Digitalio::sampling_rate() );
2622 break;
2625 // push the data back
2626 double *& sp_double = (double *&)sp;
2627 if( w == 0 )
2629 push_( sp, *sp );
2631 else
2633 push_( sp_double, *sp_double );
2640 //-----------------------------------------------------------------------------
2641 // name: execute()
2642 // desc: ...
2643 //-----------------------------------------------------------------------------
2644 void Chuck_Instr_Print_Console2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2646 uint *& sp = (uint *&)shred->reg->sp;
2647 uint type;
2648 uint w = 0;
2650 // pop word from reg stack
2651 pop_( sp, 1 );
2652 type = *sp;
2654 switch( type )
2656 case cip_int:
2657 case cip_uint:
2658 case cip_string:
2659 pop_( sp, 2 );
2660 break;
2662 case cip_double:
2663 case cip_float:
2664 case cip_dur:
2665 case cip_time:
2666 w = 1;
2667 pop_( sp, 3 );
2668 break;
2670 default:
2671 fprintf( stderr,
2672 "[chuck virtual machine]: Exception UnknownTypeToStdout '%u'\n",
2673 type );
2674 return;
2677 switch( type )
2679 case cip_int:
2680 fprintf( stderr, "%i", *((sint*)(sp+1)) );
2681 break;
2682 case cip_uint:
2683 fprintf( stderr, "%u", *((uint *)(sp+1)) );
2684 break;
2685 case cip_float:
2686 fprintf( stderr, "%.6f", *((double *)(sp+1)) );
2687 break;
2689 case cip_double:
2690 fprintf( stderr, "%.6f", *((double *)(sp+1)) );
2691 break;
2692 case cip_string:
2693 fprintf( stderr, "%s", *((char **)(sp+1)) );
2694 break;
2695 case cip_dur:
2696 fprintf( stderr, "%.4fs", *((t_CKDUR *)(sp+1)) / (double)Digitalio::sampling_rate() );
2697 break;
2698 case cip_time:
2699 fprintf( stderr, "%.4fs", *((t_CKTIME *)(sp+1)) / (double)Digitalio::sampling_rate() );
2700 break;
2703 // push
2704 push_( sp, *sp );