! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs classes combinators cpu.architecture effects generic hashtables io kernel kernel.private layouts math math.parser namespaces prettyprint quotations sequences system threads words vectors sets deques continuations.private summary alien alien.c-types alien.structs alien.strings alien.arrays libc compiler.errors stack-checker.inlining compiler.tree compiler.tree.builder compiler.tree.combinators compiler.tree.propagation.info compiler.generator.fixup compiler.generator.registers compiler.generator.iterator ; IN: compiler.generator SYMBOL: compile-queue SYMBOL: compiled : queue-compile ( word -- ) { { [ dup "forgotten" word-prop ] [ ] } { [ dup compiled get key? ] [ ] } { [ dup inlined-block? ] [ ] } { [ dup primitive? ] [ ] } [ dup compile-queue get push-front ] } cond drop ; : maybe-compile ( word -- ) dup compiled>> [ drop ] [ queue-compile ] if ; SYMBOL: compiling-word SYMBOL: compiling-label SYMBOL: compiling-loops ! Label of current word, after prologue, makes recursion faster SYMBOL: current-label-start : compiled-stack-traces? ( -- ? ) 59 getenv ; : begin-compiling ( word label -- ) H{ } clone compiling-loops set compiling-label set compiling-word set compiled-stack-traces? compiling-word get f ? 1vector literal-table set f compiling-label get compiled get set-at ; : save-machine-code ( literals relocation labels code -- ) 4array compiling-label get compiled get set-at ; : with-generator ( nodes word label quot -- ) [ >r begin-compiling r> { } make fixup save-machine-code ] with-scope ; inline GENERIC: generate-node ( node -- next ) : generate-nodes ( nodes -- ) [ current-node generate-node ] iterate-nodes end-basic-block ; : init-generate-nodes ( -- ) init-templates %save-word-xt %prologue-later current-label-start define-label current-label-start resolve-label ; : generate ( nodes word label -- ) [ init-generate-nodes [ generate-nodes ] with-node-iterator ] with-generator ; : intrinsics ( #call -- quot ) word>> "intrinsics" word-prop ; : if-intrinsics ( #call -- quot ) word>> "if-intrinsics" word-prop ; ! node M: node generate-node drop iterate-next ; : %jump ( word -- ) dup compiling-label get eq? [ drop current-label-start get ] [ %epilogue-later ] if %jump-label ; : generate-call ( label -- next ) dup maybe-compile end-basic-block dup compiling-loops get at [ %jump-label f ] [ tail-call? [ %jump f ] [ 0 frame-required %call iterate-next ] if ] ?if ; ! #recursive : compile-recursive ( node -- next ) dup label>> id>> generate-call >r [ child>> ] [ label>> word>> ] [ label>> id>> ] tri generate r> ; : compiling-loop ( word -- )