From 4c2c8f133f22232b9e64e17f8291e202fb9d9d1c Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 15 Jul 2015 11:13:52 -0700 Subject: [PATCH] vm: rename some primitives, and some cleanup. * quot-compiled? => quotation-compiled? * optimized? => word-optimized? --- .../remote-control/remote-control.factor | 2 +- basis/bootstrap/compiler/compiler.factor | 2 +- .../call-effect/call-effect.factor | 2 +- .../known-words/known-words.factor | 6 ++-- .../tools/continuations/continuations.factor | 19 +++++++----- basis/tools/deploy/shaker/shaker.factor | 2 +- core/bootstrap/primitives.factor | 6 ++-- core/kernel/kernel.factor | 2 +- core/quotations/quotations.factor | 2 +- core/words/words.factor | 2 +- vm/callstack.cpp | 6 ++-- vm/code_blocks.cpp | 7 +++-- vm/image.cpp | 4 +-- vm/primitives.hpp | 13 ++++---- vm/quotations.cpp | 30 ++++++++++--------- vm/vm.hpp | 12 ++++---- vm/words.cpp | 8 ++--- 17 files changed, 66 insertions(+), 59 deletions(-) diff --git a/basis/alien/remote-control/remote-control.factor b/basis/alien/remote-control/remote-control.factor index fabb4f7f49..58161f5090 100644 --- a/basis/alien/remote-control/remote-control.factor +++ b/basis/alien/remote-control/remote-control.factor @@ -15,7 +15,7 @@ IN: alien.remote-control void { long } cdecl [ sleep ] alien-callback ; : ?callback ( word -- alien ) - dup optimized? [ execute ] [ drop f ] if ; inline + dup word-optimized? [ execute ] [ drop f ] if ; inline : init-remote-control ( -- ) \ eval-callback ?callback OBJ-EVAL-CALLBACK set-special-object diff --git a/basis/bootstrap/compiler/compiler.factor b/basis/bootstrap/compiler/compiler.factor index 6ce7a3d44e..dd6ef784cb 100644 --- a/basis/bootstrap/compiler/compiler.factor +++ b/basis/bootstrap/compiler/compiler.factor @@ -32,7 +32,7 @@ gc : compile-unoptimized ( words -- ) [ [ subwords ] map ] keep suffix concat - [ optimized? ] reject compile ; + [ word-optimized? ] reject compile ; "debug-compiler" get [ diff --git a/basis/compiler/tree/propagation/call-effect/call-effect.factor b/basis/compiler/tree/propagation/call-effect/call-effect.factor index 16e75bee8d..361bb01286 100644 --- a/basis/compiler/tree/propagation/call-effect/call-effect.factor +++ b/basis/compiler/tree/propagation/call-effect/call-effect.factor @@ -91,7 +91,7 @@ M: quotation cached-effect [ '[ _ execute ] ] dip call-effect-slow ; inline : execute-effect-unsafe? ( word effect -- ? ) - over optimized? + over word-optimized? [ [ stack-effect { effect } declare ] dip effect<= ] [ 2drop f ] if ; inline diff --git a/basis/stack-checker/known-words/known-words.factor b/basis/stack-checker/known-words/known-words.factor index 3c04748488..c3a0cc490e 100644 --- a/basis/stack-checker/known-words/known-words.factor +++ b/basis/stack-checker/known-words/known-words.factor @@ -429,12 +429,11 @@ M: object infer-call* \ call bad-macro-input ; \ minor-gc { } { } define-primitive \ modify-code-heap { array object object } { } define-primitive \ nano-count { } { integer } define-primitive \ nano-count make-flushable -\ optimized? { word } { object } define-primitive \ profiling { object } { } define-primitive \ (get-samples) { } { object } define-primitive \ (clear-samples) { } { } define-primitive -\ quot-compiled? { quotation } { object } define-primitive \ quotation-code { quotation } { integer integer } define-primitive \ quotation-code make-flushable +\ quotation-compiled? { quotation } { object } define-primitive \ reset-dispatch-stats { } { } define-primitive \ resize-array { integer array } { array } define-primitive \ resize-byte-array { integer byte-array } { byte-array } define-primitive @@ -456,7 +455,7 @@ M: object infer-call* \ call bad-macro-input ; \ set-alien-unsigned-cell { integer c-ptr integer } { } define-primitive \ set-context-object { object fixnum } { } define-primitive \ set-fpu-state { } { } define-primitive -\ set-innermost-frame-quot { quotation callstack } { } define-primitive +\ set-innermost-frame-quotation { quotation callstack } { } define-primitive \ set-slot { object object fixnum } { } define-primitive \ set-special-object { object fixnum } { } define-primitive \ set-string-nth-fast { fixnum fixnum string } { } define-primitive @@ -469,3 +468,4 @@ M: object infer-call* \ call bad-macro-input ; \ tag { object } { fixnum } define-primitive \ tag make-foldable \ unimplemented { } { } define-primitive \ word-code { word } { integer integer } define-primitive \ word-code make-flushable +\ word-optimized? { word } { object } define-primitive diff --git a/basis/tools/continuations/continuations.factor b/basis/tools/continuations/continuations.factor index 2760afe83e..bc64fea98d 100644 --- a/basis/tools/continuations/continuations.factor +++ b/basis/tools/continuations/continuations.factor @@ -39,7 +39,7 @@ M: array add-breakpoint M: object add-breakpoint ; -: (step-into-quot) ( quot -- ) add-breakpoint call ; +: (step-into-quotation) ( quot -- ) add-breakpoint call ; : (step-into-dip) ( quot -- ) add-breakpoint dip ; @@ -47,9 +47,9 @@ M: object add-breakpoint ; : (step-into-3dip) ( quot -- ) add-breakpoint 3dip ; -: (step-into-if) ( true false ? -- ) ? (step-into-quot) ; +: (step-into-if) ( true false ? -- ) ? (step-into-quotation) ; -: (step-into-dispatch) ( array n -- ) nth (step-into-quot) ; +: (step-into-dispatch) ( array n -- ) nth (step-into-quotation) ; : (step-into-execute) ( word -- ) { @@ -57,7 +57,7 @@ M: object add-breakpoint ; { [ dup single-generic? ] [ effective-method (step-into-execute) ] } { [ dup uses \ suspend swap member? ] [ execute break ] } { [ dup primitive? ] [ execute break ] } - [ def>> (step-into-quot) ] + [ def>> (step-into-quotation) ] } cond ; \ (step-into-execute) t "step-into?" set-word-prop @@ -66,10 +66,10 @@ M: object add-breakpoint ; current-continuation callstack >>call break ; : (step-into-call-next-method) ( method -- ) - next-method-quot (step-into-quot) ; + next-method-quot (step-into-quotation) ; << { - (step-into-quot) + (step-into-quotation) (step-into-dip) (step-into-2dip) (step-into-3dip) @@ -85,7 +85,10 @@ M: object add-breakpoint ; : (change-frame) ( callstack quot -- callstack' ) [ dup innermost-frame-executing quotation? ] dip '[ - clone [ >innermost-frame< @ ] [ set-innermost-frame-quot ] [ ] tri + clone + [ >innermost-frame< @ ] + [ set-innermost-frame-quotation ] + [ ] tri ] when ; inline : change-frame ( continuation quot -- continuation' ) @@ -108,7 +111,7 @@ PRIVATE> [ nip \ break suffix ] change-frame ; { - { call [ (step-into-quot) ] } + { call [ (step-into-quotation) ] } { dip [ (step-into-dip) ] } { 2dip [ (step-into-2dip) ] } { 3dip [ (step-into-3dip) ] } diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index a4763d6d90..36bb513ee8 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -474,7 +474,7 @@ IN: tools.deploy.shaker ! Quotations which were formerly compiled must remain ! compiled. 2dup [ - 2dup [ quot-compiled? ] [ quot-compiled? not ] bi* and + 2dup [ quotation-compiled? ] [ quotation-compiled? not ] bi* and [ nip jit-compile ] [ 2drop ] if ] 2each ; diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index 1d83b10f0d..e7a0bbed7d 100755 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -466,7 +466,7 @@ tuple { "innermost-frame-scan" "kernel.private" "primitive_innermost_stack_frame_scan" ( callstack -- n ) } { "set-context-object" "kernel.private" "primitive_set_context_object" ( obj n -- ) } { "set-datastack" "kernel.private" "primitive_set_datastack" ( array -- ) } - { "set-innermost-frame-quot" "kernel.private" "primitive_set_innermost_stack_frame_quot" ( n callstack -- ) } + { "set-innermost-frame-quotation" "kernel.private" "primitive_set_innermost_stack_frame_quotation" ( n callstack -- ) } { "set-retainstack" "kernel.private" "primitive_set_retainstack" ( array -- ) } { "set-special-object" "kernel.private" "primitive_set_special_object" ( obj n -- ) } { "special-object" "kernel.private" "primitive_special_object" ( n -- obj ) } @@ -532,8 +532,8 @@ tuple { "size" "memory" "primitive_size" ( obj -- n ) } { "(save-image)" "memory.private" "primitive_save_image" ( path1 path2 then-die? -- ) } { "jit-compile" "quotations" "primitive_jit_compile" ( quot -- ) } - { "quot-compiled?" "quotations" "primitive_quot_compiled_p" ( quot -- ? ) } { "quotation-code" "quotations" "primitive_quotation_code" ( quot -- start end ) } + { "quotation-compiled?" "quotations" "primitive_quotation_compiled_p" ( quot -- ? ) } { "array>quotation" "quotations.private" "primitive_array_to_quotation" ( array -- quot ) } { "set-slot" "slots.private" "primitive_set_slot" ( value obj n -- ) } { "" "strings" "primitive_string" ( n ch -- string ) } @@ -548,8 +548,8 @@ tuple { "retainstack-for" "threads.private" "primitive_retainstack_for" ( context -- array ) } { "dispatch-stats" "tools.dispatch.private" "primitive_dispatch_stats" ( -- stats ) } { "reset-dispatch-stats" "tools.dispatch.private" "primitive_reset_dispatch_stats" ( -- ) } - { "optimized?" "words" "primitive_optimized_p" ( word -- ? ) } { "word-code" "words" "primitive_word_code" ( word -- start end ) } + { "word-optimized?" "words" "primitive_word_optimized_p" ( word -- ? ) } { "(word)" "words.private" "primitive_word" ( name vocab hashcode -- word ) } { "profiling" "tools.profiler.sampling.private" "primitive_sampling_profiler" ( ? -- ) } { "(get-samples)" "tools.profiler.sampling.private" "primitive_get_samples" ( -- samples/f ) } diff --git a/core/kernel/kernel.factor b/core/kernel/kernel.factor index 1f83aeb316..d73d480d80 100644 --- a/core/kernel/kernel.factor +++ b/core/kernel/kernel.factor @@ -55,7 +55,7 @@ PRIMITIVE: set-callstack ( callstack -- * ) PRIMITIVE: set-context-object ( obj n -- ) PRIMITIVE: set-datastack ( array -- ) PRIMITIVE: set-fpu-state ( -- ) -PRIMITIVE: set-innermost-frame-quot ( n callstack -- ) +PRIMITIVE: set-innermost-frame-quotation ( n callstack -- ) PRIMITIVE: set-retainstack ( array -- ) PRIMITIVE: set-special-object ( obj n -- ) PRIMITIVE: signal-handler ( -- ) diff --git a/core/quotations/quotations.factor b/core/quotations/quotations.factor index 1cf8f6ff64..b4817bf81c 100644 --- a/core/quotations/quotations.factor +++ b/core/quotations/quotations.factor @@ -10,8 +10,8 @@ BUILTIN: quotation cache-counter ; PRIMITIVE: jit-compile ( quot -- ) -PRIMITIVE: quot-compiled? ( quot -- ? ) PRIMITIVE: quotation-code ( quot -- start end ) +PRIMITIVE: quotation-compiled? ( quot -- ? ) quotation ( array -- quot ) diff --git a/core/words/words.factor b/core/words/words.factor index 8c7946e2bb..6e1fb31bac 100644 --- a/core/words/words.factor +++ b/core/words/words.factor @@ -11,8 +11,8 @@ BUILTIN: word { def quotation initial: [ ] } props pic-def pic-tail-def { sub-primitive read-only } ; -PRIMITIVE: optimized? ( word -- ? ) PRIMITIVE: word-code ( word -- start end ) +PRIMITIVE: word-optimized? ( word -- ? ) replace(code->code_block_for_address(addr)->scan(this, addr)); } -/* Allocates memory (jit_compile_quot) */ -void factor_vm::primitive_set_innermost_stack_frame_quot() { +/* Allocates memory (jit_compile_quotation) */ +void factor_vm::primitive_set_innermost_stack_frame_quotation() { data_root stack(ctx->pop(), this); data_root quot(ctx->pop(), this); stack.untag_check(this); quot.untag_check(this); - jit_compile_quot(quot.value(), true); + jit_compile_quotation(quot.value(), true); void* inner = stack->top(); cell addr = *(cell*)inner; diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index f5f8b3be2d..af992de545 100644 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -43,7 +43,7 @@ cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) { return w->entry_point; else { quotation* quot = untag(tagged_quot); - if (quot_compiled_p(quot)) + if (quotation_compiled_p(quot)) return quot->entry_point; else return w->entry_point; @@ -486,6 +486,7 @@ void factor_vm::undefined_symbol() { general_error(ERROR_UNDEFINED_SYMBOL, symbol, library); } -void undefined_symbol() { return current_vm()->undefined_symbol(); } - +void undefined_symbol() { + return current_vm()->undefined_symbol(); +} } diff --git a/vm/image.cpp b/vm/image.cpp index 2bb653c1d3..972b30c1aa 100644 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -300,8 +300,8 @@ void factor_vm::primitive_save_image() { where we might throw an error, so we have to throw an error here since later steps destroy the current image. */ bool then_die = to_boolean(ctx->pop()); - byte_array* path2 = tagged(ctx->pop()).untag_check(this); - byte_array* path1 = tagged(ctx->pop()).untag_check(this); + byte_array* path2 = untag_check(ctx->pop()); + byte_array* path1 = untag_check(ctx->pop()); /* Copy the paths to non-gc memory to avoid them hanging around in the saved image. */ diff --git a/vm/primitives.hpp b/vm/primitives.hpp index 7bb89f36a2..0209a4e6f6 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -27,15 +27,16 @@ namespace factor { _(full_gc) _(fwrite) _(get_samples) _(identity_hashcode) \ _(innermost_stack_frame_executing) _(innermost_stack_frame_scan) \ _(jit_compile) _(load_locals) _(lookup_method) _(mega_cache_miss) \ - _(minor_gc) _(modify_code_heap) _(nano_count) _(optimized_p) \ - _(quot_compiled_p) _(quotation_code) _(reset_dispatch_stats) \ - _(resize_array) _(resize_byte_array) _(resize_string) _(retainstack) \ - _(retainstack_for) _(sampling_profiler) _(save_image) \ - _(set_context_object) _(set_datastack) _(set_innermost_stack_frame_quot) \ + _(minor_gc) _(modify_code_heap) _(nano_count) _(quotation_code) \ + _(quotation_compiled_p) _(reset_dispatch_stats) _(resize_array) \ + _(resize_byte_array) _(resize_string) _(retainstack) _(retainstack_for) \ + _(sampling_profiler) _(save_image) _(set_context_object) \ + _(set_datastack) _(set_innermost_stack_frame_quotation) \ _(set_retainstack) _(set_slot) _(set_special_object) \ _(set_string_nth_fast) _(size) _(sleep) _(special_object) _(string) \ _(strip_stack_traces) _(tuple) _(tuple_boa) _(unimplemented) \ - _(uninitialized_byte_array) _(word) _(word_code) _(wrapper) + _(uninitialized_byte_array) _(word) _(word_code) _(word_optimized_p) \ + _(wrapper) #define EACH_ALIEN_PRIMITIVE(_) \ _(signed_cell, fixnum, from_signed_cell, to_fixnum) \ diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 45f3aa074f..88b0d22795 100644 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -167,7 +167,7 @@ void quotation_jit::emit_quot(cell quot_) { literal(array_nth(elements, 0)); else { if (compiling) - parent->jit_compile_quot(quot.value(), relocate); + parent->jit_compile_quotation(quot.value(), relocate); literal(quot.value()); } } @@ -300,8 +300,8 @@ cell quotation_jit::word_stack_frame_size(cell obj) { } /* Allocates memory */ -code_block* factor_vm::jit_compile_quot(cell owner_, cell quot_, - bool relocating) { +code_block* factor_vm::jit_compile_quotation(cell owner_, cell quot_, + bool relocating) { data_root owner(owner_, this); data_root quot(quot_, this); @@ -320,17 +320,19 @@ code_block* factor_vm::jit_compile_quot(cell owner_, cell quot_, } /* Allocates memory */ -void factor_vm::jit_compile_quot(cell quot_, bool relocating) { +void factor_vm::jit_compile_quotation(cell quot_, bool relocating) { data_root quot(quot_, this); - if (!quot_compiled_p(quot.untagged())) { + if (!quotation_compiled_p(quot.untagged())) { code_block* compiled = - jit_compile_quot(quot.value(), quot.value(), relocating); + jit_compile_quotation(quot.value(), quot.value(), relocating); quot.untagged()->entry_point = compiled->entry_point(); } } /* Allocates memory */ -void factor_vm::primitive_jit_compile() { jit_compile_quot(ctx->pop(), true); } +void factor_vm::primitive_jit_compile() { + jit_compile_quotation(ctx->pop(), true); +} cell factor_vm::lazy_jit_compile_entry_point() { return untag(special_objects[LAZY_JIT_COMPILE_WORD])->entry_point; @@ -374,9 +376,10 @@ fixnum factor_vm::quot_code_offset_to_scan(cell quot_, cell offset) { cell factor_vm::lazy_jit_compile(cell quot_) { data_root quot(quot_, this); - FACTOR_ASSERT(!quot_compiled_p(quot.untagged())); + FACTOR_ASSERT(!quotation_compiled_p(quot.untagged())); - code_block* compiled = jit_compile_quot(quot.value(), quot.value(), true); + code_block* compiled = + jit_compile_quotation(quot.value(), quot.value(), true); quot.untagged()->entry_point = compiled->entry_point(); return quot.value(); @@ -387,15 +390,14 @@ VM_C_API cell lazy_jit_compile(cell quot, factor_vm* parent) { return parent->lazy_jit_compile(quot); } -bool factor_vm::quot_compiled_p(quotation* quot) { +bool factor_vm::quotation_compiled_p(quotation* quot) { return quot->entry_point != 0 && quot->entry_point != lazy_jit_compile_entry_point(); } -void factor_vm::primitive_quot_compiled_p() { - tagged quot(ctx->pop()); - quot.untag_check(this); - ctx->push(tag_boolean(quot_compiled_p(quot.untagged()))); +void factor_vm::primitive_quotation_compiled_p() { + quotation* quot = untag_check(ctx->pop()); + ctx->push(tag_boolean(quotation_compiled_p(quot))); } /* Allocates memory */ diff --git a/vm/vm.hpp b/vm/vm.hpp index 8529ff6e24..d1120a6fab 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -450,7 +450,7 @@ struct factor_vm { word* allot_word(cell name_, cell vocab_, cell hashcode_); void primitive_word(); void primitive_word_code(); - void primitive_optimized_p(); + void primitive_word_optimized_p(); void primitive_wrapper(); void jit_compile_word(cell word_, cell def_, bool relocating); cell find_all_words(); @@ -630,7 +630,7 @@ struct factor_vm { void primitive_callstack_to_array(); void primitive_innermost_stack_frame_executing(); void primitive_innermost_stack_frame_scan(); - void primitive_set_innermost_stack_frame_quot(); + void primitive_set_innermost_stack_frame_quotation(); void primitive_callstack_bounds(); template @@ -660,12 +660,12 @@ struct factor_vm { cell lazy_jit_compile_entry_point(); void primitive_array_to_quotation(); void primitive_quotation_code(); - code_block* jit_compile_quot(cell owner_, cell quot_, bool relocating); - void jit_compile_quot(cell quot_, bool relocating); + code_block* jit_compile_quotation(cell owner_, cell quot_, bool relocating); + void jit_compile_quotation(cell quot_, bool relocating); fixnum quot_code_offset_to_scan(cell quot_, cell offset); cell lazy_jit_compile(cell quot); - bool quot_compiled_p(quotation* quot); - void primitive_quot_compiled_p(); + bool quotation_compiled_p(quotation* quot); + void primitive_quotation_compiled_p(); cell find_all_quotations(); void initialize_all_quotations(); diff --git a/vm/words.cpp b/vm/words.cpp index 68daf0732a..f171868d0e 100644 --- a/vm/words.cpp +++ b/vm/words.cpp @@ -15,13 +15,13 @@ void factor_vm::jit_compile_word(cell word_, cell def_, bool relocating) { return; code_block* compiled = - jit_compile_quot(word.value(), def.value(), relocating); + jit_compile_quotation(word.value(), def.value(), relocating); word->entry_point = compiled->entry_point(); if (to_boolean(word->pic_def)) - jit_compile_quot(word->pic_def, relocating); + jit_compile_quotation(word->pic_def, relocating); if (to_boolean(word->pic_tail_def)) - jit_compile_quot(word->pic_tail_def, relocating); + jit_compile_quotation(word->pic_tail_def, relocating); } /* Allocates memory */ @@ -81,7 +81,7 @@ void factor_vm::primitive_word_code() { ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size())); } -void factor_vm::primitive_optimized_p() { +void factor_vm::primitive_word_optimized_p() { word* w = untag_check(ctx->peek()); ctx->replace(tag_boolean(w->code()->optimized_p())); }