assorted enhancements, started 64-bit image output
parent
5542e7c199
commit
80f80acb7b
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
CC = gcc
|
||||
CFLAGS = -g -Wall
|
||||
CFLAGS = -Os -mpentiumpro -g -Wall
|
||||
LIBS = -lm
|
||||
STRIP = strip
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
- plugin should not exit jEdit on fatal errors
|
||||
- IN: format base: work with all types of numbers
|
||||
- wordpreview: don't show for string literals and comments
|
||||
- eliminate usage of long long
|
||||
- NPE in activate()/deactivate()
|
||||
- NPE in ErrorHighlight
|
||||
- 64 bit support
|
||||
- alist -vs- assoc terminology
|
||||
- clean up listener's action popups
|
||||
|
@ -53,6 +54,7 @@
|
|||
|
||||
+ listener/plugin:
|
||||
|
||||
- don't use jEdit's word finding API
|
||||
- some way to not have previous definitions from a source file
|
||||
clutter the namespace
|
||||
- use inferior.factor for everything not just listener
|
||||
|
@ -89,6 +91,8 @@
|
|||
|
||||
+ misc:
|
||||
|
||||
- telnetd: init-history
|
||||
- str-reverse primitive
|
||||
- some way to run httpd from command line
|
||||
- don't rehash strings on every startup
|
||||
- 'cascading' styles
|
||||
|
|
|
@ -48,7 +48,8 @@
|
|||
</ACTION>
|
||||
<ACTION NAME="factor-edit-dialog">
|
||||
<CODE>
|
||||
new EditWordDialog(view,FactorPlugin.getInterpreter());
|
||||
new EditWordDialog(view,FactorPlugin
|
||||
.getSideKickParser());
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="factor-usages">
|
||||
|
|
|
@ -46,9 +46,9 @@ public class EditWordDialog extends WordListDialog
|
|||
private Timer timer;
|
||||
|
||||
//{{{ EditWordDialog constructor
|
||||
public EditWordDialog(View view, FactorInterpreter interp)
|
||||
public EditWordDialog(View view, FactorSideKickParser parser)
|
||||
{
|
||||
super(view,interp,jEdit.getProperty("factor.edit-word.title"));
|
||||
super(view,parser,jEdit.getProperty("factor.edit-word.title"));
|
||||
|
||||
Box top = new Box(BoxLayout.X_AXIS);
|
||||
top.add(new JLabel(jEdit.getProperty(
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
package factor.jedit;
|
||||
|
||||
import factor.FactorWord;
|
||||
import factor.FactorWordDefinition;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.text.Position;
|
||||
import org.gjt.sp.jedit.Buffer;
|
||||
|
@ -38,12 +39,15 @@ import sidekick.*;
|
|||
public class FactorAsset extends Asset
|
||||
{
|
||||
private FactorWord word;
|
||||
private FactorWordDefinition def;
|
||||
|
||||
public FactorAsset(FactorWord word, Position start)
|
||||
public FactorAsset(FactorWord word, FactorWordDefinition def,
|
||||
Position start)
|
||||
{
|
||||
super(word.name);
|
||||
this.start = start;
|
||||
this.word = word;
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public Icon getIcon()
|
||||
|
@ -59,6 +63,6 @@ public class FactorAsset extends Asset
|
|||
public String getLongString()
|
||||
{
|
||||
return FactorWordRenderer.getWordHTMLString(
|
||||
FactorPlugin.getInterpreter(),word,false);
|
||||
FactorPlugin.getInterpreter(),word,def,false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,8 +98,6 @@ public class FactorCompletion extends SideKickCompletion
|
|||
|
||||
public ListCellRenderer getRenderer()
|
||||
{
|
||||
return new FactorWordRenderer(
|
||||
FactorPlugin.getInterpreter(),
|
||||
false);
|
||||
return new FactorWordRenderer(data.parser,false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ import sidekick.*;
|
|||
|
||||
public class FactorParsedData extends SideKickParsedData
|
||||
{
|
||||
public FactorInterpreter interp;
|
||||
public FactorSideKickParser parser;
|
||||
public String in;
|
||||
public Cons use;
|
||||
|
||||
FactorParsedData(FactorInterpreter interp, String fileName)
|
||||
FactorParsedData(FactorSideKickParser parser, String fileName)
|
||||
{
|
||||
super(fileName);
|
||||
this.interp = interp;
|
||||
this.parser = parser;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,13 @@ public class FactorPlugin extends EditPlugin
|
|||
return interp;
|
||||
} //}}}
|
||||
|
||||
//{{{ getSideKickParser() method
|
||||
public static FactorSideKickParser getSideKickParser()
|
||||
{
|
||||
return (FactorSideKickParser)ServiceManager.getService(
|
||||
"sidekick.SideKickParser","factor");
|
||||
} //}}}
|
||||
|
||||
//{{{ eval() method
|
||||
public static void eval(View view, String cmd)
|
||||
{
|
||||
|
@ -261,7 +268,7 @@ public class FactorPlugin extends EditPlugin
|
|||
else if(words.length == 1)
|
||||
insertUse(view,words[0].vocabulary);
|
||||
else
|
||||
new InsertUseDialog(view,getInterpreter(),words);
|
||||
new InsertUseDialog(view,getSideKickParser(),words);
|
||||
} //}}}
|
||||
|
||||
//{{{ insertUse() method
|
||||
|
@ -279,17 +286,24 @@ public class FactorPlugin extends EditPlugin
|
|||
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)
|
||||
if(text.startsWith("IN:") || text.startsWith("USE:"))
|
||||
{
|
||||
lastUseOffset = buffer.getLineStartOffset(i);
|
||||
lastUseOffset = buffer.getLineEndOffset(i) - 1;
|
||||
}
|
||||
else if(text.startsWith("!") || text.length() == 0)
|
||||
{
|
||||
if(i == 0)
|
||||
lastUseOffset = 0;
|
||||
else
|
||||
lastUseOffset = buffer.getLineEndOffset(i-1) - 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
String decl = "USE: " + vocab + "\n";
|
||||
String decl = "USE: " + vocab;
|
||||
if(lastUseOffset != 0)
|
||||
decl = "\n" + decl;
|
||||
buffer.insert(lastUseOffset,decl);
|
||||
showStatus(view,"inserted-use",decl);
|
||||
} //}}}
|
||||
|
|
|
@ -40,6 +40,7 @@ import sidekick.*;
|
|||
|
||||
public class FactorSideKickParser extends SideKickParser
|
||||
{
|
||||
private FactorInterpreter interp;
|
||||
private WordPreview wordPreview;
|
||||
|
||||
/**
|
||||
|
@ -53,10 +54,32 @@ public class FactorSideKickParser extends SideKickParser
|
|||
public FactorSideKickParser()
|
||||
{
|
||||
super("factor");
|
||||
wordPreview = new WordPreview();
|
||||
interp = FactorPlugin.getInterpreter();
|
||||
wordPreview = new WordPreview(this);
|
||||
worddefs = new HashMap();
|
||||
} //}}}
|
||||
|
||||
//{{{ getInterpreter() method
|
||||
public FactorInterpreter getInterpreter()
|
||||
{
|
||||
return interp;
|
||||
} //}}}
|
||||
|
||||
//{{{ getWordDefinition() method
|
||||
/**
|
||||
* Check for a word definition from a parsed source file. If one is
|
||||
* found, return it, otherwise return interpreter's definition.
|
||||
*/
|
||||
public FactorWordDefinition getWordDefinition(FactorWord word)
|
||||
{
|
||||
FactorWordDefinition def = (FactorWordDefinition)
|
||||
worddefs.get(word);
|
||||
if(def != null)
|
||||
return def;
|
||||
else
|
||||
return word.def;
|
||||
} //}}}
|
||||
|
||||
//{{{ activate() method
|
||||
/**
|
||||
* This method is called when a buffer using this parser is selected
|
||||
|
@ -95,9 +118,8 @@ public class FactorSideKickParser extends SideKickParser
|
|||
public SideKickParsedData parse(Buffer buffer,
|
||||
DefaultErrorSource errorSource)
|
||||
{
|
||||
FactorInterpreter interp = FactorPlugin.getInterpreter();
|
||||
FactorParsedData d = new FactorParsedData(
|
||||
interp,buffer.getPath());
|
||||
this,buffer.getPath());
|
||||
|
||||
String text;
|
||||
|
||||
|
@ -176,7 +198,7 @@ public class FactorSideKickParser extends SideKickParser
|
|||
if(last != null)
|
||||
last.end = buffer.createPosition(start - 1);
|
||||
|
||||
last = new FactorAsset(word,
|
||||
last = new FactorAsset(word,def,
|
||||
buffer.createPosition(start));
|
||||
d.root.add(new DefaultMutableTreeNode(last));
|
||||
}
|
||||
|
|
|
@ -38,40 +38,40 @@ public class FactorWordRenderer extends DefaultListCellRenderer
|
|||
{
|
||||
//{{{ getWordHTMLString() method
|
||||
public static String getWordHTMLString(FactorInterpreter interp,
|
||||
FactorWord word, boolean showIn)
|
||||
FactorWord word, FactorWordDefinition def, boolean showIn)
|
||||
{
|
||||
String prop = "factor.completion.plain";
|
||||
String stackEffect = null;
|
||||
|
||||
if(word.def == null)
|
||||
if(def == null)
|
||||
{
|
||||
if(word.parsing != null)
|
||||
prop = "factor.completion.parsing";
|
||||
else
|
||||
prop = "factor.completion.defer";
|
||||
}
|
||||
else if(word.def instanceof FactorShuffleDefinition)
|
||||
else if(def instanceof FactorShuffleDefinition)
|
||||
{
|
||||
prop = "factor.completion.shuffle";
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Cons def = word.def.toList(interp);
|
||||
while(def != null)
|
||||
Cons d = def.toList(interp);
|
||||
while(d != null)
|
||||
{
|
||||
if(buf.length() != 0)
|
||||
buf.append(' ');
|
||||
|
||||
buf.append(def.car);
|
||||
def = def.next();
|
||||
buf.append(d.car);
|
||||
d = d.next();
|
||||
}
|
||||
stackEffect = buf.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cons def = word.def.toList(interp);
|
||||
if(def != null && def.car instanceof FactorDocComment)
|
||||
Cons d = def.toList(interp);
|
||||
if(d != null && d.car instanceof FactorDocComment)
|
||||
{
|
||||
FactorDocComment comment = (FactorDocComment)
|
||||
def.car;
|
||||
d.car;
|
||||
if(comment.isStackComment())
|
||||
{
|
||||
prop = "factor.completion.stack";
|
||||
|
@ -100,13 +100,13 @@ public class FactorWordRenderer extends DefaultListCellRenderer
|
|||
});
|
||||
} //}}}
|
||||
|
||||
private FactorInterpreter interp;
|
||||
private FactorSideKickParser parser;
|
||||
private boolean showIn;
|
||||
|
||||
//{{{ FactorWordRenderer constructor
|
||||
public FactorWordRenderer(FactorInterpreter interp, boolean showIn)
|
||||
public FactorWordRenderer(FactorSideKickParser parser, boolean showIn)
|
||||
{
|
||||
this.interp = interp;
|
||||
this.parser = parser;
|
||||
this.showIn = showIn;
|
||||
} //}}}
|
||||
|
||||
|
@ -124,7 +124,11 @@ public class FactorWordRenderer extends DefaultListCellRenderer
|
|||
if(!(value instanceof FactorWord))
|
||||
return this;
|
||||
|
||||
setText(getWordHTMLString(interp,(FactorWord)value,showIn));
|
||||
FactorWord word = (FactorWord)value;
|
||||
setText(getWordHTMLString(parser.getInterpreter(),
|
||||
word,
|
||||
parser.getWordDefinition(word),
|
||||
showIn));
|
||||
|
||||
return this;
|
||||
} //}}}
|
||||
|
|
|
@ -40,10 +40,10 @@ import org.gjt.sp.jedit.*;
|
|||
public class InsertUseDialog extends WordListDialog
|
||||
{
|
||||
//{{{ InsertUseDialog constructor
|
||||
public InsertUseDialog(View view, FactorInterpreter interp,
|
||||
public InsertUseDialog(View view, FactorSideKickParser parser,
|
||||
FactorWord[] words)
|
||||
{
|
||||
super(view,interp,jEdit.getProperty("factor.insert-use.title"));
|
||||
super(view,parser,jEdit.getProperty("factor.insert-use.title"));
|
||||
|
||||
getContentPane().add(BorderLayout.NORTH,new JLabel(
|
||||
jEdit.getProperty("factor.insert-use.caption",
|
||||
|
|
|
@ -44,7 +44,8 @@ public abstract class WordListDialog extends EnhancedDialog
|
|||
protected JButton ok, cancel;
|
||||
|
||||
//{{{ WordListDialog constructor
|
||||
public WordListDialog(View view, FactorInterpreter interp, String title)
|
||||
public WordListDialog(View view, FactorSideKickParser parser,
|
||||
String title)
|
||||
{
|
||||
super(view,title,true);
|
||||
|
||||
|
@ -56,7 +57,7 @@ public abstract class WordListDialog extends EnhancedDialog
|
|||
|
||||
content.add(BorderLayout.CENTER,new JScrollPane(
|
||||
list = new JList()));
|
||||
list.setCellRenderer(new FactorWordRenderer(interp,true));
|
||||
list.setCellRenderer(new FactorWordRenderer(parser,true));
|
||||
|
||||
content.add(BorderLayout.SOUTH,createButtonPanel());
|
||||
} //}}}
|
||||
|
|
|
@ -39,11 +39,21 @@ import sidekick.*;
|
|||
|
||||
public class WordPreview implements CaretListener
|
||||
{
|
||||
private FactorSideKickParser parser;
|
||||
|
||||
//{{{ WordPreview constructor
|
||||
public WordPreview(FactorSideKickParser parser)
|
||||
{
|
||||
this.parser = parser;
|
||||
} //}}}
|
||||
|
||||
//{{{ caretUpdate() method
|
||||
public void caretUpdate(CaretEvent e)
|
||||
{
|
||||
showPreview((JEditTextArea)e.getSource());
|
||||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ showPreview() method
|
||||
private void showPreview(JEditTextArea textArea)
|
||||
{
|
||||
View view = textArea.getView();
|
||||
|
@ -55,14 +65,15 @@ public class WordPreview implements CaretListener
|
|||
if(data instanceof FactorParsedData)
|
||||
{
|
||||
FactorParsedData fdata = (FactorParsedData)data;
|
||||
FactorWord w = fdata.interp
|
||||
.searchVocabulary(fdata.use,word);
|
||||
FactorInterpreter interp = fdata.parser
|
||||
.getInterpreter();
|
||||
FactorWord w = interp.searchVocabulary(fdata.use,word);
|
||||
if(w != null)
|
||||
{
|
||||
view.getStatus().setMessageAndClear(
|
||||
FactorWordRenderer.getWordHTMLString(
|
||||
fdata.interp,w,true));
|
||||
interp,w,fdata.parser.getWordDefinition(w),true));
|
||||
}
|
||||
}
|
||||
}
|
||||
} //}}}
|
||||
}
|
||||
|
|
|
@ -280,7 +280,9 @@ IN: cross-compiler
|
|||
swap write-image ;
|
||||
|
||||
: make-images ( -- )
|
||||
"big-endian" off "boot.image.le" make-image
|
||||
"big-endian" on "boot.image.be" make-image
|
||||
"boot.image.le and boot.image.be have been generated." print
|
||||
;
|
||||
"64-bits" off
|
||||
"big-endian" off "boot.image.le32" make-image
|
||||
"big-endian" on "boot.image.be32" make-image
|
||||
"64-bits" on
|
||||
"big-endian" off "boot.image.le64" make-image
|
||||
"big-endian" on "boot.image.be64" make-image ;
|
||||
|
|
|
@ -223,5 +223,5 @@ USE: logic
|
|||
"size" "href" "class" "border" "rows" "cols"
|
||||
"id" "onclick" "style" "valign" "accesskey"
|
||||
"src" "language" "colspan" "onchange" "rel"
|
||||
"width" "src"
|
||||
"width"
|
||||
] [ define-attribute-word ] each
|
||||
|
|
|
@ -49,16 +49,6 @@ USE: words
|
|||
: image "image" get ;
|
||||
: emit ( cell -- ) image vector-push ;
|
||||
|
||||
: lo/hi64 ( long -- hi lo )
|
||||
dup
|
||||
-32 shift
|
||||
HEX: ffffffff bitand
|
||||
swap
|
||||
HEX: ffffffff bitand ;
|
||||
|
||||
: emit64 ( bignum -- )
|
||||
lo/hi64 "big-endian" get [ swap ] when emit emit ;
|
||||
|
||||
: fixup ( value offset -- ) image set-vector-nth ;
|
||||
|
||||
( Object memory )
|
||||
|
@ -66,7 +56,8 @@ USE: words
|
|||
: image-magic HEX: 0f0e0d0c ;
|
||||
: image-version 0 ;
|
||||
|
||||
: cell ( we're compiling for a 32-bit system ) 4 ;
|
||||
: cell "64-bits" get 8 4 ? ;
|
||||
: char "64-bits" get 4 2 ? ;
|
||||
|
||||
: tag-mask BIN: 111 ;
|
||||
: tag-bits 3 ;
|
||||
|
@ -129,14 +120,6 @@ USE: words
|
|||
|
||||
: 'fixnum ( n -- tagged ) fixnum-tag immediate ;
|
||||
|
||||
( Floats )
|
||||
|
||||
: 'float ( f -- tagged )
|
||||
object-tag here-as >r
|
||||
float-type >header emit
|
||||
0 emit ( alignment -- FIXME 64-bit arch )
|
||||
float>bits emit64 r> ;
|
||||
|
||||
( Bignums )
|
||||
|
||||
: 'bignum ( bignum -- tagged )
|
||||
|
@ -222,24 +205,22 @@ DEFER: '
|
|||
|
||||
( Strings )
|
||||
|
||||
: pack ( n n -- )
|
||||
"big-endian" get [ swap ] when 16 shift bitor emit ;
|
||||
: pad-string ( n str -- )
|
||||
tuck str-length - CHAR: \0 fill cat2 ;
|
||||
|
||||
: pack-at ( n str -- )
|
||||
2dup str-nth rot succ rot str-nth pack ;
|
||||
: emit-string ( str -- )
|
||||
"big-endian" get [ str-reverse ] unless
|
||||
0 swap [ swap 16 shift + ] str-each emit ;
|
||||
|
||||
: (pack-string) ( n str -- )
|
||||
2dup str-length >= [
|
||||
2drop
|
||||
] [
|
||||
2dup str-length pred = [
|
||||
2dup str-nth 0 pack
|
||||
] [
|
||||
2dup pack-at
|
||||
] ifte >r 2 + r> (pack-string)
|
||||
] ifte ;
|
||||
: (pack-string) ( n list -- )
|
||||
#! Emit bytes for a string, with n characters per word.
|
||||
[
|
||||
2dup str-length < [ dupd pad-string ] when
|
||||
emit-string
|
||||
] each drop ;
|
||||
|
||||
: pack-string ( str -- ) 0 swap (pack-string) ;
|
||||
: pack-string ( string -- )
|
||||
char tuck swap split-n (pack-string) ;
|
||||
|
||||
: string, ( string -- )
|
||||
object-tag here-as swap
|
||||
|
@ -327,7 +308,6 @@ IN: cross-compiler
|
|||
[
|
||||
[ fixnum? ] [ 'fixnum ]
|
||||
[ bignum? ] [ 'bignum ]
|
||||
[ float? ] [ 'float ]
|
||||
[ ratio? ] [ 'ratio ]
|
||||
[ complex? ] [ 'complex ]
|
||||
[ word? ] [ 'word ]
|
||||
|
@ -355,10 +335,18 @@ IN: cross-compiler
|
|||
( Image output )
|
||||
|
||||
: write-word ( word -- )
|
||||
"big-endian" get [
|
||||
write-big-endian-32
|
||||
"64-bits" get [
|
||||
"big-endian" get [
|
||||
write-big-endian-64
|
||||
] [
|
||||
write-little-endian-64
|
||||
] ifte
|
||||
] [
|
||||
write-little-endian-32
|
||||
"big-endian" get [
|
||||
write-big-endian-32
|
||||
] [
|
||||
write-little-endian-32
|
||||
] ifte
|
||||
] ifte ;
|
||||
|
||||
: write-image ( image file -- )
|
||||
|
|
|
@ -38,14 +38,6 @@ USE: stack
|
|||
: odd? 2 mod 1 = ;
|
||||
: even? 2 mod 0 = ;
|
||||
|
||||
: i #{ 0 1 } ; inline
|
||||
: -i #{ 0 -1 } ; inline
|
||||
: inf 1.0 0.0 / ; inline
|
||||
: -inf -1.0 0.0 / ; inline
|
||||
: e 2.7182818284590452354 ; inline
|
||||
: pi 3.14159265358979323846 ; inline
|
||||
: pi/2 1.5707963267948966 ; inline
|
||||
|
||||
: f>0 ( obj -- obj )
|
||||
#! If f at the top of the stack, turn it into 0.
|
||||
f 0 replace ;
|
||||
|
@ -71,7 +63,3 @@ USE: stack
|
|||
|
||||
: neg 0 swap - ; inline
|
||||
: recip 1 swap / ; inline
|
||||
|
||||
: deg2rad pi * 180 / ;
|
||||
|
||||
: rad2deg 180 * pi / ;
|
||||
|
|
|
@ -38,6 +38,9 @@ USE: stack
|
|||
! Hyperbolic functions:
|
||||
! cosh sech sinh cosech tanh coth
|
||||
|
||||
: deg2rad pi * 180 / ;
|
||||
: rad2deg 180 * pi / ;
|
||||
|
||||
: cos ( z -- cos )
|
||||
>rect 2dup
|
||||
fcosh swap fcos * -rot
|
||||
|
|
|
@ -77,6 +77,7 @@ USE: parser
|
|||
|
||||
!!! Math library.
|
||||
"/library/platform/jvm/real-math.factor" run-resource ! real-math
|
||||
"/library/math/constants.factor" run-resource ! math
|
||||
"/library/math/math.factor" run-resource ! math
|
||||
"/library/math/pow.factor" run-resource ! math
|
||||
"/library/math/trig-hyp.factor" run-resource ! math
|
||||
|
|
|
@ -81,6 +81,7 @@ USE: stdio
|
|||
"/library/debugger.factor"
|
||||
"/library/platform/native/init.factor"
|
||||
|
||||
"/library/math/constants.factor"
|
||||
"/library/math/math.factor"
|
||||
"/library/platform/native/math.factor"
|
||||
"/library/math/pow.factor"
|
||||
|
|
|
@ -87,3 +87,20 @@ USE: stack
|
|||
#! Split the string at each occurrence of split, and push a
|
||||
#! list of the pieces.
|
||||
[, 0 -rot (split) ,] ;
|
||||
|
||||
: split-n-advance substring , >r tuck + swap r> ;
|
||||
: split-n-finish nip dup str-length swap substring , ;
|
||||
|
||||
: (split-n) ( start n str -- )
|
||||
3dup >r dupd + r> 2dup str-length < [
|
||||
split-n-advance (split-n)
|
||||
] [
|
||||
split-n-finish 3drop
|
||||
] ifte ;
|
||||
|
||||
: split-n ( n str -- list )
|
||||
#! Split a string into n-character chunks.
|
||||
[, 0 -rot (split-n) ,] ;
|
||||
|
||||
: str-reverse ( str -- str )
|
||||
str>sbuf dup sbuf-reverse sbuf>str ;
|
||||
|
|
|
@ -43,11 +43,35 @@ USE: strings
|
|||
read1 8 shift bitor
|
||||
read1 bitor ;
|
||||
|
||||
: byte7 ( num -- byte ) -56 shift HEX: ff bitand ;
|
||||
: byte6 ( num -- byte ) -48 shift HEX: ff bitand ;
|
||||
: byte5 ( num -- byte ) -40 shift HEX: ff bitand ;
|
||||
: byte4 ( num -- byte ) -32 shift HEX: ff bitand ;
|
||||
: byte3 ( num -- byte ) -24 shift HEX: ff bitand ;
|
||||
: byte2 ( num -- byte ) -16 shift HEX: ff bitand ;
|
||||
: byte1 ( num -- byte ) -8 shift HEX: ff bitand ;
|
||||
: byte0 ( num -- byte ) HEX: ff bitand ;
|
||||
|
||||
: write-little-endian-64 ( word -- )
|
||||
dup byte0 >char write
|
||||
dup byte1 >char write
|
||||
dup byte2 >char write
|
||||
dup byte3 >char write
|
||||
dup byte4 >char write
|
||||
dup byte5 >char write
|
||||
dup byte6 >char write
|
||||
byte7 >char write ;
|
||||
|
||||
: write-big-endian-64 ( word -- )
|
||||
dup byte7 >char write
|
||||
dup byte6 >char write
|
||||
dup byte5 >char write
|
||||
dup byte4 >char write
|
||||
dup byte3 >char write
|
||||
dup byte2 >char write
|
||||
dup byte1 >char write
|
||||
byte0 >char write ;
|
||||
|
||||
: write-little-endian-32 ( word -- )
|
||||
dup byte0 >char write
|
||||
dup byte1 >char write
|
||||
|
|
|
@ -85,8 +85,8 @@ unit-test
|
|||
[ t ] [ "abc" "abd" str-compare 0 < ] unit-test
|
||||
[ t ] [ "z" "abd" str-compare 0 > ] unit-test
|
||||
|
||||
[ "fedcba" ] [ "abcdef" str>sbuf dup sbuf-reverse sbuf>str ] unit-test
|
||||
[ "edcba" ] [ "abcde" str>sbuf dup sbuf-reverse sbuf>str ] unit-test
|
||||
[ "fedcba" ] [ "abcdef" str-reverse ] unit-test
|
||||
[ "edcba" ] [ "abcde" str-reverse ] unit-test
|
||||
|
||||
native? [
|
||||
[ t ] [ "Foo" str>sbuf "Foo" str>sbuf = ] unit-test
|
||||
|
@ -103,3 +103,5 @@ native? [
|
|||
] when
|
||||
|
||||
[ f ] [ [ 0 10 "hello" substring ] [ not ] catch ] unit-test
|
||||
|
||||
[ [ "hell" "o wo" "rld" ] ] [ 4 "hello world" split-n ] unit-test
|
||||
|
|
|
@ -37,7 +37,7 @@ void throw_error(CELL error)
|
|||
|
||||
void general_error(CELL error, CELL tagged)
|
||||
{
|
||||
CELL c = cons(error,tag_cons(cons(tagged,F)));
|
||||
CELL c = cons(error,cons(tagged,F));
|
||||
if(userenv[BREAK_ENV] == 0)
|
||||
{
|
||||
/* Crash at startup */
|
||||
|
@ -57,7 +57,7 @@ void general_error(CELL error, CELL tagged)
|
|||
|
||||
void type_error(CELL type, CELL tagged)
|
||||
{
|
||||
CELL c = cons(tag_fixnum(type),tag_cons(cons(tagged,F)));
|
||||
CELL c = cons(tag_fixnum(type),cons(tagged,F));
|
||||
general_error(ERROR_TYPE,c);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,14 +54,15 @@ CELL subtract_fixnum(FIXNUM x, FIXNUM y)
|
|||
*/
|
||||
CELL multiply_fixnum(FIXNUM x, FIXNUM y)
|
||||
{
|
||||
FIXNUM prod;
|
||||
|
||||
if(x == 0 || y == 0)
|
||||
return tag_fixnum(0);
|
||||
else
|
||||
{
|
||||
FIXNUM prod = x * y;
|
||||
if(prod / x == y)
|
||||
return tag_integer(prod);
|
||||
}
|
||||
|
||||
prod = x * y;
|
||||
/* if this is not equal, we have overflow */
|
||||
if(prod / x == y)
|
||||
return tag_integer(prod);
|
||||
|
||||
return tag_object(
|
||||
s48_bignum_multiply(
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
typedef struct {
|
||||
CELL header;
|
||||
/* FIXME */
|
||||
#ifndef FACTOR_64
|
||||
CELL alignment;
|
||||
#endif
|
||||
double n;
|
||||
} FLOAT;
|
||||
|
||||
|
|
Loading…
Reference in New Issue