]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler: remove some unnecessary complexity
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 3 Feb 2010 12:36:52 +0000 (01:36 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 3 Feb 2010 12:36:52 +0000 (01:36 +1300)
basis/bootstrap/compiler/compiler.factor
basis/compiler/codegen/codegen.factor
basis/compiler/compiler-docs.factor
basis/compiler/compiler.factor
basis/compiler/tests/low-level-ir.factor

index 2d0613a7f5cae3d6d656c135d24053f5d989dda6..8e167c076af2176bcd67c68a7a3d48c5f8e265b6 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors cpu.architecture vocabs.loader system
 sequences namespaces parser kernel kernel.private classes
@@ -33,6 +33,7 @@ enable-optimizer
 gc
 
 : compile-unoptimized ( words -- )
+    [ [ subwords ] map ] keep suffix concat
     [ optimized? not ] filter compile ;
 
 "debug-compiler" get [
index ae9e5c2c3d76d2d741dfa355d4af43338c10a2e5..963ed0ab28c63967fed93efea1f7ff3d83496288 100755 (executable)
@@ -24,24 +24,12 @@ 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 ;
-
 ! Mapping _label IDs to label instances
 SYMBOL: labels
 
-: init-generator ( -- )
-    H{ } clone labels set
-    V{ } clone calls set ;
-
-: generate-insns ( asm -- code )
+: generate ( mr -- code )
     dup label>> [
-        init-generator
+        H{ } clone labels set
         instructions>> [
             [ class insn-counts get inc-at ]
             [ generate-insn ]
@@ -49,22 +37,12 @@ SYMBOL: labels
         ] each
     ] with-fixup ;
 
-: generate ( mr -- asm )
-    [
-        [ label>> ] [ generate-insns ] bi calls get
-        asm boa
-    ] with-scope ;
-
 : lookup-label ( id -- label )
     labels get [ drop <label> ] cache ;
 
 ! Special cases
 M: ##no-tco generate-insn drop ;
 
-M: ##call generate-insn word>> [ add-call ] [ %call ] bi ;
-
-M: ##jump generate-insn word>> [ add-call ] [ %jump ] bi ;
-
 M: _dispatch-label generate-insn
     label>> lookup-label
     cell 0 <repetition> %
@@ -104,6 +82,8 @@ CODEGEN: ##peek %peek
 CODEGEN: ##replace %replace
 CODEGEN: ##inc-d %inc-d
 CODEGEN: ##inc-r %inc-r
+CODEGEN: ##call %call
+CODEGEN: ##jump %jump
 CODEGEN: ##return %return
 CODEGEN: ##slot %slot
 CODEGEN: ##slot-imm %slot-imm
index 5ee0e265e432df13630e15d1293eb0ccd19d3ac4..76c93a842286d763981d10cc88a25d652dfe72be 100644 (file)
@@ -1,7 +1,7 @@
 USING: assocs compiler.cfg.builder compiler.cfg.optimizer
 compiler.errors compiler.tree.builder compiler.tree.optimizer
-compiler.units help.markup help.syntax io parser quotations
-sequences words ;
+compiler.units compiler.codegen help.markup help.syntax io
+parser quotations sequences words ;
 IN: compiler
 
 HELP: enable-optimizer
@@ -21,8 +21,6 @@ ARTICLE: "compiler-usage" "Calling the optimizing compiler"
 ARTICLE: "compiler-impl" "Compiler implementation"
 "The " { $vocab-link "compiler" } "vocabulary, in addition to providing the user-visible words of the compiler, implements the main compilation loop."
 $nl
-"Words are added to the " { $link compile-queue } " variable as needed and compiled."
-{ $subsections compile-queue }
 "Once compiled, a word is added to the assoc stored in the " { $link compiled } " variable. When compilation is complete, this assoc is passed to " { $link modify-code-heap } "."
 $nl
 "The " { $link compile-word } " word performs the actual task of compiling an individual word. The process proceeds as follows:"
@@ -30,7 +28,7 @@ $nl
   { "The " { $link frontend } " word calls " { $link build-tree } ". If this fails, the error is passed to " { $link deoptimize } ". The logic for ignoring certain compile errors generated for inline words and macros is located here. If the error is not ignorable, it is added to the global " { $link compiler-errors } " assoc (see " { $link "compiler-errors" } ")." }
   { "If the word contains a breakpoint, compilation ends here. Otherwise, all remaining steps execute until machine code is generated. Any further errors thrown by the compiler are not reported as compile errors, but instead are ordinary exceptions. This is because they indicate bugs in the compiler, not errors in user code." }
   { "The " { $link frontend } " word then calls " { $link optimize-tree } ". This produces the final optimized tree IR, and this stage of the compiler is complete." }
-  { "The " { $link backend } " word calls " { $link build-cfg } " followed by " { $link optimize-cfg } " and a few other stages. Finally, it calls " { $link save-asm } ", and adds any uncompiled words called by this word to the compilation queue with " { $link compile-dependency } "." }
+  { "The " { $link backend } " word calls " { $link build-cfg } " followed by " { $link optimize-cfg } " and a few other stages. Finally, it calls " { $link generate } "." }
 }
 "If compilation fails, the word is stored in the " { $link compiled } " assoc with a value of " { $link f } ". This causes the VM to compile the word with the non-optimizing compiler."
 $nl
index a1c9ae18fd13f243d2254d547d512b9504694abd..71fdd6cbaf7aff1adba54e13c8283d3566ee3707 100644 (file)
@@ -1,10 +1,9 @@
 ! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel namespaces arrays sequences io words fry
-continuations vocabs assocs dlists definitions math graphs
-generic generic.single combinators combinators.smart deques
-search-deques macros source-files.errors
-combinators.short-circuit classes.algebra
+continuations vocabs assocs definitions math graphs generic
+generic.single combinators combinators.smart macros
+source-files.errors combinators.short-circuit classes.algebra
 
 stack-checker stack-checker.dependencies stack-checker.inlining
 stack-checker.errors
@@ -22,20 +21,15 @@ compiler.cfg.mr
 compiler.codegen ;
 IN: compiler
 
-SYMBOL: compile-queue
 SYMBOL: compiled
 
 : compile? ( word -- ? )
     #! Don't attempt to compile certain words.
     {
         [ "forgotten" word-prop ]
-        [ compiled get key? ]
         [ inlined-block? ]
     } 1|| not ;
 
-: queue-compile ( word -- )
-    dup compile? [ compile-queue get push-front ] [ drop ] if ;
-
 : compiler-message ( string -- )
     "trace-compilation" get [ global [ print flush ] bind ] [ drop ] if ;
 
@@ -129,29 +123,10 @@ M: word combinator? inline? ;
         contains-breakpoints? [ nip deoptimize* ] [ drop ] if
     ] [ deoptimize* ] if ;
 
