]> gitweb.factorcode.org Git - factor.git/commitdiff
command for inserting USE: declarations, cfactor memory management cleanup
authorSlava Pestov <slava@factorcode.org>
Wed, 1 Sep 2004 00:31:16 +0000 (00:31 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 1 Sep 2004 00:31:16 +0000 (00:31 +0000)
19 files changed:
TODO.FACTOR.txt
actions.xml
factor/FactorNamespace.java
factor/jedit/FactorCompletion.java
factor/jedit/FactorPlugin.java
factor/jedit/FactorPlugin.props
factor/jedit/FactorSideKickParser.java
factor/jedit/FactorWordRenderer.java
factor/jedit/InsertUseDialog.java [new file with mode: 0644]
factor/jedit/factor.bsh
library/httpd/httpd.factor
library/httpd/responder.factor
native/gc.c
native/image.c
native/memory.c
native/memory.h
native/relocate.c
native/string.h
native/vector.c

index 83977b260a0de92bfc55f3de80ceb11ebfa2a9d8..4db307832f327bfdbaebd5cfd6ecce2e7e3cb6aa 100644 (file)
@@ -45,7 +45,6 @@
 \r
 - inferior hangs\r
 - plugin should not exit jEdit on fatal errors\r
-- auto insert USE:\r
 - balance needs USE:\r
 - fedit broken with listener\r
 - maple-like: press enter at old commands to evaluate there\r
index fd4a7f20a32e0d43fda6a111bcf6b4fc9e9afefd..faa5cd04c6f367c16b35ee96e4bdf1bbf4903938 100644 (file)
@@ -50,7 +50,7 @@
        </ACTION>
        <ACTION NAME="factor-balance">
                <CODE>
-                       if(textArea.selectedText == null)
+                       if(textArea.selectionCount == 0)
                                textArea.toolkit.beep();
                        else
                        {
                        }
                </CODE>
        </ACTION>
+       <ACTION NAME="factor-insert-use">
+               <CODE>
+                       if(textArea.selectionCount == 0)
+                               textArea.selectWord();
+                       factor.jedit.FactorPlugin.insertUseDialog(view,
+                               textArea.selectedText);
+               </CODE>
+       </ACTION>
 </ACTIONS>
index d7b5470ee57c1a8ff204c5fc5db186aea33782cf..a9462948a33b535f61d7b8a7820aae0884f93706 100644 (file)
@@ -81,7 +81,6 @@ public class FactorNamespace implements PublicCloneable, FactorObject
         * Cloning constructor.
         */
        public FactorNamespace(Map words, Object obj)
-               throws Exception
        {
                this.words = new TreeMap();
 
@@ -140,7 +139,7 @@ public class FactorNamespace implements PublicCloneable, FactorObject
        } //}}}
 
        //{{{ isDefined() method
-       public synchronized boolean isDefined(String name) throws Exception
+       public synchronized boolean isDefined(String name)
        {
                Object o = words.get(name);
                if(o instanceof VarBinding)
@@ -165,7 +164,7 @@ public class FactorNamespace implements PublicCloneable, FactorObject
        } //}}}
 
        //{{{ getVariable() method
-       public synchronized Object getVariable(String name) throws Exception
+       public synchronized Object getVariable(String name)
        {
                Object o = words.get(name);
                if(o instanceof VarBinding)
@@ -194,7 +193,6 @@ public class FactorNamespace implements PublicCloneable, FactorObject
 
        //{{{ setVariable() method
        public synchronized void setVariable(String name, Object value)
-               throws Exception
        {
                if(name == null)
                        throw new NullPointerException();
@@ -227,7 +225,7 @@ public class FactorNamespace implements PublicCloneable, FactorObject
                                if(!constraint.isAssignableFrom(
                                        value.getClass()))
                                {
-                                       throw new FactorRuntimeException(
+                                       throw new RuntimeException(
                                                "Can only store "
                                                + constraint
                                                + " in " + this);
@@ -314,7 +312,7 @@ public class FactorNamespace implements PublicCloneable, FactorObject
        /**
         * Returns a list of variable values.
         */
-       public synchronized Cons toValueList() throws Exception
+       public synchronized Cons toValueList()
        {
                initAllFields();
 
@@ -342,7 +340,7 @@ public class FactorNamespace implements PublicCloneable, FactorObject
        /**
         * Returns a list of pairs of variable names, and their values.
         */
-       public synchronized Cons toVarValueList() throws Exception
+       public synchronized Cons toVarValueList()
        {
                initAllFields();
 
@@ -384,16 +382,30 @@ public class FactorNamespace implements PublicCloneable, FactorObject
                        this.instance = instance;
                }
 
-               public Object get() throws Exception
+               public Object get()
                {
-                       return FactorJava.convertFromJavaType(
-                               field.get(instance));
+                       try
+                       {
+                               return FactorJava.convertFromJavaType(
+                                       field.get(instance));
+                       }
+                       catch(Exception e)
+                       {
+                               throw new RuntimeException(e);
+                       }
                }
 
-               public void set(Object value) throws Exception
+               public void set(Object value)
                {
-                       field.set(instance,FactorJava.convertToJavaType(
-                               value,field.getType()));
+                       try
+                       {
+                               field.set(instance,FactorJava.convertToJavaType(
+                                       value,field.getType()));
+                       }
+                       catch(Exception e)
+                       {
+                               throw new RuntimeException(e);
+                       }
                }
        } //}}}
 
index 0b025a13f7c6b4a9056946b16c326fe7e65c581f..d62aba94cfe0d7f4b86e8e3b430f7a31754fbaaf 100644 (file)
@@ -98,6 +98,8 @@ public class FactorCompletion extends SideKickCompletion
 
        public ListCellRenderer getRenderer()
        {
-               return new FactorWordRenderer(FactorPlugin.getInterpreter());
+               return new FactorWordRenderer(
+                       FactorPlugin.getInterpreter(),
+                       false);
        }
 }
index e563b63f072d8374ec46ce19fc2c9dd93fce3ae4..ab02ea96af130c2b0759d5395d3f8d4d4b729a36 100644 (file)
 package factor.jedit;
 
 import factor.listener.FactorListenerPanel;
-import factor.FactorInterpreter;
+import factor.*;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import org.gjt.sp.jedit.gui.*;
+import org.gjt.sp.jedit.textarea.*;
 import org.gjt.sp.jedit.*;
+import sidekick.*;
 
 public class FactorPlugin extends EditPlugin
 {
@@ -73,4 +76,108 @@ public class FactorPlugin extends EditPlugin
                        wm.getDockableWindow(DOCKABLE_NAME);
                panel.getListener().eval(cmd);
        } //}}}
+
+       //{{{ getWordAtCaret() method
+       public static String getWordAtCaret(JEditTextArea textArea)
+       {
+               if(textArea.getSelectionCount() != 0)
+                       return textArea.getSelectedText();
+
+               String line = textArea.getLineText(textArea.getCaretLine());
+               if(line.length() == 0)
+                       return null;
+
+               int caret = textArea.getCaretPosition()
+                       - textArea.getLineStartOffset(
+                       textArea.getCaretLine());
+               String noWordSep = textArea.getBuffer().getStringProperty(
+                       "noWordSep");
+               int wordStart = TextUtilities.findWordStart(line,caret,
+                       noWordSep);
+               int wordEnd = TextUtilities.findWordEnd(line,caret,
+                       noWordSep);
+               return line.substring(wordStart,wordEnd);
+       } //}}}
+       
+       //{{{ showStatus() method
+       public static void showStatus(View view, String msg, String arg)
+       {
+               view.getStatus().setMessage(
+                       jEdit.getProperty("factor.status." + msg,
+                       new String[] { arg }));
+       } //}}}
+       
+       //{{{ isUsed() method
+       private static boolean isUsed(View view, String vocab)
+       {
+               SideKickParsedData data = SideKickParsedData
+                       .getParsedData(view);
+               if(data instanceof FactorParsedData)
+               {
+                       FactorParsedData fdata = (FactorParsedData)data;
+                       Cons use = fdata.use;
+                       return Cons.contains(use,vocab);
+               }
+               else
+                       return false;
+       } //}}}
+
+       //{{{ findAllWordsNamed() method
+       private static FactorWord[] findAllWordsNamed(View view, String word)
+       {
+               ArrayList words = new ArrayList();
+               Cons vocabs = getInterpreter().vocabularies.toValueList();
+               while(vocabs != null)
+               {
+                       FactorNamespace vocab = (FactorNamespace)vocabs.car;
+                       FactorWord w = (FactorWord)vocab.getVariable(word);
+                       if(w != null)
+                               words.add(w);
+                       vocabs = vocabs.next();
+               }
+               return (FactorWord[])words.toArray(
+                       new FactorWord[words.size()]);
+       } //}}}
+
+       //{{{ insertUseDialog() method
+       public static void insertUseDialog(View view, String word)
+       {
+               FactorWord[] words = findAllWordsNamed(view,word);
+               if(words.length == 0)
+                       view.getToolkit().beep();
+               else if(words.length == 1)
+                       insertUse(view,words[0].vocabulary);
+               else
+                       new InsertUseDialog(view,words);
+       } //}}}
+
+       //{{{ insertUse() method
+       public static void insertUse(View view, String vocab)
+       {
+               if(isUsed(view,vocab))
+               {
+                       showStatus(view,"already-used",vocab);
+                       return;
+               }
+
+               Buffer buffer = view.getBuffer();
+               int lastUseOffset = 0;
+
+               for(int i = 0; i < buffer.getLineCount(); i++)
+               {
+                       String text = buffer.getLineText(i).trim();
+                       if(text.startsWith("IN:") || text.startsWith("USE:")
+                               || text.startsWith("!")
+                               || text.length() == 0)
+                       {
+                               lastUseOffset = buffer.getLineStartOffset(i);
+                       }
+                       else
+                               break;
+               }
+
+               String decl = "USE: " + vocab + "\n";
+               buffer.insert(lastUseOffset,decl);
+               showStatus(view,"inserted-use",decl);
+       } //}}]
 }
index b981d27ab8b3dc4afaca193e84917363c4c2035c..c19da80b32b4ae937d8f91a344e21ee337577067 100644 (file)
@@ -3,7 +3,7 @@
 plugin.factor.jedit.FactorPlugin.activate=defer
 
 plugin.factor.jedit.FactorPlugin.name=Factor
-plugin.factor.jedit.FactorPlugin.version=0.64
+plugin.factor.jedit.FactorPlugin.version=0.65
 plugin.factor.jedit.FactorPlugin.author=Slava Pestov
 plugin.factor.jedit.FactorPlugin.docs=/doc/plugin.html
 
@@ -15,16 +15,21 @@ plugin.factor.jedit.FactorPlugin.menu=factor \
        - \
        factor-run-file \
        factor-eval-selection \
+       - \
        factor-apropos \
+       factor-insert-use \
+       - \
        factor-edit \
        factor-see \
        factor-usages \
+       - \
        factor-balance
 
 factor.label=Factor Listener
 factor-run-file.label=Run current file
 factor-eval-selection.label=Evaluate selection
 factor-apropos.label=Apropos at caret
+factor-insert-use.label=Use word at caret
 factor-see.label=See word at caret
 factor-edit.label=Edit word at caret
 factor-usages.label=Word usages at caret
@@ -35,8 +40,15 @@ factor.title=Factor
 sidekick.parser.factor.label=Factor
 mode.factor.sidekick.parser=factor
 
-factor.completion.plain=<html>: <b>{0}</b>
-factor.completion.defer=<html>DEFER: <b>{0}</b>
-factor.completion.parsing=<html>PARSING: <b>{0}</b>
-factor.completion.stack=<html>: <b>{0}</b> {1}
-factor.completion.shuffle=<html>~&lt;&lt; <b>{0}</b> {1} &gt;&gt;~
+factor.completion.in=<font color="#eeeeee">IN: {0}</font>
+factor.completion.plain=: <b>{0}</b>
+factor.completion.defer=DEFER: <b>{0}</b>
+factor.completion.parsing=PARSING: <b>{0}</b>
+factor.completion.stack=: <b>{0}</b> {1}
+factor.completion.shuffle=~&lt;&lt; <b>{0}</b> {1} &gt;&gt;~
+
+factor.status.inserted-use=Inserted {0}
+factor.status.already-used=Already used {0}
+
+factor.insert-use.title=Insert USE: Declaration
+factor.insert-use.caption=There are multiple words named "{0}". Select the one to use:
index 452879877966516ad2e310205cafe5ed6be1d19f..abaad611a3b6fd429ed77960c98e2e5a7b93844f 100644 (file)
@@ -106,7 +106,7 @@ public class FactorSideKickParser extends SideKickParser
 
                return d;
        } //}}}
-       
+
        //{{{ addWordDefNodes() method
        private void addWordDefNodes(SideKickParsedData d, Cons parsed,
                Buffer buffer)
@@ -167,7 +167,7 @@ public class FactorSideKickParser extends SideKickParser
                return (ReadTable.DEFAULT_READTABLE.getCharacterType(ch)
                        == ReadTable.WHITESPACE);
        } //}}}
-       
+
        //{{{ canCompleteAnywhere() method
        /**
         * Returns if completion popups should be shown after any period of
index 3737f7d756f64c783aee0ea57187cbdde4ab009f..50bd616ef8c05ba80c7b25c5a9852a80125e30a5 100644 (file)
@@ -36,30 +36,13 @@ import org.gjt.sp.jedit.*;
 
 public class FactorWordRenderer extends DefaultListCellRenderer
 {
-       private FactorInterpreter interp;
-
-       public FactorWordRenderer(FactorInterpreter interp)
-       {
-               this.interp = interp;
-       }
-
-       public Component getListCellRendererComponent(
-               JList list,
-               Object value,
-               int index,
-               boolean isSelected,
-               boolean cellHasFocus)
+       //{{{ getWordHTMLString() method
+       public static String getWordHTMLString(FactorInterpreter interp,
+               FactorWord word, boolean showIn)
        {
-               super.getListCellRendererComponent(list,value,index,
-                       isSelected,cellHasFocus);
-
                String prop = "factor.completion.plain";
                String stackEffect = null;
 
-               if(!(value instanceof FactorWord))
-                       return this;
-
-               FactorWord word = (FactorWord)value;
                if(word.def == null)
                {
                        if(word.parsing != null)
@@ -97,14 +80,52 @@ public class FactorWordRenderer extends DefaultListCellRenderer
                        }
                }
 
-               setText(jEdit.getProperty(prop,
-                       new String[] {
+               String in;
+               if(showIn)
+               {
+                       in = jEdit.getProperty("factor.completion.in",
+                               new Object[] {
+                                       MiscUtilities.charsToEntities(word.vocabulary)
+                               });
+               }
+               else
+                       in = "";
+
+               return "<html>" + in + jEdit.getProperty(prop,
+                       new Object[] {
                                MiscUtilities.charsToEntities(word.name),
                                stackEffect == null
                                ? null :
                                MiscUtilities.charsToEntities(stackEffect)
-                       }));
+                       });
+       } //}}}
+
+       private FactorInterpreter interp;
+       private boolean showIn;
+
+       //{{{ FactorWordRenderer constructor
+       public FactorWordRenderer(FactorInterpreter interp, boolean showIn)
+       {
+               this.interp = interp;
+               this.showIn = showIn;
+       } //}}}
+
+       //{{{ getListCellRendererComponent() method
+       public Component getListCellRendererComponent(
+               JList list,
+               Object value,
+               int index,
+               boolean isSelected,
+               boolean cellHasFocus)
+       {
+               super.getListCellRendererComponent(list,value,index,
+                       isSelected,cellHasFocus);
+
+               if(!(value instanceof FactorWord))
+                       return this;
+
+               setText(getWordHTMLString(interp,(FactorWord)value,showIn));
 
                return this;
-       }
+       } //}}}
 }
diff --git a/factor/jedit/InsertUseDialog.java b/factor/jedit/InsertUseDialog.java
new file mode 100644 (file)
index 0000000..1022655
--- /dev/null
@@ -0,0 +1,117 @@
+/* :folding=explicit:collapseFolds=1: */
+
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004 Slava Pestov.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package factor.jedit;
+
+import factor.FactorWord;
+import javax.swing.border.*;
+import javax.swing.*;
+import java.awt.event.*;
+import java.awt.*;
+import org.gjt.sp.jedit.gui.EnhancedDialog;
+import org.gjt.sp.jedit.*;
+
+public class InsertUseDialog extends EnhancedDialog
+{
+       private View view;
+       private JList list;
+       private JButton ok, cancel;
+
+       //{{{ InsertUseDialog constructor
+       public InsertUseDialog(View view, FactorWord[] words)
+       {
+               super(view,jEdit.getProperty("factor.insert-use.title"),true);
+
+               this.view = view;
+
+               JPanel content = new JPanel(new BorderLayout());
+               content.setBorder(new EmptyBorder(12,12,12,12));
+               setContentPane(content);
+
+               content.add(BorderLayout.NORTH,new JLabel(
+                       jEdit.getProperty("factor.insert-use.caption",
+                       new String[] { words[0].name })));
+
+               content.add(BorderLayout.CENTER,new JScrollPane(
+                       list = new JList(words)));
+               list.setCellRenderer(new FactorWordRenderer(
+                       FactorPlugin.getInterpreter(),true));
+               list.setSelectedIndex(0);
+
+               content.add(BorderLayout.SOUTH,createButtonPanel());
+
+               setLocationRelativeTo(view);
+               pack();
+               setVisible(true);
+       } //}}}
+
+       //{{{ createButtonPanel() method
+       private Box createButtonPanel()
+       {
+               Box buttons = new Box(BoxLayout.X_AXIS);
+               buttons.add(Box.createGlue());
+               buttons.add(ok = new JButton(jEdit.getProperty(
+                       "common.ok")));
+               getRootPane().setDefaultButton(ok);
+               ok.addActionListener(new ActionHandler());
+               buttons.add(Box.createHorizontalStrut(12));
+               buttons.add(cancel = new JButton(jEdit.getProperty(
+                       "common.cancel")));
+               cancel.addActionListener(new ActionHandler());
+               buttons.add(Box.createGlue());
+               
+               return buttons;
+       } //}}}
+       
+       //{{{ ok() method
+       public void ok()
+       {
+               FactorWord w = (FactorWord)list.getSelectedValue();
+               FactorPlugin.insertUse(view,w.vocabulary);
+               dispose();
+       } //}}}
+
+       //{{{ cancel() method
+       public void cancel()
+       {
+               dispose();
+       } //}}}
+
+       //{{{ ActionHandler class
+       class ActionHandler implements ActionListener
+       {
+               public void actionPerformed(ActionEvent evt)
+               {
+                       if(evt.getSource() == ok)
+                               ok();
+                       else if(evt.getSource() == cancel)
+                               cancel();
+               }
+       } //}}}
+}
index 3dc16a461d0ccc9202e8122392effae2125a98cf..94667a88a9b04bd72ae9a71aba76c5914f09b76c 100644 (file)
@@ -1,6 +1,8 @@
+import factor.jedit.*;
+
 factorEval(view,str)
 {
-       factor.jedit.FactorPlugin.eval(view,str);
+       FactorPlugin.eval(view,str);
 }
 
 /* Build a Factor expression for pushing the selected word on the stack */
@@ -10,10 +12,11 @@ factorWord(view)
        data = sidekick.SideKickParsedData.getParsedData(view);
        if(data instanceof factor.jedit.FactorParsedData)
        {
-               if(textArea.selectionCount == 0)
-                       textArea.selectWord();
+               word = FactorPlugin.getWordAtCaret(textArea);
+               if(word == null)
+                       return null;
                return "\""
-                       + factor.FactorReader.charsToEscapes(textArea.selectedText)
+                       + factor.FactorReader.charsToEscapes(word)
                        + "\" " + factor.FactorReader.unparseObject(data.use)
                        + " search";
        }
index 6803b2a8728e42724469da07f5ad81c0af26fdf7..373fa21b27575fe95f83298ae9747327e0794a57 100644 (file)
@@ -67,10 +67,14 @@ USE: url-encoding
 : post-request ( url -- )
     [ "post" swap serve-responder ] with-request ;
 
+: head-request ( url -- )
+    [ "head" swap serve-responder ] with-request ;
+
 : handle-request ( arg cmd -- )
     [
         [ "GET"  = ] [ drop get-request ]
         [ "POST" = ] [ drop post-request ]
+        [ "HEAD" = ] [ drop head-request ]
         [ drop t   ] [ 2drop bad-request ]
     ] cond ;
 
index 768bd4efa45fc63fa26a207f745eca703e207b4e..eaea0d8e5aca348e178e2c82d30ddd88ebc6bd00 100644 (file)
@@ -60,6 +60,10 @@ USE: strings
         [
             drop "POST method not implemented" httpd-error
         ] "post" set
+        ( url -- )
+        [
+            drop "HEAD method not implemented" httpd-error
+        ] "head" set
     ] extend ;
 
 : get-responder ( name -- responder )
