Documentation - SkyeTheFoxyFox/sfmlog GitHub Wiki

The basic documentation of all the sfmlog instructions, as well as some other things that need to be known.

Global variables

Global variables are referenced with $, for example $playerHealth. Global variables aren't affected by the scope of the macro or function they're in.

Special variables

These are variables used to give more information to sfmlog.

Configuration

  • $PROCESSOR_TYPE: The default type of processor to use for proc if not defined. Defaults to @micro-processor
  • $SCHEMATIC_NAME: The name of the output schematic.
  • $SCHEMATIC_DESCRIPTION: The description of the output schematic.

Information

  • @cwd: The path to the current file.
  • @ctime: Epoch time in milliseconds.
  • @ptime: Execution time of sfmlog in milliseconds.

Throwaway

  • _: Any value written to it will be discarded, useful if you don't care about the output of an instruction.

Instructions

Import

import file/path.sfmlib

Executes the code contained in the file, usually this will contain macro and global variable definitions, but can technically contain anything.

Block

block blockVar @block-type x y rotation

Places a block into the schematic, writing the link name to the output variable. if rotation is excluded it with point right, if the position is excluded it will be placed in a line just below y = 0.

Proc

proc processorVar @proc-type x y
    #processor code
end

Places a processor into the schematic with the code contained within. If ran without arguments it will place a processor using the type defined in $PROCESSOR_TYPE (defaults to @micro-processor), in a square from (0,0).

Defmac

defmac MacroName arg1 arg2 ...
    #macro code
end

Defines a macro.

Mac

mac MacroName arg1 arg2 ...

Calls a macro, executing the code contained within. Unless needed, use call.

Deffun

deffun FunctionName >input <output <>bidirectional ...
    #function code
end

Defines a function. use >, <, or <> before the argument to define if it's an input, output, or both, avoid unnecessary flow directions for performance.

Fun

fun FunctionName arg1 arg2 ...

Calls a function, the code for the function is only included in processors it's called in, and is executed when the processor finishes (can be used for some goofy stuff with globals). Unless needed, use call.

Call

call CallableName arg1 arg2 ...

Calls something, either a function or a macro. This is generally the recommended option over fun and mac.

Getmac

getmac macroVar MacroName

Wraps a macro into a variable. This can be useful for passing macros into macros, and storing into tables or lists for use later.

Setmac

setmac MacroName macroVar

Unwraps a macro from a variable.

Type

type output input

Returns the type of a variable as a string.

Pset

pset var value

Writes a value to a variable.

Pop

pop operation output input1 input2

Performs numeric operations on one or two numbers. This works mostly the same as op would normally, and is useful for precomputing values.

Strop

Performs string operations.

Valid operations:

  • strop cat outputStr str1 str2 ... Concatenate any number of values to a string.
  • strop num outputNum string Convert a string to a number.
  • strop charat outputChar string index Get the character at an index of a string.
  • strop substr outputStr str start end Get a substring between start and end.
  • strop split outputStr str splitStr Split a string on another string.
  • strop rematch outStr str pattern Find the first match of a regex pattern in str.
  • strop refind start end str pattern Find the start and end of the first match.
  • strop regroups outList str pattern Get all groups for the first match.
  • strop rematchall outList str pattern Find all matches.

Strlabel

strlabel labelString

Appends a label to the output named by the input. This can be used to make jump tables and stuff automatically.

Strvar

strvar scope outputVariable inputString

Creates an identifier based on the input string, in the desired scope, and writes it to a variable. The valid values for scope are local (which defines it to be in the scope strvar is executed in), global, and unscoped. unscoped can be used to create dynamic references to links that don't exist yet.

List

Performs list operations

  • list from list value1 value2 ... Creates a list from all the arguments to the instruction. This is the intended way to initialize a list.
  • list copy outputList inputList Creates a new list with the same elements as the input list.
  • list set list value index Sets the value at an index.
  • list get output list index Gets the value at an index.
  • list append list value Appends a value to a list.
  • list insert list value index Inserts a value at an index.
  • list del list index Removes a value at an index.
  • list len output list Gets the length of a list
  • list index output list value Finds the first instance of value and returns it's index
  • list in output list value Checks if a value exists in a list

Table

Performs table operations

  • table from table key1 value1 key2 value2 ... Creates a table as key value pairs defined sequentially. This is the intended way to initialize a table.
  • table copy outputTable inputTable Creates a new table with the same elements as the input table.
  • table set table value key Sets the value of a key.
  • table get output table key Gets the value of a key.
  • table del table key Removes a key.
  • table in output table key Checks if a key exists.

File

Allows for reading from files

  • file open fileVar path Opens a text file.
  • file openbin fileVar path Opens a binary file.
  • file close fileVar Closes a file.
  • file read outputString fileVar Reads the contents of a text file to a string.
  • file readbytes outputNumber fileVar count [endianness] Reads count bytes from a binary file with the given endianness (default big endian)

If

if cond a b

elif cond a b

else

end

Performs a conditional check. Supports the same conditions as jump excluding always. This DOES NOT compile into jumps, it is purely executed on compile.

While

while condition a b

end

Loops while a condition is true.

For

for operator

end

Loops based on an operator. Valid operators are:

  • for range output start stop step or for range output stop iterates from start to stop-1 in steps of step (start defaults to 0, and step defaults to 1).
  • for list output inputList iterates over the values in a list.
  • for enumerate index value inputList iterates over a list, returning both the value, and it's index.
  • for table key value inputTable iterates over a table, returning the key and value.

Discard

discard arg1 arg2 ...

end

Executes the contained code, while writing no code to the output, and making no changes to anything unless passed in as an argument.

Log

log input1 input2 ...

Print out to the console, all arguments are concatenated together and printed. useful for debugging.

Error

error input1 input2 ...

Works like log, but instead of logging, it triggers an error.

⚠️ **GitHub.com Fallback** ⚠️