1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
5#include "runscript.hpp"
12#include "battle_globals.hpp"
14void runerror(
const char *message) {
15 fprintf(stderr,
"RUNTIME ERROR: %s\n", message);
20 runerror(
"stack overflow");
24 if (data.
type == RS_INT) {
28 fprintf(stderr,
"RUNTIME ERROR: %s: operand is not integer\n", function->
name);
34 return !(data.
type == RS_INT && data.
i == 0);
38 runerror(
"Divide by 0");
42 runerror(
"Modulo by 0");
46 for (
int index = 0; index < count; index++, data++) {
47 if (data->
type == RS_INT) {
48 printf(
"%d", data->
i);
49 }
else if (data->
type == RS_STR) {
50 printf(
"%s", data->
s);
51 }
else if (data->
type == RS_FLOAT) {
52 printf(
"%f", data->
f);
114 printf(
"\202\261\202\352\210\310\217\343\212\326\220\224\214\304\202\321\217\157\202\265"
115 "\202\252\202\305\202\253\202\334\202\271\202\361\201\102\n");
140 printf(
"not found ext %d\n", args->
i);
142 printf(
"not found ext %d\n", args->
i);
144 printf(
"illegal function call ext %d\n", args->
i);
195 for (i = 0; i < header->
prog_num; i++, entry++) {
196 if (entry->
no == no) {
204 printf(
"not found program %d\n", no);
216 return end != 0 ? 0 : 1;
227 for (i = 0; i < header->
prog_num; i++, entry++) {
228 if (entry->
no == no) {
263 case RS_ADDR_LOCAL_INDEX:
266 case RS_ADDR_POINTER_INDEX:
269 case RS_ADDR_LOCAL_FLOAT:
273 case RS_ADDR_LOCAL_INDEX_FLOAT:
278 case RS_ADDR_POINTER_INDEX_FLOAT:
286 case RS_OP_LOAD_ADDR:
291 case RS_ADDR_LOCAL_INDEX:
294 case RS_ADDR_POINTER_INDEX:
297 case RS_ADDR_LOCAL_FLOAT:
300 case RS_ADDR_LOCAL_INDEX_FLOAT:
303 case RS_ADDR_POINTER_INDEX_FLOAT:
314 case RS_OP_PUSH_CONST:
317 }
else if (
pc->
arg1 == 3) {
319 }
else if (
pc->
arg1 == 2) {
336 if (is_true(
pop())) {
347 case RS_OP_JMP_FALSE:
349 if (!is_true(
pop())) {
364 if (lhs.
type == RS_INT && rhs.
type == RS_INT) {
389 if (lhs.
type == RS_FLOAT && rhs.
type == RS_FLOAT) {
392 }
else if (lhs.
type == RS_INT && rhs.
type == RS_FLOAT) {
395 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_INT) {
399 fprintf(stderr,
"RUNTIME ERROR at _CMP: %s: operand is not number\n",
func->
name);
430 if (lhs.
type == RS_INT && rhs.
type == RS_INT) {
432 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_FLOAT) {
434 }
else if (lhs.
type == RS_INT && rhs.
type == RS_FLOAT) {
436 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_INT) {
439 fprintf(stderr,
"RUNTIME ERROR at _ADD: %s: operand is not number\n",
func->
name);
448 if (lhs.
type == RS_INT && rhs.
type == RS_INT) {
450 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_FLOAT) {
452 }
else if (lhs.
type == RS_INT && rhs.
type == RS_FLOAT) {
454 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_INT) {
457 fprintf(stderr,
"RUNTIME ERROR at _SUB: %s: operand is not number\n",
func->
name);
466 if (lhs.
type == RS_INT && rhs.
type == RS_INT) {
468 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_FLOAT) {
470 }
else if (lhs.
type == RS_INT && rhs.
type == RS_FLOAT) {
472 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_INT) {
475 fprintf(stderr,
"RUNTIME ERROR _MUL: %s: operand is not number\n",
func->
name);
489 if (lhs.
type == RS_INT && rhs.
type == RS_INT) {
491 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_FLOAT) {
493 }
else if (lhs.
type == RS_INT && rhs.
type == RS_FLOAT) {
495 }
else if (lhs.
type == RS_FLOAT && rhs.
type == RS_INT) {
498 fprintf(stderr,
"RUNTIME ERROR at _DIV: %s: operand is not number\n",
func->
name);
523 if (rhs.
type == RS_INT) {
525 }
else if (rhs.
type == RS_FLOAT) {
528 fprintf(stderr,
"RUNTIME ERROR at _INVT: %s: operand is not number\n",
func->
name);
536 if (rhs.
type == RS_INT) {
538 }
else if (rhs.
type == RS_FLOAT) {
541 fprintf(stderr,
"RUNTIME ERROR at _SIN: %s: operand is not number\n",
func->
name);
549 if (rhs.
type == RS_INT) {
551 }
else if (rhs.
type == RS_FLOAT) {
554 fprintf(stderr,
"RUNTIME ERROR at _COS: %s: operand is not number\n",
func->
name);
562 if (rhs.
type == RS_INT) {
565 fprintf(stderr,
"RUNTIME ERROR: %s: \220\256\220\224\202\305\202\310\202\242\203\111"
566 "\203\171\203\211\203\223\203\150\n",
575 if (rhs.
type == RS_INT) {
577 }
else if (rhs.
type == RS_FLOAT) {
580 fprintf(stderr,
"RUNTIME ERROR at _ITOF: %s: operand is not number\n",
func->
name);
588 if (rhs.
type == RS_INT) {
590 }
else if (rhs.
type == RS_FLOAT) {
593 fprintf(stderr,
"RUNTIME ERROR at _FTOI: %s: operand is not number\n",
func->
name);
void ext(RS_STACKDATA *args, int argc)
vmcode_t * call_func(funcdata *callee, vmcode_t *return_pc)
void exe(vmcode_t *entry)
void reload(RS_PROG_HEADER *prog)
void push_ptr(RS_STACKDATA *pointer)
void ext_func(int(**table)(RS_STACKDATA *, int), int count)
int check_program(int no)
int(** ext_func_table)(RS_STACKDATA *, int)
void push_float(float value)
void load(RS_PROG_HEADER *prog, RS_STACKDATA *stack, int stack_num, RS_CALLDATA *call, int call_num)
void push(RS_STACKDATA value)
void push_str(char *string)