From fd63917d8b78bd6a522345cf5d4ebabc478aa375 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 01:39:32 -0500 Subject: [PATCH 1/7] Multiline string literals --- extra/multiline/authors.txt | 1 + extra/multiline/multiline-docs.factor | 8 ++++++++ extra/multiline/multiline.factor | 19 +++++++++++++++++++ extra/multiline/summary.txt | 1 + 4 files changed, 29 insertions(+) create mode 100644 extra/multiline/authors.txt create mode 100644 extra/multiline/multiline-docs.factor create mode 100644 extra/multiline/multiline.factor create mode 100644 extra/multiline/summary.txt diff --git a/extra/multiline/authors.txt b/extra/multiline/authors.txt new file mode 100644 index 0000000000..f990dd0ed2 --- /dev/null +++ b/extra/multiline/authors.txt @@ -0,0 +1 @@ +Daniel Ehrenberg diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor new file mode 100644 index 0000000000..15d3ead705 --- /dev/null +++ b/extra/multiline/multiline-docs.factor @@ -0,0 +1,8 @@ +USING: help.markup help.syntax multiline ; + +HELP: STRING: +{ $syntax "STRING: name\nfoo\n;" } +{ $description "Forms a multiline string literal, or 'here document' stored in the word called name. A semicolon is used to signify the end, and that semicolon must be on a line by itself, not preceeded or followed by any whitespace. The string will have newlines in between lines and at the end." } ; + +IN: multiline +ABOUT: POSTPONE: STRING: diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor new file mode 100644 index 0000000000..e55112a5f0 --- /dev/null +++ b/extra/multiline/multiline.factor @@ -0,0 +1,19 @@ +! Copyright (C) 2007 Daniel Ehrenberg +! See http://factorcode.org/license.txt for BSD license. +USING: namespaces parser kernel sequences words quotations ; +IN: multiline + +: next-line-text ( -- str ) + lexer get dup next-line line-text ; + +: (parse-here) ( -- ) + next-line-text dup ";" = + [ drop lexer get next-line ] [ % "\n" % (parse-here) ] if ; + +: parse-here ( -- str ) + [ (parse-here) ] "" make + lexer get next-line ; + +: STRING: + CREATE dup reset-generic + parse-here 1quotation define-compound ; parsing diff --git a/extra/multiline/summary.txt b/extra/multiline/summary.txt new file mode 100644 index 0000000000..9d9c3ea73f --- /dev/null +++ b/extra/multiline/summary.txt @@ -0,0 +1 @@ +Multiline string literals From e1346ced8b9f24278c87d1dc40c4244aef87a375 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 01:54:16 -0500 Subject: [PATCH 2/7] Multiline unit test and bug fix --- extra/multiline/multiline-docs.factor | 2 +- extra/multiline/multiline-tests.factor | 9 +++++++++ extra/multiline/multiline.factor | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 extra/multiline/multiline-tests.factor diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor index 15d3ead705..d2d9c7967f 100644 --- a/extra/multiline/multiline-docs.factor +++ b/extra/multiline/multiline-docs.factor @@ -2,7 +2,7 @@ USING: help.markup help.syntax multiline ; HELP: STRING: { $syntax "STRING: name\nfoo\n;" } -{ $description "Forms a multiline string literal, or 'here document' stored in the word called name. A semicolon is used to signify the end, and that semicolon must be on a line by itself, not preceeded or followed by any whitespace. The string will have newlines in between lines and at the end." } ; +{ $description "Forms a multiline string literal, or 'here document' stored in the word called name. A semicolon is used to signify the end, and that semicolon must be on a line by itself, not preceeded or followed by any whitespace. The string will have newlines in between lines but not at the end, unless there is a blank line before the semicolon." } ; IN: multiline ABOUT: POSTPONE: STRING: diff --git a/extra/multiline/multiline-tests.factor b/extra/multiline/multiline-tests.factor new file mode 100644 index 0000000000..5ef289f4c3 --- /dev/null +++ b/extra/multiline/multiline-tests.factor @@ -0,0 +1,9 @@ +USING: multiline tools.test ; + +STRING: test-it +foo +bar + +; + +[ "foo\nbar\n" ] [ test-it ] unit-test diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor index e55112a5f0..1229dcc689 100644 --- a/extra/multiline/multiline.factor +++ b/extra/multiline/multiline.factor @@ -11,7 +11,7 @@ IN: multiline [ drop lexer get next-line ] [ % "\n" % (parse-here) ] if ; : parse-here ( -- str ) - [ (parse-here) ] "" make + [ (parse-here) ] "" make 1 head* lexer get next-line ; : STRING: From b397c369d79046d9d1ab20380503c8da5af421ff Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 17:23:56 -0500 Subject: [PATCH 3/7] Inline multiline string literals --- extra/multiline/multiline-docs.factor | 17 +++++++++++++++-- extra/multiline/multiline-tests.factor | 3 +++ extra/multiline/multiline.factor | 18 +++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor index d2d9c7967f..05ccdefe6f 100644 --- a/extra/multiline/multiline-docs.factor +++ b/extra/multiline/multiline-docs.factor @@ -4,5 +4,18 @@ HELP: STRING: { $syntax "STRING: name\nfoo\n;" } { $description "Forms a multiline string literal, or 'here document' stored in the word called name. A semicolon is used to signify the end, and that semicolon must be on a line by itself, not preceeded or followed by any whitespace. The string will have newlines in between lines but not at the end, unless there is a blank line before the semicolon." } ; -IN: multiline -ABOUT: POSTPONE: STRING: +HELP: <" +{ $syntax "<\" text \">" } +{ $description "This forms a multiline string literal ending in \">. Unlike the " { $link POSTPONE: STRING: } " form, you can end it in the middle of a line. This construct is non-nesting. In the example above, the string would be parsed as \"text\"." } ; + +{ POSTPONE: <" POSTPONE: STRING: } related-words + +HELP: parse-here +{ $values { "str" "a string" } } +{ $description "Parses a multiline string literal, as used by " { $link POSTPONE: STRING: } "." } ; + +HELP: parse-literal +{ $values { "end-text" "a string delineating the end" } { "str" "the parsed string" } } +{ $description "Parses a multiline string literal, as used by " { $link POSTPONE: <" } ". The end-text is the delimiter for the end." } ; + +{ parse-here parse-literal } related-words diff --git a/extra/multiline/multiline-tests.factor b/extra/multiline/multiline-tests.factor index 5ef289f4c3..a9b9ee2322 100644 --- a/extra/multiline/multiline-tests.factor +++ b/extra/multiline/multiline-tests.factor @@ -7,3 +7,6 @@ bar ; [ "foo\nbar\n" ] [ test-it ] unit-test +[ "foo\nbar\n" ] [ <" foo +bar + "> ] unit-test diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor index 1229dcc689..e808b78997 100644 --- a/extra/multiline/multiline.factor +++ b/extra/multiline/multiline.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces parser kernel sequences words quotations ; +USING: namespaces parser kernel sequences words quotations math ; IN: multiline : next-line-text ( -- str ) @@ -17,3 +17,19 @@ IN: multiline : STRING: CREATE dup reset-generic parse-here 1quotation define-compound ; parsing + +: (parse-literal) ( start-index end-text -- end-index ) + lexer get line-text 2dup start + [ rot dupd >r >r swap subseq % r> r> length + ] [ + rot tail % "\n" % 0 + lexer get next-line swap (parse-literal) + ] if* ; + +: parse-literal ( end-text -- str ) + [ + lexer get lexer-column swap (parse-literal) + lexer get set-lexer-column + ] "" make 1 tail 1 head* ; + +: <" + "\">" parse-literal parsed ; parsing From 4dec62ade9a9ae864f0caf62620414ada2513e01 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 22:48:20 -0500 Subject: [PATCH 4/7] macosx-x86-64 --- Makefile | 10 +++++----- vm/Config.macosx.x86.64 | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 vm/Config.macosx.x86.64 diff --git a/Makefile b/Makefile index 4c6eb2f4e6..4228a6f8ad 100644 --- a/Makefile +++ b/Makefile @@ -57,12 +57,12 @@ default: @echo "openbsd-x86-32" @echo "openbsd-x86-64" @echo "macosx-x86-32" + @echo "macosx-x86-64" @echo "macosx-ppc" @echo "solaris-x86-32" @echo "solaris-x86-64" @echo "windows-ce-arm" @echo "windows-nt-x86-32" - @echo "windows-nt-x86-64" @echo "" @echo "Additional modifiers:" @echo "" @@ -93,6 +93,9 @@ macosx-ppc: macosx-freetype macosx-x86-32: macosx-freetype $(MAKE) $(EXECUTABLE) macosx.app CONFIG=vm/Config.macosx.x86.32 +macosx-x86-64: macosx-freetype + $(MAKE) $(EXECUTABLE) macosx.app CONFIG=vm/Config.macosx.x86.64 + linux-x86-32: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.x86.32 @@ -114,9 +117,6 @@ solaris-x86-64: windows-nt-x86-32: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 -windows-nt-x86-64: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64 - windows-ce-arm: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.ce.arm @@ -142,7 +142,7 @@ clean: rm -f vm/*.o vm/resources.o: - $(WINDRES) vm/factor.rs vm/resources.o + windres vm/factor.rs vm/resources.o .c.o: $(CC) -c $(CFLAGS) -o $@ $< diff --git a/vm/Config.macosx.x86.64 b/vm/Config.macosx.x86.64 new file mode 100644 index 0000000000..e2063c4a75 --- /dev/null +++ b/vm/Config.macosx.x86.64 @@ -0,0 +1,3 @@ +include vm/Config.macosx +include vm/Config.x86.64 +CFLAGS += -arch x86_64 From 4ea887e7665b5e262b800c1e8bd71ddb95c27ed9 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 23:19:06 -0500 Subject: [PATCH 5/7] macosx-x86-64 more --- vm/platform.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm/platform.h b/vm/platform.h index 75228726a9..a3b7350b69 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -30,6 +30,8 @@ #include "os-macosx-x86.32.h" #elif defined(FACTOR_PPC) #include "os-macosx-ppc.h" + #elif defined(FACTOR_AMD64) + #include "os-macosx-x86.64.h" #else #error "Unsupported Mac OS X flavor" #endif @@ -70,6 +72,7 @@ #elif defined(FACTOR_ARM) #include "os-linux-arm.h" #elif defined(FACTOR_AMD64) + #include "os-unix-ucontext.h" #include "os-linux-x86-64.h" #else #error "Unsupported Linux flavor" From 637c1ad0e4fc48d713891ff197747f5cd39ecac4 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 23:33:05 -0500 Subject: [PATCH 6/7] macosx-x86-64 --- vm/os-macosx-x86.64.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 vm/os-macosx-x86.64.h diff --git a/vm/os-macosx-x86.64.h b/vm/os-macosx-x86.64.h new file mode 100644 index 0000000000..d2bb48c3fe --- /dev/null +++ b/vm/os-macosx-x86.64.h @@ -0,0 +1,35 @@ +/* Fault handler information. MacOSX version. +Copyright (C) 1993-1999, 2002-2003 Bruno Haible +Copyright (C) 2003 Paolo Bonzini + +Used under BSD license with permission from Paolo Bonzini and Bruno Haible, +2005-03-10: + +http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org + +Modified for Factor by Slava Pestov and Daniel Ehrenberg */ +#define MACH_EXC_STATE_TYPE x86_exception_state64_t +#define MACH_EXC_STATE_FLAVOR x86_EXCEPTION_STATE64 +#define MACH_EXC_STATE_COUNT x86_EXCEPTION_STATE64_COUNT +#define MACH_THREAD_STATE_TYPE x86_thread_state64_t +#define MACH_THREAD_STATE_FLAVOR x86_THREAD_STATE64 +#define MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT + +#if __DARWIN_UNIX03 + #define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->__faultvaddr + #define MACH_STACK_POINTER(thr_state) (thr_state)->__rsp + #define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->__rip + #define UAP_PROGRAM_COUNTER(ucontext) \ + MACH_PROGRAM_COUNTER(&(((ucontext_t *)(ucontext))->uc_mcontext->__ss)) +#else + #define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->faultvaddr + #define MACH_STACK_POINTER(thr_state) (thr_state)->rsp + #define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->rip + #define UAP_PROGRAM_COUNTER(ucontext) \ + MACH_PROGRAM_COUNTER(&(((ucontext_t *)(ucontext))->uc_mcontext->ss)) +#endif + +INLINE CELL fix_stack_pointer(CELL sp) +{ + return ((sp + 8) & ~15) - 8; +} From 34e29cd690ccde13168cc56f586f7ea69d7d5948 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 12 Dec 2007 00:33:36 -0500 Subject: [PATCH 7/7] Multiline string literal naming --- extra/multiline/multiline-docs.factor | 4 ++-- extra/multiline/multiline.factor | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor index 05ccdefe6f..7e7375cfad 100644 --- a/extra/multiline/multiline-docs.factor +++ b/extra/multiline/multiline-docs.factor @@ -14,8 +14,8 @@ HELP: parse-here { $values { "str" "a string" } } { $description "Parses a multiline string literal, as used by " { $link POSTPONE: STRING: } "." } ; -HELP: parse-literal +HELP: parse-multiline-string { $values { "end-text" "a string delineating the end" } { "str" "the parsed string" } } { $description "Parses a multiline string literal, as used by " { $link POSTPONE: <" } ". The end-text is the delimiter for the end." } ; -{ parse-here parse-literal } related-words +{ parse-here parse-multiline-string } related-words diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor index e808b78997..89a6e06053 100644 --- a/extra/multiline/multiline.factor +++ b/extra/multiline/multiline.factor @@ -18,18 +18,18 @@ IN: multiline CREATE dup reset-generic parse-here 1quotation define-compound ; parsing -: (parse-literal) ( start-index end-text -- end-index ) +: (parse-multiline-string) ( start-index end-text -- end-index ) lexer get line-text 2dup start [ rot dupd >r >r swap subseq % r> r> length + ] [ rot tail % "\n" % 0 - lexer get next-line swap (parse-literal) + lexer get next-line swap (parse-multiline-string) ] if* ; -: parse-literal ( end-text -- str ) +: parse-multiline-string ( end-text -- str ) [ - lexer get lexer-column swap (parse-literal) + lexer get lexer-column swap (parse-multiline-string) lexer get set-lexer-column ] "" make 1 tail 1 head* ; : <" - "\">" parse-literal parsed ; parsing + "\">" parse-multiline-string parsed ; parsing