diff --git a/Makefile b/Makefile index 1042731065..e02b6a672b 100755 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ factor: $(DLL_OBJS) $(EXE_OBJS) clean: rm -f vm/*.o - rm -f libfactor.a + rm -f factor*.dll libfactor*.* vm/resources.o: windres vm/factor.rs vm/resources.o diff --git a/core/alien/c-types/c-types.factor b/core/alien/c-types/c-types.factor index b665300bee..6d9c2cec14 100755 --- a/core/alien/c-types/c-types.factor +++ b/core/alien/c-types/c-types.factor @@ -358,4 +358,7 @@ M: long-long-type box-return ( type -- ) "ushort*" define-primitive-type [ string>u16-alien ] "ushort*" c-type set-c-type-prep + + win64? "longlong" "long" ? "ptrdiff_t" typedef + ] with-compilation-unit diff --git a/core/alien/syntax/syntax-docs.factor b/core/alien/syntax/syntax-docs.factor index d87b67eb59..09169e63b4 100755 --- a/core/alien/syntax/syntax-docs.factor +++ b/core/alien/syntax/syntax-docs.factor @@ -1,5 +1,6 @@ -USING: alien alien.c-types alien.structs alien.syntax -alien.syntax.private help.markup help.syntax ; +IN: alien.syntax +USING: alien alien.c-types alien.structs alien.syntax.private +help.markup help.syntax ; HELP: DLL" { $syntax "DLL\" path\"" } @@ -50,7 +51,13 @@ $nl HELP: TYPEDEF: { $syntax "TYPEDEF: old new" } { $values { "old" "a C type" } { "new" "a C type" } } -{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } +{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } +{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; + +HELP: TYPEDEF-IF: +{ $syntax "TYPEDEF-IF: word old new" } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } +{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." } { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; HELP: C-STRUCT: @@ -81,7 +88,9 @@ HELP: typedef { $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } { $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ; -{ typedef POSTPONE: TYPEDEF: } related-words +{ typedef POSTPONE: TYPEDEF: POSTPONE: TYPEDEF-IF: } related-words +{ POSTPONE: TYPEDEF: typedef POSTPONE: TYPEDEF-IF: } related-words +{ POSTPONE: TYPEDEF-IF: POSTPONE: TYPEDEF: typedef } related-words HELP: c-struct? { $values { "type" "a string" } { "?" "a boolean" } } diff --git a/core/alien/syntax/syntax.factor b/core/alien/syntax/syntax.factor index 99275d02bf..b81a91efcb 100755 --- a/core/alien/syntax/syntax.factor +++ b/core/alien/syntax/syntax.factor @@ -23,6 +23,15 @@ IN: alien.syntax PRIVATE> +: indirect-quot ( function-ptr-quot return types abi -- quot ) + [ alien-indirect ] 3curry compose ; + +: define-indirect ( abi return function-ptr-quot function-name parameters -- ) + >r pick r> parse-arglist + rot create-in dup reset-generic + >r >r swapd roll indirect-quot r> r> + -rot define-declared ; + : DLL" skip-blank parse-string dlopen parsed ; parsing : ALIEN: scan string>number parsed ; parsing @@ -37,6 +46,9 @@ PRIVATE> : TYPEDEF: scan scan typedef ; parsing +: TYPEDEF-IF: + scan-word execute scan scan rot [ typedef ] [ 2drop ] if ; parsing + : C-STRUCT: scan in get parse-definition diff --git a/core/compiler/constants/constants.factor b/core/compiler/constants/constants.factor index 3de32ab7fa..66fc8d5789 100755 --- a/core/compiler/constants/constants.factor +++ b/core/compiler/constants/constants.factor @@ -19,4 +19,4 @@ IN: compiler.constants : class-hash-offset bootstrap-cell object tag-number - ; : word-xt-offset 8 bootstrap-cells object tag-number - ; : word-code-offset 9 bootstrap-cells object tag-number - ; -: compiled-header-size 8 bootstrap-cells ; +: compiled-header-size 4 bootstrap-cells ; diff --git a/core/compiler/test/redefine.factor b/core/compiler/test/redefine.factor index 821daef203..6e652df877 100755 --- a/core/compiler/test/redefine.factor +++ b/core/compiler/test/redefine.factor @@ -17,7 +17,7 @@ DEFER: x-2 { x-1 } compile - \ x-2 word-xt eq? + \ x-2 word-xt = ] unit-test ] with-variable @@ -115,7 +115,7 @@ DEFER: g-test-3 "IN: temporary USE: math GENERIC: g-test-1 ( x -- y ) M: integer g-test-1 3 + ;" eval - \ g-test-3 word-xt eq? + \ g-test-3 word-xt = ] unit-test DEFER: g-test-5 diff --git a/core/compiler/test/simple.factor b/core/compiler/test/simple.factor index 7ce82c9a1f..9f831bb1f8 100755 --- a/core/compiler/test/simple.factor +++ b/core/compiler/test/simple.factor @@ -63,3 +63,9 @@ IN: temporary ! Regression [ ] [ [ callstack ] compile-call drop ] unit-test + +! Regression + +: empty ; + +[ "b" ] [ 1 [ empty { [ "a" ] [ "b" ] } dispatch ] compile-call ] unit-test diff --git a/core/compiler/test/templates-early.factor b/core/compiler/test/templates-early.factor index 795d331c00..e518d2de8a 100755 --- a/core/compiler/test/templates-early.factor +++ b/core/compiler/test/templates-early.factor @@ -44,7 +44,7 @@ words kernel math effects definitions compiler.units ; [ [ ] [ init-templates ] unit-test - [ ] [ \ + init-generator ] unit-test + [ ] [ init-generator ] unit-test [ t ] [ [ end-basic-block ] { } make empty? ] unit-test diff --git a/core/cpu/architecture/architecture.factor b/core/cpu/architecture/architecture.factor index 3550dcadc0..4da22ff38a 100755 --- a/core/cpu/architecture/architecture.factor +++ b/core/cpu/architecture/architecture.factor @@ -51,8 +51,8 @@ HOOK: %save-dispatch-xt compiler-backend ( -- ) M: object %save-dispatch-xt %save-word-xt ; -! Call another label -HOOK: %call-label compiler-backend ( label -- ) +! Call another word +HOOK: %call compiler-backend ( word -- ) ! Local jump for branches HOOK: %jump-label compiler-backend ( label -- ) @@ -60,10 +60,11 @@ HOOK: %jump-label compiler-backend ( label -- ) ! Test if vreg is 'f' or not HOOK: %jump-t compiler-backend ( label -- ) -! We pass the offset of the jump table start in the world table -HOOK: %call-dispatch compiler-backend ( word-table# -- ) +HOOK: %call-dispatch compiler-backend ( -- label ) -HOOK: %jump-dispatch compiler-backend ( word-table# -- ) +HOOK: %jump-dispatch compiler-backend ( -- ) + +HOOK: %dispatch-label compiler-backend ( word -- ) ! Return to caller HOOK: %return compiler-backend ( -- ) diff --git a/core/cpu/ppc/architecture/architecture.factor b/core/cpu/ppc/architecture/architecture.factor index e93d092b10..7444c21a8c 100755 --- a/core/cpu/ppc/architecture/architecture.factor +++ b/core/cpu/ppc/architecture/architecture.factor @@ -97,36 +97,40 @@ M: ppc-backend %epilogue ( n -- ) 1 1 rot ADDI 0 MTLR ; +: (%call) 11 MTLR BLRL ; + +: (%jump) 11 MTCTR BCTR ; + : %load-dlsym ( symbol dll register -- ) 0 swap LOAD32 rc-absolute-ppc-2/2 rel-dlsym ; -M: ppc-backend %call-label ( label -- ) BL ; +M: ppc-backend %call ( label -- ) BL ; M: ppc-backend %jump-label ( label -- ) B ; M: ppc-backend %jump-t ( label -- ) 0 "flag" operand f v>operand CMPI BNE ; -: (%call) 11 MTLR BLRL ; - -: dispatch-template ( word-table# quot -- ) - [ - >r - "offset" operand "n" operand 1 SRAWI - 0 11 LOAD32 rc-absolute-ppc-2/2 rel-dispatch - 11 dup "offset" operand LWZX - 11 dup word-xt-offset LWZ - r> call - ] H{ - { +input+ { { f "n" } } } - { +scratch+ { { f "offset" } } } - } with-template ; inline +: (%dispatch) ( len -- ) + 0 11 LOAD32 rc-absolute-ppc-2/2 rel-here + "offset" operand "n" operand 1 SRAWI + 11 11 "offset" operand ADD + 11 dup rot cells LWZ ; M: ppc-backend %call-dispatch ( word-table# -- ) - [ (%call) ] dispatch-template ; + [ 7 (%dispatch) (%call)