Words which didn't compile cannot be run at all
parent
05f3f9dcb9
commit
f38d2f91f6
|
@ -62,18 +62,25 @@ SYMBOLS: +optimized+ +unoptimized+ ;
|
||||||
} 1||
|
} 1||
|
||||||
] [ error-type +compiler-warning+ eq? ] bi* and ;
|
] [ error-type +compiler-warning+ eq? ] bi* and ;
|
||||||
|
|
||||||
: (fail) ( word -- * )
|
: (fail) ( word compiled -- * )
|
||||||
|
swap
|
||||||
[ compiled-unxref ]
|
[ compiled-unxref ]
|
||||||
[ f swap compiled get set-at ]
|
[ compiled get set-at ]
|
||||||
[ +unoptimized+ save-compiled-status ]
|
[ +unoptimized+ save-compiled-status ]
|
||||||
tri
|
tri
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
: not-compiled-def ( word error -- def )
|
||||||
|
'[ _ _ not-compiled ] [ ] like ;
|
||||||
|
|
||||||
: fail ( word error -- * )
|
: fail ( word error -- * )
|
||||||
[ 2dup ignore-error? [ drop f ] when swap compiler-error ] [ drop (fail) ] 2bi ;
|
2dup ignore-error?
|
||||||
|
[ drop f over def>> ]
|
||||||
|
[ 2dup not-compiled-def ] if
|
||||||
|
[ swap compiler-error ] [ (fail) ] bi-curry* bi ;
|
||||||
|
|
||||||
: frontend ( word -- nodes )
|
: frontend ( word -- nodes )
|
||||||
dup contains-breakpoints? [ (fail) ] [
|
dup contains-breakpoints? [ dup def>> (fail) ] [
|
||||||
[ build-tree-from-word ] [ fail ] recover optimize-tree
|
[ build-tree-from-word ] [ fail ] recover optimize-tree
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
@ -124,7 +131,7 @@ t compile-dependencies? set-global
|
||||||
[ (compile) yield-hook get call( -- ) ] slurp-deque ;
|
[ (compile) yield-hook get call( -- ) ] slurp-deque ;
|
||||||
|
|
||||||
: decompile ( word -- )
|
: decompile ( word -- )
|
||||||
f 2array 1array modify-code-heap ;
|
dup def>> 2array 1array modify-code-heap ;
|
||||||
|
|
||||||
: compile-call ( quot -- )
|
: compile-call ( quot -- )
|
||||||
[ dup infer define-temp ] with-compilation-unit execute ;
|
[ dup infer define-temp ] with-compilation-unit execute ;
|
||||||
|
|
|
@ -52,3 +52,5 @@ T{ error-type
|
||||||
: compiler-error ( error word -- )
|
: compiler-error ( error word -- )
|
||||||
compiler-errors get-global pick
|
compiler-errors get-global pick
|
||||||
[ [ [ <compiler-error> ] keep ] dip set-at ] [ delete-at drop ] if ;
|
[ [ [ <compiler-error> ] keep ] dip set-at ] [ delete-at drop ] if ;
|
||||||
|
|
||||||
|
ERROR: not-compiled word error ;
|
|
@ -45,8 +45,8 @@ IN: compiler.tree.builder
|
||||||
infer-quot-here ;
|
infer-quot-here ;
|
||||||
|
|
||||||
: check-effect ( word effect -- )
|
: check-effect ( word effect -- )
|
||||||
over required-stack-effect 2dup effect<=
|
swap required-stack-effect 2dup effect<=
|
||||||
[ 3drop ] [ effect-error ] if ;
|
[ 2drop ] [ effect-error ] if ;
|
||||||
|
|
||||||
: finish-word ( word -- )
|
: finish-word ( word -- )
|
||||||
current-effect check-effect ;
|
current-effect check-effect ;
|
||||||
|
|
|
@ -52,9 +52,9 @@ TUPLE: missing-effect word ;
|
||||||
: missing-effect ( word -- * )
|
: missing-effect ( word -- * )
|
||||||
pretty-word \ missing-effect inference-error ;
|
pretty-word \ missing-effect inference-error ;
|
||||||
|
|
||||||
TUPLE: effect-error word inferred declared ;
|
TUPLE: effect-error inferred declared ;
|
||||||
|
|
||||||
: effect-error ( word inferred declared -- * )
|
: effect-error ( inferred declared -- * )
|
||||||
\ effect-error inference-error ;
|
\ effect-error inference-error ;
|
||||||
|
|
||||||
TUPLE: recursive-quotation-error quot ;
|
TUPLE: recursive-quotation-error quot ;
|
||||||
|
|
|
@ -40,10 +40,7 @@ M: missing-effect summary
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
M: effect-error summary
|
M: effect-error summary
|
||||||
[
|
drop "Stack effect declaration is wrong" ;
|
||||||
"Stack effect declaration of the word " %
|
|
||||||
word>> name>> % " is wrong" %
|
|
||||||
] "" make ;
|
|
||||||
|
|
||||||
M: recursive-quotation-error error.
|
M: recursive-quotation-error error.
|
||||||
"The quotation " write
|
"The quotation " write
|
||||||
|
|
|
@ -39,4 +39,10 @@ M: source-file-error error.
|
||||||
|
|
||||||
: :warnings ( -- ) +compiler-warning+ compiler-errors. ;
|
: :warnings ( -- ) +compiler-warning+ compiler-errors. ;
|
||||||
|
|
||||||
: :linkage ( -- ) +linkage-error+ compiler-errors. ;
|
: :linkage ( -- ) +linkage-error+ compiler-errors. ;
|
||||||
|
|
||||||
|
M: not-compiled summary
|
||||||
|
word>> name>> "The word " " cannot be executed because it failed to compile" surround ;
|
||||||
|
|
||||||
|
M: not-compiled error.
|
||||||
|
[ summary print nl ] [ error>> error. ] bi ;
|
|
@ -60,8 +60,8 @@ HELP: modify-code-heap ( alist -- )
|
||||||
{ $values { "alist" "an alist" } }
|
{ $values { "alist" "an alist" } }
|
||||||
{ $description "Stores compiled code definitions in the code heap. The alist maps words to the following:"
|
{ $description "Stores compiled code definitions in the code heap. The alist maps words to the following:"
|
||||||
{ $list
|
{ $list
|
||||||
{ { $link f } " - in this case, the word is compiled with the non-optimizing compiler part of the VM." }
|
{ "a quotation - in this case, the quotation is compiled with the non-optimizing compiler and the word will call the quotation when executed." }
|
||||||
{ { $snippet "{ code labels rel words literals }" } " - in this case, a code heap block is allocated with the given data." }
|
{ { $snippet "{ code labels rel words literals }" } " - in this case, a code heap block is allocated with the given data and the word will call the code block when executed." }
|
||||||
} }
|
} }
|
||||||
{ $notes "This word is called at the end of " { $link with-compilation-unit } "." } ;
|
{ $notes "This word is called at the end of " { $link with-compilation-unit } "." } ;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ IN: compiler.units.tests
|
||||||
|
|
||||||
! Non-optimizing compiler bugs
|
! Non-optimizing compiler bugs
|
||||||
[ 1 1 ] [
|
[ 1 1 ] [
|
||||||
"A" "B" <word> [ [ 1 ] dip ] >>def dup f 2array 1array modify-code-heap
|
"A" "B" <word> [ [ 1 ] dip ] 2array 1array modify-code-heap
|
||||||
1 swap execute
|
1 swap execute
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ SYMBOL: compiler-impl
|
||||||
HOOK: recompile compiler-impl ( words -- alist )
|
HOOK: recompile compiler-impl ( words -- alist )
|
||||||
|
|
||||||
! Non-optimizing compiler
|
! Non-optimizing compiler
|
||||||
M: f recompile [ f ] { } map>assoc ;
|
M: f recompile [ dup def>> ] { } map>assoc ;
|
||||||
|
|
||||||
! Trivial compiler. We don't want to touch the code heap
|
! Trivial compiler. We don't want to touch the code heap
|
||||||
! during stage1 bootstrap, it would just waste time.
|
! during stage1 bootstrap, it would just waste time.
|
||||||
|
|
|
@ -21,14 +21,16 @@ void set_word_code(F_WORD *word, F_CODE_BLOCK *compiled)
|
||||||
word->optimizedp = T;
|
word->optimizedp = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Compile a word definition with the non-optimizing compiler. Allocates memory */
|
||||||
void default_word_code(F_WORD *word, bool relocate)
|
void jit_compile_word(F_WORD *word, CELL def, bool relocate)
|
||||||
{
|
{
|
||||||
|
REGISTER_ROOT(def);
|
||||||
REGISTER_UNTAGGED(word);
|
REGISTER_UNTAGGED(word);
|
||||||
jit_compile(word->def,relocate);
|
jit_compile(def,relocate);
|
||||||
UNREGISTER_UNTAGGED(word);
|
UNREGISTER_UNTAGGED(word);
|
||||||
|
UNREGISTER_ROOT(def);
|
||||||
|
|
||||||
word->code = untag_quotation(word->def)->code;
|
word->code = untag_quotation(def)->code;
|
||||||
word->optimizedp = F;
|
word->optimizedp = F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,15 +85,15 @@ void primitive_modify_code_heap(void)
|
||||||
|
|
||||||
CELL data = array_nth(pair,1);
|
CELL data = array_nth(pair,1);
|
||||||
|
|
||||||
if(data == F)
|
if(type_of(data) == QUOTATION_TYPE)
|
||||||
{
|
{
|
||||||
REGISTER_UNTAGGED(alist);
|
REGISTER_UNTAGGED(alist);
|
||||||
REGISTER_UNTAGGED(word);
|
REGISTER_UNTAGGED(word);
|
||||||
default_word_code(word,false);
|
jit_compile_word(word,data,false);
|
||||||
UNREGISTER_UNTAGGED(word);
|
UNREGISTER_UNTAGGED(word);
|
||||||
UNREGISTER_UNTAGGED(alist);
|
UNREGISTER_UNTAGGED(alist);
|
||||||
}
|
}
|
||||||
else
|
else if(type_of(data) == ARRAY_TYPE)
|
||||||
{
|
{
|
||||||
F_ARRAY *compiled_code = untag_array(data);
|
F_ARRAY *compiled_code = untag_array(data);
|
||||||
|
|
||||||
|
@ -115,6 +117,8 @@ void primitive_modify_code_heap(void)
|
||||||
|
|
||||||
set_word_code(word,compiled);
|
set_word_code(word,compiled);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
critical_error("Expected a quotation or an array",data);
|
||||||
|
|
||||||
REGISTER_UNTAGGED(alist);
|
REGISTER_UNTAGGED(alist);
|
||||||
update_word_xt(word);
|
update_word_xt(word);
|
||||||
|
|
|
@ -5,7 +5,7 @@ void init_code_heap(CELL size);
|
||||||
|
|
||||||
bool in_code_heap_p(CELL ptr);
|
bool in_code_heap_p(CELL ptr);
|
||||||
|
|
||||||
void default_word_code(F_WORD *word, bool relocate);
|
void jit_compile_word(F_WORD *word, CELL def, bool relocate);
|
||||||
|
|
||||||
void set_word_code(F_WORD *word, F_CODE_BLOCK *compiled);
|
void set_word_code(F_WORD *word, F_CODE_BLOCK *compiled);
|
||||||
|
|
||||||
|
|
|
@ -532,8 +532,7 @@ void compile_all_words(void)
|
||||||
{
|
{
|
||||||
F_WORD *word = untag_word(array_nth(untag_array(words),i));
|
F_WORD *word = untag_word(array_nth(untag_array(words),i));
|
||||||
REGISTER_UNTAGGED(word);
|
REGISTER_UNTAGGED(word);
|
||||||
if(word->optimizedp == F)
|
jit_compile_word(word,word->def,false);
|
||||||
default_word_code(word,false);
|
|
||||||
UNREGISTER_UNTAGGED(word);
|
UNREGISTER_UNTAGGED(word);
|
||||||
update_word_xt(word);
|
update_word_xt(word);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ F_WORD *allot_word(CELL vocab, CELL name)
|
||||||
word->code = NULL;
|
word->code = NULL;
|
||||||
|
|
||||||
REGISTER_UNTAGGED(word);
|
REGISTER_UNTAGGED(word);
|
||||||
default_word_code(word,true);
|
jit_compile_word(word,word->def,true);
|
||||||
UNREGISTER_UNTAGGED(word);
|
UNREGISTER_UNTAGGED(word);
|
||||||
|
|
||||||
REGISTER_UNTAGGED(word);
|
REGISTER_UNTAGGED(word);
|
||||||
|
|
Loading…
Reference in New Issue