! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces make math math.order math.parser sequences accessors kernel kernel.private layouts assocs words summary arrays combinators classes.algebra alien alien.c-types alien.structs alien.strings alien.arrays sets threads libc continuations.private fry cpu.architecture compiler.errors compiler.alien compiler.cfg compiler.cfg.instructions compiler.cfg.registers compiler.cfg.builder compiler.codegen.fixup ; IN: compiler.codegen GENERIC: generate-insn ( insn -- ) SYMBOL: registers : register ( vreg -- operand ) registers get at [ "Bad value" throw ] unless* ; : ?register ( obj -- operand ) dup vreg? [ register ] when ; : generate-insns ( insns -- code ) [ [ dup regs>> registers set generate-insn ] each ] { } make fixup ; TUPLE: asm label code calls ; SYMBOL: calls : add-call ( word -- ) #! Compile this word later. calls get push ; SYMBOL: compiling-word : compiled-stack-traces? ( -- ? ) 59 getenv ; ! Mapping _label IDs to label instances SYMBOL: labels : init-generator ( word -- ) H{ } clone labels set V{ } clone literal-table set V{ } clone calls set compiling-word set compiled-stack-traces? compiling-word get f ? add-literal drop ; : generate ( mr -- asm ) [ [ label>> ] [ word>> init-generator ] [ instructions>> generate-insns ] tri calls get asm boa ] with-scope ; : lookup-label ( id -- label ) labels get [ drop