add logging

This commit is contained in:
jane 2021-06-04 22:12:08 -04:00
parent 1e162cd7a5
commit 751b8dd6c0
2 changed files with 12 additions and 12 deletions

View file

@ -56,7 +56,7 @@ export const functions = {
convert_args: false convert_args: false
} }
), ),
constant: new Function( move: new Function(
(index, arg1, arg2) => { return arg2; }, (index, arg1, arg2) => { return arg2; },
{ {
requires_arg1: true, requires_arg1: true,
@ -70,15 +70,8 @@ export const functions = {
requires_arg2: true, requires_arg2: true,
convert_args: true convert_args: true
}), }),
move: new Function(
(index, arg1, arg2) => { targets[arg1] = arg2; return arg2; },
{
requires_arg1: true,
requires_arg2: true,
convert_args: false
}),
swap: new Function( swap: new Function(
(index, arg1, arg2) => { let temp = targets[arg1]; targets[arg1] = arg2; return temp; }, (index, arg1, arg2) => { let temp = targets[arg2]; targets[arg2] = targets[arg1]; return temp; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true, requires_arg2: true,
@ -109,13 +102,17 @@ function tick_pattern() {
for (let command of pattern) { for (let command of pattern) {
let name = command.command; let name = command.command;
if (functions[name]) { if (functions[name]) {
if (functions[name].options.convert_args) { if (functions[name].options && functions[name].options["convert_args"]) {
let param_arg1 = parseInt(command.arg1) || targets[command.arg1]; let param_arg1 = parseInt(command.arg1) || targets[command.arg1];
let param_arg2 = parseInt(command.arg2) || targets[command.arg2]; let param_arg2 = parseInt(command.arg2) || targets[command.arg2];
targets[command.arg1] = functions[name].func(i, param_arg1, param_arg2); let result = functions[name].func(i, param_arg1, param_arg2);
log.info(`convert ${command.arg1} ${param_arg1} ${command.arg2} ${param_arg2} ${result}`);
targets[command.arg1] = result;
} }
else { else {
targets[command.arg1] = functions[name].func(i, command.arg1, command.arg2); let result = functions[name].func(i, command.arg1, command.arg2);
log.info("no convert " + result);
targets[command.arg1] = result;
} }
} }
} }

View file

@ -28,6 +28,9 @@ export default function parse(data) {
) { ) {
errors.push(`error parsing line ${lineNumber}, invalid number of args`); errors.push(`error parsing line ${lineNumber}, invalid number of args`);
} }
else if (!match.options["convert_args"] && parseInt(arg1)) {
errors.push(`error parsing line ${lineNumber}, argument ${arg1} cannot be a number`);
}
else { else {
parsed.push( parsed.push(
{ {