Create an AoC Assembly Computer
Arguments
- registers
A list of registers
- functions
A list of functions. Registers can be referred to with
self[[register_name]]. They must have two arguments,xandy, even if only one is used. The index is iterated withprivate$.inc(j)wherejis the number of places to "jump." Example:\(x, y) private$.inc(self[[x]])will incrementself$indexbyself[[x]].- increment
(Default:
1) The number of places to increment by default.- regex
(Default:
"[, \\+]+") The pattern to use for stringr::str_split
Value
A new assembly R6 object with registers and functions as the
fields and methods, respectively. Along with the functions detailed in the
details section.
Details
try_numeric(x)
: Takes input and tries to cast it as numeric. If that fails, it returns the
original object.
val_or_index(x)
: If x is numeric, return x, otherwise return self[[x]].
call(f, x, y)
: Calls one of functions using x and y as arguments.
There are two ways the function can be used:
fis not length one andxandyare null, thenf[1](f[2], f[3])fis length one, andxandyare not null, thenf(x, y)
run(x, target, until, pattern)
: Tries to run the instructions provided by x. If x is a character
vector, it will try to split the instructions into a segments for
call(f, x, y).
x: A character vector of instructions asc("f x y")or a list of character vectors in the formatlist(c("f", "x", "y"))target: (Default:NULL) Theregisterto print as the final result. IfNULL,selfwill be printed.pattern: See theregexargument for more details.
.inc(increment)
: A private function used to increment self$index by increment.