5 * Created by Bryan Donlan on Thu 11 Aug 2005.
6 * Copyright (c) 2005-2006 Alyssa Milburn. All rights reserved.
7 * Copyright (c) 2005-2006 Bryan Donlan. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library 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 GNU
17 * Lesser General Public License for more details.
25 #include <stdlib.h> // for NULL
30 /* IMPORTANT! The order of these elements must not change, or save
31 * compatibility will be broken.
33 * Note that relocated and non-relocated bytecode elements are treated
34 * seperately; you may add additional ones before CAOS_RELOCATABLE_BEGIN
35 * and before CAOS_INVALID.
42 * Argument: An index into the constants table, with a description of the
46 /* End the script gracefully.
50 /* Invoke a caos command.
51 * Argument: An index into the commands table.
54 /* Pop two values A and B off the stack, as well as an integer flag C.
55 * Compare A and B with the given comparison mask, then push back C AND/OR
56 * the result, in accordance with the flag.
57 * Argument: A comparison flag
60 /* Push a constant onto the stack.
61 * Argument: An index into the constants table
64 /* Push a constant integer in the range of a 24-bit int onto the stack.
65 * (ie, -2^24 <= x <= 2^24 - 1)
66 * Argument: An integer
69 /* Push a bytestring onto the stack.
70 * Argument: An index into the bytestrings table.
73 /* Copies the element (argument) elements from the top of the
74 * argument stack into the top of the aux stack. The values remain on
76 * Argument: A zero-based index into the argument stack
79 /* Moves the top (argument) elements from the top of the aux
80 * stack into the top of the argument stack. This effectively reverses
81 * their order. The values are removed from the aux stack.
82 * Argument: The number of elements to move
85 /* Invokes the writeback handler for the given CAOS command.
86 * Argument: An index into the commands table.
89 /* Exhausts the specified number of time slices.
90 * Argument: A number of time slices to spend. Can be negative or zero.
93 /* Moves the top element on the value stack down (argument) places.
94 * Argument: How many places to move it down
97 /* Pseudo-instructions; marks the beginning of relocated ops. */
99 CAOS_RELOCATABLE_BEGIN
= 0x40,
100 /* Pop an integer off the stack. Jump to the given location if it's nonzero.
101 * Argument: A bytecode location (relocated).
105 /* Jump to another location in the script.
106 * Argument: A bytecode location (relocated).
110 /* Pop a value off the stack. If it's nonzero, decrement, push back,
111 * and jump to the location in the argument.
112 * Argument: A bytecode location (relocated).
116 /* Push the instruction pointer and value stack into the call stack,
117 * then jump to the given location.
118 * Argument: A bytecode location (relocated).
122 /* Pop a value off the stack. If non-null, set targ to it, and go to the
123 * given address. Otherwise, set targ to ownr, and continue.
124 * Argument: A bytecode location (relocated).
132 static inline bool op_is_valid(opcode_t opcode
) {
133 return (opcode
>= 0 && opcode
< CAOS_NONRELOC_END
)
134 || (opcode
> CAOS_RELOCATABLE_BEGIN
&& opcode
< CAOS_INVALID
);
137 static inline bool op_is_relocatable(opcode_t opcode
) {
138 return (opcode
> CAOS_RELOCATABLE_BEGIN
&& opcode
< CAOS_INVALID
);
142 enum opcode_t opcode
: 8;
144 int traceindex
; // -1 if unknown
146 caosOp(enum opcode_t oc
, int arg
, int ti
){
147 assert(op_is_valid(oc
));
148 assert(arg
>= -(1 << 24) && arg
< (1 << 24));
155 FRIEND_SERIALIZE(caosOp
);
159 std::string
dumpOp(const class Dialect
*d
, caosOp op
);
169 #define CMASK (CEQ | CLT | CGT | CBT | CBF)
170 #define CLE (CEQ | CLT)
171 #define CGE (CEQ | CGT)
172 #define CNE (CLT | CGT)
174 extern const char *cnams
[];