12.07.2015 Views

ertl-paf

ertl-paf

ertl-paf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ErtlPAF: A portable assembly languagetail-called). Since max does not follow the platform’scalling convention, it cannot be called from,e.g., C code.The second definition, printmax, follows thestandard ABI of the platform (as indicated by usingan abi: defining word. The xx- in abi:xx- 3 showsthatprintmax expects and consumes two cells fromthe data stack and 0 floats from the FP stack andproduces 0 cells and 0 floats; a C prototype for thisdefinition could be void printmax(long, long).Printmax callsmax, and the compiler can choose thecalling interface between the call and max; it callsprintf using the standard calling convention withthe call abi.printf.xxxx-, where the xxxx- indicatesthat four cells are passed as integer/addressparameters and the return value of printf is ignored.Locals are used in printmax but can be used inevery definition. Exiting from the definitions is explicit.3.5 RegistersSeveral language features correspond to real machineregisters: Stack items, locals, and values.Stack items (elements) are useful for relativelyshort-lived data and (unlike locals) can be usedfor passing arguments and return values. Thereis no stack pointer and memory area specific tothe stack, it’s just an abstraction used by thecompiler. Stack manipulation words like DUPor SWAP just modify the data flow and there isno machine code that directly corresponds tothem (indirect consequences may be, e.g., moveinstructions at control flow joins).Locals live within a definition and are a convenience:Local variables of the source languagecan be mapped directly to PAF’s locals withoutneeding register allocation or stack managementin the front end. If a source localneeds to be distributed across several PAF definitions(e.g., because a control structure ofthe source language is mapped to a PAF (tail)call), the local can be defined in each of thesedefinitions, and the constants are passed on thestack across calls; this is not as convenient asone might like, but seems to be a good compromise.Values are global (thread-local) variables whoseaddress cannot be taken, so they can be storedin registers.If stack items and locals don’t fit in the registers,they are stored in a stack that is not visible to PAF3 This paper assumes the use of a recognizer feature inthe Forth system to process parameterized names; the conventionalForth way would be to use a parsing word, in thiscase, e.g., abi: xx- printmax.code; this stack stores items from the data and FPstack, locals, and return addresses, so this does notcorrespond to the memory representation of, e.g.,the data stack. 4If values don’t fit in the registers, they are storedin global/thread-local memory.3.6 MemoryThe words c@ uw@ ul@ ( addr -- u ) load unsigned8/16/32-bit values from memory, while sc@w@ l@ ( addr -- n ) load signed 8/16/32-bit valuesfrom memory; @ (addr -- w) loads a cell (32-bit or 64-bit, depending on the machine) frommemory; sf@ df@ ( addr -- r ) load 32/64-bitfloating-point values from memory. c! w! l!! ( x addr -- ) and sf! df! ( r addr --) store stack items to memory.3.7 ArithmeticsThe usual Forth words + - * negate and orinvert lshift rshift correspond to the arithmeticand logic instructions present in every machine.There are also additional words like / m*um* um/mod sm/rem that correspond to instructionson some machines, and have to be synthesizedfrom other instructions on other machines.3.8 ComparisonThe words =?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!