Human Resource Code
Human Resource Code is an esolang based off a game called Human Resource Machine. The only commands used are those from the game as well as some extra exclusive commands. Human Resource Code is also meant to somewhat look like the code seen when attempting to paste Human Resource Machine code into notepad. This esolang was created by User:EthanPixelate.
Introduction
Like Human Resource Machine, Human Resource Code has 5 main parts to it:
- Code (Obviously)
- The "Worker"
- The "Inbox"
- The "Outbox"
- The "Carpet"
The code instructs the worker on how to take boxes from the inbox, alter them with assistance of the carpet, and outputs the result into the outbox. boxes taken from the inbox can be an integer within the range (-999,999), or a single ASCII character. To do any useful computations with these inputs, you are going to need somewhere to store the data for modification, thats where the carpet comes into play. The carpet has 128 cells all containing boxes with 0 in them, normally in Human Resource Machine all levels would have a small select number of cells with nothing in them, but to make things easier, all 128 cells in this language contain 0.
Commands
Basic IO
Human Resource Code has 4 simple input/output related commands
ASK
The "ASK" command asks the user for the input of a single integer and pushes it onto the farther side of the inbox conveyor.
ASKSTRING
The "ASKSTRING" command asks the user for their input like the above command, this time however they can input some text. For every character in the imputed string, the corresponding ASCII number is pushed onto the far side of the inbox conveyor, ending with a 0 to mark the end of the input.
INBOX
The "INBOX" command removes the box on the closer end of the inbox conveyor and gives it to the worker.
OUTBOX
The "OUTBOX" command removes the box from the worker's hands and pushes it onto the closer end of the outbox conveyor. If the box being sent to the outbox is a number, it will be followed by a space " ".
Carpet Manipulation
COPYTO <Cell>
The "COPYTO" command copies the box in the worker's hands and places the cloned box into the described position on the carpet.
Example: INBOX COPYTO 4
COPYFROM <Cell>
Likewise, the "COPYFROM" command copies a box from the described position on the carpet and gives it to the worker, causing the worker to discard any previously held box.
ADD <Cell>
Assuming that the currently held box is A and that a copy of the box on the described carped position is B, the worker discards the held box and replaces it with A+B, does not work with letter boxes.
SUB <Cell>
The "SUB" command is identical to the "ADD" command. However, instead of doing A+B, it does A-B. Note: Neither the ADD or SUB command will work on character boxes unlike Human Resource Machine
BUMPUP <Cell>
The "BUMPUP" command increments the described box on the carpet by 1.
BUMPDN <Cell>
The "BUMPDN" command decrements the described box on the carpet by 1.
Note: In Human Resource Machine, the BUMPUP and BUMPDN copies the incremented/decremented to your hands, Human Resource Code does not.
Math Example: BUMPUP 0 BUMPUP 0 BUMBUP 1 COPYFROM 0 ADD 1 OUTBOX Output: 3
Misc.
STOP
The "STOP" command simply halts execution of the program, immediately outputting the outboxed result.
TOCHAR
The "TOCHAR" command converts whatever number is in the worker's hand and converts it into an ASCII character with the number being the id of the character.
TONUM
The "TONUM" command takes the character in the worker's hands and converts it into a number, with the value being the ASCII code of the previously held character.
COMMENT or ;
This is not really a command, rather it is a comment, and will do nothing
Jumping and Controlled Flow
Jumps are a special type of command, because you first require creating some points for the jumps to go to first. To create a jump-point for your code, you simply suffix a line with a ":":
A: BLAHBLAHBLAH B: YADDAYADDAYADDA HelloThere: HELLOFRIENDS IfCellIsSomething: DOTHIS DOTHAT
Note: There must not be any white space characters in the name of the jump-point to work.
JUMP <Jump Point Name>
The "JUMP" command is a simple command that causes code execution to jump to the specified jump-point.
JUMPZ <Jump Point Name>
The "JUMPZ" command is identical to the "JUMP" command. However, the jump only occurs if the worker is holding the number 0 in their hands.
JUMPN <Jump Point Name>
The "JUMPN" command is identical to the "JUMP" command. However, the jump only occurs if the worker is holding any negative number in their hands.
JUMPC <Jump Point Name>
The "JUMPC" command is identical to the "JUMP" command. However, the jump only occurs if the worker is holding a character in their hands.
Jumping Example, this example takes the first item the inbox (assuming it is a number) and decrements it until it is 0 and outboxes it: INBOX COPYTO 0 Loop: BUMPDN 0 COPYFROM 0 JUMPZ IsZero JUMP LOOP IsZero: OUTBOX
Trying HRC
Example Programs
Truth Machine
ASK INBOX JUMPZ IsZero JUMP IsNotZero IsZero: COPYFROM 1 OUTBOX STOP IsNotZero: BUMPUP 1 Loop: COPYFROM 1 OUTBOX BUMPUP 2 JUMP Loop
Cat Program:
ASKSTRING Main: INBOX JUMPZ IfEndOfStr TOCHAR OUTBOX JUMP Main IfEndOfStr: STOP
Hello World
COPYFROM ASCII_UPPER_A COPYTO 0 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you want to actually use Human Resource Code, you need an interpereter. This section of the wiki lists some interpreters to be used for executing HRC Code.
Lua
HRC Interpereter written in Lua:
-- basic HRC interpereter created by Ethan Pixelate -- when "require"ing the module, set "m.InputCallback" to a function that determines what happens when the users input is required, the first parameter is the message asking for the input, the returned result should be the users input (duh) local m = {} function m.InputCallback(Msg)end local function StringToLines(s) local t = {} for chunk in string.gmatch(s.." ", "[^\n]+") do local Thing = string.sub(chunk,1) if string.sub(Thing,-1) == "\n" then Thing = string.sub(Thing,1,-2) end t[#t+1] = Thing --must string.sub it so that he \n isn't included end return t end function ParseLines(Lines) local Final = {} Final.JumpPoints = {} local Item = {} for k,v in pairs(Lines) do for Param in v:gmatch("%S+") do if tonumber(Param) then table.insert(Item,tonumber(Param)) else table.insert(Item,Param) end end if string.sub(v,-1) == ":" then Final.JumpPoints[string.sub(v,1,-2)] = k end table.insert(Final,Item) Item = {} end return Final end function m.Run(c) if c == "" then error("Did you forget to write code?") end local Lines = StringToLines(c) local Code = ParseLines(Lines) local Line = 1 local Final = "" local Carpet = {} Carpet.ASCII_ZERO = 48 Carpet.ASCII_UPPER_A = 65 Carpet.ASCII_LOWER_A = 97 Carpet.ASCII_SPACE = 32 local Inbox = {} local Holding for i=0,127,1 do Carpet[i] = 0 end local function HRCError(Msg) print("Output Before Failure: "..Final) error(Msg) end local function HoldingCheck() if Holding == nil then HRCError("Cannot operate because there are nothing in your hands.") end end local function CarpetLimit(CellNum) if type(CellNum) == "number" then if CellNum < 0 then HRCError("There is no cell with id "..tostring(CellNum)..", keep it at 0 or above.") end if CellNum > 127 then HRCError("There is no cell with id "..tostring(CellNum)..", keep it at 127 or bellow.") end if Carpet[CellNum] < -999 then HRCError("A box cannot have a value lower than -999, the limit is -999 to 999.") end if Carpet[CellNum] > 999 then HRCError("A box cannot have a value higher than 999, the limit is -999 to 999.") end end end local function JumpCheck(JumpName) if not Code.JumpPoints[JumpName] then HRCError("No such jump \""..JumpName.."\" exists.") end end while true do local Param = Code[Line][2] -- shorthand used in carpet related operations if Code[Line][1] == "STOP" then break elseif Code[Line][1] == "JUMP" then JumpCheck(Param) Line = Code.JumpPoints[Param] elseif Code[Line][1] == "JUMPZ" then JumpCheck(Param) if Holding == 0 then Line = Code.JumpPoints[Param] end elseif Code[Line][1] == "JUMPN" then JumpCheck(Param) if math.abs(Holding) ~= Holding then Line = Code.JumpPoints[Param] end elseif Code[Line][1] == "JUMPC" then if type(Holding) == "string" then Line = Code.JumpPoints[Param] end elseif Code[Line][1] == "COPYFROM" then CarpetLimit(Param) Holding = Carpet[Param] elseif Code[Line][1] == "COPYTO" then CarpetLimit(Param) HoldingCheck() Carpet[Param] = Holding elseif Code[Line][1] == "ADD" then HoldingCheck() CarpetLimit(Param) Holding = Holding + Carpet[Param] elseif Code[Line][1] == "SUB" then HoldingCheck() CarpetLimit(Param) Holding = Holding - Carpet[Param] elseif Code[Line][1] == "BUMPUP" then CarpetLimit(Param) Carpet[Param] = Carpet[Param] + 1 elseif Code[Line][1] == "BUMPDN" then CarpetLimit(Param) Carpet[Param] = Carpet[Param] - 1 elseif Code[Line][1] == "TONUM" then HoldingCheck() Holding = string.byte(Holding) elseif Code[Line][1] == "TOCHAR" then HoldingCheck() Holding = string.char(Holding) elseif Code[Line][1] == "OUTBOX" then HoldingCheck() if type(Holding) == "number" then Final = Final .. tostring(Holding) .. " " else Final = Final .. Holding end Holding = nil elseif Code[Line][1] == "INBOX" then if #Inbox < 1 then HRCError("Cannot take from inbox if inbox stack is empty.") end local Item = Inbox[1] table.remove(Inbox,1) Holding = Item elseif Code[Line][1] == "ASKSTRING" then local Receive = m.InputCallback("Input something") for i=1,#Receive,1 do table.insert(Inbox,string.byte(string.sub(Receive,i,i))) end table.insert(Inbox,0) elseif Code[Line][1] == "ASK" then local Receive while not tonumber(Receive) do Receive = m.InputCallback("Input a number") if not tonumber(Receive) then print("You must input a number") end end table.insert(Inbox,tonumber(Receive)) else if not Code[Line][1] == "COMMENT" or Code[Line][1] == ";" then HRCError("Unknown Command: "..Code[Line][1]) end end Line = Line + 1 if Line > #Code then break end end print("Output: "..Final) end return m