some progress towards self hosting
parent
303749e336
commit
de95f233de
|
@ -1,5 +1,8 @@
|
||||||
+ native:
|
+ native:
|
||||||
|
|
||||||
|
ERROR: I/O error: [ "primitive_read_line_fd_8" "Resource temporarily unavailable" ]
|
||||||
|
|
||||||
|
- decide if overflow is a fatal error
|
||||||
- f >n: crashes
|
- f >n: crashes
|
||||||
- typecases: type error reporting bad
|
- typecases: type error reporting bad
|
||||||
- image output
|
- image output
|
||||||
|
@ -13,7 +16,6 @@
|
||||||
- inspector: sort
|
- inspector: sort
|
||||||
- index of str
|
- index of str
|
||||||
- accept: return socket, instead of printing msg
|
- accept: return socket, instead of printing msg
|
||||||
- crash: [ primitives, ] with-image .
|
|
||||||
- enforce bottom-up in native bootstrap
|
- enforce bottom-up in native bootstrap
|
||||||
|
|
||||||
+ interactive:
|
+ interactive:
|
||||||
|
|
5
build.sh
5
build.sh
|
@ -6,3 +6,8 @@ export CFLAGS="-pedantic -Wall -Winline -Os -march=pentium4 -fomit-frame-pointer
|
||||||
$CC $CFLAGS -o f native/*.c
|
$CC $CFLAGS -o f native/*.c
|
||||||
|
|
||||||
strip f
|
strip f
|
||||||
|
|
||||||
|
#export CC=gcc
|
||||||
|
#export CFLAGS="-pedantic -Wall -g"
|
||||||
|
#
|
||||||
|
#$CC $CFLAGS -o f-debug native/*.c
|
||||||
|
|
|
@ -69,7 +69,6 @@ USE: words
|
||||||
: object-tag BIN: 011 ;
|
: object-tag BIN: 011 ;
|
||||||
: header-tag BIN: 100 ;
|
: header-tag BIN: 100 ;
|
||||||
|
|
||||||
: fixnum-mask HEX: 1fffffff ;
|
|
||||||
: immediate ( x tag -- tagged ) swap tag-bits shift< bitor ;
|
: immediate ( x tag -- tagged ) swap tag-bits shift< bitor ;
|
||||||
: >header ( id -- tagged ) header-tag immediate ;
|
: >header ( id -- tagged ) header-tag immediate ;
|
||||||
|
|
||||||
|
@ -137,7 +136,7 @@ USE: words
|
||||||
dup pooled-object dup [
|
dup pooled-object dup [
|
||||||
nip swap fixup
|
nip swap fixup
|
||||||
] [
|
] [
|
||||||
drop "Not in image: " swap cat2 throw
|
drop "Not in image: " swap word-name cat2 throw
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
: fixup-words ( -- )
|
: fixup-words ( -- )
|
||||||
|
@ -184,7 +183,7 @@ DEFER: '
|
||||||
object-tag here-as swap
|
object-tag here-as swap
|
||||||
11 >header emit
|
11 >header emit
|
||||||
dup str-length emit
|
dup str-length emit
|
||||||
dup hashcode ( fixnum-mask bitand ) emit
|
dup hashcode emit
|
||||||
pack-string
|
pack-string
|
||||||
pad ;
|
pad ;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ USE: combinators
|
||||||
USE: kernel
|
USE: kernel
|
||||||
USE: logic
|
USE: logic
|
||||||
USE: stack
|
USE: stack
|
||||||
|
USE: vectors
|
||||||
|
|
||||||
: 2list ( a b -- [ a b ] )
|
: 2list ( a b -- [ a b ] )
|
||||||
#! Construct a proper list of 2 elements.
|
#! Construct a proper list of 2 elements.
|
||||||
|
@ -338,3 +339,12 @@ DEFER: tree-contains?
|
||||||
cons-hashcode r>
|
cons-hashcode r>
|
||||||
xor
|
xor
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
|
: list>vector ( list -- vector )
|
||||||
|
dup length <vector> swap [ over vector-push ] each ;
|
||||||
|
|
||||||
|
: stack>list ( vector -- list )
|
||||||
|
[ ] swap [ swons ] vector-each ;
|
||||||
|
|
||||||
|
: vector>list ( vector -- list )
|
||||||
|
stack>list nreverse ;
|
||||||
|
|
|
@ -41,17 +41,6 @@ USE: stack
|
||||||
: set-vector-length ( vector -- length )
|
: set-vector-length ( vector -- length )
|
||||||
"factor.FactorArray" "top" jvar-set ;
|
"factor.FactorArray" "top" jvar-set ;
|
||||||
|
|
||||||
: vector>list ( vector -- list )
|
|
||||||
#! Turns a vector into a list.
|
|
||||||
[ ] "factor.FactorArray" "toList" jinvoke ;
|
|
||||||
|
|
||||||
: stack>list ( vector -- list )
|
|
||||||
#! Turns a vector into a list.
|
|
||||||
vector>list ;
|
|
||||||
|
|
||||||
: list>vector ( list -- vector )
|
|
||||||
[ "factor.Cons" ] "factor.FactorArray" jnew ;
|
|
||||||
|
|
||||||
: vector-nth ( index vector -- )
|
: vector-nth ( index vector -- )
|
||||||
[ "int" ] "factor.FactorArray" "get" jinvoke ;
|
[ "int" ] "factor.FactorArray" "get" jinvoke ;
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,6 @@ primitives,
|
||||||
"/library/platform/native/prettyprint.factor"
|
"/library/platform/native/prettyprint.factor"
|
||||||
"/library/platform/native/stack.factor"
|
"/library/platform/native/stack.factor"
|
||||||
"/library/platform/native/words.factor"
|
"/library/platform/native/words.factor"
|
||||||
"/library/platform/native/vectors.factor"
|
|
||||||
"/library/platform/native/vocabularies.factor"
|
"/library/platform/native/vocabularies.factor"
|
||||||
"/library/platform/native/unparser.factor"
|
"/library/platform/native/unparser.factor"
|
||||||
"/library/platform/native/cross-compiler.factor"
|
"/library/platform/native/cross-compiler.factor"
|
||||||
|
|
|
@ -63,6 +63,7 @@ USE: vectors
|
||||||
"Bad primitive: "
|
"Bad primitive: "
|
||||||
"Incompatible handle: "
|
"Incompatible handle: "
|
||||||
"I/O error: "
|
"I/O error: "
|
||||||
|
"Overflow"
|
||||||
] ?nth ;
|
] ?nth ;
|
||||||
|
|
||||||
: ?kernel-error ( cons -- error# param )
|
: ?kernel-error ( cons -- error# param )
|
||||||
|
|
|
@ -79,3 +79,6 @@ USE: unparser
|
||||||
drop (str>fixnum)
|
drop (str>fixnum)
|
||||||
] ifte
|
] ifte
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
|
: parse-number ( str -- num/f )
|
||||||
|
[ str>fixnum ] [ [ drop f ] when ] catch ;
|
||||||
|
|
|
@ -36,6 +36,7 @@ USE: namespaces
|
||||||
USE: stack
|
USE: stack
|
||||||
USE: strings
|
USE: strings
|
||||||
USE: words
|
USE: words
|
||||||
|
USE: vectors
|
||||||
USE: vocabularies
|
USE: vocabularies
|
||||||
USE: unparser
|
USE: unparser
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ IN: builtins
|
||||||
: f f parsed ; parsing
|
: f f parsed ; parsing
|
||||||
|
|
||||||
! Lists
|
! Lists
|
||||||
: [ f ; parsing
|
: [ [ ] ; parsing
|
||||||
: ] nreverse parsed ; parsing
|
: ] nreverse parsed ; parsing
|
||||||
|
|
||||||
: | ( syntax: | cdr ] )
|
: | ( syntax: | cdr ] )
|
||||||
|
@ -57,17 +58,23 @@ IN: builtins
|
||||||
#! 'parsed' acts accordingly.
|
#! 'parsed' acts accordingly.
|
||||||
"|" ; parsing
|
"|" ; parsing
|
||||||
|
|
||||||
|
! Vectors
|
||||||
|
: { f ; parsing
|
||||||
|
: } nreverse list>vector parsed ; parsing
|
||||||
|
|
||||||
! Colon defs
|
! Colon defs
|
||||||
|
: CREATE: scan "in" get create ;
|
||||||
|
|
||||||
: :
|
: :
|
||||||
#! Begin a word definition. Word name follows.
|
#! Begin a word definition. Word name follows.
|
||||||
scan "in" get create f ; parsing
|
CREATE: [ ] ; parsing
|
||||||
|
|
||||||
: ;
|
: ;
|
||||||
#! End a word definition.
|
#! End a word definition.
|
||||||
nreverse define ; parsing
|
nreverse define ; parsing
|
||||||
|
|
||||||
! Vocabularies
|
! Vocabularies
|
||||||
: DEFER: scan "in" get create drop ; parsing
|
: DEFER: CREATE: drop ; parsing
|
||||||
: USE: scan "use" cons@ ; parsing
|
: USE: scan "use" cons@ ; parsing
|
||||||
: IN: scan dup "use" cons@ "in" set ; parsing
|
: IN: scan dup "use" cons@ "in" set ; parsing
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
! :folding=indent: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.
|
|
||||||
|
|
||||||
IN: vectors
|
|
||||||
USE: lists
|
|
||||||
USE: stack
|
|
||||||
|
|
||||||
: stack>list ( vector -- list )
|
|
||||||
[ ] swap [ swons ] vector-each ;
|
|
||||||
|
|
||||||
: vector>list ( vector -- list )
|
|
||||||
stack>list nreverse ;
|
|
|
@ -28,6 +28,7 @@
|
||||||
IN: vectors
|
IN: vectors
|
||||||
USE: arithmetic
|
USE: arithmetic
|
||||||
USE: kernel
|
USE: kernel
|
||||||
|
USE: lists
|
||||||
USE: stack
|
USE: stack
|
||||||
|
|
||||||
: vector-empty? ( obj -- ? )
|
: vector-empty? ( obj -- ? )
|
||||||
|
|
|
@ -15,9 +15,9 @@ void critical_error(char* msg, CELL tagged)
|
||||||
|
|
||||||
void fix_stacks(void)
|
void fix_stacks(void)
|
||||||
{
|
{
|
||||||
if(env.ds < env.ds_bot + sizeof(ARRAY))
|
if(UNDERFLOW(env.ds,env.ds_bot) || OVERFLOW(env.ds,env.ds_bot))
|
||||||
reset_datastack();
|
reset_datastack();
|
||||||
if(env.cs <= env.cs_bot + sizeof(ARRAY))
|
if(UNDERFLOW(env.cs,env.cs_bot) || OVERFLOW(env.cs,env.cs_bot))
|
||||||
reset_callstack();
|
reset_callstack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ERROR_BAD_PRIMITIVE (5<<3)
|
#define ERROR_BAD_PRIMITIVE (5<<3)
|
||||||
#define ERROR_HANDLE_INCOMPAT (6<<3)
|
#define ERROR_HANDLE_INCOMPAT (6<<3)
|
||||||
#define ERROR_IO (7<<3)
|
#define ERROR_IO (7<<3)
|
||||||
|
#define ERROR_OVERFLOW (8<<3)
|
||||||
|
|
||||||
void fatal_error(char* msg, CELL tagged);
|
void fatal_error(char* msg, CELL tagged);
|
||||||
void critical_error(char* msg, CELL tagged);
|
void critical_error(char* msg, CELL tagged);
|
||||||
|
|
|
@ -31,15 +31,16 @@ void copy_object(CELL* handle)
|
||||||
CELL tag = TAG(pointer);
|
CELL tag = TAG(pointer);
|
||||||
CELL header, newpointer;
|
CELL header, newpointer;
|
||||||
|
|
||||||
if(in_zone(active,pointer))
|
|
||||||
critical_error("copy_object given newspace ptr",pointer);
|
|
||||||
|
|
||||||
if(tag == FIXNUM_TYPE)
|
if(tag == FIXNUM_TYPE)
|
||||||
{
|
{
|
||||||
/* convinience */
|
/* convinience */
|
||||||
|
gc_debug("FIXNUM",pointer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(in_zone(active,pointer))
|
||||||
|
critical_error("copy_object given newspace ptr",pointer);
|
||||||
|
|
||||||
header = get(UNTAG(pointer));
|
header = get(UNTAG(pointer));
|
||||||
|
|
||||||
if(TAG(header) == GC_COLLECTED)
|
if(TAG(header) == GC_COLLECTED)
|
||||||
|
@ -83,6 +84,7 @@ void collect_object(void)
|
||||||
break;
|
break;
|
||||||
case HANDLE_TYPE:
|
case HANDLE_TYPE:
|
||||||
collect_handle((HANDLE*)scan);
|
collect_handle((HANDLE*)scan);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
scan += size;
|
scan += size;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#define UNDERFLOW_CHECKING
|
#define UNDERFLOW_CHECKING
|
||||||
|
|
||||||
|
#define UNDERFLOW(stack,bot) ((stack) < UNTAG(bot) + sizeof(ARRAY))
|
||||||
#define OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot))
|
#define OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot))
|
||||||
|
|
||||||
INLINE void check_stacks(void)
|
INLINE void check_stacks(void)
|
||||||
|
@ -7,9 +8,9 @@ INLINE void check_stacks(void)
|
||||||
|
|
||||||
#ifdef UNDERFLOW_CHECKING
|
#ifdef UNDERFLOW_CHECKING
|
||||||
if(OVERFLOW(env.ds,env.ds_bot))
|
if(OVERFLOW(env.ds,env.ds_bot))
|
||||||
fatal_error("datastack overflow",env.ds);
|
general_error(ERROR_OVERFLOW,F);
|
||||||
if(OVERFLOW(env.cs,env.cs_bot))
|
if(OVERFLOW(env.cs,env.cs_bot))
|
||||||
fatal_error("callstack overflow",env.ds);
|
general_error(ERROR_OVERFLOW,F);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,9 @@ CELL untagged_object_size(CELL pointer)
|
||||||
case SBUF_TYPE:
|
case SBUF_TYPE:
|
||||||
size = sizeof(SBUF);
|
size = sizeof(SBUF);
|
||||||
break;
|
break;
|
||||||
|
case BIGNUM_TYPE:
|
||||||
|
size = sizeof(BIGNUM);
|
||||||
|
break;
|
||||||
case HANDLE_TYPE:
|
case HANDLE_TYPE:
|
||||||
size = sizeof(HANDLE);
|
size = sizeof(HANDLE);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -46,7 +46,7 @@ void primitive_vector_nth(void)
|
||||||
env.dt = array_nth(vector->array,index);
|
env.dt = array_nth(vector->array,index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vector_ensure_capacity(VECTOR* vector, int index)
|
void vector_ensure_capacity(VECTOR* vector, CELL index)
|
||||||
{
|
{
|
||||||
ARRAY* array = vector->array;
|
ARRAY* array = vector->array;
|
||||||
CELL capacity = array->capacity;
|
CELL capacity = array->capacity;
|
||||||
|
|
|
@ -20,7 +20,7 @@ void primitive_vector(void);
|
||||||
void primitive_vector_length(void);
|
void primitive_vector_length(void);
|
||||||
void primitive_set_vector_length(void);
|
void primitive_set_vector_length(void);
|
||||||
void primitive_vector_nth(void);
|
void primitive_vector_nth(void);
|
||||||
void vector_ensure_capacity(VECTOR* vector, int index);
|
void vector_ensure_capacity(VECTOR* vector, CELL index);
|
||||||
void primitive_set_vector_nth(void);
|
void primitive_set_vector_nth(void);
|
||||||
void fixup_vector(VECTOR* vector);
|
void fixup_vector(VECTOR* vector);
|
||||||
void collect_vector(VECTOR* vector);
|
void collect_vector(VECTOR* vector);
|
||||||
|
|
Loading…
Reference in New Issue