index a529390197bc28c01cb2d366235d7ca65fad2b11..a7e5e13575ca8c9e969c94ee1c4d53d344ac84a6 100644 (file)
@@ -38,7 +38,7 @@ void copy_object(CELL* handle)
                return;
        }
        
-       if(in_zone(active,pointer))
+       if(in_zone(&active,pointer))
                critical_error("copy_object given newspace ptr",pointer);
 
        header = get(UNTAG(pointer));
@@ -140,10 +140,10 @@ void primitive_gc(void)
        gc_in_progress = true;
 
        flip_zones();
-       scan = active->here = active->base;
+       scan = active.here = active.base;
        collect_roots();
        collect_io_tasks();
-       while(scan < active->here)
+       while(scan < active.here)
        {
                gc_debug("scan loop",scan);
                collect_next();
index de8012cc3e8a41a1a30f6eb084c3f37a21f17503..7a585f13ace4215d8b37d9c2e7f04544fb4b3d97 100644 (file)
@@ -24,10 +24,10 @@ void load_image(char* filename)
 
        size = h.size / CELLS;
 
-       if(size != fread((void*)active->base,sizeof(CELL),size,file))
+       if(size != fread((void*)active.base,sizeof(CELL),size,file))
                fatal_error("Wrong image length",h.size);
 
-       active->here = active->base + h.size;
+       active.here = active.base + h.size;
        fclose(file);
 
        fprintf(stderr," relocating...");
@@ -56,13 +56,13 @@ bool save_image(char* filename)
 
        h.magic = IMAGE_MAGIC;
        h.version = IMAGE_VERSION;
-       h.relocation_base = active->base;
+       h.relocation_base = active.base;
        h.boot = userenv[BOOT_ENV];
-       h.size = (active->here - active->base);
+       h.size = (active.here - active.base);
        h.global = userenv[GLOBAL_ENV];
 
        fwrite(&h,sizeof(HEADER),1,file);
-       fwrite((void*)active->base,h.size,1,file);
+       fwrite((void*)active.base,h.size,1,file);
 
        fclose(file);
 
index 7cad2e945501e2b15c660e457a0872ce7d95eafb..dd3d9b352533585fd47f7ae85c43c9d42043b53a 100644 (file)
@@ -19,25 +19,20 @@ void* alloc_guarded(CELL size)
        return array + pagesize;
 }
 
