! Copyright (C) 2008, 2009 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.strings alien.arrays alien.complex alien.libraries sets libc continuations.private fry cpu.architecture classes locals source-files.errors slots parser generic.parser compiler.errors compiler.alien compiler.constants compiler.cfg compiler.cfg.instructions compiler.cfg.stack-frame compiler.cfg.registers compiler.cfg.builder compiler.codegen.fixup compiler.utilities ; QUALIFIED: classes.struct QUALIFIED: alien.structs IN: compiler.codegen SYMBOL: insn-counts H{ } clone insn-counts set-global GENERIC: generate-insn ( insn -- ) TUPLE: asm label code calls ; SYMBOL: calls : add-call ( word -- ) #! Compile this word later. calls get push ; SYMBOL: compiling-word : compiled-stack-traces? ( -- ? ) 67 getenv ; ! Mapping _label IDs to label instances SYMBOL: labels : init-generator ( word -- ) H{ } clone labels set V{ } clone calls set compiling-word set compiled-stack-traces? [ compiling-word get add-literal ] when ; : generate-insns ( asm -- code ) [ [ word>> init-generator ] [ instructions>> [ [ class insn-counts get inc-at ] [ generate-insn ] bi ] each ] bi ] with-fixup ; : generate ( mr -- asm ) [ [ label>> ] [ generate-insns ] bi calls get asm boa ] with-scope ; : lookup-label ( id -- label ) labels get [ drop