├── .gitignore
├── README
├── html
├── LICENSE.html
├── allhelp.html
├── faq.html
├── faq1.html
├── forth-joy.html
├── html-head.html
├── html-manual.html
├── html-tail.html
├── j-mini-clisp.html
├── j-pico-prolog.html
├── j00ovr.html
├── j00rat.html
├── j01tut.html
├── j02maf.html
├── j03atm.html
├── j04alg.html
├── j05cmp.html
├── j06prg.html
├── j07rrs.html
├── j08cnt.html
├── j09imp.html
├── j1prospect.html
├── j1src.html
├── jmisc.html
├── joybibl.bib
├── jp-church.html
├── jp-flatjoy.html
├── jp-imper.html
├── jp-joyjoy.html
├── jp-matmul.html
├── jp-nestrec.html
├── jp-quadratic.html
├── jp-reprod.html
├── jp-survrep.html
├── jp-trutab.html
├── jpearls.html
├── plain-manual.html
├── rec-comb.html
├── refs.html
└── synops.html
├── joy.html
├── joybibl.bib
├── reading
└── the-theory-of-concatenative-combinators.html
└── src
├── agglib.joy
├── fraclib.joy
├── gc
├── .gitattributes
├── .gitignore
├── AUTHORS
├── BCC_MAKEFILE
├── CMakeLists.txt
├── ChangeLog
├── EMX_MAKEFILE
├── Makefile.am
├── Makefile.direct
├── NT_MAKEFILE
├── NT_STATIC_THREADS_MAKEFILE
├── NT_X64_STATIC_THREADS_MAKEFILE
├── NT_X64_THREADS_MAKEFILE
├── OS2_MAKEFILE
├── PCR-Makefile
├── README.QUICK
├── README.md
├── SMakefile.amiga
├── TODO
├── WCC_MAKEFILE
├── allchblk.c
├── alloc.c
├── autogen.sh
├── backgraph.c
├── bdw-gc.pc.in
├── blacklst.c
├── build
│ └── s60v3
│ │ ├── bld.inf
│ │ └── libgc.mmp
├── checksums.c
├── configure.ac
├── cord
│ ├── cord.am
│ ├── cordbscs.c
│ ├── cordprnt.c
│ ├── cordxtra.c
│ └── tests
│ │ ├── cordtest.c
│ │ ├── de.c
│ │ ├── de_cmds.h
│ │ ├── de_win.c
│ │ ├── de_win.h
│ │ └── de_win.rc
├── darwin_stop_world.c
├── dbg_mlc.c
├── digimars.mak
├── doc
│ ├── README.DGUX386
│ ├── README.Mac
│ ├── README.OS2
│ ├── README.amiga
│ ├── README.arm.cross
│ ├── README.autoconf
│ ├── README.cmake
│ ├── README.cords
│ ├── README.darwin
│ ├── README.environment
│ ├── README.ews4800
│ ├── README.hp
│ ├── README.linux
│ ├── README.macros
│ ├── README.rs6000
│ ├── README.sgi
│ ├── README.solaris2
│ ├── README.symbian
│ ├── README.uts
│ ├── README.win32
│ ├── README.win64
│ ├── debugging.html
│ ├── doc.am
│ ├── finalization.html
│ ├── gc.man
│ ├── gcdescr.html
│ ├── gcinterface.html
│ ├── leak.html
│ ├── overview.html
│ ├── porting.html
│ ├── scale.html
│ ├── simple_example.html
│ └── tree.html
├── dyn_load.c
├── extra
│ ├── AmigaOS.c
│ ├── MacOS.c
│ ├── Mac_files
│ │ ├── MacOS_config.h
│ │ ├── dataend.c
│ │ └── datastart.c
│ ├── gc.c
│ ├── msvc_dbg.c
│ ├── symbian.cpp
│ └── symbian
│ │ ├── global_end.cpp
│ │ ├── global_start.cpp
│ │ └── init_global_static_roots.cpp
├── finalize.c
├── fnlz_mlc.c
├── gc.mak
├── gc_cpp.cc
├── gc_cpp.cpp
├── gc_dlopen.c
├── gcj_mlc.c
├── headers.c
├── ia64_save_regs_in_stack.s
├── include
│ ├── cord.h
│ ├── cord_pos.h
│ ├── ec.h
│ ├── extra
│ │ ├── gc.h
│ │ └── gc_cpp.h
│ ├── gc.h
│ ├── gc_allocator.h
│ ├── gc_backptr.h
│ ├── gc_config_macros.h
│ ├── gc_cpp.h
│ ├── gc_disclaim.h
│ ├── gc_gcj.h
│ ├── gc_inline.h
│ ├── gc_mark.h
│ ├── gc_pthread_redirects.h
│ ├── gc_tiny_fl.h
│ ├── gc_typed.h
│ ├── gc_version.h
│ ├── include.am
│ ├── javaxfc.h
│ ├── leak_detector.h
│ ├── new_gc_alloc.h
│ ├── private
│ │ ├── darwin_semaphore.h
│ │ ├── darwin_stop_world.h
│ │ ├── dbg_mlc.h
│ │ ├── gc_hdrs.h
│ │ ├── gc_locks.h
│ │ ├── gc_pmark.h
│ │ ├── gc_priv.h
│ │ ├── gcconfig.h
│ │ ├── msvc_dbg.h
│ │ ├── pthread_stop_world.h
│ │ ├── pthread_support.h
│ │ ├── specific.h
│ │ └── thread_local_alloc.h
│ └── weakpointer.h
├── m4
│ └── gc_set_version.m4
├── mach_dep.c
├── malloc.c
├── mallocx.c
├── mark.c
├── mark_rts.c
├── misc.c
├── new_hblk.c
├── obj_map.c
├── os_dep.c
├── pcr_interface.c
├── pthread_start.c
├── pthread_stop_world.c
├── pthread_support.c
├── ptr_chck.c
├── real_malloc.c
├── reclaim.c
├── sparc_mach_dep.S
├── sparc_netbsd_mach_dep.s
├── sparc_sunos4_mach_dep.s
├── specific.c
├── stubborn.c
├── tests
│ ├── CMakeLists.txt
│ ├── disclaim_bench.c
│ ├── disclaim_test.c
│ ├── huge_test.c
│ ├── initsecondarythread.c
│ ├── leak_test.c
│ ├── middle.c
│ ├── realloc_test.c
│ ├── smash_test.c
│ ├── staticrootslib.c
│ ├── staticrootstest.c
│ ├── subthread_create.c
│ ├── test.c
│ ├── test_cpp.cc
│ ├── tests.am
│ ├── thread_leak_test.c
│ ├── threadkey_test.c
│ └── trace_test.c
├── thread_local_alloc.c
├── tools
│ ├── add_gc_prefix.c
│ ├── callprocs.sh
│ ├── gcname.c
│ ├── if_mach.c
│ ├── if_not_there.c
│ ├── setjmp_t.c
│ └── threadlibs.c
├── typd_mlc.c
├── win32_threads.c
└── windows-untested
│ ├── README
│ ├── gc.def
│ ├── gc.rc
│ ├── gc.ver
│ ├── stdafx.c
│ ├── stdafx.h
│ ├── vc60
│ ├── all.dsp
│ ├── gc.dsp
│ ├── gc.dsw
│ ├── libgc.dsp
│ ├── libgcmt.dsp
│ ├── test.dsp
│ ├── test_gc.dsp
│ ├── test_leak_gc.dsp
│ ├── test_leak_libgc.dsp
│ ├── test_leak_libgcmt.dsp
│ ├── test_libgc.dsp
│ ├── test_libgcmt.dsp
│ └── vc60crlf.cmd
│ ├── vc70
│ ├── all.vcproj
│ ├── gc.sln
│ ├── gc.vcproj
│ ├── libgc.vcproj
│ ├── libgcmt.vcproj
│ ├── test.vcproj
│ ├── test_gc.vcproj
│ ├── test_leak_gc.vcproj
│ ├── test_leak_libgc.vcproj
│ ├── test_leak_libgcmt.vcproj
│ ├── test_libgc.vcproj
│ └── test_libgcmt.vcproj
│ ├── vc71
│ ├── all.vcproj
│ ├── gc.sln
│ ├── gc.vcproj
│ ├── libgc.vcproj
│ ├── libgcmt.vcproj
│ ├── test.vcproj
│ ├── test_gc.vcproj
│ ├── test_leak_gc.vcproj
│ ├── test_leak_libgc.vcproj
│ ├── test_leak_libgcmt.vcproj
│ ├── test_libgc.vcproj
│ └── test_libgcmt.vcproj
│ └── vc9
│ ├── libgc.vcproj
│ ├── test_cpp_libgc.vcproj
│ ├── test_huge.vcproj
│ ├── test_leak.vcproj
│ └── test_libgc.vcproj
├── globals.h
├── grmlib.joy
├── grmtst.joy
├── grmtst.out
├── inilib.joy
├── interp.c
├── joytut.inp
├── joytut.joy
├── joytut.out
├── jp-church.joy
├── jp-joyjoy.joy
├── jp-joytst.joy
├── jp-joytst.out
├── jp-nestrec.joy
├── lazlib.joy
├── laztst.joy
├── laztst.out
├── lsplib.joy
├── lsptst.joy
├── lsptst.out
├── main.c
├── make.gc
├── make.gc-debug
├── make.nogc
├── makefile
├── modtst.joy
├── modtst.out
├── mthlib.joy
├── mtrlib.joy
├── mtrtst.joy
├── mtrtst.out
├── numlib.joy
├── plain-manual.html
├── plglib.joy
├── plgtst.joy
├── plgtst.out
├── scan.c
├── seqlib.joy
├── symlib.joy
├── symtst.joy
├── symtst.out
├── test.joy
├── tutlib.joy
├── typlib.joy
├── usrlib.joy
└── utils.c
/.gitignore:
--------------------------------------------------------------------------------
1 | src/joy
2 | src/joy-no-gc
3 | *o
4 | *~
5 | *#
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | -----------------------------------
2 |
3 | backup of the joy programming language
4 |
5 | a copy of http://www.kevinalbrecht.com/code/joy-mirror/joy.html
6 |
7 | -----------------------------------
8 |
9 | * note that
10 | the code base is not clean in my view
11 | thus I do not maintain this implementation
12 | I just learn from the design of the language
13 |
14 | * if you care about the life of joy language
15 | and you consider the code base hackable
16 | do a fork and maintain it
17 |
18 | * I also play with a joy-like language in js
19 | here : https://github.com/xieyuheng/sad-coffee
20 |
21 | -----------------------------------
22 |
23 | * dependencies
24 | joy use the following GC
25 | https://github.com/ivmai/bdwgc
26 | I do not use git submodule
27 | for the repo is too big
28 | instead the following commit is used
29 | 7aba59b5853330c9368bc16dd606e1617c704334
30 | I simply include the source code into joy's src directory
31 |
32 | -----------------------------------
33 |
34 | to build the interpreter of joy
35 | just type make
36 |
37 | -----------------------------------
38 |
39 | * joy library
40 | * usrlib.joy -- personal user library, loaded by default
41 | * inilib.joy -- the initial library of the joy system
42 | * the basic libraries
43 | * agglib.joy -- aggregates: sets, lists, strings
44 | * seqlib.joy -- sequences: lists, strings with ordering
45 | * numlib.joy -- numeric: integers, floats
46 | * symlib.joy -- symbolic manipulation (only translations)
47 | symtst.joy -- test file
48 | symtst.out -- output
49 | * the special libraries
50 | * mtrlib.joy -- matrices and vectors
51 | mtrtst.joy -- test file
52 | mtrtst.out -- output
53 | * tutlib.joy -- interactive tutorials
54 | joytut.joy -- an application
55 | joytut.com -- a (pseudo) input
56 | joytut.out -- output
57 | * lazlib.joy -- "lazy" infinite and finite lists
58 | laztst.joy -- test file
59 | laztst.out -- output
60 | * lsplib.joy -- a small (eval-apply) lisp interpreter
61 | lsplib.lsp -- a small library for this version of lisp
62 | lsptst.joy
63 | lsptst.lsp -- input
64 | lsptst.out -- output
65 | * plglib.joy -- propositional logic semantic tableaux
66 | plgtst.joy -- test file
67 | plgtst.out -- output
68 | * grmlib.joy -- grammar library (generating and parsing)
69 | grmtst.joy -- test file
70 | grmtst.out -- output
71 |
72 | -----------------------------------
73 |
--------------------------------------------------------------------------------
/html/LICENSE.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Copyright (c) 2002 Manfred von Thun
4 | All rights reserved.
5 |
6 | This license applies to all software associated with the language
7 | Joy: the interpreter written in C, the libraries and other
8 | programs written in Joy, and any other programs on this web page.
9 |
10 | Redistribution and use in source and binary forms, with or without
11 | modification, are permitted provided that the following conditions
12 | are met:
13 | 1. Redistributions of source code must retain the above copyright
14 | notice, this list of conditions and the following disclaimer.
15 | 2. Redistributions in binary form must reproduce the above copyright
16 | notice, this list of conditions and the following disclaimer in the
17 | documentation and/or other materials provided with the distribution.
18 | 3. The name of the author may not be used to endorse or promote products
19 | derived from this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/html/html-head.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/html/html-tail.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/html/j1prospect.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Prospectus for John Cowan's Joy1
4 | Prospectus for John Cowan's Joy1
5 |
6 |
7 | John Cowan's Joy1 is essentially the old prototype of Joy
8 | with the following additions:
9 |
10 | - Floats (real numbers) as a new datatype, together with
11 | numerous new functions over floats.
12 |
- Files as a datatype, together with some common functions
13 | for manipulating files and doing I/O.
14 |
- Some new string functions. Also, on most platforms, an option
15 | to include garbage collection for strings.
16 |
- Some bugs in the old prototype have been fixed. Portability
17 | has been further increased. Joy1 will still compile and run
18 | with any strictly conforming ISO C compiler.
19 |
20 |
21 | The currently supported platforms for the general garbage collector
22 | include Unix/Linux/*BSD on i386/Alpha/SPARC/SGI/HP, OS/2,
23 | Win32 native/Cygwin/DJGPP, and perhaps Macintosh. One system
24 | known *not* to work is OpenVMS (here the 4 C-files have
25 | to be compiled and linked in the usual manner).
26 | Joy1 has not yet been built on all these systems.
27 |
28 | It is intended that the new implementation become known as Joy1,
29 | and that the earlier prototype, now Joy0, should gradually fade away.
30 | However, for compatiblity reasons the prototype Joy0
31 | C sources have been updated (16-JUN-01).
32 |
33 | I am enormously grateful to John for his work.
34 |
35 |
--------------------------------------------------------------------------------
/html/j1src.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | C Sources of John Cowan's JOY1 implementation
4 |
5 |
6 | These are John Cowan's C-sources for Joy1, the new version of Joy.
7 | The sources have been compiled on various Unix and non-Unix systems
8 | apparently without any problems.
9 | (If you do not have the BDW garbage collected version yet,
10 | go back to the main page to fetch the current joy.tar.gz .)
11 |
12 | Use the files here (or just the joy1src.tar.gz at the end)
13 |
14 | IF you only have limited discspace
15 | OR you are not running unix,
16 | OR you wish to update just the C-sources:
17 |
18 |
39 |
40 | Mailto: phimvt
41 | (email: phimvt@lurac.latrobe.edu.au).
42 |
43 |
Back to
44 | Synopsis of Joy
45 |
46 |
47 |
--------------------------------------------------------------------------------
/html/jmisc.html:
--------------------------------------------------------------------------------
1 |
2 |
Miscellanous Joy matters
3 | This page contains pointers to several miniature implementations of Joy.
4 | None of them are compatible with the current version of Joy,
5 | but all of them capture its essence.
6 | Maybe they wil be of use to some people who want
7 | to write up to date versions of Joy
8 | in some language other than C.
9 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/html/jpearls.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Pearls of Joy
4 |
5 |
6 | A collection of diverse examples of program development in Joy.
7 |
8 |
28 |
29 | Mailto: phimvt
30 | (email: phimvt@lure.latrobe.edu.au).
31 |
32 |
Back to
33 | Synopsis of Joy
34 |
35 |
36 |
--------------------------------------------------------------------------------
/html/refs.html:
--------------------------------------------------------------------------------
1 |
References
2 | References
3 |
4 |
5 | - {Arbib and Manes}{1975 Chapter X}{Arbib-Manes:75}
6 |
- {Asperti and Longo}{1991 Section 4.2}{Asperti-Longo:91}
7 |
- {Backus}{1978}{Backus:78}
8 |
- {Barwise and Etchemendy}{1987}{Barwise-Etchemendy:87}
9 |
- {Bird and de Moor}{1992}{Bird-deMoor:92}
10 |
- {Bird}{1986}{Bird:86}
11 |
- {Burge}{1975}{Burge:75}
12 |
- {Curry and Feys}{1958}{Curry:58}
13 |
- {Curry}{1958}{Curry:58}
14 |
- {Henson}{1987}{Henson:87}
15 |
- {Hofstadter}{1985}{Hofstadter:85}
16 |
- {Jones}{1992}{Jones:92}
17 |
- {Malcolm}{1989}{Malcolm:89}
18 |
- {Martin}{1970}{Martin:70}
19 |
- {Meijer et al}{1991}{Meijer-etal:91}
20 |
- {Mendelson}{1964}{Mendelson:64}
21 |
- {Pierce}{1991}{Pierce:91}
22 |
- {Poigne}{1992}{Poigne:92}
23 |
- {Quine}{1971}{Quine:71}
24 |
- {Rogers}{1967}{Rogers:67}
25 |
- {Rydeheard}{1985}{Rydeheard:85}
26 |
- {Smullyan}{1961}{Smullyan:61}
27 |
- {Smullyan}{1990}{Smullyan:90}
28 |
- {Spivey}{1989}{Spivey:89}
29 |
- {Tennent}{1991 Chapter 8}{Tennent:91}
30 |
- {Wadler}{1992}{Wadler:92}
31 |
- {Walters}{1991}{Walters:91}
32 |
- {von Thun}{1995}{j00lov}
33 |
- {Barendregt}{1984 p 132}{Barendregt:84}
34 |
- {Bauer and Wϧssner}{1982 p 107}{Bauer-Woessner:82}
35 |
- {Henson}{1987 p 35}{Henson:87}
36 |
- {Henson}{1987 p 36}{Henson:87}
37 |
- {Henson}{1987 p 37}{Henson:87}
38 |
- {Kogge}{1991 p 105}{Kogge:91}
39 |
- {Paulson}{1992 p 207}{Paulson:92}
40 |
- {Phillips}{1992 p 173}{Phillips:92}
41 |
- {Phillips}{1992 p 81}{Phillips:92}
42 |
- {Poigne}{1992, p 447}{Poigne:92}
43 |
- {Schmidt}{1986 p 157}{Schmidt:86}
44 |
- {Sokolowski}{1991 p 83}{Sokolowski:91}
45 |
- {Stoy}{1977 p 72}{Stoy:77}
46 |
- {Tennent}{1976 p 442}{Tennent:76}
47 |
- {Tennent}{1991 p 218}{Tennent:91}
48 |
- {Wadler}{1992 p 14}{Wadler:92}
49 |
- {Paulson}{1992 pp 349 and 351}{Paulson:92}
50 |
- {Revesz}{1988 pp 47-48}{Revesz:88}
51 |
- {Rogers}{1967 pp 34 and 324}{Rogers:67}
52 |
- {Smullyan}{1994 pp 19, 263, 336}{Smullyan:94}
53 |
- {Winskel}{1993 pp 272 and 292}{Winskel:93}
54 |
55 |
56 |
57 | Manfred von Thun
58 | Philosophy Department, La Trobe University,
59 | Bundoora, Melbourne, VIC 3093, Australia
60 | Voice: (03) 9479 2932
61 | Email: phimvt@lure.latrobe.edu.au
62 |
63 |
--------------------------------------------------------------------------------
/html/synops.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Synopsis of the Language JOY
4 |
5 |
6 |
7 | The language Joy is a purely functional programming language.
8 | Whereas all other functional programming languages are based
9 | on the application of functions to arguments,
10 | Joy is based on the composition of functions.
11 | All such functions take a stack as argument and produce
12 | a stack as value.
13 | Consequently much of Joy looks like ordinary postfix notation.
14 | However, in Joy a function can consume any number of
15 | parameters from the stack and leave any number of results on the stack.
16 | The concatenation of appropriate programs denotes
17 | the composition of the functions which the programs denote.
18 | One of the datatypes of Joy is that of quoted programs,
19 | of which lists are a special case.
20 | Some functions expect quoted programs on top of the stack
21 | and execute them in many different ways, effectively by dequoting.
22 | So, where other functional languages use abstraction and application,
23 | Joy uses quotation and combinators -- functions which perform dequotation.
24 | As a result, there are no named formal parameters,
25 | no substitution of actual for formal parameters,
26 | and no environment of name-value pairs.
27 | Combinators in Joy
28 | behave much like functionals or higher order functions in other languages,
29 | they minimise the need for recursive and non-recursive definitions.
30 | Because there is no need for an environment,
31 | Joy has an exceptionally simple algebra,
32 | and its programs are easily manipulated by hand and by other programs.
33 | Many programs first construct another program which is then
34 | executed.
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/agglib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: agglib.joy *)
2 |
3 | LIBRA
4 |
5 | _agglib == true;
6 |
7 | (* - - - - - O P E R A T O R S - - - - - *)
8 |
9 | unitset == {} cons;
10 | unitstring == "" cons;
11 | unitlist == [] cons;
12 | pairset == {} cons cons;
13 | pairstring == "" cons cons;
14 | pairlist == [] cons cons;
15 | unpair == uncons uncons pop;
16 | second == rest first;
17 | third == rest rest first;
18 | fourth == 3 drop first;
19 | fifth == 4 drop first;
20 | string2set == {} swap shunt;
21 | elements == {} swap [swons] step;
22 | (*
23 |
set2string == "" swap [chr swons] step;
24 | *)
25 | set2string == "" [[chr] dip cons] foldr;
26 | shunt == [swons] step;
27 |
28 | (* "dipped" versions *)
29 |
30 | nulld == [null] dip;
31 | consd == [cons] dip;
32 | swonsd == [swons] dip;
33 | unconsd == [uncons] dip;
34 | unswonsd == [unswons] dip;
35 | firstd == [first] dip;
36 | restd == [rest] dip;
37 | secondd == [secondd] dip;
38 | thirdd == [third] dip;
39 |
40 | (* on two operands *)
41 |
42 | null2 == nulld null or;
43 | cons2 == swapd cons consd;
44 | uncons2 == unconsd uncons swapd;
45 | swons2 == swapd swons swonsd;
46 | unswons2 == [unswons] dip unswons swapd;
47 |
48 | zip == [null2] [pop2 []] [uncons2] [[pairlist] dip cons] linrec;
49 |
50 | from-to == (* lo hi agg *)
51 | [] cons [pop pop] swoncat
52 | [>] swap
53 | [ [dup succ] dip ]
54 | [cons]
55 | linrec;
56 | from-to-list == [] from-to;
57 | from-to-set == {} from-to;
58 | from-to-string == "" from-to;
59 |
60 | (* - - - - - C O M B I N A T O R S - - - - - *)
61 |
62 | (* Left to Right *)
63 |
64 | (* inbuilt: step map fold filter split *)
65 | (* desirable: step2 map2 fold2 *)
66 |
67 | (* cartesian product -like *)
68 | pairstep == [dupd] swoncat [step pop] cons cons step;
69 |
70 | (* Right to Left *)
71 |
72 | mapr ==
73 | [ [null] [] [uncons] ] dip (* P1 P2 P3 *)
74 | [dip cons] cons (* P4 *)
75 | linrec;
76 | foldr ==
77 | [ [ [null] ] dip (* P1 *)
78 | [] cons [pop] swoncat (* P2 *)
79 | [uncons] ] dip (* P3 *)
80 | linrec;
81 |
82 | stepr2 ==
83 | [ [null2] [pop pop] ] dip (* P1 P2 *)
84 | [dip] cons [dip] cons [uncons2] swoncat (* P3 *)
85 | tailrec;
86 | fold2 == rollupd stepr2;
87 |
88 | mapr2 == (* == zipwith B&W p 57 *)
89 | [ [null2] [pop2 []] [uncons2] ] dip (* P1 P2 P3 *)
90 | [dip cons] cons (* P4 *)
91 | linrec;
92 | foldr2 ==
93 | [ [ [null2] ] dip (* P1 *)
94 | [] cons [pop2] swoncat (* P2 *)
95 | [uncons2] ] dip (* P3 *)
96 | linrec;
97 | interleave2 == [cons cons] foldr2;
98 | interleave2list == [] interleave2;
99 |
100 | sum == 0 [+] fold;
101 | average == [sum] [size] cleave / ;
102 | variance == (* [..] variance *)
103 | 0.0 swap dup (* 0.0 [..] [..] *)
104 | [sum] [size] cleave dup (* 0.0 [..] su n n *)
105 | [ / (* 0.0 [..] av n *)
106 | [ - dup * + ] cons (* 0.0 [..] [av - dup * +] n *)
107 | step ] (* sumsq n *)
108 | dip
109 | pred / ;
110 |
111 | AGGLIB == "agglib.joy - aggregate library\n".
112 | (* end LIBRA *)
113 |
114 | "agglib is loaded\n" putchars.
115 |
116 | (* END agglib.joy *)
117 |
--------------------------------------------------------------------------------
/src/fraclib.joy:
--------------------------------------------------------------------------------
1 | (******************************************************************************
2 | * fraclib.joy - a simple fractal generator example.
3 | * Nick Forde (March 2002)
4 | * The main definition is 'mandel' which may be run without arguments.
5 | * This implementation uses a single loop through all x & y coordinates and
6 | * maintains state by manipulating the aggregate [I:z1 I:z2 F:c1 F:c2].
7 | * $Id: fraclib.joy,v 1.3 2002/03/26 16:17:06 nickf Exp nickf $
8 | ******************************************************************************)
9 |
10 | "seqlib" libload.
11 |
12 | LIBRA
13 |
14 | nrows == 30; ncols == 75; (* size of output display *)
15 | mandel == -1 nrows ncols * (* one loop for rows & cols. *)
16 | [ succ dup dup [col] dip row (* calc. column & row indices *)
17 | get_c1 swap get_c2 (* calc. coefficients 1 & 2 *)
18 | get_k putpt (* calc. k and then print *)
19 | [eol] ['\n putch] [] ifte (* put newline if appropriate *)
20 | ] times; (* loop for each cell *)
21 | row == ncols /; (* I:i -> I:row *)
22 | col == ncols rem; (* I:i -> I:col *)
23 | eol == col ncols pred =; (* I:i -> B *)
24 | putpt == 16 rem " .:,;!/>)|&IH%*#" of putch; (* we've a palette of 16 *)
25 | get_k == pairlist [0 0] swoncat (* F:c1 F:c2 -> A *)
26 | 0 [112 <= [eoloop] dip and] (* condition *)
27 | [succ [inc_zs] dip] while (* if true *)
28 | popd 1 -; (* cleanup -> I *)
29 | get_c1 == 0.10 * 1.5 -; (* outer loop coeff. I:i -> F *)
30 | get_c2 == 0.04 * 2.0 -; (* inner loop coeff. I:i -> F *)
31 | sqr_z1 == first dup *; (* A -> I *)
32 | sqr_z2 == 1 at dup *; (* A -> I *)
33 | inc_z1 == dup [sqr_z1] [sqr_z2] cleave - (* (z1*z1)-(z2*z2)+c2 *)
34 | [3 at] dip +; (* A -> I *)
35 | inc_z2 == 3 take reverse uncons uncons (* (2*z1*z2)+c1 *)
36 | uncons pop (* *)
37 | 2 * * + ; (* A -> I *)
38 | eoloop == dup sqr_z1 swap sqr_z2 + 10 <=; (* (z1*z1)+(z2*z2)<=10 A -> B *)
39 | inc_zs == dup [inc_z1] [inc_z2] cleave (* *)
40 | pairlist swap rest rest concat; (* A -> A *)
41 |
42 | FRACLIB == "fraclib.joy - fractal library\n".
43 | "fraclib is loaded\n" putchars.
44 |
45 | (******************************************************************************
46 | * END fraclib.joy
47 | ******************************************************************************)
48 |
--------------------------------------------------------------------------------
/src/gc/.gitattributes:
--------------------------------------------------------------------------------
1 | # Git repo attributes.
2 |
3 | # Ensure all text files have normalized (LF) line endings in the repository.
4 | * text=auto
5 |
6 | # These files should use CR/LF line ending:
7 | /BCC_MAKEFILE -text
8 | /digimars.mak -text
9 |
10 | # Note: "core.eol" configuration variable controls which line endings to use
11 | # for the normalized files in the working directory (the default is native).
12 |
--------------------------------------------------------------------------------
/src/gc/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignored files in bdwgc Git repo.
2 |
3 | # Binary files (in root dir, cord, tests):
4 | *.dll
5 | *.exe
6 | *.gcda
7 | *.gch
8 | *.gcno
9 | *.la
10 | *.lib
11 | *.lo
12 | *.o
13 | *.obj
14 |
15 | .dirstamp
16 | /*.gc.log
17 | /*_bench.log
18 | /*_bench.trs
19 | /*test.log
20 | /*test.trs
21 | /.libs/
22 | /Makefile
23 | /add_gc_prefix
24 | /base_lib
25 | /bdw-gc.pc
26 | /c++
27 | /config.cache
28 | /config.log
29 | /config.status
30 | /cord/cordtest
31 | /cord/de
32 | /cord/de_win.rbj
33 | /cord/de_win.res
34 | /cord/tests/de_win.res
35 | /cordtest
36 | /core
37 | /de
38 | /disclaim_bench
39 | /disclaim_test
40 | /gc-*
41 | /gc.a
42 | /gc.log
43 | /gcname
44 | /gctest
45 | /hugetest
46 | /if_mach
47 | /if_not_there
48 | /initsecondarythread_test
49 | /leaktest
50 | /libtool
51 | /middletest
52 | /realloc_test
53 | /setjmp_test
54 | /smashtest
55 | /staticrootstest
56 | /subthreadcreate_test
57 | /test-suite.log
58 | /test_cpp
59 | /test_cpp.log
60 | /test_cpp.trs
61 | /threadkey_test
62 | /threadleaktest
63 | /threadlibs
64 | /tracetest
65 |
66 | # Config, dependency and stamp files generated by configure:
67 | .deps/
68 | config.h
69 | config.h.in~
70 | stamp-h1
71 |
72 | # External library (without trailing slash to allow symlinks):
73 | /libatomic_ops*
74 | /pthreads-w32*
75 |
76 | # These files are generated by autoreconf:
77 | /Makefile.in
78 | /aclocal.m4
79 | /autom4te.cache/
80 | /compile
81 | /config.guess
82 | /config.sub
83 | /configure
84 | /depcomp
85 | /include/config.h.in
86 | /install-sh
87 | /ltmain.sh
88 | /m4/libtool.m4
89 | /m4/ltoptions.m4
90 | /m4/ltsugar.m4
91 | /m4/ltversion.m4
92 | /m4/lt~obsolete.m4
93 | /missing
94 | /mkinstalldirs
95 | /test-driver
96 |
97 | # These files are generated by CMake:
98 | /*.vcxproj
99 | /*.vcxproj.filters
100 | /CMakeCache.txt
101 | /CMakeFiles/
102 | /cmake_install.cmake
103 | /gc.sln
104 | /tests/*.vcxproj
105 | /tests/*.vcxproj.filters
106 | /tests/CMakeFiles/
107 | /tests/Makefile
108 | /tests/cmake_install.cmake
109 |
110 | # Rarely generated files (mostly by some Win/DOS compilers):
111 | /*.bsc
112 | /*.csm
113 | /*.err
114 | /*.exp
115 | /*.lb1
116 | /*.lnk
117 | /*.map
118 | /*.out
119 | /*.pdb
120 | /*.rbj
121 | /*.res
122 | /*.sbr
123 | /*.stackdump
124 | /*.sym
125 | /*.tmp
126 |
127 | # Stuff from VS build system and IDE
128 | *.vcproj.*.user
129 |
--------------------------------------------------------------------------------
/src/gc/BCC_MAKEFILE:
--------------------------------------------------------------------------------
1 | # Makefile for Borland C++ 5.5 on NT
2 | # If you have the Borland assembler, remove "-DUSE_GENERIC"
3 | #
4 | bc= c:\Borland\BCC55
5 | bcbin= $(bc)\bin
6 | bclib= $(bc)\lib
7 | bcinclude= $(bc)\include
8 |
9 | gcinclude1 = $(bc)\gc6.2\include
10 | gcinclude2 = $(bc)\gc6.2\cord
11 |
12 | cc= $(bcbin)\bcc32
13 | rc= $(bcbin)\brc32
14 | lib= $(bcbin)\tlib
15 | link= $(bcbin)\ilink32
16 | cflags= -O2 -R -v- -vi -H -H=gc.csm -I$(bcinclude);$(gcinclude1);$(gcinclude2) -L$(bclib) \
17 | -w-pro -w-aus -w-par -w-ccc -w-rch -a4
18 | defines= -DALL_INTERIOR_POINTERS -DUSE_GENERIC -DNO_GETENV -DJAVA_FINALIZATION -DGC_OPERATOR_NEW_ARRAY
19 |
20 | .c.obj:
21 | $(cc) @&&|
22 | $(cdebug) $(cflags) $(cvars) $(defines) -o$* -c $*.c
23 | |
24 |
25 | .cpp.obj:
26 | $(cc) @&&|
27 | $(cdebug) $(cflags) $(cvars) $(defines) -o$* -c $*.cpp
28 | |
29 |
30 | .rc.res:
31 | $(rc) -i$(bcinclude) -r -fo$* $*.rc
32 |
33 | XXXOBJS= XXXalloc.obj XXXreclaim.obj XXXallchblk.obj XXXmisc.obj \
34 | XXXmach_dep.obj XXXos_dep.obj XXXmark_rts.obj XXXheaders.obj XXXmark.obj \
35 | XXXobj_map.obj XXXblacklst.obj XXXfinalize.obj XXXnew_hblk.obj \
36 | XXXdbg_mlc.obj XXXmalloc.obj XXXstubborn.obj XXXdyn_load.obj \
37 | XXXtypd_mlc.obj XXXptr_chck.obj XXXgc_cpp.obj XXXmallocx.obj \
38 | XXXfnlz_mlc.obj
39 |
40 | OBJS= $(XXXOBJS:XXX=)
41 |
42 | all: gctest.exe cord\de.exe test_cpp.exe
43 |
44 | $(OBJS) test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h MAKEFILE
45 |
46 | gc.lib: $(OBJS)
47 | del gc.lib
48 | $(lib) $* @&&|
49 | $(XXXOBJS:XXX=+)
50 | |
51 |
52 | gctest.exe: tests\test.obj gc.lib
53 | $(cc) @&&|
54 | $(cflags) -W -e$* tests\test.obj gc.lib
55 | |
56 |
57 | cord\tests\de.obj cord\tests\de_win.obj: include\cord.h \
58 | include\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h
59 |
60 | cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj \
61 | cord\tests\de_win.obj cord\tests\de_win.res gc.lib
62 | $(cc) @&&|
63 | $(cflags) -W -e$* cord\cordbscs.obj cord\cordxtra.obj \
64 | cord\tests\de.obj cord\tests\de_win.obj gc.lib
65 | |
66 | $(rc) cord\tests\de_win.res cord\de.exe
67 |
68 | gc_cpp.obj: include\gc_cpp.h include\gc.h
69 |
70 | gc_cpp.cpp: gc_cpp.cc
71 | copy gc_cpp.cc gc_cpp.cpp
72 |
73 | test_cpp.cpp: tests\test_cpp.cc
74 | copy tests\test_cpp.cc test_cpp.cpp
75 |
76 | test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc.lib
77 | $(cc) @&&|
78 | $(cflags) -W -e$* test_cpp.obj gc.lib
79 | |
80 |
81 | scratch:
82 | -del *.obj *.res *.exe *.csm cord\*.obj cord\*.res cord\*.exe cord\*.csm
83 |
84 | clean:
85 | del gc.lib
86 | del *.obj
87 | del tests\test.obj
88 |
--------------------------------------------------------------------------------
/src/gc/NT_MAKEFILE:
--------------------------------------------------------------------------------
1 | # Makefile for Windows NT. Assumes Microsoft compiler, and a single thread.
2 | # Use "nmake nodebug=1 all" for optimized versions of library, gctest and editor.
3 |
4 | MY_CPU=X86
5 | CPU=$(MY_CPU)
6 | !include
7 |
8 | # Make sure that .cc is not viewed as a suffix. It is for VC++2005, but
9 | # not earlier versions. We can deal with either, but not inconsistency.
10 | .SUFFIXES:
11 | .SUFFIXES: .obj .cpp .c
12 |
13 | OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_rts.obj headers.obj mark.obj obj_map.obj blacklst.obj finalize.obj new_hblk.obj dbg_mlc.obj fnlz_mlc.obj malloc.obj stubborn.obj dyn_load.obj typd_mlc.obj ptr_chck.obj gc_cpp.obj mallocx.obj extra\msvc_dbg.obj
14 |
15 | all: gctest.exe cord\de.exe test_cpp.exe
16 |
17 | .c.obj:
18 | $(cc) $(cdebug) $(cflags) $(cvars) -Iinclude -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -D_CRT_SECURE_NO_DEPRECATE $*.c /Fo$*.obj
19 |
20 | .cpp.obj:
21 | $(cc) $(cdebug) $(cflags) $(cvars) -Iinclude -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -D_CRT_SECURE_NO_DEPRECATE $*.cpp /Fo$*.obj
22 |
23 | $(OBJS) tests\test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc_mark.h include\gc_disclaim.h include\private\msvc_dbg.h
24 |
25 | gc.lib: $(OBJS)
26 | lib /MACHINE:i386 /out:gc.lib $(OBJS)
27 | # The original NT SDK used lib32 instead of lib
28 |
29 | gctest.exe: tests\test.obj gc.lib
30 | # The following works for win32 debugging. For win32s debugging use debugtype:coff
31 | # and add mapsympe line.
32 | # This produces a "GUI" applications that opens no windows and writes to the log file
33 | # "gctest.gc.log". This is done to make the result runnable under win32s.
34 | $(link) -debug -debugtype:cv $(guiflags) -stack:131072 -out:$*.exe tests\test.obj $(guilibs) gc.lib
35 | # mapsympe -n -o gctest.sym gctest.exe
36 |
37 | cord\de_win.rbj: cord\de_win.res
38 | cvtres /MACHINE:$(MY_CPU) /OUT:cord\de_win.rbj cord\de_win.res
39 |
40 | cord\tests\de.obj cord\tests\de_win.obj: include\cord.h include\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h
41 |
42 | cord\de_win.res: cord\tests\de_win.rc cord\tests\de_win.h cord\tests\de_cmds.h
43 | $(rc) $(rcvars) -r -fo cord\de_win.res cord\tests\de_win.rc
44 |
45 | # Cord/de is a real win32 gui application.
46 | cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib
47 | $(link) -debug -debugtype:cv $(guiflags) -stack:16384 -out:cord\de.exe cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib $(guilibs)
48 |
49 | gc_cpp.obj: include\gc_cpp.h include\gc.h
50 |
51 | gc_cpp.cpp: gc_cpp.cc
52 | # copy gc_cpp.cc gc_cpp.cpp
53 |
54 | test_cpp.cpp: tests\test_cpp.cc
55 | copy tests\test_cpp.cc test_cpp.cpp
56 |
57 | # This generates the C++ test executable. The executable expects
58 | # a single numeric argument, which is the number of iterations.
59 | # The output appears in the file "test_cpp.gc.log".
60 | test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc.lib
61 | $(link) -debug -debugtype:cv $(guiflags) -stack:16384 -out:test_cpp.exe test_cpp.obj gc.lib $(guilibs)
62 |
--------------------------------------------------------------------------------
/src/gc/NT_STATIC_THREADS_MAKEFILE:
--------------------------------------------------------------------------------
1 | # Makefile for Windows NT. Assumes Microsoft compiler.
2 | # Use "nmake nodebug=1 all" for optimized versions of library, gctest and editor.
3 |
4 | MY_CPU=X86
5 | CPU=$(MY_CPU)
6 | !include
7 |
8 | # Make sure that .cc is not viewed as a suffix. It is for VC++2005, but
9 | # not earlier versions. We can deal with either, but not inconsistency.
10 | .SUFFIXES:
11 | .SUFFIXES: .obj .cpp .c
12 |
13 | # Atomic_ops installation directory. For win32, the source directory
14 | # should do, since we only need the headers.
15 | # We assume this was manually unpacked, since I'm not sure there is
16 | # a Windows standard command line tool to do this.
17 | AO_SRC_DIR=libatomic_ops/src
18 | AO_INCLUDE_DIR=$(AO_SRC_DIR)
19 |
20 | OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_rts.obj headers.obj mark.obj obj_map.obj blacklst.obj finalize.obj new_hblk.obj dbg_mlc.obj fnlz_mlc.obj malloc.obj stubborn.obj dyn_load.obj typd_mlc.obj ptr_chck.obj gc_cpp.obj mallocx.obj win32_threads.obj extra\msvc_dbg.obj thread_local_alloc.obj
21 |
22 | all: gctest.exe cord\de.exe test_cpp.exe
23 |
24 | .c.obj:
25 | $(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -DGC_THREADS -DTHREAD_LOCAL_ALLOC -DPARALLEL_MARK -D_CRT_SECURE_NO_DEPRECATE $*.c /Fo$*.obj
26 |
27 | .cpp.obj:
28 | $(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -DGC_THREADS -DTHREAD_LOCAL_ALLOC -D_CRT_SECURE_NO_DEPRECATE $*.cpp /Fo$*.obj
29 |
30 | $(OBJS) tests\test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc_mark.h include\gc_disclaim.h include\private\msvc_dbg.h
31 |
32 | gc.lib: $(OBJS)
33 | lib /MACHINE:i386 /out:gc.lib $(OBJS)
34 | # The original NT SDK used lib32 instead of lib
35 |
36 | gctest.exe: tests\test.obj gc.lib
37 | # The following works for win32 debugging. For win32s debugging use debugtype:coff
38 | # and add mapsympe line.
39 | # This produces a "GUI" applications that opens no windows and writes to the log file
40 | # "gctest.gc.log". This is done to make the result runnable under win32s.
41 | $(link) -debug -debugtype:cv $(guiflags) -stack:262144 -out:$*.exe tests\test.obj $(guilibs) gc.lib
42 | # mapsympe -n -o gctest.sym gctest.exe
43 |
44 | cord\de_win.rbj: cord\de_win.res
45 | cvtres /MACHINE:$(MY_CPU) /OUT:cord\de_win.rbj cord\de_win.res
46 |
47 | cord\tests\de.obj cord\tests\de_win.obj: include\cord.h include\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h
48 |
49 | cord\de_win.res: cord\tests\de_win.rc cord\tests\de_win.h cord\tests\de_cmds.h
50 | $(rc) $(rcvars) -r -fo cord\de_win.res cord\tests\de_win.rc
51 |
52 | # Cord/de is a real win32 gui application.
53 | cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib
54 | $(link) -debug -debugtype:cv $(guiflags) -stack:16384 -out:cord\de.exe cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib $(guilibs)
55 |
56 | gc_cpp.obj: include\gc_cpp.h include\gc.h
57 |
58 | gc_cpp.cpp: gc_cpp.cc
59 | # copy gc_cpp.cc gc_cpp.cpp
60 |
61 | test_cpp.cpp: tests\test_cpp.cc
62 | copy tests\test_cpp.cc test_cpp.cpp
63 |
64 | # This generates the C++ test executable. The executable expects
65 | # a single numeric argument, which is the number of iterations.
66 | # The output appears in the file "test_cpp.gc.log".
67 | test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc.lib
68 | $(link) -debug -debugtype:cv $(guiflags) -stack:16384 -out:test_cpp.exe test_cpp.obj gc.lib $(guilibs)
69 |
70 | AO_SCR_DIR:
71 | tar xvfz $(AO_SRC_DIR).tar.gz;
72 |
--------------------------------------------------------------------------------
/src/gc/NT_X64_STATIC_THREADS_MAKEFILE:
--------------------------------------------------------------------------------
1 | # Makefile for Windows NT. Assumes Microsoft compiler.
2 | # Use "nmake nodebug=1 all" for optimized versions of library, gctest and editor.
3 |
4 | MY_CPU=AMD64
5 | CPU=$(MY_CPU)
6 | !include
7 |
8 | # Make sure that .cc is not viewed as a suffix. It is for VC++2005, but
9 | # not earlier versions. We can deal with either, but not inconsistency.
10 | .SUFFIXES:
11 | .SUFFIXES: .obj .cpp .c
12 |
13 | # Atomic_ops installation directory. For win32, the source directory
14 | # should do, since we only need the headers.
15 | # We assume this was manually unpacked, since I'm not sure there is
16 | # a Windows standard command line tool to do this.
17 | AO_SRC_DIR=libatomic_ops/src
18 | AO_INCLUDE_DIR=$(AO_SRC_DIR)
19 |
20 | OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_rts.obj headers.obj mark.obj obj_map.obj blacklst.obj finalize.obj new_hblk.obj dbg_mlc.obj fnlz_mlc.obj malloc.obj stubborn.obj dyn_load.obj typd_mlc.obj ptr_chck.obj gc_cpp.obj mallocx.obj win32_threads.obj extra\msvc_dbg.obj thread_local_alloc.obj
21 |
22 | all: gctest.exe cord\de.exe test_cpp.exe
23 |
24 | .c.obj:
25 | $(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -DGC_THREADS -DTHREAD_LOCAL_ALLOC -D_CRT_SECURE_NO_DEPRECATE $*.c /Fo$*.obj /wd4701
26 | # Disable "may not be initialized" warnings. They're too approximate.
27 | # Disable crt security warnings, since unfortunately they warn about all sorts
28 | # of safe uses of strncpy. It would be nice to leave the rest enabled.
29 |
30 | .cpp.obj:
31 | $(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_NOT_DLL -DGC_THREADS -DTHREAD_LOCAL_ALLOC -D_CRT_SECURE_NO_DEPRECATE $*.cpp /Fo$*.obj
32 |
33 | $(OBJS) tests\test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc_mark.h include\gc_disclaim.h include\private\msvc_dbg.h
34 |
35 | gc.lib: $(OBJS)
36 | lib /MACHINE:X64 /out:gc.lib $(OBJS)
37 |
38 | gctest.exe: tests\test.obj gc.lib
39 | # This produces a "GUI" applications that opens no windows and writes to
40 | # the log file "gctest.gc.log".
41 | $(link) $(ldebug) $(guiflags) -out:$*.exe tests\test.obj $(guilibs) gc.lib
42 |
43 | cord\de_win.rbj: cord\de_win.res
44 | cvtres /MACHINE:$(MY_CPU) /OUT:cord\de_win.rbj cord\de_win.res
45 |
46 | cord\tests\de.obj cord\tests\de_win.obj: include\cord.h include\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h
47 |
48 | cord\de_win.res: cord\tests\de_win.rc cord\tests\de_win.h cord\tests\de_cmds.h
49 | $(rc) $(rcvars) -r -fo cord\de_win.res cord\tests\de_win.rc
50 |
51 | # Cord/de is a real win32 gui application.
52 | cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib
53 | $(link) $(ldebug) $(guiflags) -stack:16384 -out:cord\de.exe cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc.lib $(guilibs)
54 |
55 | gc_cpp.obj: include\gc_cpp.h include\gc.h
56 |
57 | gc_cpp.cpp: gc_cpp.cc
58 | # copy gc_cpp.cc gc_cpp.cpp
59 |
60 | test_cpp.cpp: tests\test_cpp.cc
61 | copy tests\test_cpp.cc test_cpp.cpp
62 |
63 | # This generates the C++ test executable. The executable expects
64 | # a single numeric argument, which is the number of iterations.
65 | # The output appears in the file "test_cpp.gc.log".
66 | test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc.lib
67 | $(link) $(ldebug) $(guiflags) -stack:16384 -out:test_cpp.exe test_cpp.obj gc.lib $(guilibs)
68 |
69 | AO_SCR_DIR:
70 | tar xvfz $(AO_SRC_DIR).tar.gz;
71 |
--------------------------------------------------------------------------------
/src/gc/OS2_MAKEFILE:
--------------------------------------------------------------------------------
1 | # Makefile for OS/2. Assumes IBM's compiler, static linking, and a single thread.
2 | # Adding dynamic linking support seems easy, but takes a little bit of work.
3 | # Adding thread support may be nontrivial, since we haven't yet figured out how to
4 | # look at another thread's registers.
5 |
6 | # Significantly revised for GC version 4.4 by Mark Boulter (Jan 1994).
7 |
8 | OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_rts.obj headers.obj mark.obj obj_map.obj blacklst.obj finalize.obj new_hblk.obj dbg_mlc.obj fnlz_mlc.obj malloc.obj stubborn.obj typd_mlc.obj ptr_chck.obj mallocx.obj
9 |
10 | CORDOBJS= cord\cordbscs.obj cord\cordxtra.obj cord\cordprnt.obj
11 |
12 | CC= icc
13 | CFLAGS= /O /Q /DSMALL_CONFIG /DALL_INTERIOR_POINTERS
14 | # Use /Ti instead of /O for debugging
15 | # Setjmp_test may yield overly optimistic results when compiled
16 | # without optimization.
17 |
18 | all: $(OBJS) gctest.exe cord\cordtest.exe
19 |
20 | $(OBJS) test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h
21 |
22 | ## ERASE THE LIB FIRST - if it is already there then this command will fail
23 | ## (make sure its there or erase will fail!)
24 | gc.lib: $(OBJS)
25 | echo . > gc.lib
26 | erase gc.lib
27 | LIB gc.lib $(OBJS), gc.lst
28 |
29 | mach_dep.obj: mach_dep.c
30 | $(CC) $(CFLAGS) /C mach_dep.c
31 |
32 | gctest.exe: test.obj gc.lib
33 | $(CC) $(CFLAGS) /B"/STACK:524288" /Fegctest test.obj gc.lib
34 |
35 | cord\cordbscs.obj: cord\cordbscs.c include\cord.h include\cord_pos.h
36 | $(CC) $(CFLAGS) /C /Focord\cordbscs cord\cordbscs.c
37 |
38 | cord\cordxtra.obj: cord\cordxtra.c include\cord.h include\cord_pos.h include\ec.h
39 | $(CC) $(CFLAGS) /C /Focord\cordxtra cord\cordxtra.c
40 |
41 | cord\cordprnt.obj: cord\cordprnt.c include\cord.h include\cord_pos.h include\ec.h
42 | $(CC) $(CFLAGS) /C /Focord\cordprnt cord\cordprnt.c
43 |
44 | cord\cordtest.exe: cord\tests\cordtest.c include\cord.h include\cord_pos.h include\ec.h $(CORDOBJS) gc.lib
45 | $(CC) $(CFLAGS) /B"/STACK:65536" /Fecord\cordtest cord\tests\cordtest.c gc.lib $(CORDOBJS)
46 |
--------------------------------------------------------------------------------
/src/gc/PCR-Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Default target
3 | #
4 |
5 | default: gc.o
6 |
7 | include ../config/common.mk
8 |
9 | #
10 | # compilation flags, etc.
11 | #
12 |
13 | CPPFLAGS = $(INCLUDE) $(CONFIG_CPPFLAGS) \
14 | -DPCR_NO_RENAME -DPCR_NO_HOSTDEP_ERR
15 | #CFLAGS = -DPCR $(CONFIG_CFLAGS)
16 | CFLAGS = -DPCR $(CONFIG_CFLAGS)
17 | SPECIALCFLAGS = # For code involving asm's
18 |
19 | ASPPFLAGS = $(INCLUDE) $(CONFIG_ASPPFLAGS) \
20 | -DPCR_NO_RENAME -DPCR_NO_HOSTDEP_ERR -DASM
21 |
22 | ASFLAGS = $(CONFIG_ASFLAGS)
23 |
24 | LDRFLAGS = $(CONFIG_LDRFLAGS)
25 |
26 | LDFLAGS = $(CONFIG_LDFLAGS)
27 |
28 | #
29 | # BEGIN PACKAGE-SPECIFIC PART
30 | #
31 |
32 | # Fix to point to local pcr installation directory.
33 | PCRDIR= ..
34 |
35 | COBJ= alloc.o reclaim.o allchblk.o misc.o os_dep.o mark_rts.o headers.o mark.o obj_map.o pcr_interface.o blacklst.o finalize.o new_hblk.o real_malloc.o dyn_load.o dbg_mlc.o fnlz_mlc.o malloc.o stubborn.o checksums.o solaris_threads.o typd_mlc.o ptr_chck.o mallocx.o
36 |
37 | CSRC= reclaim.c allchblk.c misc.c alloc.c mach_dep.c os_dep.c mark_rts.c headers.c mark.c obj_map.c pcr_interface.c blacklst.c finalize.c new_hblk.c real_malloc.c dyn_load.c dbg_mlc.c fnlz_mlc.c malloc.c stubborn.c checksums.c solaris_threads.c typd_mlc.c ptr_chck.c mallocx.c
38 |
39 | SHELL= /bin/sh
40 |
41 | default: gc.o
42 |
43 | gc.o: $(COBJ) mach_dep.o
44 | $(LDR) $(CONFIG_LDRFLAGS) -o gc.o $(COBJ) mach_dep.o
45 |
46 | mach_dep.o: mach_dep.c
47 | $(CC) -c $(SPECIALCFLAGS) mach_dep.c
48 |
--------------------------------------------------------------------------------
/src/gc/TODO:
--------------------------------------------------------------------------------
1 | == TODO tasks ==
2 |
3 | tests/CMakeLists.txt: Add more executables (see tests.am).
4 |
5 | Use C++0x ATM (atomic memory operations) if available (either from the
6 | compiler runtime, provided it is reliable, or from the future libatomic_ops).
7 |
8 | Add a test for libatomic_ops minimal version required (at compile time).
9 |
10 | windows-untested: Remove if CMake can generate MS Visual Studio 6.0, 7.0, 8.0
11 | project files.
12 |
13 | BCC_MAKEFILE: Remove if CMake can generate Makefile for this compiler.
14 | (Same for WCC_MAKEFILE, OS2_MAKEFILE, NT_MAKEFILE, NT_STATIC_THREADS_MAKEFILE,
15 | NT_X64_STATIC_THREADS_MAKEFILE, NT_X64_THREADS_MAKEFILE, digimars.mak,
16 | gc.mak.)
17 |
18 | BCC_MAKEFILE, EMX_MAKEFILE, OS2_MAKEFILE, PCR-Makefile, WCC_MAKEFILE,
19 | SMakefile.amiga, digimars.mak: move to "build" folder.
20 |
21 | Do type-punning via union (instead of pointer type cast) to enable safe
22 | '-fstrict-aliasing' compiler optimization option.
23 |
24 | Support CAN_HANDLE_FORK if USE_WINALLOC for Cygwin.
25 |
26 | Use madvise() on Unix/Cygwin.
27 |
28 | Use Linux VM pressure notifications to force GC and unmapping.
29 |
30 | Filter overlaps in GC_add_roots for Unix (same as for Win32).
31 |
32 | Do not resume parallel markers if only 1 core is active at GC mark start.
33 |
34 | Enable GC_set_handle_fork(1) for Darwin with GC_dirty_maintained on (both
35 | single and multi-threaded modes).
36 |
37 | Add more fields to GC_prof_stats_s (potential candidates are:
38 | requested_heapsize, max_large_allocd_bytes, large_allocd_bytes, bytes_dropped,
39 | bytes_finalized, bytes_freed, finalizer_bytes_freed, composite_in_use,
40 | atomic_in_use, GC_n_heap_sects, GC_n_memory, GC_black_list_spacing,
41 | GC_root_size, GC_max_root_size, n_root_sets, GC_total_stacksize,
42 | GC_collect_at_heapsize, GC_fail_count, GC_mark_stack_size, last_fo_entries,
43 | last_bytes_finalized, last_finalizer_notification_no, GC_dl_entries,
44 | GC_old_dl_entries, GC_used_heap_size_after_full, GC_total_stack_black_listed,
45 | signed_log_dl_table_size, GC_n_rescuing_pages, signed_log_fo_table_size,
46 | GC_excl_table_entries, GC_stack_last_cleared, GC_bytes_allocd_at_reset,
47 | GC_n_heap_bases, registered_threads_cnt, GC_max_thread_index, GC_block_count,
48 | GC_unlocked_count, GC_hdr_cache_hits, GC_hdr_cache_misses, GC_spin_count).
49 |
50 | Support musl libc (on sabotage linux).
51 |
52 | == FIXME tasks ==
53 |
54 | Solaris + GCC: make check fails with the message:
55 | libc.so.1: gctest: fatal: libgcc_s.so.1: open failed: No such file or directory
56 |
57 | Solaris/x86[_64]: gctest fails if PROC_VDB.
58 |
59 | Sun C++ 5.11: test_cpp.cc:237: Error: Too few arguments in call to
60 | "operator delete(void*, GCPlacement, extern "C" void(*)(void*,void*), void*)".
61 |
62 | Darwin/x86_64: deadlock might occur between:
63 | dlclose() -> GC_dyld_image_remove() -> GC_lock() and
64 | GC_inner_start_routine()+LOCK -> dyld_stub_binder_().
65 |
66 | HP-UX 11.00 with the vendor cc fails:
67 | Perhaps GC_push_regs was configured incorrectly? FAIL: gctest.
68 |
69 | Linux/mips64el (N32): threadleaktest crashes once every 3-4 runs (SIGSEGV in
70 | GC_delete_gc_thread(t=0) called from GC_pthread_join) if configured with
71 | --disable-shared.
72 |
73 | FreeBSD 9.0/x86_64 (gcc-4.2.1-20070831): gctest segfaults sometimes in
74 | GC_typed_mark_proc if configured with --enable-threads=pthreads.
75 |
76 | OpenBSD 5.1/i386: leaktest fails rarely (unless logging redirected to file):
77 | cannot write to stderr from GC_gcollect invoked from 'atexit' hook.
78 |
79 | NetBSD 5.1/x86: threadkey_test hangs sometimes.
80 |
81 | Cygwin: subthread_create: exception STATUS_ACCESS_VIOLATION.
82 |
83 | Cygwin: gctest: assertion failure at UNLOCK in GC_fork_parent_proc.
84 |
85 | Mingw-w32: gctest: "SuspendThread failed" sometimes occurs (if
86 | GC_DLL+GC_THREADS+GC_ASSERTIONS).
87 |
88 | Mingw: gctest (compiled with PARALLEL_MARK): launched in gdb with breakpoint
89 | at GC_mark_local, after several breakpoint hits, crashes with the messages
90 | "Caught ACCESS_VIOLATION in marker; memory mapping disappeared" and
91 | "Tried to start parallel mark in bad state", or enters deadlock.
92 |
93 | Mingw: test_cpp: crashes at some iteration if big argument (e.g., 1000) given.
94 |
--------------------------------------------------------------------------------
/src/gc/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | # This script creates (or regenerates) configure (as well as aclocal.m4,
5 | # config.h.in, Makefile.in, etc.) missing in the source repository.
6 | #
7 | # If you compile from a distribution tarball, you can skip this. Otherwise,
8 | # make sure that you have Autoconf, Automake, Libtool, and pkg-config
9 | # installed on your system, and that the corresponding *.m4 files are visible
10 | # to the aclocal. The latter can be achieved by using packages shipped by
11 | # your OS, or by installing custom versions of all four packages to the same
12 | # prefix. Otherwise, you may need to invoke autoreconf with the appropriate
13 | # -I options to locate the required *.m4 files.
14 |
15 | autoreconf -i
16 |
17 | echo
18 | echo "Ready to run './configure'."
19 |
--------------------------------------------------------------------------------
/src/gc/bdw-gc.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: Boehm-Demers-Weiser Conservative Garbage Collector
7 | Description: A garbage collector for C and C++
8 | Version: @PACKAGE_VERSION@
9 | Libs: -L${libdir} -lgc
10 | Cflags: -I${includedir}
11 |
--------------------------------------------------------------------------------
/src/gc/build/s60v3/bld.inf:
--------------------------------------------------------------------------------
1 | /*
2 | Name : bld.inf
3 | Description : This file provides the information required for building the
4 | whole of a libgc.
5 | */
6 |
7 | PRJ_PLATFORMS
8 | default armv5
9 |
10 | PRJ_MMPFILES
11 | libgc.mmp
12 |
--------------------------------------------------------------------------------
/src/gc/build/s60v3/libgc.mmp:
--------------------------------------------------------------------------------
1 | TARGET libgc.dll
2 |
3 | TARGETTYPE dll
4 | UID 0x1000008d 0x200107C2 // check uid
5 |
6 | EXPORTUNFROZEN
7 | EPOCALLOWDLLDATA
8 | //ALWAYS_BUILD_AS_ARM
9 | //nocompresstarget
10 | //srcdbg
11 | //baseaddress 00500000
12 | //LINKEROPTION CW -map libgc.map
13 | //LINKEROPTION CW -filealign 0x10000
14 |
15 | CAPABILITY PowerMgmt ReadDeviceData ReadUserData WriteDeviceData WriteUserData SwEvent LocalServices NetworkServices UserEnvironment
16 |
17 |
18 | MACRO ALL_INTERIOR_POINTERS
19 | MACRO NO_EXECUTE_PERMISSION
20 | MACRO USE_MMAP
21 | MACRO GC_DONT_REGISTER_MAIN_STATIC_DATA
22 | MACRO GC_DLL
23 | MACRO SYMBIAN
24 | //MACRO ENABLE_DISCLAIM
25 | //MACRO GC_GCJ_SUPPORT
26 |
27 | USERINCLUDE ..\..\include
28 | USERINCLUDE ..\..\include\private
29 |
30 | SYSTEMINCLUDE \epoc32\include
31 | SYSTEMINCLUDE \epoc32\include\stdapis
32 |
33 | SOURCEPATH ..\..\
34 |
35 | SOURCE allchblk.c
36 | SOURCE alloc.c
37 | SOURCE blacklst.c
38 | SOURCE dbg_mlc.c
39 | SOURCE dyn_load.c
40 | SOURCE finalize.c
41 | SOURCE fnlz_mlc.c
42 | //SOURCE gc_cpp.cpp
43 | SOURCE gcj_mlc.c
44 | SOURCE headers.c
45 | SOURCE mach_dep.c
46 | SOURCE malloc.c
47 | SOURCE mallocx.c
48 | SOURCE mark.c
49 | SOURCE mark_rts.c
50 | SOURCE misc.c
51 | SOURCE new_hblk.c
52 | SOURCE obj_map.c
53 | SOURCE os_dep.c
54 | SOURCE extra/symbian.cpp
55 | SOURCE ptr_chck.c
56 | SOURCE reclaim.c
57 | SOURCE stubborn.c
58 | SOURCE typd_mlc.c
59 |
60 | /*
61 | #ifdef ENABLE_ABIV2_MODE
62 | DEBUGGABLE_UDEBONLY
63 | #endif
64 | */
65 |
66 | // Using main() as entry point
67 | STATICLIBRARY libcrt0.lib
68 |
69 | // libc and euser are always needed when using main() entry point
70 | LIBRARY libc.lib
71 |
72 |
73 | LIBRARY euser.lib
74 | LIBRARY efsrv.lib
75 | LIBRARY avkon.lib
76 | LIBRARY eikcore.lib
77 |
--------------------------------------------------------------------------------
/src/gc/cord/cord.am:
--------------------------------------------------------------------------------
1 |
2 | lib_LTLIBRARIES += libcord.la
3 |
4 | libcord_la_LIBADD = $(top_builddir)/libgc.la
5 | libcord_la_LDFLAGS = -version-info 1:3:0 -no-undefined
6 | libcord_la_CPPFLAGS = $(AM_CPPFLAGS)
7 |
8 | libcord_la_SOURCES = \
9 | cord/cordbscs.c \
10 | cord/cordprnt.c \
11 | cord/cordxtra.c
12 |
13 | TESTS += cordtest$(EXEEXT)
14 | check_PROGRAMS += cordtest
15 | cordtest_SOURCES = cord/tests/cordtest.c
16 | cordtest_LDADD = $(top_builddir)/libgc.la $(top_builddir)/libcord.la
17 |
18 | EXTRA_DIST += \
19 | cord/tests/de.c \
20 | cord/tests/de_cmds.h \
21 | cord/tests/de_win.c \
22 | cord/tests/de_win.h \
23 | cord/tests/de_win.rc
24 |
25 | pkginclude_HEADERS += \
26 | include/cord.h \
27 | include/cord_pos.h \
28 | include/ec.h
29 |
--------------------------------------------------------------------------------
/src/gc/cord/tests/de_cmds.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to use or copy this program
8 | * for any purpose, provided the above notices are retained on all copies.
9 | * Permission to modify the code and to distribute modified code is granted,
10 | * provided the above notices are retained, and a notice that the code was
11 | * modified is included with the above copyright notice.
12 | */
13 |
14 | #ifndef DE_CMDS_H
15 |
16 | # define DE_CMDS_H
17 |
18 | # define UP 16 /* ^P */
19 | # define DOWN 14 /* ^N */
20 | # define LEFT 2 /* ^B */
21 | # define RIGHT 6 /* ^F */
22 | # define DEL 127 /* ^? */
23 | # define BS 8 /* ^H */
24 | # define UNDO 21 /* ^U */
25 | # define WRITE 23 /* ^W */
26 | # define QUIT 4 /* ^D */
27 | # define REPEAT 18 /* ^R */
28 | # define LOCATE 12 /* ^L */
29 | # define TOP 20 /* ^T */
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/src/gc/cord/tests/de_win.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to use or copy this program
8 | * for any purpose, provided the above notices are retained on all copies.
9 | * Permission to modify the code and to distribute modified code is granted,
10 | * provided the above notices are retained, and a notice that the code was
11 | * modified is included with the above copyright notice.
12 | */
13 |
14 | /* cord.h, de_cmds.h, and windows.h should be included before this. */
15 |
16 | # define OTHER_FLAG 0x100
17 | # define EDIT_CMD_FLAG 0x200
18 | # define REPEAT_FLAG 0x400
19 |
20 | # define CHAR_CMD(i) ((i) & 0xff)
21 |
22 | /* MENU: DE */
23 | #define IDM_FILESAVE (EDIT_CMD_FLAG + WRITE)
24 | #define IDM_FILEEXIT (OTHER_FLAG + 1)
25 | #define IDM_HELPABOUT (OTHER_FLAG + 2)
26 | #define IDM_HELPCONTENTS (OTHER_FLAG + 3)
27 |
28 | #define IDM_EDITPDOWN (REPEAT_FLAG + EDIT_CMD_FLAG + DOWN)
29 | #define IDM_EDITPUP (REPEAT_FLAG + EDIT_CMD_FLAG + UP)
30 | #define IDM_EDITUNDO (EDIT_CMD_FLAG + UNDO)
31 | #define IDM_EDITLOCATE (EDIT_CMD_FLAG + LOCATE)
32 | #define IDM_EDITDOWN (EDIT_CMD_FLAG + DOWN)
33 | #define IDM_EDITUP (EDIT_CMD_FLAG + UP)
34 | #define IDM_EDITLEFT (EDIT_CMD_FLAG + LEFT)
35 | #define IDM_EDITRIGHT (EDIT_CMD_FLAG + RIGHT)
36 | #define IDM_EDITBS (EDIT_CMD_FLAG + BS)
37 | #define IDM_EDITDEL (EDIT_CMD_FLAG + DEL)
38 | #define IDM_EDITREPEAT (EDIT_CMD_FLAG + REPEAT)
39 | #define IDM_EDITTOP (EDIT_CMD_FLAG + TOP)
40 |
41 |
42 |
43 |
44 | /* Windows UI stuff */
45 |
46 | LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
47 | UINT wParam, LONG lParam);
48 |
49 | LRESULT CALLBACK AboutBox( HWND hDlg, UINT message,
50 | UINT wParam, LONG lParam );
51 |
52 |
53 | /* Screen dimensions. Maintained by de_win.c. */
54 | extern int LINES;
55 | extern int COLS;
56 |
57 | /* File being edited. */
58 | extern char * arg_file_name;
59 |
60 | /* Current display position in file. Maintained by de.c */
61 | extern int dis_line;
62 | extern int dis_col;
63 |
64 | /* Current cursor position in file. */
65 | extern int line;
66 | extern int col;
67 |
68 | /*
69 | * Calls from de_win.c to de.c
70 | */
71 |
72 | CORD retrieve_screen_line(int i);
73 | /* Get the contents of i'th screen line. */
74 | /* Relies on COLS. */
75 |
76 | void set_position(int x, int y);
77 | /* Set column, row. Upper left of window = (0,0). */
78 |
79 | void do_command(int);
80 | /* Execute an editor command. */
81 | /* Agument is a command character or one */
82 | /* of the IDM_ commands. */
83 |
84 | void generic_init(void);
85 | /* OS independent initialization */
86 |
87 |
88 | /*
89 | * Calls from de.c to de_win.c
90 | */
91 |
92 | void move_cursor(int column, int line);
93 | /* Physically move the cursor on the display, */
94 | /* so that it appears at */
95 | /* (column, line). */
96 |
97 | void invalidate_line(int line);
98 | /* Invalidate line i on the screen. */
99 |
100 | void de_error(char *s);
101 | /* Display error message. */
102 |
--------------------------------------------------------------------------------
/src/gc/cord/tests/de_win.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to copy this garbage collector for any purpose,
8 | * provided the above notices are retained on all copies.
9 | */
10 |
11 | #include "windows.h"
12 | #include "de_cmds.h"
13 | #include "de_win.h"
14 |
15 |
16 | ABOUTBOX DIALOG 19, 21, 163, 47
17 | STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
18 | CAPTION "About Demonstration Text Editor"
19 | BEGIN
20 | /* ICON "DE", -1, 8, 8, 13, 13, WS_CHILD | WS_VISIBLE */
21 | LTEXT "Demonstration Text Editor", -1, 44, 8, 118, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
22 | LTEXT "Version 4.1", -1, 44, 16, 60, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
23 | PUSHBUTTON "OK", IDOK, 118, 27, 24, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
24 | END
25 |
26 |
27 | DE MENU
28 | BEGIN
29 | POPUP "&File"
30 | BEGIN
31 | MENUITEM "&Save\t^W", IDM_FILESAVE
32 | MENUITEM "E&xit\t^D", IDM_FILEEXIT
33 | END
34 |
35 | POPUP "&Edit"
36 | BEGIN
37 | MENUITEM "Page &Down\t^R^N", IDM_EDITPDOWN
38 | MENUITEM "Page &Up\t^R^P", IDM_EDITPUP
39 | MENUITEM "U&ndo\t^U", IDM_EDITUNDO
40 | MENUITEM "&Locate\t^L ... ^L", IDM_EDITLOCATE
41 | MENUITEM "D&own\t^N", IDM_EDITDOWN
42 | MENUITEM "U&p\t^P", IDM_EDITUP
43 | MENUITEM "Le&ft\t^B", IDM_EDITLEFT
44 | MENUITEM "&Right\t^F", IDM_EDITRIGHT
45 | MENUITEM "Delete &Backward\tBS", IDM_EDITBS
46 | MENUITEM "Delete F&orward\tDEL", IDM_EDITDEL
47 | MENUITEM "&Top\t^T", IDM_EDITTOP
48 | END
49 |
50 | POPUP "&Help"
51 | BEGIN
52 | MENUITEM "&Contents", IDM_HELPCONTENTS
53 | MENUITEM "&About...", IDM_HELPABOUT
54 | END
55 |
56 | MENUITEM "Page_&Down", IDM_EDITPDOWN
57 | MENUITEM "Page_&Up", IDM_EDITPUP
58 | END
59 |
60 |
61 | DE ACCELERATORS
62 | BEGIN
63 | "^R", IDM_EDITREPEAT
64 | "^N", IDM_EDITDOWN
65 | "^P", IDM_EDITUP
66 | "^L", IDM_EDITLOCATE
67 | "^B", IDM_EDITLEFT
68 | "^F", IDM_EDITRIGHT
69 | "^T", IDM_EDITTOP
70 | VK_DELETE, IDM_EDITDEL, VIRTKEY
71 | VK_BACK, IDM_EDITBS, VIRTKEY
72 | END
73 |
74 |
75 | /* DE ICON cord\de_win.ICO */
76 |
--------------------------------------------------------------------------------
/src/gc/digimars.mak:
--------------------------------------------------------------------------------
1 | # Makefile to build Hans Boehm garbage collector using the Digital Mars
2 | # compiler from www.digitalmars.com
3 | # Written by Walter Bright
4 |
5 |
6 | DEFINES=-DNDEBUG -D_WINDOWS -DGC_DLL -DALL_INTERIOR_POINTERS -DWIN32_THREADS
7 | CFLAGS=-Iinclude $(DEFINES) -wx -g
8 | LFLAGS=/ma/implib/co
9 | CC=sc
10 |
11 | .c.obj:
12 | $(CC) -c $(CFLAGS) $*
13 |
14 | .cpp.obj:
15 | $(CC) -c $(CFLAGS) -Aa $*
16 |
17 | OBJS= \
18 | allchblk.obj\
19 | alloc.obj\
20 | blacklst.obj\
21 | checksums.obj\
22 | dbg_mlc.obj\
23 | fnlz_mlc.obj\
24 | dyn_load.obj\
25 | finalize.obj\
26 | gc_cpp.obj\
27 | headers.obj\
28 | mach_dep.obj\
29 | malloc.obj\
30 | mallocx.obj\
31 | mark.obj\
32 | mark_rts.obj\
33 | misc.obj\
34 | new_hblk.obj\
35 | obj_map.obj\
36 | os_dep.obj\
37 | ptr_chck.obj\
38 | reclaim.obj\
39 | stubborn.obj\
40 | typd_mlc.obj\
41 | win32_threads.obj
42 |
43 | targets: gc.dll gc.lib gctest.exe
44 |
45 | gc.dll: $(OBJS) gc.def digimars.mak
46 | sc -ogc.dll $(OBJS) -L$(LFLAGS) gc.def kernel32.lib user32.lib
47 |
48 | gc.def: digimars.mak
49 | echo LIBRARY GC >gc.def
50 | echo DESCRIPTION "Hans Boehm Garbage Collector" >>gc.def
51 | echo EXETYPE NT >>gc.def
52 | echo EXPORTS >>gc.def
53 | echo GC_is_visible_print_proc >>gc.def
54 | echo GC_is_valid_displacement_print_proc >>gc.def
55 |
56 | clean:
57 | del gc.def
58 | del $(OBJS)
59 |
60 |
61 | gctest.exe : gc.lib tests\test.obj
62 | sc -ogctest.exe tests\test.obj gc.lib
63 |
64 | tests\test.obj : tests\test.c
65 | $(CC) -c -g -DNDEBUG -D_WINDOWS -DGC_DLL \
66 | -DALL_INTERIOR_POINTERS -DWIN32_THREADS \
67 | -Iinclude tests\test.c -otests\test.obj
68 |
69 | allchblk.obj: allchblk.c
70 | alloc.obj: alloc.c
71 | blacklst.obj: blacklst.c
72 | checksums.obj: checksums.c
73 | dbg_mlc.obj: dbg_mlc.c
74 | dyn_load.obj: dyn_load.c
75 | finalize.obj: finalize.c
76 | fnlz_mlc.obj: fnlz_mlc.c
77 | gc_cpp.obj: gc_cpp.cpp
78 | headers.obj: headers.c
79 | mach_dep.obj: mach_dep.c
80 | malloc.obj: malloc.c
81 | mallocx.obj: mallocx.c
82 | mark.obj: mark.c
83 | mark_rts.obj: mark_rts.c
84 | misc.obj: misc.c
85 | new_hblk.obj: new_hblk.c
86 | obj_map.obj: obj_map.c
87 | os_dep.obj: os_dep.c
88 | ptr_chck.obj: ptr_chck.c
89 | reclaim.obj: reclaim.c
90 | stubborn.obj: stubborn.c
91 | typd_mlc.obj: typd_mlc.c
92 | win32_threads.obj: win32_threads.c
93 |
--------------------------------------------------------------------------------
/src/gc/doc/README.DGUX386:
--------------------------------------------------------------------------------
1 | Garbage Collector (parallel iversion) for ix86 DG/UX Release R4.20MU07
2 |
3 |
4 | *READ* the file README.QUICK.
5 |
6 | You need the GCC-3.0.3 rev (DG/UX) compiler to build this tree.
7 | This compiler has the new "dgux386" threads package implemented.
8 | It also supports the switch "-pthread" needed to link correctly
9 | the DG/UX's -lrte -lthread with -lgcc and the system's -lc.
10 | Finally we support parralleli-mark for the SMP DG/UX machines.
11 | To build the garbage collector do:
12 |
13 | ./configure --enable-parallel-mark
14 | make
15 | make gctest
16 |
17 | Before you run "gctest" you need to set your LD_LIBRARY_PATH
18 | correctly so that "gctest" can find the shared library libgc.
19 | Alternatively you can do a configuration
20 |
21 | ./configure --enable-parallel-mark --disable-shared
22 |
23 | to build only the static version of libgc.
24 |
25 | To enable debugging messages please do:
26 | 1) Add the "--enable-gc-debug" flag during configuration.
27 | 2) Edit the file linux-threads.c and uncomment the line:
28 |
29 | /* #define DEBUG_THREADS 1 */ to --->
30 |
31 | #define DEBUG_THREADS 1
32 |
33 | Then give "make" as usual.
34 |
35 | In a machine with 4 CPUs (my own machine) the option parallel
36 | mark (aka --enable-parallel-mark) makes a BIG difference.
37 |
38 | Takis Psarogiannakopoulos
39 |
40 | Note (HB):
41 | The integration of this patch is currently not complete.
42 | The following patches against 6.1alpha3 where hard to move
43 | to alpha4, and are not integrated. There may also be minor
44 | problems with stylistic corrections made by me.
45 | [The diff for ltconfig and ltmain.sh was removed from this file on 2011-08-22]
46 |
--------------------------------------------------------------------------------
/src/gc/doc/README.OS2:
--------------------------------------------------------------------------------
1 | The code assumes static linking, and a single thread. The editor de has
2 | not been ported. The cord test program has. The supplied OS2_MAKEFILE
3 | assumes the IBM C Set/2 environment, but the code shouldn't.
4 |
5 | Since we haven't figured out hoe to do perform partial links or to build static
6 | libraries, clients currently need to link against a long list of executables.
7 |
--------------------------------------------------------------------------------
/src/gc/doc/README.arm.cross:
--------------------------------------------------------------------------------
1 | From: Margaret Fleck
2 |
3 | Here's the key details of what worked for me, in case anyone else needs them.
4 | There may well be better ways to do some of this, but ....
5 | -- Margaret
6 |
7 |
8 | The badge4 has a StrongArm-1110 processor and a StrongArm-1111 coprocessor.
9 |
10 | Assume that the garbage collector distribution is unpacked into /home/arm/gc6.0,
11 | which is visible to both the ARM machine and a linux desktop (e.g. via NFS mounting).
12 |
13 | Assume that you have a file /home/arm/config.site with contents something like the
14 | example attached below. Notice that our local ARM toolchain lives in
15 | /skiff/local.
16 |
17 | Go to /home/arm/gc6.0 directory. Do
18 | CONFIG_SITE=/home/arm/config.site ./configure --target=arm-linux
19 | --prefix=/home/arm/gc6.0
20 |
21 | On your desktop, do:
22 | make
23 | make install
24 | The main garbage collector library should now be in ../gc6.0/lib/libgc.so.
25 |
26 | To test the garbage collector, first do the following on your desktop
27 | make gctest
28 | ./gctest
29 | Then do the following on the ARM machine
30 | cd .libs
31 | ./lt-gctest
32 |
33 | Do not try to do "make test" (the usual way of running the test
34 | program). This does not work and seems to erase some of the important
35 | files.
36 |
37 | The gctest program claims to have succeeded. Haven't run any further tests
38 | with it, though I'll be doing so in the near future.
39 |
40 | -------------------------------
41 | # config.site for configure
42 |
43 | HOSTCC=gcc
44 |
45 | # Names of the cross-compilers
46 | CC=/skiff/local/bin/arm-linux-gcc
47 | CXX=/skiff/local/bin/arm-linux-gcc
48 |
49 | # The cross compiler specific options
50 | CFLAGS="-O2 -fno-exceptions"
51 | CXXFLAGS="-O2 -fno-exceptions"
52 | CPPFLAGS="-O2 -fno-exceptions"
53 | LDFLAGS=""
54 |
55 | # Some other programs
56 | AR=/skiff/local/bin/arm-linux-ar
57 | RANLIB=/skiff/local/bin/arm-linux-ranlib
58 | NM=/skiff/local/bin/arm-linux-nm
59 | ac_cv_path_NM=/skiff/local/bin/arm-linux-nm
60 | ac_cv_func_setpgrp_void=yes
61 | x_includes=/skiff/local/arm-linux/include/X11
62 | x_libraries=/skiff/local/arm-linux/lib/X11
63 |
--------------------------------------------------------------------------------
/src/gc/doc/README.autoconf:
--------------------------------------------------------------------------------
1 | Starting from GC v6.0, we support GNU-style builds based on automake,
2 | autoconf and libtool. This is based almost entirely on Tom Tromey's work
3 | with gcj.
4 |
5 | To build and install libraries use
6 |
7 | configure; make; make install
8 |
9 | The advantages of this process are:
10 |
11 | 1) It should eventually do a better job of automatically determining the
12 | right compiler to use, etc. It probably already does in some cases.
13 |
14 | 2) It tries to automatically set a good set of default GC parameters for
15 | the platform (e.g. thread support). It provides an easier way to configure
16 | some of the others.
17 |
18 | 3) It integrates better with other projects using a GNU-style build process.
19 |
20 | 4) It builds both dynamic and static libraries.
21 |
22 | The known disadvantages are:
23 |
24 | 1) The build scripts are much more complex and harder to debug (though largely
25 | standard). I don't understand them all, and there's probably lots of redundant
26 | stuff.
27 |
28 | 2) It probably doesn't work on all Un*x-like platforms yet. It probably will
29 | never work on the rest.
30 |
31 | 3) The scripts are not yet complete. Some of the standard GNU targets don't
32 | yet work. (Corrections/additions are very welcome.)
33 |
34 | The distribution should contain all files needed to run "configure" and "make",
35 | as well as the sources needed to regenerate the derived files. (If I missed
36 | some, please let me know.)
37 |
38 | Note that the distribution comes without "Makefile" which is generated by
39 | "configure". The distribution also contains "Makefile.direct" which is not
40 | always equivalent to the generated one.
41 |
42 | Important options to configure:
43 |
44 | --prefix=PREFIX install architecture-independent files in PREFIX
45 | [/usr/local]
46 | --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
47 | [same as prefix]
48 | --enable-threads=TYPE choose threading package
49 | --enable-parallel-mark parallelize marking and free list construction
50 | --enable-gc-debug (--enable-full-debug before about 7.0)
51 | include full support for pointer back-tracing etc.
52 |
53 |
54 | Unless --prefix is set (or --exec-prefix or one of the more obscure options),
55 | make install will install libgc.a and libgc.so in /usr/local/bin, which
56 | would typically require the "make install" to be run as root.
57 |
58 | Most commonly --enable-threads=posix or will be needed. --enable-parallel-mark
59 | is recommended for multiprocessors if it is supported on the platform.
60 |
--------------------------------------------------------------------------------
/src/gc/doc/README.cmake:
--------------------------------------------------------------------------------
1 |
2 | CMAKE
3 | -----
4 |
5 | Win32 binaries (both 32- and 64-bit) can be built using CMake. CMake is an
6 | open-source tool like automake - it generates makefiles.
7 |
8 | Some preliminary work has been done to make this work on other platforms, but
9 | the support is not yet complete.
10 |
11 | CMake will generate:
12 |
13 | Borland Makefiles
14 | MSYS Makefiles
15 | MinGW Makefiles
16 | NMake Makefiles
17 | Unix Makefiles
18 | . Visual Studio project files
19 | Visual Studio 6
20 | Visual Studio 7
21 | Visual Studio 7 .NET 2003
22 | Visual Studio 8 2005
23 | Visual Studio 8 2005 Win64
24 | Visual Studio 9 2008
25 | Visual Studio 9 2008 Win64
26 | Watcom WMake
27 |
28 |
29 | BUILD PROCESS
30 | -------------
31 |
32 | . install cmake (cmake.org)
33 | . add directory containing cmake.exe to %PATH%
34 | . run cmake from the gc root directory, passing the target with -G:
35 | e.g.,
36 | > cmake -G "Visual Studio 8 2005"
37 | use the gc.sln file generated by cmake to build gc
38 | . you can also run cmake from a build directory to build outside of
39 | the source tree. Just specify the path to the source tree:
40 | e.g.,
41 | > mkdir build
42 | > cd build
43 | > cmake .. -G "Visual Studio 8 2005"
44 |
45 |
46 | INPUT
47 | -----
48 |
49 | The main input to cmake are the CMakeLists.txt files in each directory. For
50 | help, goto cmake.org.
51 |
--------------------------------------------------------------------------------
/src/gc/doc/README.cords:
--------------------------------------------------------------------------------
1 | Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved.
2 |
3 | THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
4 | OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
5 |
6 | Permission is hereby granted to use or copy this program
7 | for any purpose, provided the above notices are retained on all copies.
8 | Permission to modify the code and to distribute modified code is granted,
9 | provided the above notices are retained, and a notice that the code was
10 | modified is included with the above copyright notice.
11 |
12 | Please send bug reports to Hans-J. Boehm.
13 |
14 | This is a string packages that uses a tree-based representation.
15 | See cord.h for a description of the functions provided. Ec.h describes
16 | "extensible cords", which are essentially output streams that write
17 | to a cord. These allow for efficient construction of cords without
18 | requiring a bound on the size of a cord.
19 |
20 | More details on the data structure can be found in
21 |
22 | Boehm, Atkinson, and Plass, "Ropes: An Alternative to Strings",
23 | Software Practice and Experience 25, 12, December 1995, pp. 1315-1330.
24 |
25 | A fundamentally similar "rope" data structure is also part of SGI's standard
26 | template library implementation, and its descendants, which include the
27 | GNU C++ library. That uses reference counting by default.
28 | There is a short description of that data structure at
29 | http://www.sgi.com/tech/stl/ropeimpl.html .
30 |
31 | All of these are descendants of the "ropes" in Xerox Cedar.
32 |
33 | cord/tests/de.c is a very dumb text editor that illustrates the use of cords.
34 | It maintains a list of file versions. Each version is simply a
35 | cord representing the file contents. Nonetheless, standard
36 | editing operations are efficient, even on very large files.
37 | (Its 3 line "user manual" can be obtained by invoking it without
38 | arguments. Note that ^R^N and ^R^P move the cursor by
39 | almost a screen. It does not understand tabs, which will show
40 | up as highlighted "I"s. Use the UNIX "expand" program first.)
41 | To build the editor, type "make cord/de" in the gc directory.
42 |
43 | This package assumes an ANSI C compiler such as gcc. It will
44 | not compile with an old-style K&R compiler.
45 |
46 | Note that CORD_printf iand friends use C functions with variable numbers
47 | of arguments in non-standard-conforming ways. This code is known to
48 | break on some platforms, notably PowerPC. It should be possible to
49 | build the remainder of the library (everything but cordprnt.c) on
50 | any platform that supports the collector.
51 |
--------------------------------------------------------------------------------
/src/gc/doc/README.ews4800:
--------------------------------------------------------------------------------
1 | GC on EWS4800
2 | -------------
3 |
4 | 1. About EWS4800
5 | EWS4800 is 32bit/64bit workstation.
6 |
7 | Vender: NEC Corporation
8 | OS: UX/4800 R9.* - R13.* (SystemV R4.2)
9 | CPU: R4000, R4400, R10000 (MIPS)
10 |
11 | 2. Compiler
12 |
13 | 32bit:
14 | Use ANSI C compiler.
15 | CC = /usr/abiccs/bin/cc
16 |
17 | 64bit:
18 | Use 64bit ANSI C compiler.
19 | CC = /usr/ccs64/bin/cc
20 | AR = /usr/ccs64/bin/ar
21 |
22 | 3. ELF file format
23 | *** Caution: The following infomation is empirical. ***
24 |
25 | 32bit:
26 | ELF file has an unique format. (See a.out(4) and end(3C).)
27 |
28 | &_start
29 | : text segment
30 | &etext
31 | DATASTART
32 | : data segment (initialized)
33 | &edata
34 | DATASTART2
35 | : data segment (uninitialized)
36 | &end
37 |
38 | Here, DATASTART and DATASTART2 are macros of GC, and are defined as
39 | the following equations. (See include/private/gcconfig.h.)
40 | The algorithm for DATASTART is similar with the function
41 | GC_SysVGetDataStart() in os_dep.c.
42 |
43 | DATASTART = ((&etext + 0x3ffff) & ~0x3ffff) + (&etext & 0xffff)
44 |
45 | Dynamically linked:
46 | DATASTART2 = (&_gp + 0x8000 + 0x3ffff) & ~0x3ffff
47 |
48 | Statically linked:
49 | DATASTART2 = &edata
50 |
51 | GC has to check addresses both between DATASTART and &edata, and
52 | between DATASTART2 and &end. If a program accesses between &etext
53 | and DATASTART, or between &edata and DATASTART2, the segmentation
54 | error occurs and the program stops.
55 |
56 | If a program is statically linked, there is not a gap between
57 | &edata and DATASTART2. The global symbol &_DYNAMIC_LINKING is used
58 | for the detection.
59 |
60 | 64bit:
61 | ELF file has a simple format. (See end(3C).)
62 |
63 | _ftext
64 | : text segment
65 | _etext
66 | _fdata = DATASTART
67 | : data segment (initialized)
68 | _edata
69 | _fbss
70 | : data segment (uninitialized)
71 | _end = DATAEND
72 |
73 | --
74 | Hironori SAKAMOTO
75 |
76 |
77 | When using the new "configure; make" build process, please
78 | run configure with the --disable-shared option. "Make check" does not
79 | yet pass with dynamic libraries. Ther reasons for that are not yet
80 | understood. (HB, paraphrasing message from Hironori SAKAMOTO.)
81 |
--------------------------------------------------------------------------------
/src/gc/doc/README.hp:
--------------------------------------------------------------------------------
1 | Dynamic loading support requires that executables be linked with -ldld.
2 | The alternative is to build the collector without defining DYNAMIC_LOADING
3 | in gcconfig.h and ensuring that all garbage collectible objects are
4 | accessible without considering statically allocated variables in dynamic
5 | libraries.
6 |
7 | The collector should compile with either plain cc or cc -Ae. Cc -Aa
8 | fails to define _HPUX_SOURCE and thus will not configure the collector
9 | correctly.
10 |
11 | Incremental collection support was reccently added, and should now work.
12 |
13 | In spite of past claims, pthread support under HP/UX 11 should now work.
14 | Define GC_HPUX_THREADS for the build. Incremental collection still does not
15 | work in combination with it.
16 |
17 | The stack finding code can be confused by putenv calls before collector
18 | initialization. Call GC_malloc or GC_init before any putenv calls.
19 |
--------------------------------------------------------------------------------
/src/gc/doc/README.rs6000:
--------------------------------------------------------------------------------
1 | We have so far failed to find a good way to determine the stack base.
2 | It is highly recommended that GC_stackbottom be set explicitly on program
3 | startup. The supplied value sometimes causes failure under AIX 4.1, though
4 | it appears to work under 3.X. HEURISTIC2 seems to work under 4.1, but
5 | involves a substantial performance penalty, and will fail if there is
6 | no limit on stack size.
7 |
8 | There is no thread support. (I assume recent versions of AIX provide
9 | pthreads? I no longer have access to a machine ...)
10 |
--------------------------------------------------------------------------------
/src/gc/doc/README.sgi:
--------------------------------------------------------------------------------
1 | Performance of the incremental collector can be greatly enhanced with
2 | -DNO_EXECUTE_PERMISSION.
3 |
4 | The collector should run with all of the -32, -n32 and -64 ABIs. Remember to
5 | define the AS macro in the Makefile to be "as -64", or "as -n32".
6 |
7 | If you use -DREDIRECT_MALLOC=GC_malloc with C++ code, your code should make
8 | at least one explicit call to malloc instead of new to ensure that the proper
9 | version of malloc is linked in.
10 |
11 | Sproc threads are not supported in this version, though there may exist other
12 | ports.
13 |
14 | Pthreads support is provided. This requires that:
15 |
16 | 1) You compile the collector with -DGC_IRIX_THREADS specified in the Makefile.
17 |
18 | 2) You have the latest pthreads patches installed.
19 |
20 | (Though the collector makes only documented pthread calls,
21 | it relies on signal/threads interactions working just right in ways
22 | that are not required by the standard. It is unlikely that this code
23 | will run on other pthreads platforms. But please tell me if it does.)
24 |
25 | 3) Every file that makes thread calls should define IRIX_THREADS and then
26 | include gc.h. Gc.h redefines some of the pthread primitives as macros which
27 | also provide the collector with information it requires.
28 |
29 | 4) pthread_cond_wait and pthread_cond_timed_wait should be prepared for
30 | premature wakeups. (I believe the pthreads and realted standards require this
31 | anyway. Irix pthreads often terminate a wait if a signal arrives.
32 | The garbage collector uses signals to stop threads.)
33 |
34 | 5) It is expensive to stop a thread waiting in IO at the time the request is
35 | initiated. Applications with many such threads may not exhibit acceptable
36 | performance with the collector. (Increasing the heap size may help.)
37 |
38 | 6) The collector should not be compiled with -DREDIRECT_MALLOC. This
39 | confuses some library calls made by the pthreads implementation, which
40 | expect the standard malloc.
41 |
--------------------------------------------------------------------------------
/src/gc/doc/README.solaris2:
--------------------------------------------------------------------------------
1 | The collector supports both incremental collection and threads under
2 | Solaris 2. The incremental collector normally retrieves page dirty information
3 | through the appropriate /proc calls. But it can also be configured
4 | (by defining MPROTECT_VDB instead of PROC_VDB in gcconfig.h) to use mprotect
5 | and signals. This may result in shorter pause times, but it is no longer
6 | safe to issue arbitrary system calls that write to the heap.
7 |
8 | Under other UNIX versions,
9 | the collector normally obtains memory through sbrk. There is some reason
10 | to expect that this is not safe if the client program also calls the system
11 | malloc, or especially realloc. The sbrk man page strongly suggests this is
12 | not safe: "Many library routines use malloc() internally, so use brk()
13 | and sbrk() only when you know that malloc() definitely will not be used by
14 | any library routine." This doesn't make a lot of sense to me, since there
15 | seems to be no documentation as to which routines can transitively call malloc.
16 | Nonetheless, under Solaris2, the collector now allocates
17 | memory using mmap by default. (It defines USE_MMAP in gcconfig.h.)
18 | You may want to reverse this decisions if you use -DREDIRECT_MALLOC=...
19 |
20 | Note:
21 | Before you run "make check", you need to set your LD_LIBRARY_PATH correctly
22 | (e.g., to "/usr/local/lib") so that tests can find the shared library
23 | libgcc_s.so.1. Alternatively, you can configure with --disable-shared.
24 |
25 | SOLARIS THREADS:
26 |
27 | Threads support is enabled by configure "--enable-threads=posix" option.
28 | (In case of GCC compiler, multi-threading support is on by default.)
29 | This causes the collector to be compiled with -D GC_THREADS (or
30 | -D GC_SOLARIS_THREADS) ensuring thread safety.
31 | This assumes use of the pthread_ interface. Old style Solaris threads
32 | are no longer supported.
33 | Thread-local allocation is now on by default. Parallel marking is on by
34 | default starting from GC v7.3 but it could be enabled or disabled manually
35 | by the corresponding "--enable/disable-parallel-mark" options.
36 |
37 | It is also essential that gc.h be included in files that call pthread_create,
38 | pthread_join, pthread_detach, or dlopen. gc.h macro defines these to also do
39 | GC bookkeeping, etc. gc.h must be included with one or both of these macros
40 | defined, otherwise these replacements are not visible. A collector built in
41 | this way way only be used by programs that are linked with the threads library.
42 |
43 | Since 5.0 alpha5, dlopen disables collection temporarily,
44 | unless USE_PROC_FOR_LIBRARIES is defined. In some unlikely cases, this
45 | can result in unpleasant heap growth. But it seems better than the
46 | race/deadlock issues we had before.
47 |
48 | If threads are used on an X86 processor with malloc redirected to
49 | GC_malloc, it is necessary to call GC_INIT explicitly before forking the
50 | first thread. (This avoids a deadlock arising from calling GC_thr_init
51 | with the allocation lock held.)
52 |
53 | It appears that there is a problem in using gc_cpp.h in conjunction with
54 | Solaris threads and Sun's C++ runtime. Apparently the overloaded new operator
55 | is invoked by some iostream initialization code before threads are correctly
56 | initialized. As a result, call to thr_self() in garbage collector
57 | initialization SEGV faults. Currently the only known workaround is to not
58 | invoke the garbage collector from a user defined global operator new, or to
59 | have it invoke the garbage-collector's allocators only after main has started.
60 | (Note that the latter requires a moderately expensive test in operator
61 | delete.)
62 |
63 | I encountered "symbol : offet .... is non-aligned" errors. These
64 | appear to be traceable to the use of the GNU assembler with the Sun linker.
65 | The former appears to generate a relocation not understood by the latter.
66 | The fix appears to be to use a consistent tool chain. (As a non-Solaris-expert
67 | my solution involved hacking the libtool script, but I'm sure you can
68 | do something less ugly.)
69 |
70 | Hans-J. Boehm
71 | (The above contains my personal opinions, which are probably not shared
72 | by anyone else.)
73 |
--------------------------------------------------------------------------------
/src/gc/doc/README.symbian:
--------------------------------------------------------------------------------
1 | Instructions for Symbian:
2 | 1. base version: libgc 7.1
3 | 2. Build: use libgc.mmp
4 | 3. Limitations
5 | 3.1.No multi-threaded support
6 |
7 | 3.2. Be careful with limitation that emulator introduces: Static roots are not
8 | dynamically accessible (there are Symbian APIs for this purpose but are just
9 | stubs, returning irrelevant values).
10 | Consequently, on emulator, you can only use dlls or exe, and retrieve static
11 | roots by calling global_init_static_root per dll (or exe).
12 | On target, only libs are supported, because static roots are retrieved by
13 | linker flags, by calling global_init_static_root in main exe.
14 |
--------------------------------------------------------------------------------
/src/gc/doc/README.uts:
--------------------------------------------------------------------------------
1 | Alistair Crooks supplied the port. He used Lexa C version 2.1.3 with
2 | -Xa to compile.
3 |
--------------------------------------------------------------------------------
/src/gc/doc/README.win64:
--------------------------------------------------------------------------------
1 | 64-bit Windows on AMD64/Intel EM64T is somewhat supported in the 7.0
2 | and later release. A collector can be built with Microsoft Visual C++ 2005
3 | or with mingw-w64 gcc.
4 | More testing would clearly be helpful.
5 |
6 | NT_X64_STATIC_THREADS_MAKEFILE has been used in
7 | this environment. Copy this file to MAKEFILE, and then type "nmake"
8 | in a Visual C++ command line window to build the static library
9 | and the usual test programs. To verify that the collector is
10 | at least somewhat functional, run gctest.exe. This should create
11 | gctest.gc.log after a few seconds.
12 |
13 | This process is completely analogous to NT_STATIC_THREADS_MAKEFILE
14 | for the 32-bit version.
15 |
16 | A similar procedure using NT_X64_THREADS_MAKEFILE should be usable to
17 | build the dynamic library. Test_cpp.exe did not seem to run correctly this
18 | way. It seems that we're getting the wrong instances of operator new/delete
19 | in some cases. The C tests seemed OK.
20 |
21 | Note that currently a few warnings are still generated by default,
22 | and a number of others have been explicitly turned off in the makefile.
23 |
24 | VC++ note: to suppress warnings use -D_CRT_SECURE_NO_DEPRECATE.
25 |
26 | gcc note: -fno-strict-aliasing should be used if optimizing.
27 |
--------------------------------------------------------------------------------
/src/gc/doc/doc.am:
--------------------------------------------------------------------------------
1 | #
2 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
3 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
4 | #
5 | # Permission is hereby granted to use or copy this program
6 | # for any purpose, provided the above notices are retained on all copies.
7 | # Permission to modify the code and to distribute modified code is granted,
8 | # provided the above notices are retained, and a notice that the code was
9 | # modified is included with the above copyright notice.
10 |
11 | ## Process this file with automake to produce Makefile.in.
12 |
13 | # installed documentation
14 | #
15 | dist_pkgdata_DATA = \
16 | AUTHORS \
17 | README.md \
18 | doc/README.DGUX386 \
19 | doc/README.Mac \
20 | doc/README.OS2 \
21 | doc/README.amiga \
22 | doc/README.arm.cross \
23 | doc/README.autoconf \
24 | doc/README.cmake \
25 | doc/README.cords \
26 | doc/README.darwin \
27 | doc/README.environment \
28 | doc/README.ews4800 \
29 | doc/README.hp \
30 | doc/README.linux \
31 | doc/README.macros \
32 | doc/README.rs6000 \
33 | doc/README.sgi \
34 | doc/README.solaris2 \
35 | doc/README.symbian \
36 | doc/README.uts \
37 | doc/README.win32 \
38 | doc/README.win64 \
39 | doc/debugging.html \
40 | doc/finalization.html \
41 | doc/gc.man \
42 | doc/gcdescr.html \
43 | doc/gcinterface.html \
44 | doc/leak.html \
45 | doc/overview.html \
46 | doc/porting.html \
47 | doc/scale.html \
48 | doc/simple_example.html \
49 | doc/tree.html
50 |
--------------------------------------------------------------------------------
/src/gc/extra/Mac_files/MacOS_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | MacOS_config.h
3 |
4 | Configuration flags for Macintosh development systems.
5 |
6 |
7 |
8 | 11/16/95 pcb Updated compilation flags to reflect latest 4.6 Makefile.
9 |
10 | by Patrick C. Beard.
11 | */
12 | /* Boehm, November 17, 1995 12:10 pm PST */
13 |
14 | #ifdef __MWERKS__
15 |
16 | // for CodeWarrior Pro with Metrowerks Standard Library (MSL).
17 | // #define MSL_USE_PRECOMPILED_HEADERS 0
18 | #include
19 | #endif /* __MWERKS__ */
20 |
21 | // these are defined again in gc_priv.h.
22 | #undef TRUE
23 | #undef FALSE
24 |
25 | #define ALL_INTERIOR_POINTERS // follows interior pointers.
26 | //#define DONT_ADD_BYTE_AT_END // no padding.
27 | //#define SMALL_CONFIG // whether to use a smaller heap.
28 | #define USE_TEMPORARY_MEMORY // use Macintosh temporary memory.
29 |
--------------------------------------------------------------------------------
/src/gc/extra/Mac_files/dataend.c:
--------------------------------------------------------------------------------
1 | /*
2 | dataend.c
3 |
4 | A hack to get the extent of global data for the Macintosh.
5 |
6 | by Patrick C. Beard.
7 | */
8 |
9 | long __dataend;
10 |
--------------------------------------------------------------------------------
/src/gc/extra/Mac_files/datastart.c:
--------------------------------------------------------------------------------
1 | /*
2 | datastart.c
3 |
4 | A hack to get the extent of global data for the Macintosh.
5 |
6 | by Patrick C. Beard.
7 | */
8 |
9 | long __datastart;
10 |
--------------------------------------------------------------------------------
/src/gc/extra/gc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | /* This file could be used for the following purposes: */
19 | /* - get the complete GC as a single link object file (module); */
20 | /* - enable more compiler optimizations. */
21 |
22 | /* Tip: to get the highest level of compiler optimizations, the typical */
23 | /* compiler options (GCC) to use are: */
24 | /* -O3 -fno-strict-aliasing -march=native -Wall -fprofile-generate/use */
25 |
26 | /* Warning: GCC for Linux (for C++ clients only): Use -fexceptions both */
27 | /* for GC and the client otherwise GC_thread_exit_proc() is not */
28 | /* guaranteed to be invoked (see the comments in pthread_start.c). */
29 |
30 |
31 | #define GC_INNER STATIC
32 | #define GC_EXTERN GC_INNER
33 | /* STATIC is defined in gcconfig.h. */
34 |
35 | /* Small files go first... */
36 | #include "../backgraph.c"
37 | #include "../blacklst.c"
38 | #include "../checksums.c"
39 | #include "../gcj_mlc.c"
40 | #include "../headers.c"
41 | #include "../malloc.c"
42 | #include "../new_hblk.c"
43 | #include "../obj_map.c"
44 | #include "../ptr_chck.c"
45 | #include "../stubborn.c"
46 |
47 | #include "gc_inline.h"
48 | #include "../allchblk.c"
49 | #include "../alloc.c"
50 | #include "../dbg_mlc.c"
51 | #include "../finalize.c"
52 | #include "../fnlz_mlc.c"
53 | #include "../mallocx.c"
54 | #include "../mark.c"
55 | #include "../mark_rts.c"
56 | #include "../reclaim.c"
57 | #include "../typd_mlc.c"
58 |
59 | #include "../misc.c"
60 | #include "../os_dep.c"
61 | #include "../thread_local_alloc.c"
62 |
63 | /* Most platform-specific files go here... */
64 | #include "../darwin_stop_world.c"
65 | #include "../dyn_load.c"
66 | #include "../gc_dlopen.c"
67 | #include "../mach_dep.c"
68 | #include "../pcr_interface.c"
69 | #include "../pthread_stop_world.c"
70 | #include "../pthread_support.c"
71 | #include "../specific.c"
72 | #include "../win32_threads.c"
73 |
74 | #ifndef GC_PTHREAD_START_STANDALONE
75 | # include "../pthread_start.c"
76 | #endif
77 |
78 | /* Restore pthread calls redirection (if altered in */
79 | /* pthread_stop_world.c, pthread_support.c or win32_threads.c). */
80 | /* This is only useful if directly included from application */
81 | /* (instead of linking gc). */
82 | #ifndef GC_NO_THREAD_REDIRECTS
83 | # define GC_PTHREAD_REDIRECTS_ONLY
84 | # include "gc_pthread_redirects.h"
85 | #endif
86 |
87 | /* real_malloc.c, extra/MacOS.c, extra/msvc_dbg.c are not included. */
88 |
--------------------------------------------------------------------------------
/src/gc/extra/symbian.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | int GC_get_main_symbian_stack_base()
14 | {
15 | TThreadStackInfo aInfo;
16 | TInt err = RThread().StackInfo(aInfo);
17 | if ( !err )
18 | {
19 | return aInfo.iBase;
20 | }
21 | else
22 | {
23 | return 0;
24 | }
25 | }
26 |
27 | char* GC_get_private_path_and_zero_file()
28 | {
29 | // always on c: drive
30 | RFs fs;
31 | fs.Connect();
32 | fs.CreatePrivatePath( EDriveC );
33 | TFileName path;
34 | fs.PrivatePath( path );
35 | fs.Close();
36 | _LIT( KCDrive, "c:" );
37 | path.Insert( 0, KCDrive );
38 |
39 |
40 | //convert to char*, assume ascii
41 | TBuf8 path8;
42 | path8.Copy( path );
43 | _LIT8( KZero8, "zero" );
44 | path8.Append( KZero8 );
45 |
46 | size_t size = path8.Length() + 1;
47 | char* copyChar = (char*) malloc( size );
48 | memcpy( copyChar, path8.PtrZ(), size );
49 |
50 | return copyChar; // ownership passed
51 | }
52 |
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/gc/extra/symbian/global_end.cpp:
--------------------------------------------------------------------------------
1 | // Symbian-specific file.
2 |
3 | // INCLUDE FILES
4 | #include "private/gcconfig.h"
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | int winscw_data_end;
11 |
12 | #ifdef __cplusplus
13 | }
14 | #endif
15 |
16 | // End Of File
17 |
--------------------------------------------------------------------------------
/src/gc/extra/symbian/global_start.cpp:
--------------------------------------------------------------------------------
1 | // Symbian-specific file.
2 |
3 | // INCLUDE FILES
4 | #include "private/gcconfig.h"
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | int winscw_data_start;
11 |
12 | #ifdef __cplusplus
13 | }
14 | #endif
15 |
16 | // End Of File
17 |
--------------------------------------------------------------------------------
/src/gc/extra/symbian/init_global_static_roots.cpp:
--------------------------------------------------------------------------------
1 | // Symbian-specific file.
2 |
3 | // INCLUDE FILES
4 | #include
5 |
6 | #include "private/gcconfig.h"
7 | #include "gc.h"
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | void GC_init_global_static_roots()
14 | {
15 | ptr_t dataStart = NULL;
16 | ptr_t dataEnd = NULL;
17 | # if defined (__WINS__)
18 | extern int winscw_data_start, winscw_data_end;
19 | dataStart = ((ptr_t)&winscw_data_start);
20 | dataEnd = ((ptr_t)&winscw_data_end);
21 | # else
22 | extern int Image$$RW$$Limit[], Image$$RW$$Base[];
23 | dataStart = ((ptr_t)Image$$RW$$Base);
24 | dataEnd = ((ptr_t)Image$$RW$$Limit);
25 | # endif
26 |
27 | GC_add_roots(dataStart, dataEnd);
28 |
29 | }
30 |
31 | #ifdef __cplusplus
32 | }
33 | #endif
34 |
--------------------------------------------------------------------------------
/src/gc/gc_cpp.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to copy this code for any purpose,
8 | * provided the above notices are retained on all copies.
9 | */
10 |
11 | /*************************************************************************
12 | This implementation module for gc_c++.h provides an implementation of
13 | the global operators "new" and "delete" that calls the Boehm
14 | allocator. All objects allocated by this implementation will be
15 | uncollectible but part of the root set of the collector.
16 |
17 | You should ensure (using implementation-dependent techniques) that the
18 | linker finds this module before the library that defines the default
19 | built-in "new" and "delete".
20 | **************************************************************************/
21 |
22 | #ifdef HAVE_CONFIG_H
23 | # include "config.h"
24 | #endif
25 |
26 | #ifndef GC_BUILD
27 | # define GC_BUILD
28 | #endif
29 |
30 | #include "gc_cpp.h"
31 |
32 | #if !defined(GC_NEW_DELETE_NEED_THROW) && defined(__GNUC__) \
33 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
34 | # define GC_NEW_DELETE_NEED_THROW
35 | #endif
36 |
37 | #ifdef GC_NEW_DELETE_NEED_THROW
38 | # include /* for std::bad_alloc */
39 | # define GC_DECL_NEW_THROW throw(std::bad_alloc)
40 | # define GC_DECL_DELETE_THROW throw()
41 | #else
42 | # define GC_DECL_NEW_THROW /* empty */
43 | # define GC_DECL_DELETE_THROW /* empty */
44 | #endif // !GC_NEW_DELETE_NEED_THROW
45 |
46 | #ifndef _MSC_VER
47 |
48 | void* operator new(size_t size) GC_DECL_NEW_THROW {
49 | return GC_MALLOC_UNCOLLECTABLE(size);
50 | }
51 |
52 | # if !defined(__CYGWIN__)
53 | void operator delete(void* obj) GC_DECL_DELETE_THROW {
54 | GC_FREE(obj);
55 | }
56 | # endif // !__CYGWIN__
57 |
58 | # ifdef GC_OPERATOR_NEW_ARRAY
59 | void* operator new[](size_t size) GC_DECL_NEW_THROW {
60 | return GC_MALLOC_UNCOLLECTABLE(size);
61 | }
62 |
63 | void operator delete[](void* obj) GC_DECL_DELETE_THROW {
64 | GC_FREE(obj);
65 | }
66 | # endif // GC_OPERATOR_NEW_ARRAY
67 |
68 | #endif // !_MSC_VER
69 |
--------------------------------------------------------------------------------
/src/gc/gc_cpp.cpp:
--------------------------------------------------------------------------------
1 | // Visual C++ seems to prefer a .cpp extension to .cc
2 | #include "gc_cpp.cc"
3 |
--------------------------------------------------------------------------------
/src/gc/ia64_save_regs_in_stack.s:
--------------------------------------------------------------------------------
1 | .text
2 | .align 16
3 | .global GC_save_regs_in_stack
4 | .proc GC_save_regs_in_stack
5 | GC_save_regs_in_stack:
6 | .body
7 | flushrs
8 | ;;
9 | mov r8=ar.bsp
10 | br.ret.sptk.few rp
11 | .endp GC_save_regs_in_stack
12 |
--------------------------------------------------------------------------------
/src/gc/include/ec.h:
--------------------------------------------------------------------------------
1 | # ifndef EC_H
2 | # define EC_H
3 |
4 | # ifndef CORD_H
5 | # include "cord.h"
6 | # endif
7 |
8 | /* Extensible cords are strings that may be destructively appended to. */
9 | /* They allow fast construction of cords from characters that are */
10 | /* being read from a stream. */
11 | /*
12 | * A client might look like:
13 | *
14 | * {
15 | * CORD_ec x;
16 | * CORD result;
17 | * char c;
18 | * FILE *f;
19 | *
20 | * ...
21 | * CORD_ec_init(x);
22 | * while(...) {
23 | * c = getc(f);
24 | * ...
25 | * CORD_ec_append(x, c);
26 | * }
27 | * result = CORD_balance(CORD_ec_to_cord(x));
28 | *
29 | * If a C string is desired as the final result, the call to CORD_balance
30 | * may be replaced by a call to CORD_to_char_star.
31 | */
32 |
33 | # ifndef CORD_BUFSZ
34 | # define CORD_BUFSZ 128
35 | # endif
36 |
37 | typedef struct CORD_ec_struct {
38 | CORD ec_cord;
39 | char * ec_bufptr;
40 | char ec_buf[CORD_BUFSZ+1];
41 | } CORD_ec[1];
42 |
43 | /* This structure represents the concatenation of ec_cord with */
44 | /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */
45 |
46 | /* Flush the buffer part of the extended chord into ec_cord. */
47 | /* Note that this is almost the only real function, and it is */
48 | /* implemented in 6 lines in cordxtra.c */
49 | void CORD_ec_flush_buf(CORD_ec x);
50 |
51 | /* Convert an extensible cord to a cord. */
52 | # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord)
53 |
54 | /* Initialize an extensible cord. */
55 | #define CORD_ec_init(x) \
56 | ((x)[0].ec_cord = 0, (void)((x)[0].ec_bufptr = (x)[0].ec_buf))
57 |
58 | /* Append a character to an extensible cord. */
59 | #define CORD_ec_append(x, c) \
60 | (((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ ? \
61 | (CORD_ec_flush_buf(x), 0) : 0), \
62 | (void)(*(x)[0].ec_bufptr++ = (c)))
63 |
64 | /* Append a cord to an extensible cord. Structure remains shared with */
65 | /* original. */
66 | void CORD_ec_append_cord(CORD_ec x, CORD s);
67 |
68 | # endif /* EC_H */
69 |
--------------------------------------------------------------------------------
/src/gc/include/extra/gc.h:
--------------------------------------------------------------------------------
1 | /* This file is installed for backward compatibility. */
2 | #include
3 |
--------------------------------------------------------------------------------
/src/gc/include/extra/gc_cpp.h:
--------------------------------------------------------------------------------
1 | /* This file is installed for backward compatibility. */
2 | #include
3 |
--------------------------------------------------------------------------------
/src/gc/include/gc_disclaim.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007-2011 by Hewlett-Packard Company. All rights reserved.
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to use or copy this program
8 | * for any purpose, provided the above notices are retained on all copies.
9 | * Permission to modify the code and to distribute modified code is granted,
10 | * provided the above notices are retained, and a notice that the code was
11 | * modified is included with the above copyright notice.
12 | *
13 | */
14 |
15 | #ifndef GC_DISCLAIM_H
16 | #define GC_DISCLAIM_H
17 |
18 | #include "gc.h"
19 |
20 | /* This API is defined only if the library has been suitably compiled */
21 | /* (i.e. with ENABLE_DISCLAIM defined). */
22 |
23 | /* Prepare the object kind used by GC_finalized_malloc. Call it from */
24 | /* your initialization code or, at least, at some point before using */
25 | /* finalized allocations. The function is thread-safe. */
26 | GC_API void GC_CALL GC_init_finalized_malloc(void);
27 |
28 | /* Type of a disclaim call-back. */
29 | typedef int (GC_CALLBACK * GC_disclaim_proc)(void * /*obj*/);
30 |
31 | /* Register "proc" to be called on each object of "kind" ready to be */
32 | /* reclaimed. If "proc" returns non-zero, the collector will not */
33 | /* reclaim the object on this GC cycle. Objects reachable from "proc" */
34 | /* will be protected from collection if "mark_from_all" is non-zero, */
35 | /* but at the expense that long chains of objects will take many cycles */
36 | /* to reclaim. */
37 | GC_API void GC_CALL GC_register_disclaim_proc(int /*kind*/,
38 | GC_disclaim_proc /*proc*/,
39 | int /*mark_from_all*/);
40 |
41 | /* The finalizer closure used by GC_finalized_malloc. */
42 | struct GC_finalizer_closure {
43 | GC_finalization_proc proc;
44 | void *cd;
45 | };
46 |
47 | /* Allocate "size" bytes which is finalized by "fc". This uses a */
48 | /* dedicated object kind with a disclaim procedure, and is more */
49 | /* efficient than GC_register_finalizer and friends. */
50 | /* GC_init_finalized_malloc must be called before using this. */
51 | GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
52 | GC_finalized_malloc(size_t /*size*/,
53 | const struct GC_finalizer_closure * /*fc*/);
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/gc/include/gc_pthread_redirects.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | /* Our pthread support normally needs to intercept a number of thread */
19 | /* calls. We arrange to do that here, if appropriate. */
20 |
21 | /* Included from gc.h only. Included only if GC_PTHREADS. */
22 | #if defined(GC_H) && defined(GC_PTHREADS)
23 |
24 | /* We need to intercept calls to many of the threads primitives, so */
25 | /* that we can locate thread stacks and stop the world. */
26 | /* Note also that the collector cannot always see thread specific data. */
27 | /* Thread specific data should generally consist of pointers to */
28 | /* uncollectible objects (allocated with GC_malloc_uncollectable, */
29 | /* not the system malloc), which are deallocated using the destructor */
30 | /* facility in thr_keycreate. Alternatively, keep a redundant pointer */
31 | /* to thread specific data on the thread stack. */
32 |
33 | #ifndef GC_PTHREAD_REDIRECTS_ONLY
34 | # include
35 |
36 | # ifndef GC_NO_DLOPEN
37 | # include
38 | GC_API void *GC_dlopen(const char * /* path */, int /* mode */);
39 | # endif /* !GC_NO_DLOPEN */
40 |
41 | # ifndef GC_NO_PTHREAD_SIGMASK
42 | # include
43 | GC_API int GC_pthread_sigmask(int /* how */, const sigset_t *,
44 | sigset_t * /* oset */);
45 | # endif /* !GC_NO_PTHREAD_SIGMASK */
46 |
47 | # ifndef GC_PTHREAD_CREATE_CONST
48 | /* This is used for pthread_create() only. */
49 | # define GC_PTHREAD_CREATE_CONST const
50 | # endif
51 |
52 | GC_API int GC_pthread_create(pthread_t *,
53 | GC_PTHREAD_CREATE_CONST pthread_attr_t *,
54 | void *(*)(void *), void * /* arg */);
55 | GC_API int GC_pthread_join(pthread_t, void ** /* retval */);
56 | GC_API int GC_pthread_detach(pthread_t);
57 |
58 | # ifndef GC_NO_PTHREAD_CANCEL
59 | GC_API int GC_pthread_cancel(pthread_t);
60 | # endif
61 |
62 | # if defined(GC_PTHREAD_EXIT_ATTRIBUTE) && !defined(GC_PTHREAD_EXIT_DECLARED)
63 | # define GC_PTHREAD_EXIT_DECLARED
64 | GC_API void GC_pthread_exit(void *) GC_PTHREAD_EXIT_ATTRIBUTE;
65 | # endif
66 | #endif /* !GC_PTHREAD_REDIRECTS_ONLY */
67 |
68 | #if !defined(GC_NO_THREAD_REDIRECTS) && !defined(GC_USE_LD_WRAP)
69 | /* Unless the compiler supports #pragma extern_prefix, the Tru64 */
70 | /* UNIX redefines some POSIX thread functions to use */
71 | /* mangled names. Anyway, it's safe to undef them before redefining. */
72 | # undef pthread_create
73 | # undef pthread_join
74 | # undef pthread_detach
75 | # define pthread_create GC_pthread_create
76 | # define pthread_join GC_pthread_join
77 | # define pthread_detach GC_pthread_detach
78 |
79 | # ifndef GC_NO_PTHREAD_SIGMASK
80 | # undef pthread_sigmask
81 | # define pthread_sigmask GC_pthread_sigmask
82 | # endif
83 | # ifndef GC_NO_DLOPEN
84 | # undef dlopen
85 | # define dlopen GC_dlopen
86 | # endif
87 | # ifndef GC_NO_PTHREAD_CANCEL
88 | # undef pthread_cancel
89 | # define pthread_cancel GC_pthread_cancel
90 | # endif
91 | # ifdef GC_PTHREAD_EXIT_ATTRIBUTE
92 | # undef pthread_exit
93 | # define pthread_exit GC_pthread_exit
94 | # endif
95 | #endif /* !GC_NO_THREAD_REDIRECTS */
96 |
97 | #endif /* GC_PTHREADS */
98 |
--------------------------------------------------------------------------------
/src/gc/include/gc_version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | /* This should never be included directly; it is included only from gc.h. */
19 | #if defined(GC_H)
20 |
21 | /* The policy regarding version numbers: development code has odd */
22 | /* "minor" number (and "micro" part is 0); when development is finished */
23 | /* and a release is prepared, "minor" number is incremented (keeping */
24 | /* "micro" number still zero), whenever a defect is fixed a new release */
25 | /* is prepared incrementing "micro" part to odd value (the most stable */
26 | /* release has the biggest "micro" number). */
27 |
28 | /* The version here should match that in configure/configure.ac */
29 | /* Eventually this one may become unnecessary. For now we need */
30 | /* it to keep the old-style build process working. */
31 | #define GC_TMP_VERSION_MAJOR 7
32 | #define GC_TMP_VERSION_MINOR 5
33 | #define GC_TMP_VERSION_MICRO 0 /* 7.5.0 */
34 |
35 | #ifdef GC_VERSION_MAJOR
36 | # if GC_TMP_VERSION_MAJOR != GC_VERSION_MAJOR \
37 | || GC_TMP_VERSION_MINOR != GC_VERSION_MINOR \
38 | || GC_TMP_VERSION_MICRO != GC_VERSION_MICRO
39 | # error Inconsistent version info. Check README.md, include/gc_version.h and configure.ac.
40 | # endif
41 | #else
42 | # define GC_VERSION_MAJOR GC_TMP_VERSION_MAJOR
43 | # define GC_VERSION_MINOR GC_TMP_VERSION_MINOR
44 | # define GC_VERSION_MICRO GC_TMP_VERSION_MICRO
45 | #endif /* !GC_VERSION_MAJOR */
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/src/gc/include/include.am:
--------------------------------------------------------------------------------
1 | #
2 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
3 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
4 | #
5 | # Permission is hereby granted to use or copy this program
6 | # for any purpose, provided the above notices are retained on all copies.
7 | # Permission to modify the code and to distribute modified code is granted,
8 | # provided the above notices are retained, and a notice that the code was
9 | # modified is included with the above copyright notice.
10 |
11 | ## Process this file with automake to produce part of Makefile.in.
12 |
13 | # installed headers
14 | #
15 | pkginclude_HEADERS += \
16 | include/gc.h \
17 | include/gc_allocator.h \
18 | include/gc_backptr.h \
19 | include/gc_config_macros.h \
20 | include/gc_disclaim.h \
21 | include/gc_gcj.h \
22 | include/gc_inline.h \
23 | include/gc_mark.h \
24 | include/gc_pthread_redirects.h \
25 | include/gc_tiny_fl.h \
26 | include/gc_typed.h \
27 | include/gc_version.h \
28 | include/javaxfc.h \
29 | include/leak_detector.h \
30 | include/weakpointer.h
31 |
32 | # headers which are not installed
33 | #
34 | dist_noinst_HEADERS += \
35 | include/cord.h \
36 | include/cord_pos.h \
37 | include/ec.h \
38 | include/new_gc_alloc.h \
39 | include/private/darwin_semaphore.h \
40 | include/private/darwin_stop_world.h \
41 | include/private/dbg_mlc.h \
42 | include/private/gc_hdrs.h \
43 | include/private/gc_locks.h \
44 | include/private/gc_pmark.h \
45 | include/private/gc_priv.h \
46 | include/private/gcconfig.h \
47 | include/private/msvc_dbg.h \
48 | include/private/pthread_stop_world.h \
49 | include/private/pthread_support.h \
50 | include/private/specific.h \
51 | include/private/thread_local_alloc.h
52 |
53 | # unprefixed header
54 | include_HEADERS += \
55 | include/extra/gc.h
56 |
--------------------------------------------------------------------------------
/src/gc/include/javaxfc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | #ifndef GC_H
19 | # include "gc.h"
20 | #endif
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | /*
27 | * Invoke all remaining finalizers that haven't yet been run. (Since the
28 | * notifier is not called, this should be called from a separate thread.)
29 | * This function is needed for strict compliance with the Java standard,
30 | * which can make the runtime guarantee that all finalizers are run.
31 | * This is problematic for several reasons:
32 | * 1) It means that finalizers, and all methods called by them,
33 | * must be prepared to deal with objects that have been finalized in
34 | * spite of the fact that they are still referenced by statically
35 | * allocated pointer variables.
36 | * 1) It may mean that we get stuck in an infinite loop running
37 | * finalizers which create new finalizable objects, though that's
38 | * probably unlikely.
39 | * Thus this is not recommended for general use.
40 | */
41 | GC_API void GC_CALL GC_finalize_all(void);
42 |
43 | #ifdef __cplusplus
44 | } /* end of extern "C" */
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/gc/include/leak_detector.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2011 by Hewlett-Packard Development Company.
3 | * All rights reserved.
4 | *
5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 | *
8 | * Permission is hereby granted to use or copy this program
9 | * for any purpose, provided the above notices are retained on all copies.
10 | * Permission to modify the code and to distribute modified code is granted,
11 | * provided the above notices are retained, and a notice that the code was
12 | * modified is included with the above copyright notice.
13 | */
14 |
15 | #ifndef GC_LEAK_DETECTOR_H
16 | #define GC_LEAK_DETECTOR_H
17 |
18 | /* Include leak_detector.h (e.g., via GCC --include directive) */
19 | /* to turn BoehmGC into a Leak Detector. */
20 |
21 | #ifndef GC_DEBUG
22 | # define GC_DEBUG
23 | #endif
24 | #include "gc.h"
25 |
26 | #ifndef GC_DONT_INCLUDE_STDLIB
27 | /* We ensure stdlib.h and string.h are included before */
28 | /* redirecting malloc() and the accompanying functions. */
29 | # include
30 | # include
31 | #endif
32 |
33 | #undef malloc
34 | #define malloc(n) GC_MALLOC(n)
35 | #undef calloc
36 | #define calloc(m,n) GC_MALLOC((m)*(n))
37 | #undef free
38 | #define free(p) GC_FREE(p)
39 | #undef realloc
40 | #define realloc(p,n) GC_REALLOC(p,n)
41 |
42 | #undef strdup
43 | #define strdup(s) GC_STRDUP(s)
44 | #undef strndup
45 | #define strndup(s,n) GC_STRNDUP(s,n)
46 |
47 | #ifdef GC_REQUIRE_WCSDUP
48 | /* The collector should be built with GC_REQUIRE_WCSDUP */
49 | /* defined as well to redirect wcsdup(). */
50 | # include
51 | # undef wcsdup
52 | # define wcsdup(s) GC_WCSDUP(s)
53 | #endif
54 |
55 | #undef memalign
56 | #define memalign(a,n) GC_memalign(a,n)
57 | #undef posix_memalign
58 | #define posix_memalign(p,a,n) GC_posix_memalign(p,a,n)
59 |
60 | #ifndef CHECK_LEAKS
61 | # define CHECK_LEAKS() GC_gcollect()
62 | /* Note 1: CHECK_LEAKS does not have GC prefix (preserved for */
63 | /* backward compatibility). */
64 | /* Note 2: GC_gcollect() is also called automatically in the */
65 | /* leak-finding mode at program exit. */
66 | #endif
67 |
68 | #endif /* GC_LEAK_DETECTOR_H */
69 |
--------------------------------------------------------------------------------
/src/gc/include/private/darwin_semaphore.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | #ifndef GC_DARWIN_SEMAPHORE_H
19 | #define GC_DARWIN_SEMAPHORE_H
20 |
21 | #if !defined(GC_DARWIN_THREADS)
22 | # error darwin_semaphore.h included with GC_DARWIN_THREADS not defined
23 | #endif
24 |
25 | /* This is a very simple semaphore implementation for Darwin. It is */
26 | /* implemented in terms of pthread calls so it is not async signal */
27 | /* safe. But this is not a problem because signals are not used to */
28 | /* suspend threads on Darwin. */
29 |
30 | typedef struct {
31 | pthread_mutex_t mutex;
32 | pthread_cond_t cond;
33 | int value;
34 | } sem_t;
35 |
36 | GC_INLINE int sem_init(sem_t *sem, int pshared, int value) {
37 | if (pshared != 0) {
38 | errno = EPERM; /* unsupported */
39 | return -1;
40 | }
41 | sem->value = value;
42 | if (pthread_mutex_init(&sem->mutex, NULL) != 0)
43 | return -1;
44 | if (pthread_cond_init(&sem->cond, NULL) != 0) {
45 | (void)pthread_mutex_destroy(&sem->mutex);
46 | return -1;
47 | }
48 | return 0;
49 | }
50 |
51 | GC_INLINE int sem_post(sem_t *sem) {
52 | if (pthread_mutex_lock(&sem->mutex) != 0)
53 | return -1;
54 | sem->value++;
55 | if (pthread_cond_signal(&sem->cond) != 0) {
56 | (void)pthread_mutex_unlock(&sem->mutex);
57 | return -1;
58 | }
59 | return pthread_mutex_unlock(&sem->mutex) != 0 ? -1 : 0;
60 | }
61 |
62 | GC_INLINE int sem_wait(sem_t *sem) {
63 | if (pthread_mutex_lock(&sem->mutex) != 0)
64 | return -1;
65 | while (sem->value == 0) {
66 | if (pthread_cond_wait(&sem->cond, &sem->mutex) != 0) {
67 | (void)pthread_mutex_unlock(&sem->mutex);
68 | return -1;
69 | }
70 | }
71 | sem->value--;
72 | return pthread_mutex_unlock(&sem->mutex) != 0 ? -1 : 0;
73 | }
74 |
75 | GC_INLINE int sem_destroy(sem_t *sem) {
76 | return pthread_cond_destroy(&sem->cond) != 0
77 | || pthread_mutex_destroy(&sem->mutex) != 0 ? -1 : 0;
78 | }
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/src/gc/include/private/darwin_stop_world.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | #ifndef GC_DARWIN_STOP_WORLD_H
19 | #define GC_DARWIN_STOP_WORLD_H
20 |
21 | #if !defined(GC_DARWIN_THREADS)
22 | # error darwin_stop_world.h included without GC_DARWIN_THREADS defined
23 | #endif
24 |
25 | #include
26 | #include
27 |
28 | struct thread_stop_info {
29 | mach_port_t mach_thread;
30 | ptr_t stack_ptr; /* Valid only when thread is in a "blocked" state. */
31 | };
32 |
33 | #ifndef DARWIN_DONT_PARSE_STACK
34 | GC_INNER ptr_t GC_FindTopOfStack(unsigned long);
35 | #endif
36 |
37 | #ifdef MPROTECT_VDB
38 | GC_INNER void GC_mprotect_stop(void);
39 | GC_INNER void GC_mprotect_resume(void);
40 | #endif
41 |
42 | #if defined(PARALLEL_MARK) && !defined(GC_NO_THREADS_DISCOVERY)
43 | GC_INNER GC_bool GC_is_mach_marker(thread_act_t);
44 | #endif
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/src/gc/include/private/msvc_dbg.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2004-2005 Andrei Polushin
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 | #ifndef _MSVC_DBG_H
23 | #define _MSVC_DBG_H
24 |
25 | #include
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | #if !MSVC_DBG_DLL
32 | #define MSVC_DBG_EXPORT
33 | #elif MSVC_DBG_BUILD
34 | #define MSVC_DBG_EXPORT __declspec(dllexport)
35 | #else
36 | #define MSVC_DBG_EXPORT __declspec(dllimport)
37 | #endif
38 |
39 | #ifndef MAX_SYM_NAME
40 | #define MAX_SYM_NAME 2000
41 | #endif
42 |
43 | typedef void* HANDLE;
44 | typedef struct _CONTEXT CONTEXT;
45 |
46 | MSVC_DBG_EXPORT size_t GetStackFrames(size_t skip, void* frames[], size_t maxFrames);
47 | MSVC_DBG_EXPORT size_t GetStackFramesFromContext(HANDLE hProcess, HANDLE hThread, CONTEXT* context, size_t skip, void* frames[], size_t maxFrames);
48 |
49 | MSVC_DBG_EXPORT size_t GetModuleNameFromAddress(void* address, char* moduleName, size_t size);
50 | MSVC_DBG_EXPORT size_t GetModuleNameFromStack(size_t skip, char* moduleName, size_t size);
51 |
52 | MSVC_DBG_EXPORT size_t GetSymbolNameFromAddress(void* address, char* symbolName, size_t size, size_t* offsetBytes);
53 | MSVC_DBG_EXPORT size_t GetSymbolNameFromStack(size_t skip, char* symbolName, size_t size, size_t* offsetBytes);
54 |
55 | MSVC_DBG_EXPORT size_t GetFileLineFromAddress(void* address, char* fileName, size_t size, size_t* lineNumber, size_t* offsetBytes);
56 | MSVC_DBG_EXPORT size_t GetFileLineFromStack(size_t skip, char* fileName, size_t size, size_t* lineNumber, size_t* offsetBytes);
57 |
58 | MSVC_DBG_EXPORT size_t GetDescriptionFromAddress(void* address, const char* format, char* description, size_t size);
59 | MSVC_DBG_EXPORT size_t GetDescriptionFromStack(void*const frames[], size_t count, const char* format, char* description[], size_t size);
60 |
61 | /* Compatibility with */
62 | MSVC_DBG_EXPORT int backtrace(void* addresses[], int count);
63 | MSVC_DBG_EXPORT char** backtrace_symbols(void*const addresses[], int count);
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 |
69 | #endif/*_MSVC_DBG_H*/
70 |
--------------------------------------------------------------------------------
/src/gc/include/private/pthread_stop_world.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | #ifndef GC_PTHREAD_STOP_WORLD_H
19 | #define GC_PTHREAD_STOP_WORLD_H
20 |
21 | struct thread_stop_info {
22 | # ifndef GC_OPENBSD_UTHREADS
23 | word last_stop_count; /* GC_last_stop_count value when thread */
24 | /* last successfully handled a suspend */
25 | /* signal. */
26 | # endif
27 |
28 | ptr_t stack_ptr; /* Valid only when stopped. */
29 |
30 | # ifdef NACL
31 | /* Grab NACL_GC_REG_STORAGE_SIZE pointers off the stack when */
32 | /* going into a syscall. 20 is more than we need, but it's an */
33 | /* overestimate in case the instrumented function uses any callee */
34 | /* saved registers, they may be pushed to the stack much earlier. */
35 | /* Also, on amd64 'push' puts 8 bytes on the stack even though */
36 | /* our pointers are 4 bytes. */
37 | # define NACL_GC_REG_STORAGE_SIZE 20
38 | ptr_t reg_storage[NACL_GC_REG_STORAGE_SIZE];
39 | # endif
40 | };
41 |
42 | GC_INNER void GC_stop_init(void);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/gc/m4/gc_set_version.m4:
--------------------------------------------------------------------------------
1 | #
2 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
3 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
4 | #
5 | # Permission is hereby granted to use or copy this program
6 | # for any purpose, provided the above notices are retained on all copies.
7 | # Permission to modify the code and to distribute modified code is granted,
8 | # provided the above notices are retained, and a notice that the code was
9 | # modified is included with the above copyright notice.
10 |
11 | # GC_SET_VERSION
12 | # sets and AC_DEFINEs GC_VERSION_MAJOR, GC_VERSION_MINOR and GC_VERSION_MICRO
13 | # based on the contents of PACKAGE_VERSION; PACKAGE_VERSION must conform to
14 | # [0-9]+[.][0-9]+[.][0-9]+
15 | #
16 | AC_DEFUN([GC_SET_VERSION], [
17 | AC_MSG_CHECKING(GC version numbers)
18 | GC_VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\([[0-9]][[0-9]]*\)[[.]].*$/\1/g'`
19 | GC_VERSION_MINOR=`echo $PACKAGE_VERSION | sed 's/^[[^.]]*[[.]]\([[0-9]][[0-9]]*\).*$/\1/g'`
20 | GC_VERSION_MICRO=`echo $PACKAGE_VERSION | sed 's/^[[^.]]*[[.]][[^.]]*[[.]]\([[0-9]][[0-9]]*\)$/\1/g'`
21 |
22 | if test :$GC_VERSION_MAJOR: = :: \
23 | -o :$GC_VERSION_MINOR: = :: \
24 | -o :$GC_VERSION_MICRO: = :: ;
25 | then
26 | AC_MSG_RESULT(invalid)
27 | AC_MSG_ERROR([nonconforming PACKAGE_VERSION='$PACKAGE_VERSION'])
28 | fi
29 |
30 | AC_DEFINE_UNQUOTED([GC_VERSION_MAJOR], $GC_VERSION_MAJOR,
31 | [The major version number of this GC release.])
32 | AC_DEFINE_UNQUOTED([GC_VERSION_MINOR], $GC_VERSION_MINOR,
33 | [The minor version number of this GC release.])
34 | AC_DEFINE_UNQUOTED([GC_VERSION_MICRO], $GC_VERSION_MICRO,
35 | [The micro version number of this GC release.])
36 | AC_MSG_RESULT(major=$GC_VERSION_MAJOR minor=$GC_VERSION_MINOR \
37 | micro=$GC_VERSION_MICRO)
38 | ])
39 |
40 | sinclude(libtool.m4)
41 |
--------------------------------------------------------------------------------
/src/gc/obj_map.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 | * Copyright (c) 1991, 1992 by Xerox Corporation. All rights reserved.
4 | * Copyright (c) 1999-2001 by Hewlett-Packard Company. All rights reserved.
5 | *
6 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
7 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8 | *
9 | * Permission is hereby granted to use or copy this program
10 | * for any purpose, provided the above notices are retained on all copies.
11 | * Permission to modify the code and to distribute modified code is granted,
12 | * provided the above notices are retained, and a notice that the code was
13 | * modified is included with the above copyright notice.
14 | */
15 |
16 | #include "private/gc_priv.h"
17 |
18 | /* Routines for maintaining maps describing heap block
19 | * layouts for various object sizes. Allows fast pointer validity checks
20 | * and fast location of object start locations on machines (such as SPARC)
21 | * with slow division.
22 | */
23 |
24 | /* Consider pointers that are offset bytes displaced from the beginning */
25 | /* of an object to be valid. */
26 |
27 | GC_API void GC_CALL GC_register_displacement(size_t offset)
28 | {
29 | DCL_LOCK_STATE;
30 |
31 | LOCK();
32 | GC_register_displacement_inner(offset);
33 | UNLOCK();
34 | }
35 |
36 | GC_INNER void GC_register_displacement_inner(size_t offset)
37 | {
38 | if (offset >= VALID_OFFSET_SZ) {
39 | ABORT("Bad argument to GC_register_displacement");
40 | }
41 | if (!GC_valid_offsets[offset]) {
42 | GC_valid_offsets[offset] = TRUE;
43 | GC_modws_valid_offsets[offset % sizeof(word)] = TRUE;
44 | }
45 | }
46 |
47 | #ifdef MARK_BIT_PER_GRANULE
48 | /* Add a heap block map for objects of size granules to obj_map. */
49 | /* Return FALSE on failure. */
50 | /* A size of 0 granules is used for large objects. */
51 | GC_INNER GC_bool GC_add_map_entry(size_t granules)
52 | {
53 | unsigned displ;
54 | short * new_map;
55 |
56 | if (granules > BYTES_TO_GRANULES(MAXOBJBYTES)) granules = 0;
57 | if (GC_obj_map[granules] != 0) {
58 | return(TRUE);
59 | }
60 | new_map = (short *)GC_scratch_alloc(MAP_LEN * sizeof(short));
61 | if (new_map == 0) return(FALSE);
62 | GC_COND_LOG_PRINTF(
63 | "Adding block map for size of %u granules (%u bytes)\n",
64 | (unsigned)granules, (unsigned)GRANULES_TO_BYTES(granules));
65 | if (granules == 0) {
66 | for (displ = 0; displ < BYTES_TO_GRANULES(HBLKSIZE); displ++) {
67 | new_map[displ] = 1; /* Nonzero to get us out of marker fast path. */
68 | }
69 | } else {
70 | for (displ = 0; displ < BYTES_TO_GRANULES(HBLKSIZE); displ++) {
71 | new_map[displ] = (short)(displ % granules);
72 | }
73 | }
74 | GC_obj_map[granules] = new_map;
75 | return(TRUE);
76 | }
77 | #endif /* MARK_BIT_PER_GRANULE */
78 |
79 | GC_INNER void GC_initialize_offsets(void)
80 | {
81 | unsigned i;
82 | if (GC_all_interior_pointers) {
83 | for (i = 0; i < VALID_OFFSET_SZ; ++i)
84 | GC_valid_offsets[i] = TRUE;
85 | } else {
86 | BZERO(GC_valid_offsets, sizeof(GC_valid_offsets));
87 | for (i = 0; i < sizeof(word); ++i)
88 | GC_modws_valid_offsets[i] = FALSE;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/gc/pthread_start.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | /* We want to make sure that GC_thread_exit_proc() is unconditionally */
19 | /* invoked, even if the client is not compiled with -fexceptions, but */
20 | /* the GC is. The workaround is to put GC_inner_start_routine() in its */
21 | /* own file (pthread_start.c), and undefine __EXCEPTIONS in the GCC */
22 | /* case at the top of the file. FIXME: it's still unclear whether this */
23 | /* will actually cause the exit handler to be invoked last when */
24 | /* thread_exit is called (and if -fexceptions is used). */
25 | #if defined(__GNUC__) && defined(__linux__)
26 | /* We undefine __EXCEPTIONS to avoid using GCC __cleanup__ attribute. */
27 | /* The current NPTL implementation of pthread_cleanup_push uses */
28 | /* __cleanup__ attribute when __EXCEPTIONS is defined (-fexceptions). */
29 | /* The stack unwinding and cleanup with __cleanup__ attributes work */
30 | /* correctly when everything is compiled with -fexceptions, but it is */
31 | /* not the requirement for this library clients to use -fexceptions */
32 | /* everywhere. With __EXCEPTIONS undefined, the cleanup routines are */
33 | /* registered with __pthread_register_cancel thus should work anyway. */
34 | # undef __EXCEPTIONS
35 | #endif
36 |
37 | #include "private/pthread_support.h"
38 |
39 | #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
40 |
41 | #include
42 | #include
43 |
44 | /* Invoked from GC_start_routine(). */
45 | GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
46 | struct GC_stack_base *sb, void *arg)
47 | {
48 | void * (*start)(void *);
49 | void * start_arg;
50 | void * result;
51 | volatile GC_thread me =
52 | GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
53 |
54 | # ifndef NACL
55 | pthread_cleanup_push(GC_thread_exit_proc, me);
56 | # endif
57 | result = (*start)(start_arg);
58 | # if defined(DEBUG_THREADS) && !defined(GC_PTHREAD_START_STANDALONE)
59 | GC_log_printf("Finishing thread %p\n", (void *)pthread_self());
60 | # endif
61 | me -> status = result;
62 | # ifndef NACL
63 | pthread_cleanup_pop(1);
64 | /* Cleanup acquires lock, ensuring that we can't exit while */
65 | /* a collection that thinks we're alive is trying to stop us. */
66 | # endif
67 | return result;
68 | }
69 |
70 | #endif /* GC_PTHREADS */
71 |
--------------------------------------------------------------------------------
/src/gc/real_malloc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 | *
5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 | *
8 | * Permission is hereby granted to use or copy this program
9 | * for any purpose, provided the above notices are retained on all copies.
10 | * Permission to modify the code and to distribute modified code is granted,
11 | * provided the above notices are retained, and a notice that the code was
12 | * modified is included with the above copyright notice.
13 | */
14 |
15 | # ifdef HAVE_CONFIG_H
16 | # include "config.h"
17 | # endif
18 |
19 | # ifdef PCR
20 | /*
21 | * This definition should go in its own file that includes no other
22 | * header files. Otherwise, we risk not getting the underlying system
23 | * malloc.
24 | */
25 | # define PCR_NO_RENAME
26 | # include
27 |
28 | void * real_malloc(size_t size)
29 | {
30 | return(malloc(size));
31 | }
32 |
33 | # else
34 |
35 | extern int GC_quiet;
36 | /* ANSI C doesn't allow translation units to be empty. */
37 | /* So we guarantee this one is nonempty. */
38 |
39 | #endif /* PCR */
40 |
--------------------------------------------------------------------------------
/src/gc/sparc_mach_dep.S:
--------------------------------------------------------------------------------
1 | ! SPARCompiler 3.0 and later apparently no longer handles
2 | ! asm outside functions. So we need a separate .s file
3 | ! This is only set up for SunOS 5, not SunOS 4.
4 | ! Assumes this is called before the stack contents are
5 | ! examined.
6 |
7 | .seg "text"
8 | .globl GC_save_regs_in_stack
9 | GC_save_regs_in_stack:
10 | #if defined(__arch64__) || defined(__sparcv9)
11 | save %sp,-128,%sp
12 | flushw
13 | ret
14 | restore %sp,2047+128,%o0
15 | #else /* 32 bit SPARC */
16 | ta 0x3 ! ST_FLUSH_WINDOWS
17 | mov %sp,%o0
18 | retl
19 | nop
20 | #endif /* 32 bit SPARC */
21 | .GC_save_regs_in_stack_end:
22 | .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack
23 |
24 | ! GC_clear_stack_inner(arg, limit) clears stack area up to limit and
25 | ! returns arg. Stack clearing is crucial on SPARC, so we supply
26 | ! an assembly version that s more careful. Assumes limit is hotter
27 | ! than sp, and limit is 8 byte aligned.
28 | .globl GC_clear_stack_inner
29 | GC_clear_stack_inner:
30 | #if defined(__arch64__) || defined(__sparcv9)
31 | mov %sp,%o2 ! Save sp
32 | add %sp,2047-8,%o3 ! p = sp+bias-8
33 | add %o1,-2047-192,%sp ! Move sp out of the way,
34 | ! so that traps still work.
35 | ! Includes some extra words
36 | ! so we can be sloppy below.
37 | loop:
38 | stx %g0,[%o3] ! *(long *)p = 0
39 | cmp %o3,%o1
40 | bgu,pt %xcc, loop ! if (p > limit) goto loop
41 | add %o3,-8,%o3 ! p -= 8 (delay slot)
42 | retl
43 | mov %o2,%sp ! Restore sp., delay slot
44 | #else /* 32 bit SPARC */
45 | mov %sp,%o2 ! Save sp
46 | add %sp,-8,%o3 ! p = sp-8
47 | clr %g1 ! [g0,g1] = 0
48 | add %o1,-0x60,%sp ! Move sp out of the way,
49 | ! so that traps still work.
50 | ! Includes some extra words
51 | ! so we can be sloppy below.
52 | loop:
53 | std %g0,[%o3] ! *(long long *)p = 0
54 | cmp %o3,%o1
55 | bgu loop ! if (p > limit) goto loop
56 | add %o3,-8,%o3 ! p -= 8 (delay slot)
57 | retl
58 | mov %o2,%sp ! Restore sp., delay slot
59 | #endif /* 32 bit SPARC */
60 | .GC_clear_stack_inner_end:
61 | .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner
62 |
--------------------------------------------------------------------------------
/src/gc/sparc_netbsd_mach_dep.s:
--------------------------------------------------------------------------------
1 | ! SPARCompiler 3.0 and later apparently no longer handles
2 | ! asm outside functions. So we need a separate .s file
3 | ! This is only set up for SunOS 4.
4 | ! Assumes this is called before the stack contents are
5 | ! examined.
6 |
7 | #include "machine/asm.h"
8 |
9 | .seg "text"
10 | .globl _C_LABEL(GC_save_regs_in_stack)
11 | .globl _C_LABEL(GC_push_regs)
12 | _C_LABEL(GC_save_regs_in_stack):
13 | _C_LABEL(GC_push_regs):
14 | ta 0x3 ! ST_FLUSH_WINDOWS
15 | mov %sp,%o0
16 | retl
17 | nop
18 |
19 | .globl _C_LABEL(GC_clear_stack_inner)
20 | _C_LABEL(GC_clear_stack_inner):
21 | mov %sp,%o2 ! Save sp
22 | add %sp,-8,%o3 ! p = sp-8
23 | clr %g1 ! [g0,g1] = 0
24 | add %o1,-0x60,%sp ! Move sp out of the way,
25 | ! so that traps still work.
26 | ! Includes some extra words
27 | ! so we can be sloppy below.
28 | loop:
29 | std %g0,[%o3] ! *(long long *)p = 0
30 | cmp %o3,%o1
31 | bgu loop ! if (p > limit) goto loop
32 | add %o3,-8,%o3 ! p -= 8 (delay slot)
33 | retl
34 | mov %o2,%sp ! Restore sp., delay slot
35 |
--------------------------------------------------------------------------------
/src/gc/sparc_sunos4_mach_dep.s:
--------------------------------------------------------------------------------
1 | ! SPARCompiler 3.0 and later apparently no longer handles
2 | ! asm outside functions. So we need a separate .s file
3 | ! This is only set up for SunOS 4.
4 | ! Assumes this is called before the stack contents are
5 | ! examined.
6 |
7 | .seg "text"
8 | .globl _GC_save_regs_in_stack
9 | .globl _GC_push_regs
10 | _GC_save_regs_in_stack:
11 | _GC_push_regs:
12 | ta 0x3 ! ST_FLUSH_WINDOWS
13 | mov %sp,%o0
14 | retl
15 | nop
16 |
17 | .globl _GC_clear_stack_inner
18 | _GC_clear_stack_inner:
19 | mov %sp,%o2 ! Save sp
20 | add %sp,-8,%o3 ! p = sp-8
21 | clr %g1 ! [g0,g1] = 0
22 | add %o1,-0x60,%sp ! Move sp out of the way,
23 | ! so that traps still work.
24 | ! Includes some extra words
25 | ! so we can be sloppy below.
26 | loop:
27 | std %g0,[%o3] ! *(long long *)p = 0
28 | cmp %o3,%o1
29 | bgu loop ! if (p > limit) goto loop
30 | add %o3,-8,%o3 ! p -= 8 (delay slot)
31 | retl
32 | mov %o2,%sp ! Restore sp., delay slot
33 |
--------------------------------------------------------------------------------
/src/gc/stubborn.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 | *
5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 | *
8 | * Permission is hereby granted to use or copy this program
9 | * for any purpose, provided the above notices are retained on all copies.
10 | * Permission to modify the code and to distribute modified code is granted,
11 | * provided the above notices are retained, and a notice that the code was
12 | * modified is included with the above copyright notice.
13 | */
14 |
15 | #include "private/gc_priv.h"
16 |
17 | #if defined(MANUAL_VDB)
18 |
19 | /* Stubborn object (hard to change, nearly immutable) allocation. */
20 | /* This interface is deprecated. We mostly emulate it using */
21 | /* MANUAL_VDB. But that imposes the additional constraint that */
22 | /* written, but not yet GC_dirty()ed objects must be referenced */
23 | /* by a stack. */
24 |
25 | void GC_dirty(ptr_t p);
26 |
27 | GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_stubborn(size_t lb)
28 | {
29 | return(GC_malloc(lb));
30 | }
31 |
32 | GC_API void GC_CALL GC_end_stubborn_change(const void *p)
33 | {
34 | GC_dirty((ptr_t)p);
35 | }
36 |
37 | GC_API void GC_CALL GC_change_stubborn(const void *p GC_ATTR_UNUSED)
38 | {
39 | }
40 |
41 | #else /* !MANUAL_VDB */
42 |
43 | GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_stubborn(size_t lb)
44 | {
45 | return(GC_malloc(lb));
46 | }
47 |
48 | GC_API void GC_CALL GC_end_stubborn_change(const void *p GC_ATTR_UNUSED)
49 | {
50 | }
51 |
52 | GC_API void GC_CALL GC_change_stubborn(const void *p GC_ATTR_UNUSED)
53 | {
54 | }
55 |
56 | #endif /* !MANUAL_VDB */
57 |
--------------------------------------------------------------------------------
/src/gc/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | # Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | # Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | # Copyright (c) 2000-2010 by Hewlett-Packard Company. All rights reserved.
6 | ##
7 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 | ##
10 | # Permission is hereby granted to use or copy this program
11 | # for any purpose, provided the above notices are retained on all copies.
12 | # Permission to modify the code and to distribute modified code is granted,
13 | # provided the above notices are retained, and a notice that the code was
14 | # modified is included with the above copyright notice.
15 | ##
16 |
17 | ADD_DEFINITIONS(-DGC_NOT_DLL)
18 | ADD_EXECUTABLE(gctest WIN32 test.c)
19 | TARGET_LINK_LIBRARIES(gctest gc-lib)
20 |
--------------------------------------------------------------------------------
/src/gc/tests/huge_test.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | #ifndef GC_IGNORE_WARN
7 | /* Ignore misleading "Out of Memory!" warning (which is printed on */
8 | /* every GC_MALLOC call below) by defining this macro before "gc.h" */
9 | /* inclusion. */
10 | # define GC_IGNORE_WARN
11 | #endif
12 |
13 | #include "gc.h"
14 |
15 | /*
16 | * Check that very large allocation requests fail. "Success" would usually
17 | * indicate that the size was somehow converted to a negative
18 | * number. Clients shouldn't do this, but we should fail in the
19 | * expected manner.
20 | */
21 |
22 | #define GC_SWORD_MAX ((GC_signed_word)(((GC_word)-1) >> 1))
23 |
24 | int main(void)
25 | {
26 | void *r;
27 | GC_INIT();
28 |
29 | GC_set_max_heap_size(100*1024*1024);
30 | /* Otherwise heap expansion aborts when deallocating large block. */
31 | /* That's OK. We test this corner case mostly to make sure that */
32 | /* it fails predictably. */
33 | GC_expand_hp(1024*1024*5);
34 | r = GC_MALLOC(GC_SWORD_MAX - 1024);
35 | if (NULL != r) {
36 | fprintf(stderr,
37 | "Size SWORD_MAX-1024 allocation unexpectedly succeeded\n");
38 | exit(1);
39 | }
40 | r = GC_MALLOC(GC_SWORD_MAX);
41 | if (NULL != r) {
42 | fprintf(stderr,
43 | "Size SWORD_MAX allocation unexpectedly succeeded\n");
44 | exit(1);
45 | }
46 | r = GC_MALLOC((GC_word)GC_SWORD_MAX + 1024);
47 | if (NULL != r) {
48 | fprintf(stderr,
49 | "Size SWORD_MAX+1024 allocation unexpectedly succeeded\n");
50 | exit(1);
51 | }
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/src/gc/tests/initsecondarythread.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Ludovic Courtes
3 | *
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 | *
7 | * Permission is hereby granted to use or copy this program
8 | * for any purpose, provided the above notices are retained on all copies.
9 | * Permission to modify the code and to distribute modified code is granted,
10 | * provided the above notices are retained, and a notice that the code was
11 | * modified is included with the above copyright notice.
12 | */
13 |
14 | /* Make sure 'GC_INIT' can be called from threads other than the initial
15 | * thread.
16 | */
17 |
18 | #ifdef HAVE_CONFIG_H
19 | # include "config.h"
20 | #endif
21 |
22 | #ifndef GC_THREADS
23 | # define GC_THREADS
24 | #endif
25 |
26 | #define GC_NO_THREAD_REDIRECTS 1
27 | /* Do not redirect thread creation and join calls. */
28 |
29 | #include "gc.h"
30 |
31 | #ifdef GC_PTHREADS
32 | # include
33 | #else
34 | # include
35 | #endif
36 |
37 | #include
38 | #include
39 |
40 | #ifdef GC_PTHREADS
41 | static void *thread(void *arg)
42 | #else
43 | static DWORD WINAPI thread(LPVOID arg)
44 | #endif
45 | {
46 | GC_INIT();
47 | (void)GC_MALLOC(123);
48 | (void)GC_MALLOC(12345);
49 | # ifdef GC_PTHREADS
50 | return arg;
51 | # else
52 | return (DWORD)(GC_word)arg;
53 | # endif
54 | }
55 |
56 | #include "private/gcconfig.h"
57 |
58 | int main(void)
59 | {
60 | # ifdef GC_PTHREADS
61 | int code;
62 | pthread_t t;
63 | # else
64 | HANDLE t;
65 | DWORD thread_id;
66 | # endif
67 | # if !(defined(BEOS) || defined(MSWIN32) || defined(MSWINCE) \
68 | || defined(CYGWIN32) || defined(GC_OPENBSD_UTHREADS) \
69 | || (defined(DARWIN) && !defined(NO_PTHREAD_GET_STACKADDR_NP)) \
70 | || (defined(LINUX) && !defined(NACL)) \
71 | || (defined(GC_SOLARIS_THREADS) && !defined(_STRICT_STDC)) \
72 | || (!defined(STACKBOTTOM) && (defined(HEURISTIC1) \
73 | || (!defined(LINUX_STACKBOTTOM) && !defined(FREEBSD_STACKBOTTOM)))))
74 | /* GC_INIT() must be called from main thread only. */
75 | GC_INIT();
76 | # endif
77 | # ifdef GC_PTHREADS
78 | if ((code = pthread_create (&t, NULL, thread, NULL)) != 0) {
79 | fprintf(stderr, "Thread creation failed %d\n", code);
80 | return 1;
81 | }
82 | if ((code = pthread_join (t, NULL)) != 0) {
83 | fprintf(stderr, "Thread join failed %d\n", code);
84 | return 1;
85 | }
86 | # else
87 | t = CreateThread(NULL, 0, thread, 0, 0, &thread_id);
88 | if (t == NULL) {
89 | fprintf(stderr, "Thread creation failed %d\n", (int)GetLastError());
90 | return 1;
91 | }
92 | if (WaitForSingleObject(t, INFINITE) != WAIT_OBJECT_0) {
93 | fprintf(stderr, "Thread join failed %d\n", (int)GetLastError());
94 | CloseHandle(t);
95 | return 1;
96 | }
97 | CloseHandle(t);
98 | # endif
99 | return 0;
100 | }
101 |
--------------------------------------------------------------------------------
/src/gc/tests/leak_test.c:
--------------------------------------------------------------------------------
1 | #include "leak_detector.h"
2 |
3 | int main(void) {
4 | int *p[10];
5 | int i;
6 | GC_set_find_leak(1); /* for new collect versions not compiled */
7 | /* with -DFIND_LEAK. */
8 |
9 | GC_INIT(); /* Needed if thread-local allocation is enabled. */
10 | /* FIXME: This is not ideal. */
11 | for (i = 0; i < 10; ++i) {
12 | p[i] = malloc(sizeof(int)+i);
13 | }
14 | CHECK_LEAKS();
15 | for (i = 1; i < 10; ++i) {
16 | free(p[i]);
17 | }
18 | for (i = 0; i < 9; ++i) {
19 | p[i] = malloc(sizeof(int)+i);
20 | }
21 | CHECK_LEAKS();
22 | CHECK_LEAKS();
23 | CHECK_LEAKS();
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/src/gc/tests/middle.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test at the boundary between small and large objects.
3 | * Inspired by a test case from Zoltan Varga.
4 | */
5 | #include "gc.h"
6 | #include
7 |
8 | int main (void)
9 | {
10 | int i;
11 |
12 | GC_set_all_interior_pointers(0);
13 | GC_INIT();
14 |
15 | for (i = 0; i < 20000; ++i) {
16 | (void)GC_malloc_atomic(4096);
17 | (void)GC_malloc(4096);
18 | }
19 | for (i = 0; i < 20000; ++i) {
20 | (void)GC_malloc_atomic(2048);
21 | (void)GC_malloc(2048);
22 | }
23 | printf("Final heap size is %lu\n", (unsigned long)GC_get_heap_size());
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/src/gc/tests/realloc_test.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include "gc.h"
5 |
6 | #define COUNT 10000000
7 |
8 | int main(void) {
9 | int i;
10 | unsigned long last_heap_size = 0;
11 |
12 | GC_INIT();
13 |
14 | for (i = 0; i < COUNT; i++) {
15 | int **p = GC_MALLOC(sizeof(int *));
16 | int *q = GC_MALLOC_ATOMIC(sizeof(int));
17 |
18 | if (p == 0 || *p != 0) {
19 | fprintf(stderr, "GC_malloc returned garbage (or NULL)\n");
20 | exit(1);
21 | }
22 |
23 | *p = GC_REALLOC(q, 2 * sizeof(int));
24 |
25 | if (i % 10 == 0) {
26 | unsigned long heap_size = (unsigned long)GC_get_heap_size();
27 | if (heap_size != last_heap_size) {
28 | printf("Heap size: %lu\n", heap_size);
29 | last_heap_size = heap_size;
30 | }
31 | }
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/src/gc/tests/smash_test.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test that overwrite error detection works reasonably.
3 | */
4 | #define GC_DEBUG
5 | #include "gc.h"
6 |
7 | #include
8 |
9 | #define COUNT 7000
10 | #define SIZE 40
11 |
12 | char * A[COUNT];
13 |
14 | int main(void)
15 | {
16 | int i;
17 | char *p;
18 |
19 | GC_INIT();
20 |
21 | for (i = 0; i < COUNT; ++i) {
22 | A[i] = p = GC_MALLOC(SIZE);
23 |
24 | if (i%3000 == 0) GC_gcollect();
25 | if (i%5678 == 0 && p != 0) p[SIZE + i/2000] = 42;
26 | }
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/src/gc/tests/staticrootslib.c:
--------------------------------------------------------------------------------
1 |
2 | /* This test file is intended to be compiled into a DLL. */
3 |
4 | #ifndef GC_DEBUG
5 | # define GC_DEBUG
6 | #endif
7 |
8 | #include "gc.h"
9 |
10 | #ifndef GC_TEST_EXPORT_API
11 | # if defined(GC_VISIBILITY_HIDDEN_SET) \
12 | && !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
13 | # define GC_TEST_EXPORT_API \
14 | extern __attribute__((__visibility__("default")))
15 | # else
16 | # define GC_TEST_EXPORT_API extern
17 | # endif
18 | #endif
19 |
20 | struct treenode {
21 | struct treenode *x;
22 | struct treenode *y;
23 | };
24 |
25 | static struct treenode *root[10] = { 0 };
26 | static struct treenode *root_nz[10] = { (void *)(GC_word)2 };
27 |
28 | #ifdef STATICROOTSLIB2
29 | # define libsrl_getpelem libsrl_getpelem2
30 | #else
31 |
32 | GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i)
33 | {
34 | struct treenode * r = GC_MALLOC(sizeof(struct treenode));
35 | if (0 == i) return 0;
36 | if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
37 | if (r) {
38 | r -> x = libsrl_mktree(i-1);
39 | r -> y = libsrl_mktree(i-1);
40 | }
41 | return r;
42 | }
43 |
44 | GC_TEST_EXPORT_API void * libsrl_init(void)
45 | {
46 | # ifndef STATICROOTSLIB_INIT_IN_MAIN
47 | GC_INIT();
48 | # endif
49 | return GC_MALLOC(sizeof(struct treenode));
50 | }
51 |
52 | #endif /* !STATICROOTSLIB2 */
53 |
54 | GC_TEST_EXPORT_API struct treenode ** libsrl_getpelem(int i, int j)
55 | {
56 | return &((j & 1) != 0 ? root_nz : root)[i];
57 | }
58 |
--------------------------------------------------------------------------------
/src/gc/tests/staticrootstest.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #ifndef GC_DEBUG
6 | # define GC_DEBUG
7 | #endif
8 |
9 | #include "gc.h"
10 | #include "gc_backptr.h"
11 |
12 | #ifndef GC_TEST_IMPORT_API
13 | # define GC_TEST_IMPORT_API extern
14 | #endif
15 |
16 | /* Should match that in staticrootslib.c. */
17 | struct treenode {
18 | struct treenode *x;
19 | struct treenode *y;
20 | };
21 |
22 | struct treenode *root[10] = { NULL };
23 |
24 | /* Same as "root" variable but initialized to some non-zero value (to */
25 | /* be placed to .data section instead of .bss). */
26 | struct treenode *root_nz[10] = { (void *)(GC_word)1 };
27 |
28 | static char *staticroot = 0;
29 |
30 | GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i);
31 | GC_TEST_IMPORT_API void * libsrl_init(void);
32 | GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem(int i, int j);
33 |
34 | GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem2(int i, int j);
35 |
36 | int main(void)
37 | {
38 | int i, j;
39 |
40 | # ifdef STATICROOTSLIB_INIT_IN_MAIN
41 | GC_INIT();
42 | # endif
43 | staticroot = libsrl_init();
44 | if (NULL == staticroot) {
45 | fprintf(stderr, "GC_malloc returned NULL\n");
46 | return 2;
47 | }
48 | memset(staticroot, 0x42, sizeof(struct treenode));
49 | GC_gcollect();
50 | for (j = 0; j < 4; j++) {
51 | for (i = 0; i < (int)(sizeof(root) / sizeof(root[0])); ++i) {
52 | # ifdef STATICROOTSLIB2
53 | *libsrl_getpelem2(i, j) = libsrl_mktree(12);
54 | # endif
55 | *libsrl_getpelem(i, j) = libsrl_mktree(12);
56 | ((j & 1) != 0 ? root_nz : root)[i] = libsrl_mktree(12);
57 | GC_gcollect();
58 | }
59 | for (i = 0; i < (int)sizeof(struct treenode); ++i) {
60 | if (staticroot[i] != 0x42) {
61 | fprintf(stderr, "Memory check failed\n");
62 | return -1;
63 | }
64 | }
65 | }
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/src/gc/tests/subthread_create.c:
--------------------------------------------------------------------------------
1 |
2 | #ifdef HAVE_CONFIG_H
3 | /* For PARALLEL_MARK */
4 | # include "config.h"
5 | #endif
6 |
7 | #ifndef GC_THREADS
8 | # define GC_THREADS
9 | #endif
10 | #include "gc.h"
11 |
12 | #ifdef PARALLEL_MARK
13 | # define AO_REQUIRE_CAS
14 | #endif
15 | #include "atomic_ops.h"
16 |
17 | #include
18 |
19 | #ifdef AO_HAVE_fetch_and_add
20 |
21 | #ifdef GC_PTHREADS
22 | # include
23 | #else
24 | # include
25 | #endif
26 |
27 | #include
28 | #include
29 |
30 | #ifndef MAX_SUBTHREAD_DEPTH
31 | # define INITIAL_THREAD_COUNT 31
32 | # define MAX_ALIVE_THREAD_COUNT 55
33 | # define MAX_SUBTHREAD_DEPTH 7
34 | # define MAX_SUBTHREAD_COUNT 200
35 | #endif
36 |
37 | #ifndef DECAY_NUMER
38 | # define DECAY_NUMER 15
39 | # define DECAY_DENOM 16
40 | #endif
41 |
42 | volatile AO_t thread_created_cnt = 0;
43 | volatile AO_t thread_ended_cnt = 0;
44 |
45 | #ifdef GC_PTHREADS
46 | void *entry(void *arg)
47 | #else
48 | DWORD WINAPI entry(LPVOID arg)
49 | #endif
50 | {
51 | int thread_num = AO_fetch_and_add(&thread_created_cnt, 1);
52 | GC_word my_depth = (GC_word)arg + 1;
53 |
54 | if (my_depth <= MAX_SUBTHREAD_DEPTH
55 | && thread_num < MAX_SUBTHREAD_COUNT
56 | && (thread_num % DECAY_DENOM) < DECAY_NUMER
57 | && (int)(thread_num - AO_load(&thread_ended_cnt))
58 | <= MAX_ALIVE_THREAD_COUNT) {
59 | # ifdef GC_PTHREADS
60 | int err;
61 | pthread_t th;
62 | err = pthread_create(&th, NULL, entry, (void *)my_depth);
63 | if (err) {
64 | fprintf(stderr, "Thread #%d creation failed: %s", thread_num,
65 | strerror(err));
66 | exit(2);
67 | }
68 | # else
69 | HANDLE th;
70 | DWORD thread_id;
71 | th = CreateThread(NULL, 0, entry, (LPVOID)my_depth, 0, &thread_id);
72 | if (th == NULL) {
73 | fprintf(stderr, "Thread #%d creation failed: %d\n", thread_num,
74 | (int)GetLastError());
75 | exit(2);
76 | }
77 | CloseHandle(th);
78 | # endif
79 | }
80 |
81 | AO_fetch_and_add(&thread_ended_cnt, 1);
82 | return 0;
83 | }
84 |
85 | int main(void)
86 | {
87 | int i;
88 | # ifdef GC_PTHREADS
89 | int err;
90 | pthread_t th[INITIAL_THREAD_COUNT];
91 | # else
92 | HANDLE th[INITIAL_THREAD_COUNT];
93 | # endif
94 |
95 | GC_INIT();
96 | for (i = 0; i < INITIAL_THREAD_COUNT; ++i) {
97 | # ifdef GC_PTHREADS
98 | err = pthread_create(&th[i], NULL, entry, 0);
99 | if (err) {
100 | fprintf(stderr, "Thread creation failed: %s", strerror(err));
101 | exit(1);
102 | }
103 | # else
104 | DWORD thread_id;
105 | th[i] = CreateThread(NULL, 0, entry, 0, 0, &thread_id);
106 | if (th[i] == NULL) {
107 | fprintf(stderr, "Thread creation failed: %d\n",
108 | (int)GetLastError());
109 | exit(1);
110 | }
111 | # endif
112 | }
113 |
114 | for (i = 0; i < INITIAL_THREAD_COUNT; ++i) {
115 | # ifdef GC_PTHREADS
116 | void *res;
117 | err = pthread_join(th[i], &res);
118 | if (err) {
119 | fprintf(stderr, "Failed to join thread: %s", strerror(err));
120 | exit(1);
121 | }
122 | # else
123 | if (WaitForSingleObject(th[i], INFINITE) != WAIT_OBJECT_0) {
124 | fprintf(stderr, "Failed to join thread: %d\n",
125 | (int)GetLastError());
126 | CloseHandle(th[i]);
127 | exit(1);
128 | }
129 | CloseHandle(th[i]);
130 | # endif
131 | }
132 | printf("subthread_create: created %d threads (%d ended)\n",
133 | (int)AO_load(&thread_created_cnt), (int)AO_load(&thread_ended_cnt));
134 | return 0;
135 | }
136 |
137 | #else
138 |
139 | int main(void)
140 | {
141 | printf("subthread_create test skipped\n");
142 | return 0;
143 | }
144 |
145 | #endif /* !AO_HAVE_fetch_and_add */
146 |
--------------------------------------------------------------------------------
/src/gc/tests/thread_leak_test.c:
--------------------------------------------------------------------------------
1 |
2 | #ifdef HAVE_CONFIG_H
3 | # include "config.h"
4 | #endif
5 |
6 | #ifndef GC_THREADS
7 | # define GC_THREADS
8 | #endif
9 |
10 | #include "leak_detector.h"
11 |
12 | #ifdef GC_PTHREADS
13 | # include
14 | #else
15 | # include
16 | #endif
17 |
18 | #include
19 |
20 | #ifdef GC_PTHREADS
21 | void * test(void * arg)
22 | #else
23 | DWORD WINAPI test(LPVOID arg)
24 | #endif
25 | {
26 | int *p[10];
27 | int i;
28 | for (i = 0; i < 10; ++i) {
29 | p[i] = malloc(sizeof(int)+i);
30 | }
31 | CHECK_LEAKS();
32 | for (i = 1; i < 10; ++i) {
33 | free(p[i]);
34 | }
35 | # ifdef GC_PTHREADS
36 | return arg;
37 | # else
38 | return (DWORD)(GC_word)arg;
39 | # endif
40 | }
41 |
42 | #define NTHREADS 5
43 |
44 | int main(void) {
45 | int i;
46 | # ifdef GC_PTHREADS
47 | pthread_t t[NTHREADS];
48 | # else
49 | HANDLE t[NTHREADS];
50 | DWORD thread_id;
51 | # endif
52 | int code;
53 |
54 | GC_set_find_leak(1); /* for new collect versions not compiled */
55 | /* with -DFIND_LEAK. */
56 | GC_INIT();
57 |
58 | for (i = 0; i < NTHREADS; ++i) {
59 | # ifdef GC_PTHREADS
60 | code = pthread_create(t + i, 0, test, 0);
61 | # else
62 | t[i] = CreateThread(NULL, 0, test, 0, 0, &thread_id);
63 | code = t[i] != NULL ? 0 : (int)GetLastError();
64 | # endif
65 | if (code != 0) {
66 | fprintf(stderr, "Thread creation failed %d\n", code);
67 | exit(2);
68 | }
69 | }
70 |
71 | for (i = 0; i < NTHREADS; ++i) {
72 | # ifdef GC_PTHREADS
73 | code = pthread_join(t[i], 0);
74 | # else
75 | code = WaitForSingleObject(t[i], INFINITE) == WAIT_OBJECT_0 ? 0 :
76 | (int)GetLastError();
77 | # endif
78 | if (code != 0) {
79 | fprintf(stderr, "Thread join failed %d\n", code);
80 | exit(2);
81 | }
82 | }
83 |
84 | CHECK_LEAKS();
85 | CHECK_LEAKS();
86 | CHECK_LEAKS();
87 | return 0;
88 | }
89 |
--------------------------------------------------------------------------------
/src/gc/tests/threadkey_test.c:
--------------------------------------------------------------------------------
1 |
2 | #ifdef HAVE_CONFIG_H
3 | # include "config.h"
4 | #endif
5 |
6 | #ifndef GC_THREADS
7 | # define GC_THREADS
8 | #endif
9 |
10 | #define GC_NO_THREAD_REDIRECTS 1
11 |
12 | #include "gc.h"
13 |
14 | #if (!defined(GC_PTHREADS) || defined(GC_SOLARIS_THREADS) \
15 | || defined(__native_client__)) && !defined(SKIP_THREADKEY_TEST)
16 | /* FIXME: Skip this test on Solaris for now. The test may fail on */
17 | /* other targets as well. Currently, tested only on Linux, Cygwin */
18 | /* and Darwin. */
19 | # define SKIP_THREADKEY_TEST
20 | #endif
21 |
22 | #ifdef SKIP_THREADKEY_TEST
23 |
24 | #include
25 |
26 | int main (void)
27 | {
28 | printf("threadkey_test skipped\n");
29 | return 0;
30 | }
31 |
32 | #else
33 |
34 | #include
35 |
36 | pthread_key_t key;
37 |
38 | #ifdef GC_SOLARIS_THREADS
39 | /* pthread_once_t key_once = { PTHREAD_ONCE_INIT }; */
40 | #else
41 | pthread_once_t key_once = PTHREAD_ONCE_INIT;
42 | #endif
43 |
44 | void * entry (void *arg)
45 | {
46 | pthread_setspecific(key,
47 | (void *)GC_HIDE_POINTER(GC_STRDUP("hello, world")));
48 | return arg;
49 | }
50 |
51 | void * GC_CALLBACK on_thread_exit_inner (struct GC_stack_base * sb, void * arg)
52 | {
53 | int res = GC_register_my_thread (sb);
54 | pthread_t t;
55 | int creation_res; /* Used to suppress a warning about */
56 | /* unchecked pthread_create() result. */
57 |
58 | creation_res = GC_pthread_create (&t, NULL, entry, NULL);
59 | if (res == GC_SUCCESS)
60 | GC_unregister_my_thread ();
61 |
62 | return arg ? (void*)(GC_word)creation_res : 0;
63 | }
64 |
65 | void on_thread_exit (void *v)
66 | {
67 | GC_call_with_stack_base (on_thread_exit_inner, v);
68 | }
69 |
70 | void make_key (void)
71 | {
72 | pthread_key_create (&key, on_thread_exit);
73 | }
74 |
75 | #ifndef LIMIT
76 | # define LIMIT 30
77 | #endif
78 |
79 | int main (void)
80 | {
81 | int i;
82 | GC_INIT ();
83 |
84 | # ifdef GC_SOLARIS_THREADS
85 | pthread_key_create (&key, on_thread_exit);
86 | # else
87 | pthread_once (&key_once, make_key);
88 | # endif
89 | for (i = 0; i < LIMIT; i++) {
90 | pthread_t t;
91 | void *res;
92 | if (GC_pthread_create (&t, NULL, entry, NULL) == 0
93 | && (i & 1) != 0) {
94 | (void)GC_pthread_join(t, &res);
95 | }
96 | }
97 | return 0;
98 | }
99 |
100 | #endif /* !SKIP_THREADKEY_TEST */
101 |
--------------------------------------------------------------------------------
/src/gc/tests/trace_test.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #ifndef GC_DEBUG
5 | # define GC_DEBUG
6 | #endif
7 |
8 | #include "gc.h"
9 | #include "gc_backptr.h"
10 |
11 | struct treenode {
12 | struct treenode *x;
13 | struct treenode *y;
14 | } * root[10];
15 |
16 | struct treenode * mktree(int i) {
17 | struct treenode * r = GC_MALLOC(sizeof(struct treenode));
18 | if (0 == i) return 0;
19 | if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
20 | if (r == NULL) {
21 | fprintf(stderr, "Out of memory\n");
22 | exit(1);
23 | }
24 | r -> x = mktree(i-1);
25 | r -> y = mktree(i-1);
26 | return r;
27 | }
28 |
29 | int main(void)
30 | {
31 | int i;
32 | GC_INIT();
33 | for (i = 0; i < 10; ++i) {
34 | root[i] = mktree(12);
35 | }
36 | GC_generate_random_backtrace();
37 | GC_generate_random_backtrace();
38 | GC_generate_random_backtrace();
39 | GC_generate_random_backtrace();
40 | return 0;
41 | }
42 |
--------------------------------------------------------------------------------
/src/gc/tools/add_gc_prefix.c:
--------------------------------------------------------------------------------
1 | # include
2 | # include
3 |
4 | int main(int argc, char ** argv)
5 | {
6 | int i;
7 |
8 | for (i = 1; i < argc; i++) {
9 | printf("gc-%d.%d.%d/%s ",
10 | GC_VERSION_MAJOR, GC_VERSION_MINOR, GC_VERSION_MICRO, argv[i]);
11 | }
12 | return(0);
13 | }
14 |
--------------------------------------------------------------------------------
/src/gc/tools/callprocs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | GC_DEBUG=1
3 | export GC_DEBUG
4 | $* 2>&1 | awk '{print "0x3e=c\""$0"\""};/^\t##PC##=/ {if ($2 != 0) {print $2"?i"}}' | adb $1 | sed "s/^ >/>/"
5 |
--------------------------------------------------------------------------------
/src/gc/tools/gcname.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | printf("gc-%d.%d.%d",
7 | GC_VERSION_MAJOR, GC_VERSION_MINOR, GC_VERSION_MICRO);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/src/gc/tools/if_mach.c:
--------------------------------------------------------------------------------
1 | /* Conditionally execute a command based on machine and OS from gcconfig.h */
2 |
3 | # include "private/gc_priv.h"
4 | # include
5 | # include
6 | # include
7 |
8 | int main(int argc, char **argv)
9 | {
10 | if (argc < 4) goto Usage;
11 | if (strcmp(MACH_TYPE, argv[1]) != 0) return(0);
12 | if (strcmp(OS_TYPE, "") != 0 && strcmp(argv[2], "") != 0
13 | && strcmp(OS_TYPE, argv[2]) != 0) return(0);
14 | fprintf(stderr, "^^^^Starting command^^^^\n");
15 | fflush(stdout);
16 | execvp(argv[3], argv+3);
17 | perror("Couldn't execute");
18 |
19 | Usage:
20 | fprintf(stderr, "Usage: %s mach_type os_type command\n", argv[0]);
21 | fprintf(stderr, "Currently mach_type = %s, os_type = %s\n",
22 | MACH_TYPE, OS_TYPE);
23 | return(1);
24 | }
25 |
--------------------------------------------------------------------------------
/src/gc/tools/if_not_there.c:
--------------------------------------------------------------------------------
1 | /* Conditionally execute a command based if the file argv[1] doesn't exist */
2 | /* Except for execvp, we stick to ANSI C. */
3 |
4 | # include "private/gc_priv.h"
5 | # include
6 | # include
7 | # include
8 | #ifdef __DJGPP__
9 | #include
10 | #endif /* __DJGPP__ */
11 |
12 | int main(int argc, char **argv)
13 | {
14 | FILE * f;
15 | #ifdef __DJGPP__
16 | DIR * d;
17 | #endif /* __DJGPP__ */
18 | if (argc < 3) goto Usage;
19 | if ((f = fopen(argv[1], "rb")) != 0
20 | || (f = fopen(argv[1], "r")) != 0) {
21 | fclose(f);
22 | return(0);
23 | }
24 | #ifdef __DJGPP__
25 | if ((d = opendir(argv[1])) != 0) {
26 | closedir(d);
27 | return(0);
28 | }
29 | #endif
30 | printf("^^^^Starting command^^^^\n");
31 | fflush(stdout);
32 | execvp(argv[2], argv+2);
33 | exit(1);
34 |
35 | Usage:
36 | fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
37 | return(1);
38 | }
39 |
--------------------------------------------------------------------------------
/src/gc/tools/threadlibs.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 | * Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
6 | * All rights reserved.
7 | *
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 | *
11 | * Permission is hereby granted to use or copy this program
12 | * for any purpose, provided the above notices are retained on all copies.
13 | * Permission to modify the code and to distribute modified code is granted,
14 | * provided the above notices are retained, and a notice that the code was
15 | * modified is included with the above copyright notice.
16 | */
17 |
18 | # include "private/gc_priv.h"
19 |
20 | # include
21 |
22 | int main(void)
23 | {
24 | # if defined(GC_USE_LD_WRAP)
25 | printf("-Wl,--wrap -Wl,dlopen "
26 | "-Wl,--wrap -Wl,pthread_create -Wl,--wrap -Wl,pthread_join "
27 | "-Wl,--wrap -Wl,pthread_detach -Wl,--wrap -Wl,pthread_sigmask "
28 | "-Wl,--wrap -Wl,pthread_exit -Wl,--wrap -Wl,pthread_cancel\n");
29 | # endif
30 | # if (defined(GC_LINUX_THREADS) && !defined(PLATFORM_ANDROID)) \
31 | || defined(GC_IRIX_THREADS) || defined(GC_DARWIN_THREADS) \
32 | || defined(GC_AIX_THREADS) || defined(GC_GNU_THREADS)
33 | # ifdef GC_USE_DLOPEN_WRAP
34 | printf("-ldl ");
35 | # endif
36 | printf("-lpthread\n");
37 | # endif
38 | # if defined(GC_OPENBSD_THREADS)
39 | printf("-pthread\n");
40 | # endif
41 | # if defined(GC_FREEBSD_THREADS)
42 | # ifdef GC_USE_DLOPEN_WRAP
43 | printf("-ldl ");
44 | # endif
45 | # if (__FREEBSD_version >= 500000)
46 | printf("-lpthread\n");
47 | # else
48 | printf("-pthread\n");
49 | # endif
50 | # endif
51 | # if defined(GC_NETBSD_THREADS)
52 | printf("-lpthread -lrt\n");
53 | # endif
54 |
55 | # if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS)
56 | printf("-lpthread -lrt\n");
57 | # endif
58 | # if defined(GC_SOLARIS_THREADS)
59 | printf("-lthread -lposix4\n");
60 | /* Is this right for recent versions? */
61 | # endif
62 | # if defined(GC_WIN32_THREADS) && defined(CYGWIN32)
63 | printf("-lpthread\n");
64 | # endif
65 | # if defined(GC_WIN32_PTHREADS)
66 | # ifdef PTW32_STATIC_LIB
67 | /* assume suffix s for static version of the win32 pthread library */
68 | printf("-lpthreadGC2s -lws2_32\n");
69 | # else
70 | printf("-lpthreadGC2\n");
71 | # endif
72 | # endif
73 | # if defined(GC_OSF1_THREADS)
74 | printf("-pthread -lrt"); /* DOB: must be -pthread, not -lpthread */
75 | # endif
76 | /* You need GCC 3.0.3 to build this one! */
77 | /* DG/UX native gcc doesn't know what "-pthread" is */
78 | # if defined(GC_DGUX386_THREADS)
79 | printf("-ldl -pthread\n");
80 | # endif
81 | return 0;
82 | }
83 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/README:
--------------------------------------------------------------------------------
1 | gc.def should probably be removed completely.
2 |
3 | I removed an apparently erroneous line for GC_CreateThread. Unfortunately
4 | gc.def is referenced in various other places I cannot easily edit. -HB
5 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/gc.def:
--------------------------------------------------------------------------------
1 | EXPORTS
2 | GC_version DATA
3 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/gc.rc:
--------------------------------------------------------------------------------
1 | #include "gc.ver"
2 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/gc.ver:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "../include/../version.h"
5 |
6 | #define GC_VERSION_REVISION 0
7 |
8 | #define GC_VERSION ((GC_VERSION_MAJOR) * 100 + GC_VERSION_MINOR)
9 | #define GC_FULL_VERSION ((GC_VERSION) * 10000 + GC_VERSION_MICRO)
10 |
11 | #ifndef __T
12 | # ifdef UNICODE
13 | # define __T(x) L ## x
14 | # else
15 | # define __T(x) x
16 | # endif
17 | #endif
18 |
19 | #define PP_TSTR(x) __T(#x)
20 | #define PP_EVAL_TSTR(x) PP_TSTR(x)
21 |
22 | #define GC_VERSION_STR PP_EVAL_TSTR(GC_VERSION_MAJOR) __T(".") PP_EVAL_TSTR(GC_VERSION_MINOR)
23 | #define GC_FULL_VERSION_STR PP_EVAL_TSTR(GC_VERSION_MAJOR) __T(".") PP_EVAL_TSTR(GC_VERSION_MINOR) __T(".") PP_EVAL_TSTR(GC_VERSION_MICRO) __T(".") PP_EVAL_TSTR(GC_VERSION_REVISION)
24 | #define GC_FULL_VERSION_CSV GC_VERSION_MAJOR, GC_VERSION_MINOR, GC_VERSION_MICRO, GC_VERSION_REVISION
25 |
26 | #ifdef _DEBUG
27 | #define VER_DEBUG VS_FF_DEBUG
28 | #else
29 | #define VER_DEBUG 0
30 | #endif
31 |
32 | #ifdef _BETA
33 | #define VER_PRERELEASE VS_FF_PRERELEASE
34 | #else
35 | #define VER_PRERELEASE 0
36 | #endif
37 |
38 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
39 | #pragma code_page(1252)
40 |
41 | VS_VERSION_INFO VERSIONINFO
42 | FILEVERSION GC_FULL_VERSION_CSV
43 | PRODUCTVERSION GC_FULL_VERSION_CSV
44 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
45 | FILEFLAGS VER_DEBUG | VER_PRERELEASE
46 | FILEOS VOS__WINDOWS32
47 | FILETYPE VFT_DLL
48 | FILESUBTYPE VFT2_UNKNOWN
49 | BEGIN
50 | BLOCK "StringFileInfo"
51 | BEGIN
52 | BLOCK "040904B0"
53 | BEGIN
54 | VALUE "CompanyName", "\
55 | Hans-J. Boehm, \
56 | Alan J. Demers, \
57 | Xerox Corporation, \
58 | Silicon Graphics, \
59 | and Hewlett-Packard Company. \
60 | \0"
61 | VALUE "LegalCopyright", "\
62 | Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers. \
63 | Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. \
64 | Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved. \
65 | Copyright (c) 1999-2004 by Hewlett-Packard. All rights reserved. \
66 | \0"
67 |
68 | VALUE "OriginalFilename", "GC.DLL\0"
69 | VALUE "InternalName", "GC\0"
70 | VALUE "FileDescription", "Conservative Garbage Collector for C and C++\0"
71 | VALUE "FileVersion", GC_FULL_VERSION_STR
72 |
73 | VALUE "ProductName", "Conservative Garbage Collector for C and C++\0"
74 | VALUE "ProductVersion", GC_FULL_VERSION_STR
75 | END
76 | END
77 | BLOCK "VarFileInfo"
78 | BEGIN
79 | VALUE "Translation", 0x409, 1200
80 | END
81 | END
82 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/stdafx.c:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/stdafx.h:
--------------------------------------------------------------------------------
1 | #define WIN32_LEAN_AND_MEAN
2 | #include
3 |
4 | #pragma warning(error: 4013) // function undefined; assuming extern returning int
5 |
6 | #ifdef _MT
7 | # define GC_THREADS 1
8 | #endif
9 |
10 | #ifdef _DEBUG
11 | # define GC_DEBUG
12 | #endif
13 |
14 | #define SAVE_CALL_CHAIN
15 | #define SAVE_CALL_COUNT 8
16 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc60/all.dsp:
--------------------------------------------------------------------------------
1 | # Microsoft Developer Studio Project File - Name="all" - Package Owner=<4>
2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00
3 | # ** DO NOT EDIT **
4 |
5 | # TARGTYPE "Win32 (x86) Generic Project" 0x010a
6 |
7 | CFG=all - Win32 Debug
8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE,
9 | !MESSAGE use the Export Makefile command and run
10 | !MESSAGE
11 | !MESSAGE NMAKE /f "all.mak".
12 | !MESSAGE
13 | !MESSAGE You can specify a configuration when running NMAKE
14 | !MESSAGE by defining the macro CFG on the command line. For example:
15 | !MESSAGE
16 | !MESSAGE NMAKE /f "all.mak" CFG="all - Win32 Debug"
17 | !MESSAGE
18 | !MESSAGE Possible choices for configuration are:
19 | !MESSAGE
20 | !MESSAGE "all - Win32 Release" (based on "Win32 (x86) Generic Project")
21 | !MESSAGE "all - Win32 Debug" (based on "Win32 (x86) Generic Project")
22 | !MESSAGE
23 |
24 | # Begin Project
25 | # PROP AllowPerConfigDependencies 0
26 | # PROP Scc_ProjName ""
27 | # PROP Scc_LocalPath ""
28 | MTL=midl.exe
29 |
30 | !IF "$(CFG)" == "all - Win32 Release"
31 |
32 | # PROP BASE Use_MFC 0
33 | # PROP BASE Use_Debug_Libraries 0
34 | # PROP BASE Output_Dir "Release"
35 | # PROP BASE Intermediate_Dir "Release"
36 | # PROP BASE Target_Dir ""
37 | # PROP Use_MFC 0
38 | # PROP Use_Debug_Libraries 0
39 | # PROP Output_Dir "..\..\..\bin"
40 | # PROP Intermediate_Dir "..\..\..\obj\Release"
41 | # PROP Target_Dir ""
42 |
43 | !ELSEIF "$(CFG)" == "all - Win32 Debug"
44 |
45 | # PROP BASE Use_MFC 0
46 | # PROP BASE Use_Debug_Libraries 1
47 | # PROP BASE Output_Dir "Debug"
48 | # PROP BASE Intermediate_Dir "Debug"
49 | # PROP BASE Target_Dir ""
50 | # PROP Use_MFC 0
51 | # PROP Use_Debug_Libraries 1
52 | # PROP Output_Dir "..\..\..\bin"
53 | # PROP Intermediate_Dir "..\..\..\obj\Debug"
54 | # PROP Target_Dir ""
55 |
56 | !ENDIF
57 |
58 | # Begin Target
59 |
60 | # Name "all - Win32 Release"
61 | # Name "all - Win32 Debug"
62 | # End Target
63 | # End Project
64 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc60/test.dsp:
--------------------------------------------------------------------------------
1 | # Microsoft Developer Studio Project File - Name="test" - Package Owner=<4>
2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00
3 | # ** DO NOT EDIT **
4 |
5 | # TARGTYPE "Win32 (x86) Generic Project" 0x010a
6 |
7 | CFG=test - Win32 Debug
8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE,
9 | !MESSAGE use the Export Makefile command and run
10 | !MESSAGE
11 | !MESSAGE NMAKE /f "test.mak".
12 | !MESSAGE
13 | !MESSAGE You can specify a configuration when running NMAKE
14 | !MESSAGE by defining the macro CFG on the command line. For example:
15 | !MESSAGE
16 | !MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug"
17 | !MESSAGE
18 | !MESSAGE Possible choices for configuration are:
19 | !MESSAGE
20 | !MESSAGE "test - Win32 Release" (based on "Win32 (x86) Generic Project")
21 | !MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Generic Project")
22 | !MESSAGE
23 |
24 | # Begin Project
25 | # PROP testowPerConfigDependencies 0
26 | # PROP Scc_ProjName ""
27 | # PROP Scc_LocalPath ""
28 | MTL=midl.exe
29 |
30 | !IF "$(CFG)" == "test - Win32 Release"
31 |
32 | # PROP BASE Use_MFC 0
33 | # PROP BASE Use_Debug_Libraries 0
34 | # PROP BASE Output_Dir "Release"
35 | # PROP BASE Intermediate_Dir "Release"
36 | # PROP BASE Target_Dir ""
37 | # PROP Use_MFC 0
38 | # PROP Use_Debug_Libraries 0
39 | # PROP Output_Dir "..\..\..\bin"
40 | # PROP Intermediate_Dir "..\..\..\obj\Release"
41 | # PROP Target_Dir ""
42 |
43 | !ELSEIF "$(CFG)" == "test - Win32 Debug"
44 |
45 | # PROP BASE Use_MFC 0
46 | # PROP BASE Use_Debug_Libraries 1
47 | # PROP BASE Output_Dir "Debug"
48 | # PROP BASE Intermediate_Dir "Debug"
49 | # PROP BASE Target_Dir ""
50 | # PROP Use_MFC 0
51 | # PROP Use_Debug_Libraries 1
52 | # PROP Output_Dir "..\..\..\bin"
53 | # PROP Intermediate_Dir "..\..\..\obj\Debug"
54 | # PROP Target_Dir ""
55 |
56 | !ENDIF
57 |
58 | # Begin Target
59 |
60 | # Name "test - Win32 Release"
61 | # Name "test - Win32 Debug"
62 | # End Target
63 | # End Project
64 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc60/vc60crlf.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | rem This script will convert Unix-style line endings into Windows format.
3 |
4 | for %%P in (*.ds?) do call :fixline %%P
5 | goto :eof
6 |
7 | :fixline
8 | @echo on
9 | if exist "%~1.new" del "%~1.new"
10 | for /f %%S in (%1) do (
11 | echo %%S>>"%~1.new"
12 | )
13 | ren %1 "%~1.bak"
14 | ren "%~1.new" %1
15 | goto :eof
16 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc70/all.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
12 |
13 |
14 |
20 |
22 |
24 |
26 |
28 |
29 |
35 |
37 |
39 |
41 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc70/test.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
12 |
13 |
14 |
20 |
22 |
24 |
26 |
28 |
29 |
35 |
37 |
39 |
41 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc71/all.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
12 |
13 |
14 |
21 |
23 |
27 |
29 |
31 |
32 |
39 |
41 |
45 |
47 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/gc/windows-untested/vc71/test.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
12 |
13 |
14 |
21 |
23 |
27 |
29 |
31 |
32 |
39 |
41 |
45 |
47 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/grmtst.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyuheng/joy/0510200e381cc2365fe2f936f8d4540702789593/src/grmtst.out
--------------------------------------------------------------------------------
/src/inilib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: inilib.joy *)
2 |
3 | LIBRA
4 |
5 | _inilib == true;
6 |
7 |
8 | (* - - - - - I N P U T O U T P U T - - - - *)
9 |
10 | newline == '\n putch;
11 | putln == put newline;
12 | space == '\032 putch;
13 | bell == '\007 putch;
14 | (* this is now a primitive in raw Joy:
15 | putchars == [putch] step;
16 | *)
17 | putstrings == [putchars] step;
18 |
19 | ask == "Please " putchars putchars newline get;
20 |
21 | (* - - - - - O P E R A T O R S - - - - - *)
22 |
23 | dup2 == dupd dup swapd;
24 | pop2 == pop pop;
25 | newstack == [] unstack;
26 | truth == true;
27 | falsity == false;
28 | to-upper == ['a >=] [32 -] [] ifte;
29 | to-lower == ['a < ] [32 +] [] ifte;
30 | boolean == [logical] [set] sequor;
31 | numerical == [integer] [float] sequor;
32 | swoncat == swap concat;
33 |
34 | (* date and time *)
35 |
36 | weekdays ==
37 | [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday"
38 | "Saturday" "Sunday" ];
39 | months ==
40 | [ "JAN" "FEB" "MAR" "APR" "MAY" "JUN"
41 | "JUL" "AUG" "SEP" "OCT" "NOV" "DEC" ];
42 | localtime-strings ==
43 | time localtime
44 | [ [ 0 at 'd 4 4 format ]
45 | [ 1 at pred months of ]
46 | [ 2 at 'd 2 2 format ]
47 | [ 3 at 'd 2 2 format ]
48 | [ 4 at 'd 2 2 format ]
49 | [ 5 at 'd 2 2 format ]
50 | [ 6 at [] ["true"] ["false"] ifte ]
51 | [ 7 at 'd 5 5 format ]
52 | [ 8 at pred weekdays of ] ]
53 | [i] map
54 | popd;
55 | today ==
56 | localtime-strings
57 | [ [8 at] [" "] [2 at] ["-"] [1 at] ["-"] [0 at rest rest] ]
58 | [i] map
59 | popd
60 | "" [concat] fold;
61 | now ==
62 | localtime-strings
63 | 3 drop
64 | [ [0 at] [":"] [1 at] [":"] [2 at] ]
65 | [i] map
66 | popd
67 | "" [concat] fold;
68 | show-todaynow ==
69 | today putchars space now putchars newline;
70 |
71 | (* program operators *)
72 |
73 | conjoin == [[false] ifte] cons cons;
74 | disjoin == [ifte] cons [true] swons cons;
75 | negate == [[false] [true] ifte] cons;
76 |
77 | (* - - - - - C O M B I N A T O R S - - - - - *)
78 |
79 | sequor == [pop true] swap ifte;
80 | sequand == [pop false] ifte;
81 | dipd == [dip] cons dip;
82 | dip2 == [dip] cons dip;
83 | dip3 == [dip2] cons dip;
84 | call == [] cons i;
85 | i2 == [dip] dip i;
86 | nullary2 == [nullary] cons dup i2 swapd;
87 | (* this is now a primitive in raw Joy:
88 | unary2 == [unary ] cons dup i2;
89 | *)
90 | repeat == dupd swap [i] dip2 while;
91 | forever == maxint swap times;
92 |
93 | (* library inclusion *)
94 |
95 | verbose == false;
96 | libload ==
97 | [ '_ swons intern body null ]
98 | [ ".joy" concat include ]
99 | [ [ verbose ]
100 | [ putchars " is already loaded\n" putchars ]
101 | [ pop ]
102 | ifte ]
103 | ifte;
104 | basic-libload ==
105 | "agglib" libload
106 | "seqlib" libload
107 | "numlib" libload;
108 | special-libload ==
109 | "mtrlib" libload
110 | "tutlib" libload
111 | "lazlib" libload
112 | "lsplib" libload
113 | "symlib" libload;
114 |
115 | all-libload == basic-libload special-libload;
116 |
117 | INILIB == "inilib.joy - the initial library, assumed everywhere\n".
118 | (* end LIBRA *)
119 |
120 | "inilib is loaded\n" putchars.
121 |
122 | (* END inilib.joy *)
123 |
--------------------------------------------------------------------------------
/src/joytut.inp:
--------------------------------------------------------------------------------
1 | (* FILE: joytut.inp *)
2 |
3 | "joytut.joy" include.
4 | 1 setecho.
5 |
6 | (* input that might have come from a terminal *)
7 |
8 | joytut.
9 | hahaha
10 | 1234
11 | 42
12 | 36
13 | 5
14 | 7
15 | [2 4 7]
16 | [ 8 9 3 ]
17 | [ [5 3] 5 3]
18 | [ [5 3] 5 3]
19 | [73]
20 |
21 | [ 9 4 16]
22 | [ 10 + ]
23 | [5 3 7]
24 | [ 20 <]
25 |
26 | 15
27 | -8
28 | [ 0 =]
29 | [ succ ]
30 | [ factorial *]
31 | [ dup pred ]
32 | [ * ]
33 |
34 | 2
35 |
36 | [6 4 8]
37 | [ 10 + ]
38 | [5 3 7]
39 | [ 20 <]
40 |
41 | 999
42 |
--------------------------------------------------------------------------------
/src/joytut.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyuheng/joy/0510200e381cc2365fe2f936f8d4540702789593/src/joytut.out
--------------------------------------------------------------------------------
/src/jp-joyjoy.joy:
--------------------------------------------------------------------------------
1 | (* File: jp-joyjoy.joy
2 | Joy interpreters written in Joy
3 | *)
4 |
5 | LIBRA
6 |
7 | HIDE
8 | cr1 == pop [joy] cons;
9 | cr2 == pop [[joy] cons] app2;
10 | cr3 == pop [[joy] cons] app3;
11 | cr4 == pop [[joy] cons] app4
12 | IN
13 | joy ==
14 | [ [ [ joy body joy ]
15 | [ true ]
16 | [ 'A ]
17 | [ [] ]
18 | [ "" ]
19 | [ {} ]
20 | [ 0 ]
21 | [ dup pop dup ]
22 | [ swap pop swap ]
23 | [ pop pop pop ]
24 | [ + pop + ]
25 | [ - pop - ]
26 | [ and pop and ]
27 | [ cons pop cons ]
28 | [ i pop joy ]
29 | [ dip cr1 dip ]
30 | [ step cr1 step ]
31 | [ map cr1 map ]
32 | [ filter cr1 filter ]
33 | [ times cr1 times ]
34 | [ app1 cr1 app1 ]
35 | [ app2 cr1 app2 ]
36 | [ app3 cr1 app3 ]
37 | [ app4 cr1 app4 ]
38 | [ ifte cr3 ifte ]
39 | [ linrec cr4 linrec ]
40 | [ binrec cr4 binrec ]
41 | [ dup put [] cons i ] ]
42 | opcase
43 | i ]
44 | step
45 | END;
46 |
47 | joy0 ==
48 | [ [ [ joy0 body joy0 ]
49 | [ [] ]
50 | [ pop pop pop ]
51 | [ cons pop cons ]
52 | [ opcase pop opcase ]
53 | [ body pop body ]
54 | [ i pop joy0 ]
55 | [ step pop [joy0] cons step ]
56 | [ [] cons i ] ]
57 | opcase
58 | i ]
59 | step.
60 |
61 | (* some additional versions of joy0 with tracing *)
62 |
63 | LIBRA
64 |
65 | joy0s == (* joy0 with short trace *)
66 | newline "joy0s :" putchars newline
67 | [ [ [ joy0s body joy0s ]
68 | [ [] ]
69 | [ pop pop pop ]
70 | [ cons pop cons ]
71 | [ opcase pop opcase ]
72 | [ body pop body ]
73 | [ i pop joy0s ]
74 | [ step pop [joy0] cons step ]
75 | [ [] cons i ] ]
76 | opcase
77 | i ]
78 | step;
79 |
80 | joy0l == (* joy0 with long trace *)
81 | newline "joy0l :" putchars newline
82 | [ dup put (* long trace *)
83 | [ [ joy0l body joy0l ]
84 | [ [] ]
85 | [ pop pop pop ]
86 | [ cons pop cons ]
87 | [ opcase pop opcase ]
88 | [ body pop body ]
89 | [ i pop joy0l ]
90 | [ step pop [joy0] cons step ]
91 | [ [] cons i ] ]
92 | opcase
93 | i ]
94 | step.
95 |
96 | (* END of jp-joyjoy.joy *)
97 |
--------------------------------------------------------------------------------
/src/jp-joytst.joy:
--------------------------------------------------------------------------------
1 | (* FILE: jp-joytst.joy - test file for jp-joyjoy.joy *)
2 |
3 | "jp-joyjoy" libinclude.
4 |
5 | 1 setecho.
6 | (* testing the tracing versions of joy0: joy0s and joy0l *)
7 |
8 | 2 3 + "\nfinal answer = " putchars.
9 |
10 | [ 2 3 + ] joy0s "\nfinal answer = " putchars.
11 |
12 | [ [ 2 3 + ] joy0s ] joy0s "\nfinal answer = " putchars.
13 |
14 | [ [ [ 2 3 + ] joy0s ] joy0s ] joy0s "\nfinal answer = " putchars.
15 |
16 | [ 2 3 + ] joy0l "\nfinal answer = " putchars.
17 |
18 | [ [ 2 3 + ] joy0l ] joy0l "\nfinal answer = " putchars.
19 |
20 | [ [ [ 2 3 + ] joy0l ] joy0l ] joy0l "\nfinal answer = " putchars.
21 |
22 | (* and as a final absurdity, with no tracing at all: *)
23 |
24 | [[[[[ 2 3 +] joy0] joy0] joy0] joy0] joy0 "\nfinal answer = "putchars.
25 |
26 | (* END jp-joytst.joy *)
27 |
--------------------------------------------------------------------------------
/src/jp-joytst.out:
--------------------------------------------------------------------------------
1 | JOY - compiled at 11:59:37 on Jul 2 2001 (NOBDW)
2 | Copyright 2001 by Manfred von Thun
3 | usrlib is loaded
4 | inilib is loaded
5 | agglib is loaded
6 | Thursday 19-JUL-01 19:31:55
7 | (* testing the tracing versions of joy0: joy0s and joy0l *)
8 |
9 | 2 3 + "\nfinal answer = " putchars.
10 |
11 | final answer = 5
12 |
13 | [ 2 3 + ] joy0s "\nfinal answer = " putchars.
14 |
15 | joy0s :
16 |
17 | final answer = 5
18 |
19 | [ [ 2 3 + ] joy0s ] joy0s "\nfinal answer = " putchars.
20 |
21 | joy0s :
22 |
23 | joy0s :
24 |
25 | joy0s :
26 |
27 |
28 | joy0s :
29 | joy0s :
30 | joy0s :
31 |
32 |
33 | final answer = 5
34 |
35 | [ [ [ 2 3 + ] joy0s ] joy0s ] joy0s "\nfinal answer = " putchars.
36 |
37 | joy0s :
38 |
39 | joy0s :
40 |
41 | joy0s :
42 |
43 |
44 | joy0s :
45 | joy0s :
46 | joy0s :
47 |
48 |
49 | joy0s :
50 |
51 | joy0s :
52 |
53 |
54 | joy0s :
55 | joy0s :
56 | joy0s :
57 |
58 |
59 | final answer = 5
60 |
61 | [ 2 3 + ] joy0l "\nfinal answer = " putchars.
62 |
63 | joy0l :
64 | 2 3 +
65 | final answer = 5
66 |
67 | [ [ 2 3 + ] joy0l ] joy0l "\nfinal answer = " putchars.
68 |
69 | joy0l :
70 | [2 3 +] joy0l
71 | joy0l :
72 | newline
73 | joy0l :
74 | '
75 | putch
76 | "joy0l :" putchars
77 | joy0l :
78 | [putch] step joy0l :newline
79 | joy0l :
80 | '
81 | putch
82 | [dup put [[joy0l body joy0l] [[]] [pop pop pop] [cons pop cons] [opcase pop opcase] [body pop body] [i pop joy0l] [step pop [joy0] cons step] [[] cons i]] opcase i] step 2 3 +
83 | final answer = 5
84 |
85 | [ [ [ 2 3 + ] joy0l ] joy0l ] joy0l "\nfinal answer = " putchars.
86 |
87 | joy0l :
88 | [[2 3 +] joy0l] joy0l
89 | joy0l :
90 | newline
91 | joy0l :
92 | '
93 | putch
94 | "joy0l :" putchars
95 | joy0l :
96 | [putch] step joy0l :newline
97 | joy0l :
98 | '
99 | putch
100 | [dup put [[joy0l body joy0l] [[]] [pop pop pop] [cons pop cons] [opcase pop opcase] [body pop body] [i pop joy0l] [step pop [joy0] cons step] [[] cons i]] opcase i] step [2 3 +] joy0l
101 | joy0l :
102 | newline
103 | joy0l :
104 | '
105 | putch
106 | "joy0l :" putchars
107 | joy0l :
108 | [putch] step joy0l :newline
109 | joy0l :
110 | '
111 | putch
112 | [dup put [[joy0l body joy0l] [[]] [pop pop pop] [cons pop cons] [opcase pop opcase] [body pop body] [i pop joy0l] [step pop [joy0] cons step] [[] cons i]] opcase i] step 2 3 + gc - 305 nodes inspected, 162 nodes copied, clock: 1
113 |
114 | final answer = 5
115 |
116 | (* and as a final absurdity, with no tracing at all: *)
117 |
118 | [[[[[ 2 3 +] joy0] joy0] joy0] joy0] joy0 "\nfinal answer = "putchars.
119 | gc - 2359 nodes inspected, 1249 nodes copied, clock: 1
120 | gc - 3729 nodes inspected, 1976 nodes copied, clock: 1
121 | gc - 2941 nodes inspected, 1558 nodes copied, clock: 1
122 | gc - 4636 nodes inspected, 2456 nodes copied, clock: 1
123 | gc - 3100 nodes inspected, 1643 nodes copied, clock: 1
124 |
125 | final answer = 5
126 |
127 | (* END jp-joytst.joy *)
128 | time: 8 CPU, 6 gc (= 75%)
129 |
--------------------------------------------------------------------------------
/src/lazlib.joy:
--------------------------------------------------------------------------------
1 |
2 | (* FILE: lazlib.joy *)
3 |
4 | LIBRA
5 |
6 | _lazlib == true;
7 |
8 | (* predicates *)
9 |
10 | Null == null;
11 |
12 | (* operators *)
13 |
14 | First == first;
15 | Rest == rest first i;
16 | Uncons == uncons first i;
17 | Cons == [] cons cons;
18 | Second == Rest First;
19 | Third == Rest Rest First;
20 | Drop == [Rest] times;
21 | N-th == pred Drop First;
22 | Size ==
23 | 0 swap
24 | [Null not] [[succ] dip Rest] while
25 | pop;
26 | Take ==
27 | [ Null ]
28 | [ pop pop [] ]
29 | [ [Uncons] dip pred ] (* note: lazy Uncons *)
30 | [ cons ] (* note: ordinary cons *)
31 | linrec;
32 |
33 | (* constructors *)
34 |
35 | From == (* f *)
36 | dup succ (* f f' *)
37 | [From] cons (* f [f' From] *)
38 | Cons; (* [f [f' From]] *)
39 |
40 | From-to == (* f t *)
41 | [ > ]
42 | [ pop pop [] ]
43 | [ [dup succ] dip (* f f' t *)
44 | [From-to] cons cons (* f [f' t From-to] *)
45 | Cons ] (* [f [f' t From-to]] *)
46 | ifte;
47 |
48 | (* combinators *)
49 |
50 | From-to-by == (* f t [B] *)
51 | (* else-part: *)
52 | [ dup [From-to-by] cons (* f t [B] [[B] From-to-by] *)
53 | swapd cons (* f [B] [t [B] From-to-by] *)
54 | [dupd i] dip cons (* f [B(f) t [B] From-to-by] *)
55 | Cons ] (* [f B(f) t [B] From-to-by]] *)
56 | (* ifpart, else-part: *)
57 | [ [pop >]
58 | [pop pop pop] ] dip
59 | ifte;
60 |
61 | From-by == (* f [B] *)
62 | dupd (* f f [B] *)
63 | dup [i] dip (* f B(f) [B] *)
64 | [From-by] cons cons (* f [B(f) [B] From-by] *)
65 | Cons; (* [f [B(f) [B] From-by]] *)
66 |
67 | Map == (* s [F] *)
68 | [pop Null]
69 | [[]] (* [] *)
70 | [ [Uncons] dip (* f r [F] *)
71 | dup swapd (* f [F] r [F] *)
72 | [Map] cons cons (* f [F] [r [F] Map] *)
73 | [i] dip (* F(f) [r [F] Map] *)
74 | Cons ] (* [ F(f) [r [F] Map] ] *)
75 | ifte;
76 |
77 | Filter == (* s [P] *)
78 | [pop Null]
79 | [[]] (* [] *)
80 | [ dup (* s [P] [P] *)
81 | [ [i not] cons [first] swoncat
82 | [Rest]
83 | while
84 | Uncons ]
85 | dip
86 | [Filter] cons cons (* f [r [P] Filter] *)
87 | Cons ] (* [ f [r [P] Filter] ] *)
88 | ifte;
89 |
90 | (* examples *)
91 |
92 | Naturals == 0 From;
93 | Positives == 1 From;
94 | Evens == 0 [2 +] From-by;
95 | Odds == 1 [2 +] From-by;
96 | Powers-of-2 == 1 [2 *] From-by;
97 | Ones == 1 [] From-by;
98 | Squares == Naturals [dup *] Map;
99 |
100 | LAZLIB == "lazlib.joy - lazy list library\n".
101 |
102 | (* end LIBRA *)
103 |
104 | "lazlib is loaded\n" putchars.
105 |
106 | (* END lazlib.joy *)
107 |
--------------------------------------------------------------------------------
/src/laztst.joy:
--------------------------------------------------------------------------------
1 | (* FILE: laztst.joy *)
2 |
3 | "\nTesting lazy lists in the library lazlib.joy\n" putchars.
4 |
5 | "lazlib" libload.
6 | "numlib" libload.
7 | 2 setecho.
8 |
9 | (* Some lazy lists defined in the library *)
10 |
11 | Naturals.
12 | Evens.
13 | Powers-of-2.
14 |
15 | (* Rest and Drop *)
16 |
17 | Naturals.
18 | Naturals Rest.
19 | Naturals Rest Rest.
20 | Naturals 2 Drop.
21 | Naturals 3 Drop.
22 |
23 | Ones.
24 | Ones Rest.
25 | Ones 10 Drop.
26 |
27 | (* First, Second, Third, N-th, Take *)
28 |
29 | Evens First.
30 | Evens Second.
31 | Evens Third.
32 | Evens 3 N-th.
33 | Evens 4 N-th.
34 | Evens 10 Take.
35 | Powers-of-2 5 N-th.
36 | Powers-of-2 10 N-th.
37 | Powers-of-2 20 N-th.
38 | Powers-of-2 20 Drop.
39 | Powers-of-2 21 N-th.
40 | Powers-of-2 10 Take.
41 | Powers-of-2 5 Drop 5 Take.
42 | Ones 5 Take.
43 | Ones 5 Drop 5 Take.
44 |
45 | (* user constructed infinite lazy lists *)
46 |
47 | 1 [1.1 *] From-by.
48 | 1 [1.1 *] From-by Rest.
49 | 1 [1.1 *] From-by Third.
50 | 1 [1.1 *] From-by 10 Drop.
51 | 1 [1.1 *] From-by 10 N-th.
52 | 1 [1.1 *] From-by 10 Take.
53 |
54 | true [not] From-by.
55 | true [not] From-by Third.
56 | true [not] From-by 3 Drop.
57 | true [not] From-by 10 Take.
58 |
59 | "" ['a swons] From-by 7 Take.
60 | [] [[] cons] From-by 7 Take.
61 |
62 | (* user constructed finite lazy lists *)
63 |
64 | '0 '9 From-to . (* digits *)
65 | '0 '9 From-to Third.
66 | '0 '9 From-to 9 Drop.
67 | '0 '9 From-to 9 Drop Null.
68 | '0 '9 From-to 10 Drop.
69 | '0 '9 From-to 10 Drop Null.
70 | '0 '9 From-to 5 Take.
71 | '0 '9 From-to 10 Take.
72 |
73 | 10 50 [3 +] From-to-by.
74 | 10 50 [3 +] From-to-by Third.
75 | (* Map and Filter *)
76 |
77 | Naturals [dup *] Map 10 Take.
78 | Naturals [prime] Filter 10 Take.
79 |
80 | Naturals [fib] Map [3 rem null] Filter 10 Take.
81 | Naturals [prime] Filter [dup *] Map 10 Take.
82 |
83 |
84 | 1000001 From. (* naturals > 1 Million *)
85 | 1000001 From [prime] Filter. (* primes > 1 Million *)
86 | 1000001 From [prime] Filter Third. (* third prime > 1 Million *)
87 | 1000001 From [prime] Filter 50 Take.(* fifty primes > 1 Million *)
88 |
89 | (* END: laztst.joy *)
90 |
--------------------------------------------------------------------------------
/src/lsptst.joy:
--------------------------------------------------------------------------------
1 | (* FILE: lsptst.joy *)
2 |
3 | "\nTesting the Lisp interpreter lisp in the library lsplib.joy\n" putchars.
4 |
5 | "lsplib" libload.
6 | 0 __settracegc.
7 | 1 setecho.
8 | DEFINE l-prompt == "".
9 | lisp.
10 |
11 | (* CONSTANTS *)
12 | 123.456
13 | false
14 | "hello world"
15 | [ QUOTE [Peter Paul Mary] ]
16 | [ QUOTE [1 2 3 4 5] ]
17 |
18 | (* PRIMITIVE FUNCTIONS *)
19 | [ CAR [QUOTE [Peter Paul Mary]] ]
20 | [ CDR [QUOTE [1 2 3 4 5]] ]
21 | [ CONS Fred [QUOTE [Peter Paul]] ]
22 | [ ATOM Fred ]
23 | [ ATOM [QUOTE [1 2 3]] ]
24 | [ NULL [QUOTE [1 2 3]] ]
25 | [ NULL [QUOTE []] ]
26 | [ EQ 2 3 ]
27 | [ LIST [CDR [QUOTE [1 2 3]]] [ATOM 123] ]
28 | [ [LAMBDA [lis] CAR [CDR lis]] [QUOTE [11 22 33]] ]
29 |
30 | (* "BORROWED" from JOY *)
31 | [ + [* 2 5] [- 10 7] ]
32 | [ and true false ]
33 | [ or true false ]
34 | [ > 3 4 ]
35 | [ and [NULL [QUOTE []]] [NULL [QUOTE [Bob]]] ]
36 | [ map [QUOTE [10 11 12 13 14 15 16]] [QUOTE [prime]] ]
37 | [ filter [QUOTE [10 11 12 13 14 15 16]] [QUOTE [prime]] ]
38 |
39 | [ include "OK" "lsptst.lsp" ] (* "BORROWED" include *)
40 |
41 | (* back to lsptst.joy *)
42 | EXIT (* from Lisp *)
43 |
44 | (* END: lsptst.joy *)
45 |
--------------------------------------------------------------------------------
/src/lsptst.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyuheng/joy/0510200e381cc2365fe2f936f8d4540702789593/src/lsptst.out
--------------------------------------------------------------------------------
/src/make.gc:
--------------------------------------------------------------------------------
1 | # makefile for Joy
2 |
3 | HDRS = globals.h
4 | SRCS = interp.c scan.c utils.c main.c
5 | OBJS = interp.o scan.o utils.o main.o
6 | CC = gcc -g -ansi -pedantic -Wall -D_C_SOURCE=1 -DGC_BDW
7 |
8 | joy: $(OBJS) gc/gc.a
9 | # $(CC) $(OBJS) gc/gc.a -lm -o joy
10 | $(CC) -static $(OBJS) -L gc/.libs -lgc -lm -o joy
11 |
12 | $(OBJS): $(HDRS)
13 |
14 | gc/gc.a:
15 | cd gc; ./autogen.sh ; ./configure ; $(MAKE)
16 |
--------------------------------------------------------------------------------
/src/make.gc-debug:
--------------------------------------------------------------------------------
1 | # makefile for Joy
2 |
3 | HDRS = globals.h
4 | SRCS = interp.c scan.c utils.c main.c
5 | OBJS = interp.o scan.o utils.o main.o
6 | CC = gcc -g -ansi -pedantic -Wall -D_C_SOURCE=1 -DGC_BDW -DDEBUG
7 |
8 | joy: $(OBJS) gc/gc.a
9 | # $(CC) $(OBJS) gc/gc.a -lm -o joy
10 | $(CC) -static $(OBJS) -L gc/.libs -lgc -lm -o joy
11 |
12 | $(OBJS): $(HDRS)
13 |
14 | gc/gc.a:
15 | cd gc; $(MAKE)
16 |
--------------------------------------------------------------------------------
/src/make.nogc:
--------------------------------------------------------------------------------
1 | # makefile for Joy without BDW gc
2 |
3 | HDRS = globals.h
4 | SRCS = interp.c scan.c utils.c main.c
5 | OBJS = interp.o scan.o utils.o main.o
6 | CC = gcc -g -ansi -pedantic -Wall -D_C_SOURCE=1
7 |
8 | joy: $(OBJS)
9 | $(CC) $(OBJS) -lm -o joy-no-gc
10 |
11 | $(OBJS): $(HDRS)
12 |
--------------------------------------------------------------------------------
/src/makefile:
--------------------------------------------------------------------------------
1 | .ONESHELL:
2 |
3 | joy:
4 | make -f make.gc
5 |
6 | joy-no-gc:
7 | make -f make.nogc
8 |
9 | clean:
10 | rm -f joy
11 | rm -f joy-no-gc
12 | rm -f gc.succ gc.fail *.o
13 | cd gc; $(MAKE) clean
14 |
--------------------------------------------------------------------------------
/src/modtst.joy:
--------------------------------------------------------------------------------
1 | 2 setecho.
2 | 1 setundeferror.
3 | DEFINE
4 | # English French German
5 | zero == 0 0 pop;
6 | one == zero 1 +;
7 | HIDE
8 | un == one;
9 | deux == zero one un + +
10 | IN
11 | two == deux;
12 | three == zero un + deux +;
13 | END;
14 | four == two three + one -;
15 | HIDE
16 | trois == two succ;
17 | HIDE
18 | eins == one;
19 | zwei == one dup +;
20 | drei == eins zwei +;
21 | IN
22 | quatre == drei eins +;
23 | END;
24 | cinq == two trois +
25 | IN
26 | five == cinq;
27 | six == trois three +;
28 | seven == trois drei + succ;
29 | END;
30 | END
31 |
32 | zero.
33 | one.
34 | two.
35 | three.
36 | four.
37 | five.
38 | six.
39 | seven. # should complain about undefined drei !
40 |
41 | HIDE
42 | twenty == 20; thirty == 30;
43 | IN
44 | fifty == twenty thirty +;
45 | END
46 |
47 | fifty.
48 | thirty. # should complain about undefined thirty !
49 |
50 | MODULE m1
51 | PRIVATE
52 | a == "a"; b == "b"
53 | PUBLIC
54 | ab == a b concat; ba == b a concat;
55 | abba == ab ba concat
56 | END
57 |
58 | # correct usage of fields:
59 | m1.ab .
60 | m1.ba .
61 | m1.abba .
62 | # incorrect usage of fields: no such field
63 | m1.a .
64 | m1.b .
65 |
66 | MODULE m2
67 | PRIVATE
68 | a == "A"; b == "B"
69 | PUBLIC
70 | ab == a b concat; ba == b a concat;
71 | abba == ab ba concat;
72 | HIDE
73 | c == "C"; d == "D"
74 | IN
75 | cd == c d concat;
76 | abc == a b concat c concat
77 | END;
78 | bcd == b cd concat
79 | END
80 |
81 | # correct usage of fields:
82 | m2.ab .
83 | m2.ba .
84 | m2.abba .
85 | m2.cd .
86 | m2.abc .
87 | m2.bcd .
88 |
89 | # incorrect usage of fields: no such field
90 | m2.a .
91 | m2.b .
92 | m2.c .
93 | m2.d .
94 |
95 |
--------------------------------------------------------------------------------
/src/modtst.out:
--------------------------------------------------------------------------------
1 | JOY - compiled at 16:57:51 on Mar 17 2003 (BDW)
2 | Copyright 2001 by Manfred von Thun
3 | usrlib is loaded
4 | inilib is loaded
5 | agglib is loaded
6 | 1 setundeferror.
7 | DEFINE
8 | # English French German
9 | zero == 0 0 pop;
10 | one == zero 1 +;
11 | HIDE
12 | un == one;
13 | deux == zero one un + +
14 | IN
15 | two == deux;
16 | three == zero un + deux +;
17 | END;
18 | four == two three + one -;
19 | HIDE
20 | trois == two succ;
21 | HIDE
22 | eins == one;
23 | zwei == one dup +;
24 | drei == eins zwei +;
25 | IN
26 | quatre == drei eins +;
27 | END;
28 | cinq == two trois +
29 | IN
30 | five == cinq;
31 | six == trois three +;
32 | seven == trois drei + succ;
33 | END;
34 | END
35 |
36 | zero.
37 | 0
38 | one.
39 | 1
40 | two.
41 | 2
42 | three.
43 | 3
44 | four.
45 | 4
46 | five.
47 | 5
48 | six.
49 | 6
50 | seven. # should complain about undefined drei !
51 | run time error: definition needed for drei
52 |
53 | HIDE
54 | twenty == 20; thirty == 30;
55 | IN
56 | fifty == twenty thirty +;
57 | END
58 |
59 | fifty.
60 | 50
61 | thirty. # should complain about undefined thirty !
62 | run time error: definition needed for thirty
63 |
64 | MODULE m1
65 | PRIVATE
66 | a == "a"; b == "b"
67 | PUBLIC
68 | ab == a b concat; ba == b a concat;
69 | abba == ab ba concat
70 | END
71 |
72 | # correct usage of fields:
73 | m1.ab .
74 | "ab"
75 | m1.ba .
76 | "ba"
77 | m1.abba .
78 | "abba"
79 | # incorrect usage of fields: no such field
80 | m1.a .
81 | m1.a .
82 | ^
83 | no such field in module
84 | []
85 | m1.b .
86 | m1.b .
87 | ^
88 | no such field in module
89 | []
90 |
91 | MODULE m2
92 | PRIVATE
93 | a == "A"; b == "B"
94 | PUBLIC
95 | ab == a b concat; ba == b a concat;
96 | abba == ab ba concat;
97 | HIDE
98 | c == "C"; d == "D"
99 | IN
100 | cd == c d concat;
101 | abc == a b concat c concat
102 | END;
103 | bcd == b cd concat
104 | END
105 |
106 | # correct usage of fields:
107 | m2.ab .
108 | "AB"
109 | m2.ba .
110 | "BA"
111 | m2.abba .
112 | "ABBA"
113 | m2.cd .
114 | "CD"
115 | m2.abc .
116 | "ABC"
117 | m2.bcd .
118 | "BCD"
119 |
120 | # incorrect usage of fields: no such field
121 | m2.a .
122 | m2.a .
123 | ^
124 | no such field in module
125 | []
126 | m2.b .
127 | m2.b .
128 | ^
129 | no such field in module
130 | []
131 | m2.c .
132 | m2.c .
133 | ^
134 | no such field in module
135 | []
136 | m2.d .
137 | m2.d .
138 | ^
139 | no such field in module
140 | []
141 |
142 |
--------------------------------------------------------------------------------
/src/mthlib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: mthlib.joy *)
2 |
3 | basic-libload.
4 |
5 | LIBRA
6 |
7 | _mthlib == true;
8 |
9 | (* REMOVE THIS, PUT IN OBJ LIBRARY *)
10 | (* "object oriented" lists:
11 | constructor kons,
12 | selectors kar,kdr (messages) *)
13 | kons == [] cons cons [of] cons;
14 | kar == 0 swap i;
15 | kdr == 1 swap i;
16 |
17 | (* NOTE : This file defines just two programs:
18 | 1. Numerical Calculator - calc
19 | 2. Symbolic Differentiation - diff
20 | All two programs expect input in Lisp notation *)
21 |
22 | (* - - - N U M E R I C A L C A L C U L A T O R - - - *)
23 |
24 | (* e.g. [* 10 [+ 2.2 3.3]] calc. *)
25 |
26 | calc ==
27 | [ numerical ]
28 | [ ]
29 | [ unswons
30 | [ dup [+ - * /] in ]
31 | [ [ [calc] map uncons first ] dip
32 | call ]
33 | [ "bad operator\n" put ]
34 | ifte ]
35 | ifte;
36 |
37 | (* - - - S Y M B O L I C D I F F E R E N T I A T I O N - - - *)
38 |
39 | (* REFS: SICP p 106, Henderson p 39 *)
40 |
41 | HIDE
42 |
43 | _msum == pairlist [+] swoncat;
44 | (* optimised for addition of 0 : *)
45 | _makesum == (* e1 e2 *)
46 | [ [ [ [numerical] unary2 and ] (* n1 n2 ? *)
47 | + ]
48 | [ [ numerical ] (* e1 n2 ? *)
49 | [0 =] [pop] [_msum] ifte ]
50 | [ [ pop numerical ] (* n1 e2 ? *)
51 | [pop 0 =] [popd] [_msum] ifte ]
52 | [ _msum] ] (* e1 e2 ! *)
53 | cond;
54 |
55 | _mprod == pairlist [*] swoncat;
56 | (* optimised for multiplication by 0 and 1 : *)
57 | _makeproduct == (* e1 e2 *)
58 | [ [ [ [numerical] unary2 and ] (* n1 n2 ? *)
59 | * ]
60 | [ [ numerical ] (* e1 n2 ? *)
61 | [ [ [0 =] popd ] (* 0 ? *)
62 | [ [1 =] pop ] (* 1 ? *)
63 | [ _mprod ] ] (* e1 n2 ! *)
64 | cond ]
65 | [ [ pop numerical ] (* n1 e2 ? *)
66 | [ [ [pop 0 =] pop ] (* 0 ? *)
67 | [ [pop 1 =] popd ] (* 1 ? *)
68 | [ _mprod ] ] (* n1 e2 ! *)
69 | cond ]
70 | [ _mprod ] ] (* e1 e2 ! *)
71 | cond
72 |
73 | IN
74 |
75 | (* [var] exp diff => the derivative of exp w.r.t. var *)
76 | diff == (* [v] e *)
77 | [ [ [numerical]
78 | pop pop 0 ] (* => 0 *)
79 | [ [leaf]
80 | [[first] dip = ] (* v e = ? *)
81 | [pop pop 1] (* => 1 *)
82 | [pop pop 0] (* => 0 *)
83 | ifte ]
84 | [ [list]
85 | unswons
86 | [ [ +
87 | pop unpair (* [v] e1 e2 *)
88 | [diff] unary2 (* [v] d1 d2 *)
89 | _makesum popd ] (* => s *)
90 | [ *
91 | pop unpair (* [v] e1 e2 *)
92 | dup2 (* [v] e1 e2 e1 e2 *)
93 | [[diff] unary2] dip2 (* [v] d1 d2 e1 e2 *)
94 | rollup (* [v] d1 e2 d2 e1 *)
95 | _makeproduct [_makeproduct] dip (* [v] p1 p2 *)
96 | _makesum popd ] (* => s *)
97 | [] ]
98 | opcase i ]
99 | [] ]
100 | cond
101 |
102 | END;
103 |
104 | MTHLIB == "mthlib.joy - symbolic mathematics library\n".
105 |
106 | (* end LIBRA *)
107 |
108 | "mthlib is loaded\n" putchars.
109 |
110 | (* END mthlib.joy *)
111 |
--------------------------------------------------------------------------------
/src/mtrlib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: mtrlib.joy *)
2 |
3 | "seqlib" libload "numlib" libload.
4 |
5 | LIBRA
6 |
7 | _mtrlib == true;
8 |
9 | (* VECTORS *)
10 | (* predicate *)
11 | vv-samesize == [size] dip size =;
12 | (* operators *)
13 | n-e-vector == [] cons [times] cons cons
14 | [] swap infra;
15 | v-negate-v == 0 swap [-]sv-bin-v;
16 | v-invert-v == 1.0 swap [/]sv-bin-v;
17 |
18 | (* vectors and scalars *)
19 | (* combinators *)
20 | sv-bin-v == map popd;
21 | vs-bin-v == cons map;
22 | vs-cbin-v == swapd map popd; (* efficiency *)
23 |
24 | (* two vectors *)
25 | (* predicate *)
26 | vv-comformable == [size] dip size =;
27 |
28 | (* combinators *)
29 | vv-bin-v == mapr2;
30 | vv-2bin-s == [mapr2 uncons] dip step;
31 |
32 | (* vector to matrix *)
33 | (* unary operators *)
34 | v-1row-m == [] cons;
35 | v-1col-m == [] swap [swons] sv-bin-v;
36 | v-zdiag-m ==
37 | [ small ]
38 | [ [null] [] [[] cons] ifte ]
39 | [ uncons ]
40 | [ dup [first rest 0 swons cons] dip
41 | [0 swons] map
42 | cons ]
43 | linrec;
44 | v-e-diag-m ==
45 | (*P4*) dup
46 | [ [swons cons] cons [first rest] swoncat ] dip
47 | [swons] cons
48 | [map cons] cons [dip] swoncat cons [dup] swoncat
49 | (*P1*) [ [small]
50 | (*P2*) [[null] [] [[] cons] ifte]
51 | (*P3*) [uncons] ] dip
52 | (*go*) linrec;
53 |
54 | (* combinator *)
55 | vv-bin-m == [map popd] cons cons map;
56 |
57 | (* MATRICES *)
58 |
59 | m-dimensions == dup [size] dip first size;
60 | mm-conformable == [size] dip first size =;
61 | mm-samedimensions == [m-dimensions] dip m-dimensions
62 | swapd = [=] dip and;
63 | (* operators *)
64 | mm-vercat-m == concat;
65 | mm-horcat-m == [concat] mapr2;
66 | m-transpose-m == (* READE p 133 *)
67 | [ [null] [true] [[null] some] ifte ]
68 | [ pop [] ]
69 | [ [[first] map] [[rest] map] cleave ]
70 | [ cons ]
71 | linrec;
72 |
73 | (* matrices and scalars *)
74 | sm-bin-m == [sv-bin-v] cons map popd;
75 | ms-bin-m == cons [map] cons map;
76 | ms-cbin-m == swapd sm-bin-m; (* efficiency *)
77 |
78 | (* matrices and vectors *)
79 |
80 | (* two matrices *)
81 | mm-bin-m == [mapr2] cons mapr2;
82 |
83 | mm-add-m == [+] mm-bin-m;
84 | mm-mul-m ==
85 | transpose
86 | [ [[*] mapr2 0 [+] fold] map popd ] cons
87 | map;
88 |
89 | mm-2bin-m ==
90 | [fold] cons [[mapr2 unswons] cons] dip concat
91 | [ transpose ] dip
92 | [ map popd ] cons cons
93 | map;
94 |
95 | m-print == putlist;
96 | (*
97 | "[ " putchars
98 | [ null ]
99 | [ pop ]
100 | [ unswons
101 | put
102 | [ "\n " putchars put ] step ]
103 | ifte
104 | "]\n" putchars.
105 | *)
106 |
107 | MTRLIB == "mtrlib.joy - matrix/vector library\n".
108 |
109 | (* end LIBRA *)
110 |
111 |
112 | "mtrlib is loaded\n" putchars.
113 |
114 | (* END mtrlib.joy *)
115 |
--------------------------------------------------------------------------------
/src/numlib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: numlib.joy *)
2 |
3 | LIBRA
4 |
5 | _numlib == true;
6 |
7 | (* predicates *)
8 |
9 | positive == 0 >;
10 | negative == 0 <;
11 | even == 2 rem null;
12 | odd == even not;
13 | prime ==
14 | 2
15 | [ [dup * >] nullary [rem 0 >] dip and ]
16 | [ succ ]
17 | while
18 | dup * < ;
19 |
20 | (* functions *)
21 |
22 | fact == [1 1] dip [dup [*] dip succ] times pop;
23 | fib == [1 0] dip [swap [+] unary] times popd;
24 | (*
25 | nfib == [1 1] dip [dup [+ succ] dip swap] times pop;
26 | *)
27 | gcd == [0 >] [dup rollup rem] while pop;
28 |
29 | fahrenheit == 9 * 5 / 32 + ;
30 | celsius == 32 - 5 * 9 / ;
31 |
32 | pi == 3.14159265;
33 | e == 1.0 exp;
34 | radians == pi * 180 / ;
35 | sindeg == radians sin;
36 | cosdeg == radians cos;
37 | tandeg == radians tan;
38 |
39 | (* find roots of the quadratic equation with coefficients a b c :
40 | a * X^2 + b * X + c = 0 *)
41 | qroots == (* a b c *)
42 | [ pop pop null ] (* a = 0 ? *)
43 | (* degenerate cases: *)
44 | [ [ pop null ] (* b = 0 ? *)
45 | [ [ null ] (* c = 0 ? *)
46 | [ [_INF] ] (* => [_INF] *)
47 | [ [] ] (* => [] *)
48 | ifte
49 | [ pop pop pop ] dip ]
50 | [ 0 swap - swap 1.0 * / (* float divisor *)
51 | [] cons popd ] (* => [ -c/b ] *)
52 | ifte ]
53 | (* standard cases: *)
54 | [ [ [ dup * swap ] dip
55 | 4 * * - ] unary (* b^2 - 4ac *)
56 | [ 0 < ] (* b^2 - 4ac negative ? *)
57 | [ pop pop pop [_COMPLEX] ] (* => [_COMPLEX] *)
58 | [ [ 0 swap - 1.0 * (* -b (floated) *)
59 | swap 2 * ] dip (* 2a *)
60 | [ 0 = ] (* b^2 - 4ac zero ? *)
61 | [ pop / [] cons ] (* => [-b / 2a] *)
62 | [ sqrt swapd dup2 - [+] dip (* -b+s -b-s *)
63 | [] cons cons (* [ -b+s -b-s ]*)
64 | swap [/] cons map ] (* => [(-b+s)/2a (-b-s)/2a]*)
65 | ifte ]
66 | ifte ]
67 | ifte;
68 |
69 | (* combinators *)
70 |
71 | deriv == [unary2 swap - 0.001 /] cons [dup 0.001 +] swoncat;
72 |
73 | (* Newton's method for finding roots of equations in one variable,
74 | for example to find the temperature at which Fahrenheit = Celsius:
75 | "using 5 as a guess, find the X for which X = fahrenheit(X)
76 | or X - fahrenheit(X) = 0
77 | in Joy: 5 [dup fahrenheit -] newton => -40
78 | or -100 [dup celsius -] newton => -40
79 | So -40 is the fixpoint for the two conversion functions.
80 | *)
81 | newton == (* Usage: guess [F] newton *)
82 | dup deriv (* guess [F] [D] *)
83 | [ pop i abs 0.0001 > ] (* too big ? *)
84 | [ [dupd] dip (* guess guess [F] [D] *)
85 | dup2 (* guess guess [F] [D] [F] [D] *)
86 | [[cleave / - ] dip]
87 | dip ] (* newguess [F] [D] *)
88 | while
89 | pop pop;
90 | use-newton == [[-] cons] dip swoncat 1 swap newton;
91 | cube-root == [dup dup * *] use-newton;
92 |
93 | NUMLIB == "numlib.joy - numerical library\n".
94 | (* end LIBRA *)
95 |
96 | "numlib is loaded\n" putchars.
97 |
98 | (* END numlib.joy *)
99 |
--------------------------------------------------------------------------------
/src/test.joy:
--------------------------------------------------------------------------------
1 | "inilib.joy" include.
2 |
3 |
4 | "numlib.joy" include.
5 |
6 | 1001.1 cube-root.
7 |
8 | argc.
9 |
10 | argv.
11 |
12 | quit.
13 |
14 |
--------------------------------------------------------------------------------
/src/tutlib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: tutlib.joy *)
2 |
3 | LIBRA
4 |
5 | _tutlib == true;
6 | pause ==
7 | bell "\nTo return, hit Control-" putchars control-eof putch newline
8 | terminal include;
9 | pausing == putchars pause;
10 | praise ==
11 | [ "Good." "Splendid." "Excellent." "Great." "Terrific." ]
12 | rand 5 rem at putchars newline;
13 | get-integer ==
14 | get
15 | [ integer not ]
16 | [ pop "An integer is expected:\n" putchars get ]
17 | while;
18 | get-list ==
19 | get
20 | [ list not ]
21 | [ pop "A list is expected:\n" putchars get ]
22 | while;
23 | get-quote ==
24 | get
25 | [ list not ]
26 | [ pop "A quotation is expected:\n" putchars get ]
27 | while;
28 | expecting ==
29 | [ equal ]
30 | [ pop pop praise [succ] dip]
31 | [ "No, the right answer is: " putchars put pop newline ]
32 | ifte
33 | succ;
34 | expecting-from ==
35 | [ [equal] some ]
36 | [ pop pop praise [succ] dip]
37 | [ "No, the right answer must be one of the following:\n\t" putchars
38 | [put " " putchars] step pop newline ]
39 | ifte
40 | succ;
41 | ini-stats ==
42 | 0 0 ;
43 | put-stats ==
44 | "You answered " putchars [put] dip
45 | "of the " putchars put
46 | "questions correctly.\n\n" putchars;
47 |
48 | (* the following assume a "Table Of Contents" definition of the form
49 | toc-of-tutorial == [ [ [Q0] "Title" ]
50 | [ [Q1] "1 H1 " ]
51 | [ [Q1] "2 H2 " ]
52 | .... ]
53 | where each Qi is a quote, each Hi is a section heading. *)
54 |
55 | toc-all-headings ==
56 | toc-of-tutorial rest
57 | [space space second putchars newline] step;
58 | toc-one-heading ==
59 | toc-of-tutorial of second putchars newline newline;
60 | toc-do-section0 ==
61 | terminal include
62 | newline
63 | 0 toc-one-heading
64 | "Contents:\n" putchars toc-all-headings newline
65 | toc-of-tutorial first first i;
66 | toc-ask-for-section ==
67 | "\nTo repeat something, here are the sections again\n"
68 | putchars
69 | toc-all-headings
70 | [ "Type the number of the section you want, or \n"
71 | "type 0 to do all sections, or\n"
72 | "type any other number (even negative) to quit.\n" ]
73 | putstrings
74 | get-integer
75 | [toc-of-tutorial size >=] [0 swap -] [] ifte;
76 | toc-do-section ==
77 | toc-of-tutorial of first i;
78 | toc-repeat-sections ==
79 | toc-ask-for-section
80 | [ 0 >= ]
81 | [ toc-do-section
82 | toc-ask-for-section ]
83 | while;
84 | toc-do-sec0-loop ==
85 | toc-do-section0
86 | toc-repeat-sections
87 | pop
88 | "Leaving " putchars 0 toc-one-heading
89 | "\nBye\n\n" putchars;
90 |
91 |
92 | TUTLIB == "tutlib.joy - tutorial library, for interaction".
93 | (* end LIBRA *)
94 |
95 | time srand. (* set seed for rand *)
96 |
97 | (* END tutlib.joy *)
98 |
--------------------------------------------------------------------------------
/src/usrlib.joy:
--------------------------------------------------------------------------------
1 | (* FILE: usrlib.joy - if it exists, then it is loaded by default *)
2 |
3 | LIBRA
4 |
5 | RAWJOY1 == "the primitives of the Joy1 system\n";
6 | _usrlib == true;
7 |
8 | (* personalise:
9 | myname == "Abigail Aardvark";
10 | myphone == 12345678;
11 | etc *)
12 |
13 | HIDE
14 | returned == "\007\nReturned to Joy\n" putchars
15 | IN
16 | (* unix:
17 | unix == true;
18 | control-eof == 'D;
19 | terminal == "/dev/tty";
20 | ls == "ls -la" system;
21 | editor == "vi ";
22 | escape ==
23 | "\nTo return to Joy, type: exit\n" putchars
24 | "csh" system
25 | returned;
26 | etc *)
27 |
28 | (* vms: *)
29 | vms == true;
30 | control-eof == 'Z;
31 | terminal == "tt:";
32 | dir == "DIR/DATE" system returned;
33 | editor == "TECO ";
34 | escape ==
35 | "\nTo return to Joy, hit Control-" putchars
36 | control-eof putch '\n putch
37 | "@tt:" system
38 | returned;
39 | (* etc *)
40 |
41 | edit ==
42 | dup editor swap concat system
43 | dup "Including " putchars putchars '\n putch
44 | include
45 | returned;
46 |
47 | find-in ==
48 | [ [ [ [unix] first body null not ]
49 | " " swap concat concat "grep " swap concat system ]
50 | [ [ [vms] first body null not ]
51 | swap " " swap concat concat "SEARCH " swap concat system ]
52 | [ "unknown operating system for find-in\n" putchars ] ]
53 | cond
54 | returned;
55 | standard-setting == 1 setautoput 1 setundeferror;
56 | USRLIB == "usrlib.joy - (personal) user library\n"
57 |
58 | END. (* end HIDE and LIBRA *)
59 |
60 | (* demo:
61 | "library" "*.joy" find-in.
62 | etc *)
63 |
64 | "usrlib is loaded\n" putchars.
65 |
66 | standard-setting.
67 |
68 | "inilib.joy" include.
69 | (* assuming inilib.joy was included: *)
70 | "agglib" libload.
71 |
72 | DEFINE verbose == true. (* Example of over-riding inilib.joy *)
73 |
74 | (* END usrlib.joy *)
75 |
--------------------------------------------------------------------------------