From 32271498be6226c5045668605cc4ff78f9e49c8d Mon Sep 17 00:00:00 2001 From: DrMaxNix Date: Sat, 1 Oct 2022 21:00:49 +0200 Subject: [PATCH] :tada: `jmp` command --- src/command/jmp.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/command/jmp.js diff --git a/src/command/jmp.js b/src/command/jmp.js new file mode 100644 index 0000000..91dc22c --- /dev/null +++ b/src/command/jmp.js @@ -0,0 +1,36 @@ +Juicescript.command_define({ + name: "jmp", + alias: ["jump", "goto"], + + validate: function(runner){ + // count + runner.argument_validate_count(1); + if(runner.has_error) return; + + // types + runner.argument_validate_type(1, Juicescript.argument_type.VALUE); + }, + + execute: function(runner){ + // GET FLAG DATA // + // flag name + let flag = runner.argument_value(1); + + // load this scope's flag list + let flag_list = runner.scope_tree.flag; + + // check if this flag exists + if(!Object.keys(flag_list).includes(flag)){ + // ignore with error + runner.error("unknown flag '" + flag + "'"); + return; + } + + // get number of following command + let following_command_number = flag_list[flag].command_next; + + + // SET COMMAND COUNTER // + runner.counter = following_command_number; + } +});