diff --git a/doc/lectures.out b/doc/lectures.out new file mode 100755 index 000000000..22a2ca2f6 --- /dev/null +++ b/doc/lectures.out @@ -0,0 +1,22 @@ +\BOOKMARK [1][-]{section.1}{Introduction:\040Languages,\040Semantics,\040Interpreters,\040Compilers}{}% 1 +\BOOKMARK [2][-]{subsection.1.1}{Language\040and\040semantics}{section.1}% 2 +\BOOKMARK [2][-]{subsection.1.2}{Interpreters}{section.1}% 3 +\BOOKMARK [2][-]{subsection.1.3}{Compilers}{section.1}% 4 +\BOOKMARK [2][-]{subsection.1.4}{The\040first\040example:\040language\040of\040expressions}{section.1}% 5 +\BOOKMARK [1][-]{section.2}{Statements,\040Stack\040Machine,\040Stack\040Machine\040Compiler}{}% 6 +\BOOKMARK [2][-]{subsection.2.1}{Statements}{section.2}% 7 +\BOOKMARK [1][-]{section.3}{Stack\040Machine}{}% 8 +\BOOKMARK [2][-]{subsection.3.1}{A\040Compiler\040for\040the\040Stack\040Machine}{section.3}% 9 +\BOOKMARK [1][-]{section.4}{Structural\040Induction}{}% 10 +\BOOKMARK [2][-]{subsection.4.1}{Structural\040Control\040Flow}{section.4}% 11 +\BOOKMARK [2][-]{subsection.4.2}{Extended\040Stack\040Machine}{section.4}% 12 +\BOOKMARK [2][-]{subsection.4.3}{Syntax\040Extensions}{section.4}% 13 +\BOOKMARK [1][-]{section.5}{Procedures}{}% 14 +\BOOKMARK [1][-]{section.6}{Extended\040Stack\040Machine}{}% 15 +\BOOKMARK [1][-]{section.7}{Functions}{}% 16 +\BOOKMARK [2][-]{subsection.7.1}{Functions\040in\040Expressions}{section.7}% 17 +\BOOKMARK [2][-]{subsection.7.2}{Return\040Statement}{section.7}% 18 +\BOOKMARK [1][-]{section.8}{Arrays\040and\040strings}{}% 19 +\BOOKMARK [2][-]{subsection.8.1}{Adding\040arrays\040on\040expression\040level}{section.8}% 20 +\BOOKMARK [2][-]{subsection.8.2}{Adding\040arrays\040on\040statement\040level}{section.8}% 21 +\BOOKMARK [2][-]{subsection.8.3}{Strings}{section.8}% 22 diff --git a/doc/lectures.pdf b/doc/lectures.pdf new file mode 100755 index 000000000..0d6499723 Binary files /dev/null and b/doc/lectures.pdf differ diff --git a/regression/x86only/Makefile b/regression/x86only/Makefile index d78ca38c1..3584822b1 100644 --- a/regression/x86only/Makefile +++ b/regression/x86only/Makefile @@ -7,7 +7,7 @@ RC=../../src/rc.opt check: $(TESTS) $(TESTS): %: %.expr - @RC_RUNTIME=../../runtime $(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log + @RC_RUNTIME=../../runtime $(RC) $< && cat $@.input | ./$@ > $@.log && diff -u $@.log orig/$@.log clean: rm -f test*.log *.s *~ $(TESTS) diff --git a/regression/x86only/test003 b/regression/x86only/test003 new file mode 100755 index 000000000..6ce1e26c8 Binary files /dev/null and b/regression/x86only/test003 differ diff --git a/regression/x86only/test003.log b/regression/x86only/test003.log new file mode 100644 index 000000000..87c796b83 --- /dev/null +++ b/regression/x86only/test003.log @@ -0,0 +1,394 @@ +Bsexp: allocate 16! +alloc: current: f7fe9000 16;new current: f7fe9040 +Bsexp: allocate 16! +alloc: current: f7fe9040 16;new current: f7fe9080 +Bsexp: allocate 16! +alloc: current: f7fe9080 16;new current: f7fe90c0 +Bsexp: allocate 16! +alloc: current: f7fe90c0 16;new current: f7fe9100 +Bsexp: allocate 16! +alloc: current: f7fe9100 16;new current: f7fe9140 +Bsexp: allocate 16! +alloc: current: f7fe9140 16;new current: f7fe9180 +Bsexp: allocate 16! +alloc: current: f7fe9180 16;new current: f7fe91c0 +Bsexp: allocate 16! +alloc: call gc: 16 + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fe9000, f_end = 0xf7fe9200, +data at 0xf7fe9000(=>0xf7fe9008): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fe9040 +data at 0xf7fe9040(=>0xf7fe9048): SEXP + tag(cons) 3 0xf7fe9008 +len = 4, new cur = 0xf7fe9080 +data at 0xf7fe9080(=>0xf7fe9088): SEXP + tag(cons) 2 0xf7fe9048 +len = 4, new cur = 0xf7fe90c0 +data at 0xf7fe90c0(=>0xf7fe90c8): SEXP + tag(cons) 1 0xf7fe9088 +len = 4, new cur = 0xf7fe9100 +data at 0xf7fe9100(=>0xf7fe9108): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fe9140 +data at 0xf7fe9140(=>0xf7fe9148): SEXP + tag(cons) 3 0 +len = 4, new cur = 0xf7fe9180 +data at 0xf7fe9180(=>0xf7fe9188): SEXP + tag(cons) 2 0xf7fe9148 +len = 4, new cur = 0xf7fe91c0 + +gc: current: f7fbc000; to_space.b = f7fbc000; to_space.e = f7fbc200; f_space.b = f7fe9000; f_space.e = f7fe9200 +gc: data is scanned +gc_test_and_copy_root: root ff98e3a0 f7fe9108 +gc_copy: f7fe9108 cur = f7fbc000 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9108 (f7fe9100) -> f7fbc008 (f7fbc000); new-current = f7fbc040 +gc_test_and_copy_root: root ff98e3a4 f7fe90c8 +gc_copy: f7fe90c8 cur = f7fbc040 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9088 cur = f7fbc080 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9048 cur = f7fbc0c0 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9008 cur = f7fbc100 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9008 (f7fe9000) -> f7fbc108 (f7fbc100); new-current = f7fbc140 +copy_elements: fix f7fe9048: f7fbc108 +gc_copy: f7fe9048 (f7fe9040) -> f7fbc0c8 (f7fbc0c0); new-current = f7fbc140 +copy_elements: fix f7fe9088: f7fbc0c8 +gc_copy: f7fe9088 (f7fe9080) -> f7fbc088 (f7fbc080); new-current = f7fbc140 +copy_elements: fix f7fe90c8: f7fbc088 +gc_copy: f7fe90c8 (f7fe90c0) -> f7fbc048 (f7fbc040); new-current = f7fbc140 +gc: end: (allocate!) return f7fbc140; from_space.current f7fbc180; from_space.end + +gc END + + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fbc000, f_end = 0xf7fbc200, +data at 0xf7fbc000(=>0xf7fbc008): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fbc040 +data at 0xf7fbc040(=>0xf7fbc048): SEXP + tag(cons) 1 0xf7fbc088 +len = 4, new cur = 0xf7fbc080 +data at 0xf7fbc080(=>0xf7fbc088): SEXP + tag(cons) 2 0xf7fbc0c8 +len = 4, new cur = 0xf7fbc0c0 +data at 0xf7fbc0c0(=>0xf7fbc0c8): SEXP + tag(cons) 3 0xf7fbc108 +len = 4, new cur = 0xf7fbc100 +data at 0xf7fbc100(=>0xf7fbc108): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fbc140 +data at 0xf7fbc140 +printFromSpace: end! +=================== + +Bsexp: allocate 16! +alloc: current: f7fbc180 16;new current: f7fbc1c0 +Bsexp: allocate 16! +alloc: call gc: 16 + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fbc000, f_end = 0xf7fbc200, +data at 0xf7fbc000(=>0xf7fbc008): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fbc040 +data at 0xf7fbc040(=>0xf7fbc048): SEXP + tag(cons) 1 0xf7fbc088 +len = 4, new cur = 0xf7fbc080 +data at 0xf7fbc080(=>0xf7fbc088): SEXP + tag(cons) 2 0xf7fbc0c8 +len = 4, new cur = 0xf7fbc0c0 +data at 0xf7fbc0c0(=>0xf7fbc0c8): SEXP + tag(cons) 3 0xf7fbc108 +len = 4, new cur = 0xf7fbc100 +data at 0xf7fbc100(=>0xf7fbc108): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fbc140 +data at 0xf7fbc140(=>0xf7fbc148): SEXP + tag(cons) 6 0 +len = 4, new cur = 0xf7fbc180 +data at 0xf7fbc180(=>0xf7fbc188): SEXP + tag(cons) 5 0xf7fbc148 +len = 4, new cur = 0xf7fbc1c0 + +gc: current: f7fe9000; to_space.b = f7fe9000; to_space.e = f7fe9200; f_space.b = f7fbc000; f_space.e = f7fbc200 +gc: data is scanned +gc_test_and_copy_root: root ff98e394 f7fbc188 +gc_copy: f7fbc188 cur = f7fe9000 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc148 cur = f7fe9040 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc148 (f7fbc140) -> f7fe9048 (f7fe9040); new-current = f7fe9080 +copy_elements: fix f7fbc188: f7fe9048 +gc_copy: f7fbc188 (f7fbc180) -> f7fe9008 (f7fe9000); new-current = f7fe9080 +gc_test_and_copy_root: root ff98e3a0 f7fbc008 +gc_copy: f7fbc008 cur = f7fe9080 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc008 (f7fbc000) -> f7fe9088 (f7fe9080); new-current = f7fe90c0 +gc_test_and_copy_root: root ff98e3a4 f7fbc048 +gc_copy: f7fbc048 cur = f7fe90c0 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc088 cur = f7fe9100 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc0c8 cur = f7fe9140 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc108 cur = f7fe9180 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fbc108 (f7fbc100) -> f7fe9188 (f7fe9180); new-current = f7fe91c0 +copy_elements: fix f7fbc0c8: f7fe9188 +gc_copy: f7fbc0c8 (f7fbc0c0) -> f7fe9148 (f7fe9140); new-current = f7fe91c0 +copy_elements: fix f7fbc088: f7fe9148 +gc_copy: f7fbc088 (f7fbc080) -> f7fe9108 (f7fe9100); new-current = f7fe91c0 +copy_elements: fix f7fbc048: f7fe9108 +gc_copy: f7fbc048 (f7fbc040) -> f7fe90c8 (f7fe90c0); new-current = f7fe91c0 +gc pre-extend_spaces : f7fe91c0 10 f7fe9200 +extend: 0xf7fbc000 0xf7fe9000 0xf7fbc000 0xf7fe9000 +extend: 0xf7fbc200 0xf7fe9200 0xf7fe91c0 +gc post-extend_spaces: f7fe91c0 10 f7fe9400 +gc: end: (allocate!) return f7fe91c0; from_space.current f7fe9200; from_space.end + +gc END + + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fe9000, f_end = 0xf7fe9400, +data at 0xf7fe9000(=>0xf7fe9008): SEXP + tag(cons) 5 0xf7fe9048 +len = 4, new cur = 0xf7fe9040 +data at 0xf7fe9040(=>0xf7fe9048): SEXP + tag(cons) 6 0 +len = 4, new cur = 0xf7fe9080 +data at 0xf7fe9080(=>0xf7fe9088): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fe90c0 +data at 0xf7fe90c0(=>0xf7fe90c8): SEXP + tag(cons) 1 0xf7fe9108 +len = 4, new cur = 0xf7fe9100 +data at 0xf7fe9100(=>0xf7fe9108): SEXP + tag(cons) 2 0xf7fe9148 +len = 4, new cur = 0xf7fe9140 +data at 0xf7fe9140(=>0xf7fe9148): SEXP + tag(cons) 3 0xf7fe9188 +len = 4, new cur = 0xf7fe9180 +data at 0xf7fe9180(=>0xf7fe9188): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fe91c0 +data at 0xf7fe91c0 +printFromSpace: end! +=================== + +Bsexp: allocate 16! +alloc: current: f7fe9200 16;new current: f7fe9240 +Bsexp: allocate 16! +alloc: current: f7fe9240 16;new current: f7fe9280 +Bsexp: allocate 16! +alloc: current: f7fe9280 16;new current: f7fe92c0 +Bsexp: allocate 16! +alloc: current: f7fe92c0 16;new current: f7fe9300 +Bsexp: allocate 16! +alloc: current: f7fe9300 16;new current: f7fe9340 +Bsexp: allocate 16! +alloc: current: f7fe9340 16;new current: f7fe9380 +Bsexp: allocate 16! +alloc: current: f7fe9380 16;new current: f7fe93c0 +Bsexp: allocate 16! +alloc: call gc: 16 + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fe9000, f_end = 0xf7fe9400, +data at 0xf7fe9000(=>0xf7fe9008): SEXP + tag(cons) 5 0xf7fe9048 +len = 4, new cur = 0xf7fe9040 +data at 0xf7fe9040(=>0xf7fe9048): SEXP + tag(cons) 6 0 +len = 4, new cur = 0xf7fe9080 +data at 0xf7fe9080(=>0xf7fe9088): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fe90c0 +data at 0xf7fe90c0(=>0xf7fe90c8): SEXP + tag(cons) 1 0xf7fe9108 +len = 4, new cur = 0xf7fe9100 +data at 0xf7fe9100(=>0xf7fe9108): SEXP + tag(cons) 2 0xf7fe9148 +len = 4, new cur = 0xf7fe9140 +data at 0xf7fe9140(=>0xf7fe9148): SEXP + tag(cons) 3 0xf7fe9188 +len = 4, new cur = 0xf7fe9180 +data at 0xf7fe9180(=>0xf7fe9188): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fe91c0 +data at 0xf7fe91c0(=>0xf7fe91c8): SEXP + tag(cons) 0xf7fe9008 0 +len = 4, new cur = 0xf7fe9200 +data at 0xf7fe9200(=>0xf7fe9208): SEXP + tag(cons) 4 0xf7fe91c8 +len = 4, new cur = 0xf7fe9240 +data at 0xf7fe9240(=>0xf7fe9248): SEXP + tag(cons) 0xf7fe9208 0 +len = 4, new cur = 0xf7fe9280 +data at 0xf7fe9280(=>0xf7fe9288): SEXP + tag(cons) 0xf7fe9188 0xf7fe9248 +len = 4, new cur = 0xf7fe92c0 +data at 0xf7fe92c0(=>0xf7fe92c8): SEXP + tag(cons) 0xf7fe9088 0xf7fe9288 +len = 4, new cur = 0xf7fe9300 +data at 0xf7fe9300(=>0xf7fe9308): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fe9340 +data at 0xf7fe9340(=>0xf7fe9348): SEXP + tag(cons) 3 0xf7fe9308 +len = 4, new cur = 0xf7fe9380 +data at 0xf7fe9380(=>0xf7fe9388): SEXP + tag(cons) 2 0xf7fe9348 +len = 4, new cur = 0xf7fe93c0 + +gc: current: f7fbc000; to_space.b = f7fbc000; to_space.e = f7fbc400; f_space.b = f7fe9000; f_space.e = f7fe9400 +gc: data is scanned +gc_test_and_copy_root: root ff98e398 f7fe9388 +gc_copy: f7fe9388 cur = f7fbc000 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9348 cur = f7fbc040 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9308 cur = f7fbc080 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9308 (f7fe9300) -> f7fbc088 (f7fbc080); new-current = f7fbc0c0 +copy_elements: fix f7fe9348: f7fbc088 +gc_copy: f7fe9348 (f7fe9340) -> f7fbc048 (f7fbc040); new-current = f7fbc0c0 +copy_elements: fix f7fe9388: f7fbc048 +gc_copy: f7fe9388 (f7fe9380) -> f7fbc008 (f7fbc000); new-current = f7fbc0c0 +gc_test_and_copy_root: root ff98e3a0 f7fe92c8 +gc_copy: f7fe92c8 cur = f7fbc0c0 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9088 cur = f7fbc100 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9088 (f7fe9080) -> f7fbc108 (f7fbc100); new-current = f7fbc140 +copy_elements: fix f7fe92c8: f7fbc108 +gc_copy: f7fe9288 cur = f7fbc140 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9188 cur = f7fbc180 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9188 (f7fe9180) -> f7fbc188 (f7fbc180); new-current = f7fbc1c0 +copy_elements: fix f7fe9288: f7fbc188 +gc_copy: f7fe9248 cur = f7fbc1c0 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9208 cur = f7fbc200 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe91c8 cur = f7fbc240 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9008 cur = f7fbc280 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9048 cur = f7fbc2c0 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9048 (f7fe9040) -> f7fbc2c8 (f7fbc2c0); new-current = f7fbc300 +copy_elements: fix f7fe9008: f7fbc2c8 +gc_copy: f7fe9008 (f7fe9000) -> f7fbc288 (f7fbc280); new-current = f7fbc300 +copy_elements: fix f7fe91c8: f7fbc288 +gc_copy: f7fe91c8 (f7fe91c0) -> f7fbc248 (f7fbc240); new-current = f7fbc300 +copy_elements: fix f7fe9208: f7fbc248 +gc_copy: f7fe9208 (f7fe9200) -> f7fbc208 (f7fbc200); new-current = f7fbc300 +copy_elements: fix f7fe9248: f7fbc208 +gc_copy: f7fe9248 (f7fe9240) -> f7fbc1c8 (f7fbc1c0); new-current = f7fbc300 +copy_elements: fix f7fe9288: f7fbc1c8 +gc_copy: f7fe9288 (f7fe9280) -> f7fbc148 (f7fbc140); new-current = f7fbc300 +copy_elements: fix f7fe92c8: f7fbc148 +gc_copy: f7fe92c8 (f7fe92c0) -> f7fbc0c8 (f7fbc0c0); new-current = f7fbc300 +gc_test_and_copy_root: root ff98e3a4 f7fe90c8 +gc_copy: f7fe90c8 cur = f7fbc300 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9108 cur = f7fbc340 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9148 cur = f7fbc380 starts +len1 = 2, len2=848787, len3 = 2 +gc_copy: f7fe9188 cur = f7fbc3c0 starts +gc_copy: IS_FORWARD_PTR: return! f7fbc188 +copy_elements: fix f7fe9148: f7fbc188 +gc_copy: f7fe9148 (f7fe9140) -> f7fbc388 (f7fbc380); new-current = f7fbc3c0 +copy_elements: fix f7fe9108: f7fbc388 +gc_copy: f7fe9108 (f7fe9100) -> f7fbc348 (f7fbc340); new-current = f7fbc3c0 +copy_elements: fix f7fe90c8: f7fbc348 +gc_copy: f7fe90c8 (f7fe90c0) -> f7fbc308 (f7fbc300); new-current = f7fbc3c0 +gc pre-extend_spaces : f7fbc3c0 10 f7fbc400 +extend: 0xf7fe9000 0xf7fbc000 0xf7fe9000 0xf7fbc000 +extend: 0xf7fe9400 0xf7fbc400 0xf7fbc3c0 +gc post-extend_spaces: f7fbc3c0 10 f7fbc800 +gc: end: (allocate!) return f7fbc3c0; from_space.current f7fbc400; from_space.end + +gc END + + +HEAP SNAPSHOT +=================== +f_begin = 0xf7fbc000, f_end = 0xf7fbc800, +data at 0xf7fbc000(=>0xf7fbc008): SEXP + tag(cons) 2 0xf7fbc048 +len = 4, new cur = 0xf7fbc040 +data at 0xf7fbc040(=>0xf7fbc048): SEXP + tag(cons) 3 0xf7fbc088 +len = 4, new cur = 0xf7fbc080 +data at 0xf7fbc080(=>0xf7fbc088): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fbc0c0 +data at 0xf7fbc0c0(=>0xf7fbc0c8): SEXP + tag(cons) 0xf7fbc108 0xf7fbc148 +len = 4, new cur = 0xf7fbc100 +data at 0xf7fbc100(=>0xf7fbc108): SEXP + tag(cons) 1 0 +len = 4, new cur = 0xf7fbc140 +data at 0xf7fbc140(=>0xf7fbc148): SEXP + tag(cons) 0xf7fbc188 0xf7fbc1c8 +len = 4, new cur = 0xf7fbc180 +data at 0xf7fbc180(=>0xf7fbc188): SEXP + tag(cons) 4 0 +len = 4, new cur = 0xf7fbc1c0 +data at 0xf7fbc1c0(=>0xf7fbc1c8): SEXP + tag(cons) 0xf7fbc208 0 +len = 4, new cur = 0xf7fbc200 +data at 0xf7fbc200(=>0xf7fbc208): SEXP + tag(cons) 4 0xf7fbc248 +len = 4, new cur = 0xf7fbc240 +data at 0xf7fbc240(=>0xf7fbc248): SEXP + tag(cons) 0xf7fbc288 0 +len = 4, new cur = 0xf7fbc280 +data at 0xf7fbc280(=>0xf7fbc288): SEXP + tag(cons) 5 0xf7fbc2c8 +len = 4, new cur = 0xf7fbc2c0 +data at 0xf7fbc2c0(=>0xf7fbc2c8): SEXP + tag(cons) 6 0 +len = 4, new cur = 0xf7fbc300 +data at 0xf7fbc300(=>0xf7fbc308): SEXP + tag(cons) 1 0xf7fbc348 +len = 4, new cur = 0xf7fbc340 +data at 0xf7fbc340(=>0xf7fbc348): SEXP + tag(cons) 2 0xf7fbc388 +len = 4, new cur = 0xf7fbc380 +data at 0xf7fbc380(=>0xf7fbc388): SEXP + tag(cons) 3 0xf7fbc188 +len = 4, new cur = 0xf7fbc3c0 +data at 0xf7fbc3c0 +printFromSpace: end! +=================== + +Barray: create n = 4 +alloc: current: f7fbc400 20;new current: f7fbc450 +alloc: current: f7fbc450 8;new current: f7fbc470 +alloc: current: f7fbc470 6;new current: f7fbc488 +0 +alloc: current: f7fbc488 8;new current: f7fbc4a8 +alloc: current: f7fbc4a8 17;new current: f7fbc4ec +{1, 2, 3, 4} +alloc: current: f7fbc4ec 8;new current: f7fbc50c +alloc: current: f7fbc50c 28;new current: f7fbc57c +{{1}, {4}, {4, {5, 6}}} +alloc: current: f7fbc57c 8;new current: f7fbc59c +alloc: current: f7fbc59c 17;new current: f7fbc5e0 +{1, 2, 3, 4} diff --git a/regression/x86only/test003.s b/regression/x86only/test003.s new file mode 100644 index 000000000..3379a7f9d --- /dev/null +++ b/regression/x86only/test003.s @@ -0,0 +1,578 @@ + .data + +filler: .fill 6, 4, 1 + + .globl __gc_data_start + + .globl __gc_data_end + +__gc_data_start: + +global_i: .int 1 + +global_lists: .int 1 + +__gc_data_end: + +string_0: .string "%s\n" + + .text + + .globl main + +# LABEL ("main") / [] + +main: + +# BEGIN ("main", [], []) / [] + + pushl %ebp + movl %esp, %ebp + subl $Lmain_SIZE, %esp + movl %esp, %edi + movl $filler, %esi + movl $LSmain_SIZE, %ecx + rep movsl +# CALL ("L__gc_init", 0) / [] + + call L__gc_init + addl $0, %esp + movl %eax, %ebx +# DROP / [R (0)] + +# LDA ("lists") / [] + + leal global_lists, %ebx +# CONST (0) / [R (0)] + + movl $1, %ecx +# CONST (1) / [R (1); R (0)] + + movl $3, %esi +# CONST (2) / [R (2); R (1); R (0)] + + movl $5, %edi +# CONST (3) / [R (3); R (2); R (1); R (0)] + + movl $7, -4(%ebp) +# CONST (4) / [S (0); R (3); R (2); R (1); R (0)] + + movl $9, -8(%ebp) +# CONST (0) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -12(%ebp) +# SEXP ("cons", 2) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -16(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -16(%ebp) + pushl -12(%ebp) + pushl -8(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -8(%ebp) +# SEXP ("cons", 2) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -12(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -12(%ebp) + pushl -8(%ebp) + pushl -4(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -4(%ebp) +# SEXP ("cons", 2) / [S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -8(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl -8(%ebp) + pushl -4(%ebp) + pushl %edi + pushl $3 + call Bsexp + addl $16, %esp + popl %esi + popl %ecx + popl %ebx + movl %eax, %edi +# SEXP ("cons", 2) / [R (3); R (2); R (1); R (0)] + + movl $848787, -4(%ebp) + pushl %ebx + pushl %ecx + pushl -4(%ebp) + pushl %edi + pushl %esi + pushl $3 + call Bsexp + addl $16, %esp + popl %ecx + popl %ebx + movl %eax, %esi +# CONST (1) / [R (2); R (1); R (0)] + + movl $3, %edi +# CONST (0) / [R (3); R (2); R (1); R (0)] + + movl $1, -4(%ebp) +# SEXP ("cons", 2) / [S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -8(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl -8(%ebp) + pushl -4(%ebp) + pushl %edi + pushl $3 + call Bsexp + addl $16, %esp + popl %esi + popl %ecx + popl %ebx + movl %eax, %edi +# CONST (2) / [R (3); R (2); R (1); R (0)] + + movl $5, -4(%ebp) +# CONST (3) / [S (0); R (3); R (2); R (1); R (0)] + + movl $7, -8(%ebp) +# CONST (0) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -12(%ebp) +# SEXP ("cons", 2) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -16(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -16(%ebp) + pushl -12(%ebp) + pushl -8(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -8(%ebp) +# SEXP ("cons", 2) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -12(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -12(%ebp) + pushl -8(%ebp) + pushl -4(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -4(%ebp) +# CONST (4) / [S (0); R (3); R (2); R (1); R (0)] + + movl $9, -8(%ebp) +# CONST (5) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $11, -12(%ebp) +# CONST (6) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $13, -16(%ebp) +# CONST (0) / [S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -20(%ebp) +# SEXP ("cons", 2) / [S (4); S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -24(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -24(%ebp) + pushl -20(%ebp) + pushl -16(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -16(%ebp) +# SEXP ("cons", 2) / [S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -20(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -20(%ebp) + pushl -16(%ebp) + pushl -12(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -12(%ebp) +# CONST (0) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -16(%ebp) +# SEXP ("cons", 2) / [S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -20(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -20(%ebp) + pushl -16(%ebp) + pushl -12(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -12(%ebp) +# SEXP ("cons", 2) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -16(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -16(%ebp) + pushl -12(%ebp) + pushl -8(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -8(%ebp) +# CONST (0) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -12(%ebp) +# SEXP ("cons", 2) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -16(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -16(%ebp) + pushl -12(%ebp) + pushl -8(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -8(%ebp) +# SEXP ("cons", 2) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -12(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -12(%ebp) + pushl -8(%ebp) + pushl -4(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -4(%ebp) +# SEXP ("cons", 2) / [S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -8(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl -8(%ebp) + pushl -4(%ebp) + pushl %edi + pushl $3 + call Bsexp + addl $16, %esp + popl %esi + popl %ecx + popl %ebx + movl %eax, %edi +# CONST (1) / [R (3); R (2); R (1); R (0)] + + movl $3, -4(%ebp) +# CONST (2) / [S (0); R (3); R (2); R (1); R (0)] + + movl $5, -8(%ebp) +# CONST (3) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $7, -12(%ebp) +# CONST (4) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $9, -16(%ebp) +# CONST (0) / [S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $1, -20(%ebp) +# SEXP ("cons", 2) / [S (4); S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -24(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -24(%ebp) + pushl -20(%ebp) + pushl -16(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -16(%ebp) +# SEXP ("cons", 2) / [S (3); S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -20(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -20(%ebp) + pushl -16(%ebp) + pushl -12(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -12(%ebp) +# SEXP ("cons", 2) / [S (2); S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -16(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -16(%ebp) + pushl -12(%ebp) + pushl -8(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -8(%ebp) +# SEXP ("cons", 2) / [S (1); S (0); R (3); R (2); R (1); R (0)] + + movl $848787, -12(%ebp) + pushl %ebx + pushl %ecx + pushl %esi + pushl %edi + pushl -12(%ebp) + pushl -8(%ebp) + pushl -4(%ebp) + pushl $3 + call Bsexp + addl $16, %esp + popl %edi + popl %esi + popl %ecx + popl %ebx + movl %eax, -4(%ebp) +# CALL (".array", 4) / [S (0); R (3); R (2); R (1); R (0)] + + pushl %ebx + pushl -4(%ebp) + pushl %edi + pushl %esi + pushl %ecx + pushl $4 + call Barray + addl $20, %esp + popl %ebx + movl %eax, %ecx +# STI / [R (1); R (0)] + + movl %ecx, %eax + movl %eax, (%ebx) + movl %eax, %ebx +# DROP / [R (0)] + +# LDA ("i") / [] + + leal global_i, %ebx +# CONST (0) / [R (0)] + + movl $1, %ecx +# STI / [R (1); R (0)] + + movl %ecx, %eax + movl %eax, (%ebx) + movl %eax, %ebx +# DROP / [R (0)] + +# JMP ("L55") / [] + + jmp L55 +# LABEL ("L54") / [] + +L54: + +# STRING ("%s\\n") / [] + + movl $string_0, %ebx + pushl %ebx + call Bstring + addl $4, %esp + movl %eax, %ebx +# LD ("lists") / [R (0)] + + movl global_lists, %ecx +# LD ("i") / [R (1); R (0)] + + movl global_i, %esi +# CALL (".elem", 2) / [R (2); R (1); R (0)] + + pushl %ebx + pushl %esi + pushl %ecx + call Belem + addl $8, %esp + popl %ebx + movl %eax, %ecx +# CALL (".stringval", 1) / [R (1); R (0)] + + pushl %ebx + pushl %ecx + call Bstringval + addl $4, %esp + popl %ebx + movl %eax, %ecx +# CALL ("Lprintf", 2) / [R (1); R (0)] + + pushl %ecx + pushl %ebx + call Lprintf + addl $8, %esp + movl %eax, %ebx +# DROP / [R (0)] + +# LDA ("i") / [] + + leal global_i, %ebx +# LD ("i") / [R (0)] + + movl global_i, %ecx +# CONST (1) / [R (1); R (0)] + + movl $3, %esi +# BINOP ("+") / [R (2); R (1); R (0)] + + addl %esi, %ecx + decl %ecx +# STI / [R (1); R (0)] + + movl %ecx, %eax + movl %eax, (%ebx) + movl %eax, %ebx +# DROP / [R (0)] + +# LABEL ("L55") / [] + +L55: + +# LD ("i") / [] + + movl global_i, %ebx +# LD ("lists") / [R (0)] + + movl global_lists, %ecx +# CALL (".length", 1) / [R (1); R (0)] + + pushl %ebx + pushl %ecx + call Blength + addl $4, %esp + popl %ebx + movl %eax, %ecx +# BINOP ("<") / [R (1); R (0)] + + xorl %eax, %eax + cmpl %ecx, %ebx + setl %al + sall %eax + orl $0x0001, %eax + movl %eax, %ebx +# CJMP ("nz", "L54") / [R (0)] + + sarl %ebx + cmpl $0, %ebx + jnz L54 +# CONST (0) / [] + + movl $1, %ebx +# CALL ("Lraw", 1) / [R (0)] + + pushl %ebx + call Lraw + addl $4, %esp + movl %eax, %ebx +# RET / [R (0)] + + movl %ebx, %eax + jmp Lmain_epilogue +# END / [] + +Lmain_epilogue: + + movl %ebp, %esp + popl %ebp + ret + .set Lmain_SIZE, 24 + + .set LSmain_SIZE, 6 + diff --git a/regression/x86only/vgcore.3910 b/regression/x86only/vgcore.3910 new file mode 100644 index 000000000..81220a5b3 Binary files /dev/null and b/regression/x86only/vgcore.3910 differ diff --git a/runtime/gc_runtime.s b/runtime/gc_runtime.s index e10fcc71b..5f71d4da8 100644 --- a/runtime/gc_runtime.s +++ b/runtime/gc_runtime.s @@ -11,6 +11,7 @@ __gc_stack_top: .long 0 .globl __post_gc .globl L__gc_init .globl __gc_root_scan_stack + .globl __gc_trace_registers .extern init_pool .extern gc_test_and_copy_root .text @@ -112,3 +113,19 @@ returnn: movl %ebp, %esp popl %ebp ret + + + + +__gc_trace_registers: + pushl %ebp + movl %esp, %ebp + + pushl %ebx + call gc_test_and_copy_root + popl %ebx + + movl %ebp, %esp + popl %ebp + ret + diff --git a/runtime/runtime.a b/runtime/runtime.a new file mode 100644 index 000000000..8107fb407 Binary files /dev/null and b/runtime/runtime.a differ diff --git a/runtime/runtime.c b/runtime/runtime.c index 9075105a9..f1d5553ce 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -8,7 +8,24 @@ # include # include -// # define DEBUG_PRINT 1 +# define DEBUG_PRINT 1 +/* GC pool structure and data; declared here in order to allow debug print */ +typedef struct { + size_t * begin; + size_t * end; + size_t * current; + size_t size; +} pool; + +static pool from_space; +static pool to_space; +size_t *current; +/* end */ + +/* GC extern invariant for built-in functions */ +extern void __pre_gc (); +extern void __post_gc (); +/* end */ # define STRING_TAG 0x00000001 # define ARRAY_TAG 0x00000003 @@ -20,6 +37,9 @@ # define TO_DATA(x) ((data*)((char*)(x)-sizeof(int))) # define TO_SEXP(x) ((sexp*)((char*)(x)-2*sizeof(int))) +//new +# define GET_TAG_FROM_SEXP(x) (LEN(x)) + # define UNBOXED(x) (((int) (x)) & 0x0001) # define UNBOX(x) (((int) (x)) >> 1) # define BOX(x) ((((int) (x)) << 1) | 0x0001) @@ -48,17 +68,10 @@ char* de_hash (int n) { char *p = (char*) BOX (NULL); chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNJPQRSTUVWXYZ"; p = &buf[5]; - -#ifdef DEBUG_PRINT - printf ("de_hash: tag: %d\n", n); -#endif *p-- = 0; while (n != 0) { -#ifdef DEBUG_PRINT - printf ("char: %c\n", chars [n & 0x003F]); -#endif *p-- = chars [n & 0x003F]; n = n >> 6; } @@ -135,7 +148,8 @@ static void printValue (void *p) { break; case SEXP_TAG: { - char * tag = de_hash (TO_SEXP(p)->tag); + // char * tag = de_hash (TO_SEXP(p)->tag); + char * tag = de_hash (GET_TAG_FROM_SEXP(TO_SEXP(p)->tag)); if (strcmp (tag, "cons") == 0) { data *b = a; @@ -279,6 +293,10 @@ extern void* Bsexp (int n, ...) { } r->tag = va_arg(args, int); + + // new line (next) + r->tag = SEXP_TAG | ((r->tag) << 3); + va_end(args); __post_gc(); @@ -289,7 +307,8 @@ extern void* Bsexp (int n, ...) { extern int Btag (void *d, int t, int n) { data *r = (data*) BOX (NULL); r = TO_DATA(d); - return BOX(TAG(r->tag) == SEXP_TAG && TO_SEXP(d)->tag == t && LEN(r->tag) == n); + return BOX(TAG(r->tag) == SEXP_TAG && + GET_TAG_FROM_SEXP(TO_SEXP(d)->tag) == t && LEN(r->tag) == n); } extern int Barray_patt (void *d, int n) { @@ -421,29 +440,17 @@ extern int Lwrite (int n) { extern const size_t __gc_data_end, __gc_data_start; extern void L__gc_init (); -extern void __pre_gc (); -extern void __post_gc (); - extern void __gc_root_scan_stack (); +extern void __gc_trace_registers (); /* ======================================== */ /* Mark-and-copy */ /* ======================================== */ static size_t SPACE_SIZE = 128; +// static size_t SPACE_SIZE = 1280; # define POOL_SIZE (2*SPACE_SIZE) -typedef struct { - size_t * begin; - size_t * end; - size_t * current; - size_t size; -} pool; - -static pool from_space; -static pool to_space; -size_t * current; - static void swap (size_t ** a, size_t ** b) { size_t * t = *a; *a = *b; @@ -492,19 +499,23 @@ static void copy_elements (size_t *where, size_t *from, int len) { } static void extend_spaces (void) { - void *p1 = mremap(from_space.begin, SPACE_SIZE, 2*SPACE_SIZE, 0); - void *p2 = mremap(to_space.begin , SPACE_SIZE, 2*SPACE_SIZE, 0); - if (p1 == MAP_FAILED || p2 == MAP_FAILED) { - perror("ERROR: extend_spaces: mmap failed\n"); + void *p1 = (void *) BOX (NULL), *p2 = (void *) BOX (NULL); + size_t old_space_size = SPACE_SIZE * sizeof(size_t), + new_space_size = (SPACE_SIZE << 1) * sizeof(size_t); + p1 = mremap(from_space.begin, old_space_size, new_space_size, 0); + p2 = mremap(to_space.begin , old_space_size, new_space_size, 0); + if (p1 == MAP_FAILED || p2 == MAP_FAILED) { + perror("EROOR: extend_spaces: mmap failed\n"); exit (1); } #ifdef DEBUG_PRINT - printf ("extend: %x %x %x %x\n", p1, p2, from_space.begin, to_space.begin); - printf ("extend: %x %x %x\n", from_space.end, to_space.end, current); + printf ("extend: %p %p %p %p\n", p1, p2, from_space.begin, to_space.begin); + printf ("extend: %p %p %p\n" , from_space.end, to_space.end, current); + fflush (stdout); #endif from_space.end += SPACE_SIZE; to_space.end += SPACE_SIZE; - SPACE_SIZE += SPACE_SIZE; + SPACE_SIZE = SPACE_SIZE << 1; from_space.size = SPACE_SIZE; to_space.size = SPACE_SIZE; } @@ -627,14 +638,14 @@ extern void gc_root_scan_data (void) { } extern void init_pool (void) { - from_space.begin = mmap(NULL, SPACE_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); - to_space.begin = mmap(NULL, SPACE_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); - if (to_space.begin == MAP_FAILED || - from_space.begin == MAP_FAILED) { - perror("ERROR: init_pool: mmap failed\n"); - exit (1); + size_t space_size = SPACE_SIZE * sizeof(size_t); + from_space.begin = mmap (NULL, space_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); + to_space.begin = mmap (NULL, space_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); + if (to_space.begin == MAP_FAILED || from_space.begin == MAP_FAILED) { + perror ("EROOR: init_pool: mmap failed\n"); + exit (1); } from_space.current = from_space.begin; from_space.end = from_space.begin + SPACE_SIZE; @@ -658,6 +669,7 @@ static void * gc (size_t size) { #ifdef DEBUG_PRINT printf("gc: data is scanned\n"); #endif + __gc_trace_registers (); __gc_root_scan_stack (); if (!IN_PASSIVE_SPACE(current)) { perror ("ASSERT: !IN_PASSIVE_SPACE(current)\n"); @@ -685,6 +697,71 @@ static void * gc (size_t size) { return (void *) current; } +static void printFromSpace (void) { + size_t * cur = from_space.begin, *tmp = NULL; + data * d = NULL; + sexp * s = NULL; + size_t len = 0; +#ifdef DEBUG_PRINT + printf ("\nHEAP SNAPSHOT\n===================\n"); + printf ("f_begin = %p, f_end = %p,\n", from_space.begin, from_space.end); + while (cur < from_space.current) { + printf ("data at %p", cur); + d = (data *) cur; + + switch (TAG(d->tag)) { + + case STRING_TAG: + printf ("(=>%p): STRING\n\t%s\n", d->contents, d->contents); + len = LEN(d->tag) + 1; + fflush (stdout); + break; + + case ARRAY_TAG: + printf ("(=>%p): ARRAY\n\t", d->contents); + len = LEN(d->tag); + for (int i = 0; i < len; i++) { + int elem = ((int*)d->contents)[i]; + if (UNBOXED(elem)) printf ("%d ", elem); + else printf ("%p ", elem); + } + len += 1; + printf ("\n"); + fflush (stdout); + break; + + case SEXP_TAG: + s = (sexp *) d; + d = (data *) &(s->contents); + char * tag = de_hash (GET_TAG_FROM_SEXP(s->tag)); + printf ("(=>%p): SEXP\n\ttag(%s) ", s->contents.contents, tag); + len = LEN(d->tag); + tmp = (s->contents.contents); + for (int i = 0; i < len; i++) { + int elem = ((int*)tmp)[i]; + if (UNBOXED(elem)) printf ("%d ", UNBOX(elem)); + else printf ("%p ", elem); + } + len += 2; + printf ("\n"); + fflush (stdout); + break; + + case 0: + printf ("\nprintFromSpace: end!\n===================\n\n"); + return; + + default: + printf ("\nprintFromSpace: ERROR: bad tag %d", TAG(d->tag)); + fflush (stdout); + exit (1); + } + cur += len * sizeof(int); + printf ("len = %zu, new cur = %p\n", len, cur); + } +#endif +} + extern void * alloc (size_t size) { void * p = (void*)BOX(NULL); if (from_space.current + size < from_space.end) { @@ -700,6 +777,13 @@ extern void * alloc (size_t size) { } #ifdef DEBUG_PRINT printf("alloc: call gc: %zu\n", size); + fflush (stdout); #endif - return gc (size); + printFromSpace(); + p = gc (size); +#ifdef DEBUG_PRINT + printf("gc END\n\n"); +#endif + printFromSpace(); + return p; } diff --git a/src/.depend b/src/.depend new file mode 100644 index 000000000..a59e5ad6d --- /dev/null +++ b/src/.depend @@ -0,0 +1,8 @@ +Driver.cmo : X86.cmo SM.cmo Language.cmo +Driver.cmx : X86.cmx SM.cmx Language.cmx +Language.cmo : +Language.cmx : +SM.cmo : Language.cmo +SM.cmx : Language.cmx +X86.cmo : SM.cmo Language.cmo +X86.cmx : SM.cmx Language.cmx diff --git a/src/SM.ml b/src/SM.ml index 880a173b6..5c44ef75a 100644 --- a/src/SM.ml +++ b/src/SM.ml @@ -263,10 +263,10 @@ let compile (defs, p) = add_code (compile_expr lsv env e) lsv false [CALL (".stringval", 1)] | Expr.Assign (x, e) -> let lassn, env = env#get_label in - (*(match x with - | Expr.Ref x -> add_code (compile_expr lassn env e) lassn false [ST x] - | _ ->*) add_code (compile_list lassn env [x; e]) lassn false [match x with Expr.ElemRef _ -> STA | _ -> STI] - (*--) *) + add_code (compile_list lassn env [x; e]) lassn false [match x with Expr.ElemRef _ -> STA | _ -> STI] + (* (match x with + * | Expr.Ref x -> add_code (compile_expr lassn env e) lassn false [ST x] + * | _ -> add_code (compile_list lassn env [x; e]) lassn false [match x with Expr.ElemRef _ -> STA | _ -> STI]) *) | Expr.Skip -> env, false, [] diff --git a/src/rc.opt b/src/rc.opt new file mode 100755 index 000000000..2ad775f74 Binary files /dev/null and b/src/rc.opt differ