-ZONE* zalloc(CELL size)
+void init_zone(ZONE* z, CELL size)
 {
-       ZONE* z = (ZONE*)malloc(sizeof(ZONE));
-       if(z == 0)
-               fatal_error("Cannot allocate zone header",size);
        z->base = z->here = align8((CELL)malloc(size));
        if(z->base == 0)
                fatal_error("Cannot allocate zone",size);
        z->limit = z->base + size;
        z->alarm = z->base + (size * 3) / 4;
        z->base = align8(z->base);
-       return z;
 }
 
 void init_arena(CELL size)
 {
-       z1 = zalloc(size);
-       z2 = zalloc(size);
-       active = z1;
+       init_zone(&active,size);
+       init_zone(&prior,size);
        allot_profiling = false;
        gc_in_progress = false;
 }
@@ -65,14 +60,14 @@ void allot_profile_step(CELL a)
 
 void check_memory(void)
 {
-       if(active->here > active->alarm)
+       if(active.here > active.alarm)
        {
-               if(active->here > active->limit)
+               if(active.here > active.limit)
                {
                        fprintf(stderr,"Out of memory\n");
-                       fprintf(stderr,"active->base  = %ld\n",active->base);
-                       fprintf(stderr,"active->here  = %ld\n",active->here);
-                       fprintf(stderr,"active->limit = %ld\n",active->limit);
+                       fprintf(stderr,"active.base  = %ld\n",active.base);
+                       fprintf(stderr,"active.here  = %ld\n",active.here);
+                       fprintf(stderr,"active.limit = %ld\n",active.limit);
                        fflush(stderr);
                        exit(1);
                }
@@ -84,16 +79,9 @@ void check_memory(void)
 
 void flip_zones()
 {
-       if(active == z1)
-       {
-               prior = z1;
-               active = z2;
-       }
-       else
-       {
-               prior = z2;
-               active = z1;
-       }
+       ZONE z = prior;
+       active = prior;
+       prior = z;
 }
 
 bool in_zone(ZONE* z, CELL pointer)
@@ -104,8 +92,8 @@ bool in_zone(ZONE* z, CELL pointer)
 void primitive_room(void)
 {
        /* push: free total */
-       dpush(tag_integer(active->limit - active->here));
-       dpush(tag_integer(active->limit - active->base));
+       dpush(tag_integer(active.limit - active.here));
+       dpush(tag_integer(active.limit - active.base));
 }
 
 void primitive_allot_profiling(void)
index 02d96f6be12cf931f58578e97f4a287ecf6702a4..bcbbf018a2f755b5f3a39053f88004e7fa3deaae 100644 (file)
@@ -5,15 +5,13 @@ typedef struct {
        CELL limit;
 } ZONE;
 
-ZONE* z1;
-ZONE* z2;
-ZONE* active; /* either z1 or z2 */
-ZONE* prior; /* if active==z1, z2; if active==z2, z1 */
+ZONE active;
+ZONE prior;
 
 bool allot_profiling;
 
 void* alloc_guarded(CELL size);
-ZONE* zalloc(CELL size);
+void init_zone(ZONE* zone, CELL size);
 void init_arena(CELL size);
 void flip_zones();
 
@@ -27,8 +25,8 @@ INLINE CELL align8(CELL a)
 
 INLINE void* allot(CELL a)
 {
-       CELL h = active->here;
-       active->here += align8(a);
+       CELL h = active.here;
+       active.here += align8(a);
 #ifdef FACTOR_PROFILER
        if(allot_profiling)
                allot_profile_step(align8(a));
index 791b61ec7eda07bd659e7ed80a694aea4df3b750..16e1eda1da89803476196a7bc949aa33c26833f4 100644 (file)
@@ -3,7 +3,7 @@
 void fixup(CELL* cell)
 {
        if(TAG(*cell) != FIXNUM_TYPE)
-               *cell += (active->base - relocation_base);
+               *cell += (active.base - relocation_base);
 }
 
 void relocate_object()
@@ -63,7 +63,7 @@ void relocate(CELL r)
        fixup(&userenv[BOOT_ENV]);
        fixup(&userenv[GLOBAL_ENV]);
 
-       relocating = active->base;
+       relocating = active.base;
 
        /* The first two objects in the image must always be F, T */
        init_object(&F,F_TYPE);
@@ -76,7 +76,7 @@ void relocate(CELL r)
        
        for(;;)
        {
-               if(relocating >= active->here)
+               if(relocating >= active.here)
                        break;
 
                relocate_next();
index 556052fc8cdb99516abef698891845d3c6108b44..fa3ebae962c6a21eb49b3b2a2250fb945a1847e4 100644 (file)
@@ -49,7 +49,7 @@ void primitive_substring(void);
 
 INLINE STRING* fixup_untagged_string(STRING* str)
 {
-       return (STRING*)((CELL)str + (active->base - relocation_base));
+       return (STRING*)((CELL)str + (active.base - relocation_base));
 }
 
 INLINE STRING* copy_untagged_string(STRING* str)
index 4dbc708657db28e78e8c6be501e91b636fe316e1..9e90624177e4a54054683cfcd5837f935c06c0b6 100644 (file)
@@ -72,7 +72,7 @@ void primitive_set_vector_nth(void)
 void fixup_vector(VECTOR* vector)
 {
        vector->array = (ARRAY*)((CELL)vector->array
-               + (active->base - relocation_base));
+               + (active.base - relocation_base));
 }
 
 void collect_vector(VECTOR* vector)