-: compile-dependency ( word -- )
-    #! If a word calls an unoptimized word, try to compile the callee.
-    dup optimized? [ drop ] [ queue-compile ] if ;
-
-! Only switch this off for debugging.
-SYMBOL: compile-dependencies?
-
-t compile-dependencies? set-global
-
-: compile-dependencies ( asm -- )
-    compile-dependencies? get
-    [ calls>> [ compile-dependency ] each ] [ drop ] if ;
-
-: save-asm ( asm -- )
-    [ [ code>> ] [ label>> ] bi compiled get set-at ]
-    [ compile-dependencies ]
-    bi ;
-
 : backend ( tree word -- )
     build-cfg [
         [ optimize-cfg build-mr ] with-cfg
-        generate
-        save-asm
+        [ generate ] [ label>> ] bi compiled get set-at
     ] each ;
 
 : compile-word ( word -- )
@@ -166,9 +141,6 @@ t compile-dependencies? set-global
         } cleave
     ] with-return ;
 
-: compile-loop ( deque -- )
-    [ compile-word yield-hook get call( -- ) ] slurp-deque ;
-
 SINGLETON: optimizing-compiler
 
 M: optimizing-compiler update-call-sites ( class generic -- words )
@@ -180,16 +152,11 @@ M: optimizing-compiler update-call-sites ( class generic -- words )
     ] assoc-filter keys ;
 
 M: optimizing-compiler recompile ( words -- alist )
-    [
-        <hashed-dlist> compile-queue set
-        H{ } clone compiled set
-        [
-            [ queue-compile ]
-            [ subwords [ compile-dependency ] each ] bi
-        ] each
-        compile-queue get compile-loop
+    H{ } clone compiled [
+        [ compile? ] filter
+        [ compile-word yield-hook get call( -- ) ] each
         compiled get >alist
-    ] with-scope
+    ] with-variable
     "--- compile done" compiler-message ;
 
 M: optimizing-compiler to-recompile ( -- words )
index a2d8bf4b2b269900f564b5b4f6d58c84cb55bd1a..bc7f3fa2f2d313fc2ba93a0387ed7525b75e2589 100644 (file)
@@ -8,7 +8,7 @@ IN: compiler.tests.low-level-ir
 
 : compile-cfg ( cfg -- word )
     gensym
-    [ build-mr generate code>> ] dip
+    [ build-mr generate ] dip
     [ associate >alist t t modify-code-heap ] keep ;
 
 : compile-test-cfg ( -- word )