Package: vizh
vizhAn esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.OverviewHere is an implementation ofmemcpy:Yes, you literally pass an image file to the compiler.The "parser" is based on computer vision and the backend produces C code.Here's how the parser understands the program (produced if you pass--debug-parserwhen compiling):Here's a C program which calls into the function:#include<stdio.h>// Supplied by linking with the vizh object filevoidmemcopy(uint8_t*,uint8_t*,uint8_t*);intmain(){uint8_tstr[]="Hello!";uint8_tsize=sizeof(str);uint8_tto[sizeof(str)];memcopy(&size,str,to);puts(to);}We can compile this into an executable in a single command:$vizhmemcopy.pngmain_memcopy.c-omemcopyThen run it:$./memcopyHello!ErrorsBut what if you make an error, like this?Well you get the best compiler errors you'll ever see:ImplementationThe provided implementation is calledvizhand compiles to C and can link executables.InstallationYou can installvizhdirectly fromPyPi:$pipinstallvizhDependenciesvizhdepends onOpenCV,cffi, andTesseract OCR.You can install OpenCV and cffi withpip:$pipinstallopencv-pythoncffiYou'll have to install Tesseract OCR separately.See their documentationfor instructions.UsageUsage: vizh [OPTIONS] [INPUTS]...

Options:
  --version               Show the version and exit.
  -c, --compile-only      Only compile, don't link.
  -o, --output-file PATH  Output file for executables or vizh object files.
  -q, --quiet             Suppress output.
  --debug-parser          Display how the parser understands your source file.
  --help                  Show this message and exit.The compiler can take any combination of image files, C sources files, and object files.You may need to set theTESSDATA_PREFIXenvironment variable to the folder containing Tesseract data. If you're on Linux this is likely/usr/share/tesseract-ocr/<version>/tessdata.LanguageAbstract MachineThe vizh abstract machine consists of:Some number oftapeswhich are contiguous groups of 8-bit unsigned integersA read/write head with storage for a single 8-bit unsigned integerThe initial state of the abstract machine is:A single tape of size 4096 is allocated with all cells initialised to 0The read/write head is initialised to the left-most cell of this tapeSeeinstructionsfor the valid operations on the abstract machine.ProgramA vizh program consists of a number of functions, each in its own image file. (What image types are allowed? Ideally at least png and jpg)The entry point to a vizh program is a function calledmain. (Note that themainfunction gets mangled asvizh_main. For all other functions the symbol name is the same as the vizh name).FunctionsA vizh function is an image file containing:The name of the function at the top left of the imageThe number of arguments (tapes) it takes at the top right of the imageA sequnce of instructions in a horizontal linesFunction names are alphanumeric:[a-zA-Z][a-zA-Z0-9]*.The tapes available to a vizh function consist of its tape arguments. On entry to the function the r/w head is initialised to the start of the first tape argument, if any.A function returns when control flow reaches the end of its instructions.Any tapes allocated by a function are automatically deallocated when the function exits.Function CallsWhen you call a function subsequent pointer arguments are taken from the currently active tape onwards.For example, given the following state of the abstract machine where^is the last position of the r/w head on that tape and$is the active tape:t1 01234
     ^
$t2 99999
    ^
 t3 00000
    ^Then a call to a function that takes two tapes would supply the argumentst2, t3.InstructionsThe valid instructions in vizh and their encodings are:Left arrow: move the r/w head leftRight arrow: move the r/w head rightUp arrow: move the r/w head to the tape above the current oneDown arrow: move the r/w head to the tape below the current oneFunction name in a circle: call the given functionnot yet implemented+: increment the value pointed to by the r/w head by1-: decrement the value pointed to by the r/w head by1Equilateral triangle with the point at the top: read the cell pointed to by the r/w head into the r/w head storageEquilateral triangle with the point at the bottom: write the value stored in r/w head storage into the cell pointed to by the r/w head[<instructions>]: loop over the instructions between the brackets until the value pointed to by the r/w head at the start of the loop is0When you move the r/w head up or down, the position it was last at for the previous tape is saved. E.g. given this state of the abstract where^is the last position of the r/w head on that tape and$is the active tape:$t0 01234
    ^  
 t1 01234
    ^The sequence of instructions "right right right down" would result in this state:t0 01234
       ^  
$t1 01234
    ^CommentsComments in vizh are anything enclosed in a rectangle. Stick what you want in there.Standard LibraryThe vizh standard library is calledlibv. Much of it is implemented in vizh itself and it is built when you installvizh. It provides the following functions:I/Oreadin: read an ASCII character from stdin and write its integral representation into the cell pointed to by the r/w headprint: print the value of the cell pointed to by the r/w head to stout, interpreted as an ASCII characterputstr: write the null-terminated ASCII string starting at the position pointed to by the r/w head to stdout.Stringsgeta: puts the characteraat the current position of the r/w head.getA: puts the characterAat the current position of the r/w head.Arithmeticaddgiven tape cellsa,bfrom the r/w head, results ina+b,0.mulgiven tape cellsa,b,cfrom the r/w head, results ina*b,0,0.zerogiven tape cellafrom the r/w head, results in0Memorynewtape: allocate a new secondary tape underneath the last one currently allocated for this function (or the primary tape if there are no secondary tapes)freetape: deallocate the bottom-most secondary tape for this function (no-op if there are not any)