Merge remote-tracking branch 'brson/repl'

Conflicts:
	mk/install.mk
	src/rt/rustrt.def.in
This commit is contained in:
Brian Anderson 2012-11-04 13:42:39 -08:00
commit 1b0c6665d9
24 changed files with 2298 additions and 33 deletions

View File

@ -23,6 +23,7 @@ Benjamin Peterson <benjamin@python.org>
Brendan Eich <brendan@mozilla.org> Brendan Eich <brendan@mozilla.org>
Brian Anderson <banderson@mozilla.com> Brian Anderson <banderson@mozilla.com>
Brian J. Burg <burg@cs.washington.edu> Brian J. Burg <burg@cs.washington.edu>
Brian Leibig <brian.leibig@gmail.com>
Chris Double <chris.double@double.co.nz> Chris Double <chris.double@double.co.nz>
Chris Peterson <cpeterson@mozilla.com> Chris Peterson <cpeterson@mozilla.com>
Damian Gryski <damian@gryski.com> Damian Gryski <damian@gryski.com>

View File

@ -460,8 +460,9 @@ TSREQS := \
FUZZ := $(HBIN2_H_$(CFG_HOST_TRIPLE))/fuzzer$(X) FUZZ := $(HBIN2_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
CARGO := $(HBIN2_H_$(CFG_HOST_TRIPLE))/cargo$(X) CARGO := $(HBIN2_H_$(CFG_HOST_TRIPLE))/cargo$(X)
RUSTDOC := $(HBIN2_H_$(CFG_HOST_TRIPLE))/rustdoc$(X) RUSTDOC := $(HBIN2_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
RUSTI := $(HBIN2_H_$(CFG_HOST_TRIPLE))/rusti$(X)
all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC) all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC) $(RUSTI)
endif endif

2
configure vendored
View File

@ -529,7 +529,7 @@ for t in $CFG_TARGET_TRIPLES
do do
make_dir rt/$t make_dir rt/$t
for i in \ for i in \
isaac bigint sync test arch/i386 arch/x86_64 \ isaac linenoise bigint sync test arch/i386 arch/x86_64 \
libuv libuv/src/ares libuv/src/eio libuv/src/ev libuv libuv/src/ares libuv/src/eio libuv/src/ev
do do
make_dir rt/$t/$i make_dir rt/$t/$i

View File

@ -22,6 +22,7 @@ PKG_FILES := \
$(addprefix $(S)src/, \ $(addprefix $(S)src/, \
README.txt \ README.txt \
cargo \ cargo \
rusti \
rustc \ rustc \
compiletest \ compiletest \
etc \ etc \

View File

@ -75,6 +75,7 @@ install-host: $(SREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBFUZZER)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBFUZZER))
$(Q)$(call INSTALL,$(HB2),$(PHB),cargo$(X)) $(Q)$(call INSTALL,$(HB2),$(PHB),cargo$(X))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBCARGO)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBCARGO))
$(Q)$(call INSTALL,$(HB2),$(PHB),rusti$(X))
$(Q)$(call INSTALL,$(HB2),$(PHB),rustdoc$(X)) $(Q)$(call INSTALL,$(HB2),$(PHB),rustdoc$(X))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBRUSTDOC)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_LIBRUSTDOC))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME))
@ -95,6 +96,7 @@ HOST_LIB_FROM_HL_GLOB = \
uninstall: uninstall:
$(Q)rm -f $(PHB)/rustc$(X) $(Q)rm -f $(PHB)/rustc$(X)
$(Q)rm -f $(PHB)/cargo$(X) $(Q)rm -f $(PHB)/cargo$(X)
$(Q)rm -f $(PHB)/rusti$(X)
$(Q)rm -f $(PHB)/rustdoc$(X) $(Q)rm -f $(PHB)/rustdoc$(X)
$(Q)rm -f $(PHL)/$(CFG_RUSTLLVM) $(Q)rm -f $(PHL)/$(CFG_RUSTLLVM)
$(Q)rm -f $(PHL)/$(CFG_FUZZER) $(Q)rm -f $(PHL)/$(CFG_FUZZER)

View File

@ -103,7 +103,7 @@ endif
# Hack: not sure how to test if a file exists in make other than this # Hack: not sure how to test if a file exists in make other than this
OS_SUPP = $(patsubst %,--suppressions=%,\ OS_SUPP = $(patsubst %,--suppressions=%,\
$(wildcard $(CFG_SRC_DIR)src/etc/$(CFG_OSTYPE).supp*)) $(wildcard $(CFG_SRC_DIR)src/etc/$(CFG_OSTYPE).supp*))
ifneq ($(findstring mingw,$(CFG_OSTYPE)),) ifneq ($(findstring mingw,$(CFG_OSTYPE)),)
CFG_WINDOWSY := 1 CFG_WINDOWSY := 1
@ -212,24 +212,37 @@ ifeq ($(CFG_C_COMPILER),clang)
ifeq ($(origin CPP),default) ifeq ($(origin CPP),default)
CPP=clang -E CPP=clang -E
endif endif
CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g CFG_GCCISH_CFLAGS += -Wall -Werror -g
CFG_GCCISH_CXXFLAGS += -fno-rtti
CFG_GCCISH_LINK_FLAGS += -g CFG_GCCISH_LINK_FLAGS += -g
# These flags will cause the compiler to produce a .d file # These flags will cause the compiler to produce a .d file
# next to the .o file that lists header deps. # next to the .o file that lists header deps.
CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d) CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d)
define CFG_MAKE_CC define CFG_MAKE_CC
CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CC) \
$$(CFG_GCCISH_CFLAGS) $$(CFG_CLANG_CFLAGS) \ $$(CFG_GCCISH_CFLAGS) $$(CFG_CLANG_CFLAGS) \
$$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \ $$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \
$$(CFG_CLANG_CFLAGS_$$(HOST_$(1))) \ $$(CFG_CLANG_CFLAGS_$$(HOST_$(1))) \
$$(CFG_DEPEND_FLAGS) \ $$(CFG_DEPEND_FLAGS) \
-c -o $$(1) $$(2) -c -o $$(1) $$(2)
CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CC) \
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \ $$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \
$$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \ $$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \
$$(call CFG_INSTALL_NAME,$$(4)) $$(call CFG_INSTALL_NAME,$$(4))
CFG_COMPILE_CXX_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \
$$(CFG_GCCISH_CFLAGS) $$(CFG_CLANG_CFLAGS) \
$$(CFG_GCCISH_CXXFLAGS) \
$$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \
$$(CFG_CLANG_CFLAGS_$$(HOST_$(1))) \
$$(CFG_DEPEND_FLAGS) \
-c -o $$(1) $$(2)
CFG_LINK_CXX_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \
$$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \
$$(call CFG_INSTALL_NAME,$$(4))
endef endef
$(foreach target,$(CFG_TARGET_TRIPLES), \ $(foreach target,$(CFG_TARGET_TRIPLES), \
@ -245,24 +258,38 @@ ifeq ($(CFG_C_COMPILER),gcc)
ifeq ($(origin CPP),default) ifeq ($(origin CPP),default)
CPP=gcc -E CPP=gcc -E
endif endif
CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g CFG_GCCISH_CFLAGS += -Wall -Werror -g
CFG_GCCISH_CXXFLAGS += -fno-rtti
CFG_GCCISH_LINK_FLAGS += -g CFG_GCCISH_LINK_FLAGS += -g
# These flags will cause the compiler to produce a .d file # These flags will cause the compiler to produce a .d file
# next to the .o file that lists header deps. # next to the .o file that lists header deps.
CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d) CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d)
define CFG_MAKE_CC define CFG_MAKE_CC
CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CC) \
$$(CFG_GCCISH_CFLAGS) \ $$(CFG_GCCISH_CFLAGS) \
$$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \ $$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \
$$(CFG_GCC_CFLAGS) \ $$(CFG_GCC_CFLAGS) \
$$(CFG_GCC_CFLAGS_$$(HOST_$(1))) \ $$(CFG_GCC_CFLAGS_$$(HOST_$(1))) \
$$(CFG_DEPEND_FLAGS) \ $$(CFG_DEPEND_FLAGS) \
-c -o $$(1) $$(2) -c -o $$(1) $$(2)
CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CC) \
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \ $$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \
$$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \ $$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \
$$(call CFG_INSTALL_NAME,$$(4))
CFG_COMPILE_CXX_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \
$$(CFG_GCCISH_CFLAGS) \
$$(CFG_GCCISH_CXXFLAGS) \
$$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \
$$(CFG_GCC_CFLAGS) \
$$(CFG_GCC_CFLAGS_$$(HOST_$(1))) \
$$(CFG_DEPEND_FLAGS) \
-c -o $$(1) $$(2)
CFG_LINK_CXX_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1))) \
$$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2) \
$$(call CFG_INSTALL_NAME,$$(4)) $$(call CFG_INSTALL_NAME,$$(4))
endef endef
@ -285,4 +312,4 @@ define CFG_MAKE_ASSEMBLER
endef endef
$(foreach target,$(CFG_TARGET_TRIPLES),\ $(foreach target,$(CFG_TARGET_TRIPLES),\
$(eval $(call CFG_MAKE_ASSEMBLER,$(target)))) $(eval $(call CFG_MAKE_ASSEMBLER,$(target))))

View File

@ -8,7 +8,8 @@ else
$(wildcard $(S)src/test/*/*.rs \ $(wildcard $(S)src/test/*/*.rs \
$(S)src/test/*/*/*.rs) \ $(S)src/test/*/*/*.rs) \
$(wildcard $(S)src/fuzzer/*.rs) \ $(wildcard $(S)src/fuzzer/*.rs) \
$(wildcard $(S)src/cargo/*.rs) $(wildcard $(S)src/cargo/*.rs) \
$(wildcard $(S)src/rusti/*.rs)
PP_INPUTS_FILTERED = $(shell echo $(PP_INPUTS) | xargs grep -L \ PP_INPUTS_FILTERED = $(shell echo $(PP_INPUTS) | xargs grep -L \
"no-reformat\|xfail-pretty\|xfail-test") "no-reformat\|xfail-pretty\|xfail-test")

View File

@ -42,7 +42,7 @@ define DEF_RUNTIME_TARGETS
# Runtime (C++) library variables # Runtime (C++) library variables
###################################################################### ######################################################################
RUNTIME_CS_$(1) := \ RUNTIME_CXXS_$(1) := \
rt/sync/timer.cpp \ rt/sync/timer.cpp \
rt/sync/lock_and_signal.cpp \ rt/sync/lock_and_signal.cpp \
rt/sync/rust_thread.cpp \ rt/sync/rust_thread.cpp \
@ -77,6 +77,8 @@ RUNTIME_CS_$(1) := \
rt/arch/$$(HOST_$(1))/context.cpp \ rt/arch/$$(HOST_$(1))/context.cpp \
rt/arch/$$(HOST_$(1))/gpr.cpp rt/arch/$$(HOST_$(1))/gpr.cpp
RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \ RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
rt/arch/$$(HOST_$(1))/ccall.S \ rt/arch/$$(HOST_$(1))/ccall.S \
rt/arch/$$(HOST_$(1))/record_sp.S rt/arch/$$(HOST_$(1))/record_sp.S
@ -103,9 +105,11 @@ endif
RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX) RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX)
RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \ RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
-I $$(S)src/rt/arch/$$(HOST_$(1)) \ -I $$(S)src/rt/arch/$$(HOST_$(1)) \
-I $$(S)src/libuv/include -I $$(S)src/rt/linenoise \
RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \ -I $$(S)src/libuv/include
RUNTIME_OBJS_$(1) := $$(RUNTIME_CXXS_$(1):rt/%.cpp=rt/$(1)/%.o) \
$$(RUNTIME_CS_$(1):rt/%.c=rt/$(1)/%.o) \
$$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o) $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)) ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1))
@ -115,6 +119,11 @@ ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))
RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1)) RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS) rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
@$$(call E, compile: $$@)
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
$$(SNAP_DEFINES)) $$<
rt/$(1)/%.o: rt/%.c $$(MKFILE_DEPS)
@$$(call E, compile: $$@) @$$(call E, compile: $$@)
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \ $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
$$(SNAP_DEFINES)) $$< $$(SNAP_DEFINES)) $$<
@ -132,7 +141,7 @@ rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
$$(RUNTIME_DEF_$(1)) \ $$(RUNTIME_DEF_$(1)) \
$$(RUNTIME_LIBS_$(1)) $$(RUNTIME_LIBS_$(1))
@$$(call E, link: $$@) @$$(call E, link: $$@)
$$(Q)$$(call CFG_LINK_C_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \ $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
$$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \ $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \
$$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME)) $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME))

View File

@ -25,14 +25,14 @@ ALL_OBJ_FILES += $$(RUSTLLVM_OBJS_OBJS_$(1))
rustllvm/$(1)/$(CFG_RUSTLLVM): $$(RUSTLLVM_OBJS_OBJS_$(1)) \ rustllvm/$(1)/$(CFG_RUSTLLVM): $$(RUSTLLVM_OBJS_OBJS_$(1)) \
$$(MKFILE_DEPS) $$(RUSTLLVM_DEF_$(1)) $$(MKFILE_DEPS) $$(RUSTLLVM_DEF_$(1))
@$$(call E, link: $$@) @$$(call E, link: $$@)
$$(Q)$$(call CFG_LINK_C_$(1),$$@,$$(RUSTLLVM_OBJS_OBJS_$(1)) \ $$(Q)$$(call CFG_LINK_CXX_$(1),$$@,$$(RUSTLLVM_OBJS_OBJS_$(1)) \
$$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS_$(1)) \ $$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS_$(1)) \
$$(CFG_GCCISH_POST_LIB_FLAGS) \ $$(CFG_GCCISH_POST_LIB_FLAGS) \
$$(LLVM_LDFLAGS_$(1)),$$(RUSTLLVM_DEF_$(1)),$$(CFG_RUSTLLVM)) $$(LLVM_LDFLAGS_$(1)),$$(RUSTLLVM_DEF_$(1)),$$(CFG_RUSTLLVM))
rustllvm/$(1)/%.o: rustllvm/%.cpp $$(MKFILE_DEPS) $$(LLVM_CONFIG_$(1)) rustllvm/$(1)/%.o: rustllvm/%.cpp $$(MKFILE_DEPS) $$(LLVM_CONFIG_$(1))
@$$(call E, compile: $$@) @$$(call E, compile: $$@)
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(LLVM_CXXFLAGS_$(1)) $$(RUSTLLVM_INCS_$(1))) $$< $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(LLVM_CXXFLAGS_$(1)) $$(RUSTLLVM_INCS_$(1))) $$<
endef endef
# Instantiate template for all stages # Instantiate template for all stages

View File

@ -122,6 +122,7 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \ ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
$(S)src/rt/bigint/bigint_int.cpp \ $(S)src/rt/bigint/bigint_int.cpp \
$(S)src/rt/miniz.cpp \ $(S)src/rt/miniz.cpp \
$(S)src/rt/linenoise/linenoise.c \
,$(ALL_CS)) ,$(ALL_CS))
ALL_HS := $(wildcard $(S)src/rt/*.h \ ALL_HS := $(wildcard $(S)src/rt/*.h \
$(S)src/rt/*/*.h \ $(S)src/rt/*/*.h \
@ -135,6 +136,7 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
$(S)src/rt/msvc/stdint.h \ $(S)src/rt/msvc/stdint.h \
$(S)src/rt/msvc/inttypes.h \ $(S)src/rt/msvc/inttypes.h \
$(S)src/rt/bigint/bigint.h \ $(S)src/rt/bigint/bigint.h \
$(S)src/rt/linenoise/linenoise.h \
,$(ALL_HS)) ,$(ALL_HS))
tidy: tidy:
@ -229,6 +231,7 @@ check-stage$(1)-T-$(2)-H-$(3): \
check-stage$(1)-T-$(2)-H-$(3)-bench \ check-stage$(1)-T-$(2)-H-$(3)-bench \
check-stage$(1)-T-$(2)-H-$(3)-pretty \ check-stage$(1)-T-$(2)-H-$(3)-pretty \
check-stage$(1)-T-$(2)-H-$(3)-rustdoc \ check-stage$(1)-T-$(2)-H-$(3)-rustdoc \
check-stage$(1)-T-$(2)-H-$(3)-rusti \
check-stage$(1)-T-$(2)-H-$(3)-cargo \ check-stage$(1)-T-$(2)-H-$(3)-cargo \
check-stage$(1)-T-$(2)-H-$(3)-doc-tutorial \ check-stage$(1)-T-$(2)-H-$(3)-doc-tutorial \
check-stage$(1)-T-$(2)-H-$(3)-doc-tutorial-ffi \ check-stage$(1)-T-$(2)-H-$(3)-doc-tutorial-ffi \
@ -289,6 +292,9 @@ check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty: \
check-stage$(1)-T-$(2)-H-$(3)-rustdoc: \ check-stage$(1)-T-$(2)-H-$(3)-rustdoc: \
check-stage$(1)-T-$(2)-H-$(3)-rustdoc-dummy check-stage$(1)-T-$(2)-H-$(3)-rustdoc-dummy
check-stage$(1)-T-$(2)-H-$(3)-rusti: \
check-stage$(1)-T-$(2)-H-$(3)-rusti-dummy
check-stage$(1)-T-$(2)-H-$(3)-cargo: \ check-stage$(1)-T-$(2)-H-$(3)-cargo: \
check-stage$(1)-T-$(2)-H-$(3)-cargo-dummy check-stage$(1)-T-$(2)-H-$(3)-cargo-dummy
@ -371,6 +377,24 @@ check-stage$(1)-T-$(2)-H-$(3)-rustdoc-dummy: \
$$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS) \ $$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS) \
--logfile tmp/check-stage$(1)-T-$(2)-H-$(3)-rustdoc.log --logfile tmp/check-stage$(1)-T-$(2)-H-$(3)-rustdoc.log
# Rules for the rusti test runner
$(3)/test/rustitest.stage$(1)-$(2)$$(X): \
$$(RUSTI_CRATE) $$(RUSTI_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
check-stage$(1)-T-$(2)-H-$(3)-rusti-dummy: \
$(3)/test/rustitest.stage$(1)-$(2)$$(X)
@$$(call E, run: $$<)
$$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS) \
--logfile tmp/check-stage$(1)-T-$(2)-H-$(3)-rusti.log
# Rules for the cargo test runner # Rules for the cargo test runner
$(3)/test/cargotest.stage$(1)-$(2)$$(X): \ $(3)/test/cargotest.stage$(1)-$(2)$$(X): \
@ -756,6 +780,9 @@ check-stage$(1)-H-$(2)-pretty-pretty: \
check-stage$(1)-H-$(2)-rustdoc: \ check-stage$(1)-H-$(2)-rustdoc: \
$$(foreach target,$$(CFG_TARGET_TRIPLES), \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \
check-stage$(1)-T-$$(target)-H-$(2)-rustdoc) check-stage$(1)-T-$$(target)-H-$(2)-rustdoc)
check-stage$(1)-H-$(2)-rusti: \
$$(foreach target,$$(CFG_TARGET_TRIPLES), \
check-stage$(1)-T-$$(target)-H-$(2)-rusti)
check-stage$(1)-H-$(2)-cargo: \ check-stage$(1)-H-$(2)-cargo: \
$$(foreach target,$$(CFG_TARGET_TRIPLES), \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \
check-stage$(1)-T-$$(target)-H-$(2)-cargo) check-stage$(1)-T-$$(target)-H-$(2)-cargo)

View File

@ -18,6 +18,10 @@ CARGO_INPUTS := $(wildcard $(S)src/cargo/*rs)
RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rc RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rc
RUSTDOC_INPUTS := $(wildcard $(S)src/rustdoc/*.rs) RUSTDOC_INPUTS := $(wildcard $(S)src/rustdoc/*.rs)
# Rusti, the JIT REPL
RUSTI_CRATE := $(S)src/rusti/rusti.rc
RUSTI_INPUTS := $(wildcard $(S)src/rusti/*.rs)
# FIXME: These are only built for the host arch. Eventually we'll # FIXME: These are only built for the host arch. Eventually we'll
# have tools that need to built for other targets. # have tools that need to built for other targets.
define TOOLS_STAGE_N define TOOLS_STAGE_N
@ -126,6 +130,21 @@ $$(HBIN$(2)_H_$(4))/rustdoc$$(X): \
@$$(call E, cp: $$@) @$$(call E, cp: $$@)
$$(Q)cp $$< $$@ $$(Q)cp $$< $$@
$$(TBIN$(1)_T_$(4)_H_$(3))/rusti$$(X): \
$$(RUSTI_CRATE) $$(RUSTI_INPUTS) \
$$(TSREQ$(1)_T_$(4)_H_$(3)) \
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC)
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$<
$$(HBIN$(2)_H_$(4))/rusti$$(X): \
$$(TBIN$(1)_T_$(4)_H_$(3))/rusti$$(X) \
$$(HSREQ$(2)_H_$(4))
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
endef endef
$(foreach host,$(CFG_TARGET_TRIPLES), \ $(foreach host,$(CFG_TARGET_TRIPLES), \

View File

@ -30,6 +30,8 @@ compiletest/ The test runner
cargo/ The package manager cargo/ The package manager
rusti/ The JIT REPL
rustdoc/ The Rust API documentation tool rustdoc/ The Rust API documentation tool
llvm/ The LLVM submodule llvm/ The LLVM submodule

69
src/libstd/rl.rs Normal file
View File

@ -0,0 +1,69 @@
use libc::{c_char, c_int};
extern mod rustrt {
#[legacy_exports];
fn linenoise(prompt: *c_char) -> *c_char;
fn linenoiseHistoryAdd(line: *c_char) -> c_int;
fn linenoiseHistorySetMaxLen(len: c_int) -> c_int;
fn linenoiseHistorySave(file: *c_char) -> c_int;
fn linenoiseHistoryLoad(file: *c_char) -> c_int;
fn linenoiseSetCompletionCallback(callback: *u8);
fn linenoiseAddCompletion(completions: *(), line: *c_char);
}
/// Add a line to history
pub fn add_history(line: ~str) -> bool {
do str::as_c_str(line) |buf| {
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
}
}
/// Set the maximum amount of lines stored
pub fn set_history_max_len(len: int) -> bool {
rustrt::linenoiseHistorySetMaxLen(len as c_int) == 1 as c_int
}
/// Save line history to a file
pub fn save_history(file: ~str) -> bool {
do str::as_c_str(file) |buf| {
rustrt::linenoiseHistorySave(buf) == 1 as c_int
}
}
/// Load line history from a file
pub fn load_history(file: ~str) -> bool {
do str::as_c_str(file) |buf| {
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
}
}
/// Print out a prompt and then wait for input and return it
pub fn read(prompt: ~str) -> Option<~str> {
do str::as_c_str(prompt) |buf| unsafe {
let line = rustrt::linenoise(buf);
if line.is_null() { None }
else { Some(str::raw::from_c_str(line)) }
}
}
pub type CompletionCb = fn~(~str, fn(~str));
fn complete_key(_v: @CompletionCb) {}
/// Bind to the main completion callback
pub fn complete(cb: CompletionCb) unsafe {
task::local_data::local_data_set(complete_key, @(move cb));
extern fn callback(line: *c_char, completions: *()) unsafe {
let cb = copy *task::local_data::local_data_get(complete_key).get();
do cb(str::raw::from_c_str(line)) |suggestion| {
do str::as_c_str(suggestion) |buf| {
rustrt::linenoiseAddCompletion(completions, buf);
}
}
}
rustrt::linenoiseSetCompletionCallback(callback);
}

View File

@ -83,6 +83,7 @@ pub mod arena;
pub mod par; pub mod par;
pub mod cmp; pub mod cmp;
pub mod base64; pub mod base64;
pub mod rl;
#[cfg(unicode)] #[cfg(unicode)]
mod unicode; mod unicode;

View File

@ -0,0 +1,47 @@
# Linenoise
A minimal, zero-config, BSD licensed, readline replacement.
News: linenoise now includes minimal completion support, thanks to Pieter Noordhuis (@pnoordhuis).
News: linenoise is now part of [Android](http://android.git.kernel.org/?p=platform/system/core.git;a=tree;f=liblinenoise;h=56450eaed7f783760e5e6a5993ef75cde2e29dea;hb=HEAD Android)!
## Can a line editing library be 20k lines of code?
Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?
So what usually happens is either:
* Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
* Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
The result is a pollution of binaries without line editing support.
So I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.
## Terminals, in 2010.
Apparently almost every terminal you can happen to use today has some kind of support for VT100 alike escape sequences. So I tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere I tried to use it.
Since it's so young I guess there are a few bugs, or the lib may not compile or work with some operating system, but it's a matter of a few weeks and eventually we'll get it right, and there will be no excuses for not shipping command line tools without built-in line editing support.
The library is currently less than 400 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
## Tested with...
* Linux text only console ($TERM = linux)
* Linux KDE terminal application ($TERM = xterm)
* Linux xterm ($TERM = xterm)
* Mac OS X iTerm ($TERM = xterm)
* Mac OS X default Terminal.app ($TERM = xterm)
* OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
* IBM AIX 6.1
* FreeBSD xterm ($TERM = xterm)
Please test it everywhere you can and report back!
## Let's push this forward!
Please fork it and add something interesting and send me a pull request. What's especially interesting are fixes, new key bindings, completion.
Send feedbacks to antirez at gmail

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include "linenoise.h"
#ifndef NO_COMPLETION
void completion(const char *buf, linenoiseCompletions *lc) {
if (buf[0] == 'h') {
linenoiseAddCompletion(lc,"hello");
linenoiseAddCompletion(lc,"hello there");
}
}
#endif
int main(void) {
char *line;
#ifndef NO_COMPLETION
linenoiseSetCompletionCallback(completion);
#endif
linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
while((line = linenoise("hello> ")) != NULL) {
if (line[0] != '\0') {
printf("echo: '%s'\n", line);
linenoiseHistoryAdd(line);
linenoiseHistorySave("history.txt"); /* Save every new entry */
}
free(line);
}
return 0;
}

1391
src/rt/linenoise/linenoise.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
/* linenoise.h -- guerrilla line editing library against the idea that a
* line editing lib needs to be 20,000 lines of C code.
*
* See linenoise.c for more information.
*
* ------------------------------------------------------------------------
*
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __LINENOISE_H
#define __LINENOISE_H
#ifndef NO_COMPLETION
typedef struct linenoiseCompletions {
size_t len;
char **cvec;
} linenoiseCompletions;
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
#endif
char *linenoise(const char *prompt);
int linenoiseHistoryAdd(const char *line);
int linenoiseHistorySetMaxLen(int len);
int linenoiseHistorySave(const char *filename);
int linenoiseHistoryLoad(const char *filename);
void linenoiseHistoryFree(void);
char **linenoiseHistory(int *len);
#endif /* __LINENOISE_H */

115
src/rt/linenoise/utf8.c Normal file
View File

@ -0,0 +1,115 @@
/**
* UTF-8 utility functions
*
* (c) 2010 Steve Bennett <steveb@workware.net.au>
*
* See LICENCE for licence details.
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "utf8.h"
#ifdef USE_UTF8
int utf8_fromunicode(char *p, unsigned short uc)
{
if (uc <= 0x7f) {
*p = uc;
return 1;
}
else if (uc <= 0x7ff) {
*p++ = 0xc0 | ((uc & 0x7c0) >> 6);
*p = 0x80 | (uc & 0x3f);
return 2;
}
else {
*p++ = 0xe0 | ((uc & 0xf000) >> 12);
*p++ = 0x80 | ((uc & 0xfc0) >> 6);
*p = 0x80 | (uc & 0x3f);
return 3;
}
}
int utf8_charlen(int c)
{
if ((c & 0x80) == 0) {
return 1;
}
if ((c & 0xe0) == 0xc0) {
return 2;
}
if ((c & 0xf0) == 0xe0) {
return 3;
}
if ((c & 0xf8) == 0xf0) {
return 4;
}
/* Invalid sequence */
return -1;
}
int utf8_strlen(const char *str, int bytelen)
{
int charlen = 0;
if (bytelen < 0) {
bytelen = strlen(str);
}
while (bytelen) {
int c;
int l = utf8_tounicode(str, &c);
charlen++;
str += l;
bytelen -= l;
}
return charlen;
}
int utf8_index(const char *str, int index)
{
const char *s = str;
while (index--) {
int c;
s += utf8_tounicode(s, &c);
}
return s - str;
}
int utf8_charequal(const char *s1, const char *s2)
{
int c1, c2;
utf8_tounicode(s1, &c1);
utf8_tounicode(s2, &c2);
return c1 == c2;
}
int utf8_tounicode(const char *str, int *uc)
{
unsigned const char *s = (unsigned const char *)str;
if (s[0] < 0xc0) {
*uc = s[0];
return 1;
}
if (s[0] < 0xe0) {
if ((s[1] & 0xc0) == 0x80) {
*uc = ((s[0] & ~0xc0) << 6) | (s[1] & ~0x80);
return 2;
}
}
else if (s[0] < 0xf0) {
if (((str[1] & 0xc0) == 0x80) && ((str[2] & 0xc0) == 0x80)) {
*uc = ((s[0] & ~0xe0) << 12) | ((s[1] & ~0x80) << 6) | (s[2] & ~0x80);
return 3;
}
}
/* Invalid sequence, so just return the byte */
*uc = *s;
return 1;
}
#endif

79
src/rt/linenoise/utf8.h Normal file
View File

@ -0,0 +1,79 @@
#ifndef UTF8_UTIL_H
#define UTF8_UTIL_H
/**
* UTF-8 utility functions
*
* (c) 2010 Steve Bennett <steveb@workware.net.au>
*
* See LICENCE for licence details.
*/
#ifndef USE_UTF8
#include <ctype.h>
/* No utf-8 support. 1 byte = 1 char */
#define utf8_strlen(S, B) ((B) < 0 ? (int)strlen(S) : (B))
#define utf8_tounicode(S, CP) (*(CP) = (unsigned char)*(S), 1)
#define utf8_index(C, I) (I)
#define utf8_charlen(C) 1
#else
/**
* Converts the given unicode codepoint (0 - 0xffff) to utf-8
* and stores the result at 'p'.
*
* Returns the number of utf-8 characters (1-3).
*/
int utf8_fromunicode(char *p, unsigned short uc);
/**
* Returns the length of the utf-8 sequence starting with 'c'.
*
* Returns 1-4, or -1 if this is not a valid start byte.
*
* Note that charlen=4 is not supported by the rest of the API.
*/
int utf8_charlen(int c);
/**
* Returns the number of characters in the utf-8
* string of the given byte length.
*
* Any bytes which are not part of an valid utf-8
* sequence are treated as individual characters.
*
* The string *must* be null terminated.
*
* Does not support unicode code points > \uffff
*/
int utf8_strlen(const char *str, int bytelen);
/**
* Returns the byte index of the given character in the utf-8 string.
*
* The string *must* be null terminated.
*
* This will return the byte length of a utf-8 string
* if given the char length.
*/
int utf8_index(const char *str, int charindex);
/**
* Returns the unicode codepoint corresponding to the
* utf-8 sequence 'str'.
*
* Stores the result in *uc and returns the number of bytes
* consumed.
*
* If 'str' is null terminated, then an invalid utf-8 sequence
* at the end of the string will be returned as individual bytes.
*
* If it is not null terminated, the length *must* be checked first.
*
* Does not support unicode code points > \uffff
*/
int utf8_tounicode(const char *str, int *uc);
#endif
#endif

View File

@ -203,3 +203,10 @@ rust_uv_ip4_port
rust_uv_ip6_port rust_uv_ip6_port
rust_uv_tcp_getpeername rust_uv_tcp_getpeername
rust_uv_tcp_getpeername6 rust_uv_tcp_getpeername6
linenoise
linenoiseSetCompletionCallback
linenoiseAddCompletion
linenoiseHistoryAdd
linenoiseHistorySetMaxLen
linenoiseHistorySave
linenoiseHistoryLoad

33
src/rusti/rusti.rc Normal file
View File

@ -0,0 +1,33 @@
// rusti - REPL using the JIT backend
#[link(name = "rusti",
vers = "0.4",
uuid = "7fb5bf52-7d45-4fee-8325-5ad3311149fc",
url = "https://github.com/mozilla/rust/tree/master/src/rusti")];
#[crate_type = "bin"];
#[no_core];
#[allow(vecs_implicitly_copyable,
non_implicitly_copyable_typarams)];
extern mod core(vers = "0.4");
extern mod std(vers = "0.4");
extern mod rustc(vers = "0.4");
extern mod syntax(vers = "0.4");
use core::*;
use io::{ReaderUtil, WriterUtil};
use rustc::back;
use rustc::driver::{driver, session};
use rustc::front;
use rustc::lib::llvm::llvm;
use rustc::metadata::{creader, filesearch};
use rustc::middle::{freevars, kind, lint, trans, ty, typeck};
use rustc::middle;
use syntax::{ast, ast_util, codemap, diagnostic, fold, parse, print, visit};
use syntax::ast_util::*;
use parse::token;
use print::{pp, pprust};
use std::rl;

325
src/rusti/rusti.rs Normal file
View File

@ -0,0 +1,325 @@
/**
* A structure shared across REPL instances for storing history
* such as statements and view items. I wish the AST was sendable.
*/
struct Repl {
prompt: ~str,
binary: ~str,
running: bool,
view_items: ~str,
stmts: ~str
}
/// A utility function that hands off a pretty printer to a callback.
fn with_pp(intr: @token::ident_interner,
cb: fn(pprust::ps, io::Writer)) -> ~str {
do io::with_str_writer |writer| {
let pp = pprust::rust_printer(writer, intr);
cb(pp, writer);
pp::eof(pp.s);
}
}
/**
* The AST (or the rest of rustc) are not sendable yet,
* so recorded things are printed to strings. A terrible hack that
* needs changes to rustc in order to be outed. This is unfortunately
* going to cause the REPL to regress in parser performance,
* because it has to parse the statements and view_items on each
* input.
*/
fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
let view_items = if blk.node.view_items.len() > 0 {
let new_view_items = do with_pp(intr) |pp, writer| {
for blk.node.view_items.each |view_item| {
pprust::print_view_item(pp, *view_item);
writer.write_line(~"");
}
};
debug!("new view items %s", new_view_items);
repl.view_items + "\n" + new_view_items
} else { repl.view_items };
let stmts = if blk.node.stmts.len() > 0 {
let new_stmts = do with_pp(intr) |pp, writer| {
for blk.node.stmts.each |stmt| {
match stmt.node {
ast::stmt_decl(*) => {
pprust::print_stmt(pp, **stmt);
writer.write_line(~"");
}
ast::stmt_expr(expr, _) | ast::stmt_semi(expr, _) => {
match expr.node {
ast::expr_assign(*) |
ast::expr_assign_op(*) |
ast::expr_swap(*) => {
pprust::print_stmt(pp, **stmt);
writer.write_line(~"");
}
_ => {}
}
}
}
}
};
debug!("new stmts %s", new_stmts);
repl.stmts + "\n" + new_stmts
} else { repl.stmts };
Repl{
view_items: view_items,
stmts: stmts,
.. repl
}
}
/// Run an input string in a Repl, returning the new Repl.
fn run(repl: Repl, input: ~str) -> Repl {
let options: @session::options = @{
crate_type: session::unknown_crate,
binary: repl.binary,
addl_lib_search_paths: ~[os::getcwd()],
.. *session::basic_options()
};
debug!("building driver input");
let head = include_str!("wrapper.rs");
let foot = fmt!("%s\nfn main() {\n%s\n\nprint({\n%s\n})\n}",
repl.view_items, repl.stmts, input);
let wrapped = driver::str_input(head + foot);
debug!("inputting %s", head + foot);
debug!("building a driver session");
let sess = driver::build_session(options, diagnostic::emit);
debug!("building driver configuration");
let cfg = driver::build_configuration(sess,
repl.binary,
wrapped);
debug!("parsing");
let mut crate = driver::parse_input(sess, cfg, wrapped);
let mut opt = None;
for crate.node.module.items.each |item| {
match item.node {
ast::item_fn(_, _, _, blk) => {
if item.ident == sess.ident_of(~"main") {
opt = blk.node.expr;
}
}
_ => {}
}
}
let blk = match opt.get().node {
ast::expr_call(_, exprs, _) => {
match exprs[0].node {
ast::expr_block(blk) => @blk,
_ => fail
}
}
_ => fail
};
debug!("configuration");
crate = front::config::strip_unconfigured_items(crate);
debug!("maybe building test harness");
crate = front::test::modify_for_testing(sess, crate);
debug!("expansion");
crate = syntax::ext::expand::expand_crate(sess.parse_sess,
sess.opts.cfg,
crate);
debug!("intrinsic injection");
crate = front::intrinsic_inject::inject_intrinsic(sess, crate);
debug!("core injection");
crate = front::core_inject::maybe_inject_libcore_ref(sess, crate);
debug!("building lint settings table");
lint::build_settings_crate(sess, crate);
debug!("ast indexing");
let ast_map = syntax::ast_map::map_crate(sess.diagnostic(), *crate);
debug!("external crate/lib resolution");
creader::read_crates(sess.diagnostic(), *crate, sess.cstore,
sess.filesearch,
session::sess_os_to_meta_os(sess.targ_cfg.os),
sess.opts.static, sess.parse_sess.interner);
debug!("language item collection");
let lang_items = middle::lang_items::collect_language_items(crate, sess);
debug!("resolution");
let {def_map: def_map,
exp_map2: exp_map2,
trait_map: trait_map} = middle::resolve::resolve_crate(sess,
lang_items,
crate);
debug!("freevar finding");
let freevars = freevars::annotate_freevars(def_map, crate);
debug!("region_resolution");
let region_map = middle::region::resolve_crate(sess, def_map, crate);
debug!("region paramaterization inference");
let rp_set = middle::region::determine_rp_in_crate(sess, ast_map,
def_map, crate);
debug!("typechecking");
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
region_map, rp_set, move lang_items, crate);
let (method_map, vtable_map) = typeck::check_crate(ty_cx, trait_map,
crate);
debug!("const marking");
middle::const_eval::process_crate(crate, def_map, ty_cx);
debug!("const checking");
middle::check_const::check_crate(sess, crate, ast_map, def_map,
method_map, ty_cx);
debug!("privacy checking");
middle::privacy::check_crate(ty_cx, &method_map, crate);
debug!("loop checking");
middle::check_loop::check_crate(ty_cx, crate);
debug!("alt checking");
middle::check_alt::check_crate(ty_cx, crate);
debug!("liveness checking");
let last_use_map = middle::liveness::check_crate(ty_cx,
method_map, crate);
debug!("borrow checking");
let (root_map, mutbl_map) = middle::borrowck::check_crate(ty_cx,
method_map,
last_use_map,
crate);
debug!("kind checking");
kind::check_crate(ty_cx, method_map, last_use_map, crate);
debug!("lint checking");
lint::check_crate(ty_cx, crate);
let maps = {mutbl_map: mutbl_map,
root_map: root_map,
last_use_map: last_use_map,
method_map: method_map,
vtable_map: vtable_map};
debug!("translation");
let (llmod, _) = trans::base::trans_crate(sess, crate, ty_cx,
~path::from_str("<repl>"),
exp_map2, maps);
let pm = llvm::LLVMCreatePassManager();
debug!("executing jit");
back::link::jit::exec(sess, pm, llmod, 0, false);
llvm::LLVMDisposePassManager(pm);
debug!("recording input into repl history");
record(repl, blk, sess.parse_sess.interner)
}
/// Run a command, e.g. :clear, :exit, etc.
fn run_cmd(repl: &mut Repl, _in: io::Reader, _out: io::Writer,
cmd: ~str, _args: ~[~str]) {
match cmd {
~"exit" => repl.running = false,
~"clear" => {
repl.view_items = ~"";
repl.stmts = ~"";
// FIXME: Win32 version of linenoise doesn't have the required function
//rl::clear();
}
~"help" => {
io::println(~":clear - clear the screen\n" +
~":exit - exit from the repl\n" +
~":help - show this message");
}
_ => io::println(~"unknown cmd: " + cmd)
}
}
fn main() {
let args = os::args();
let in = io::stdin();
let out = io::stdout();
let mut repl = Repl {
prompt: ~"rusti> ",
binary: args[0],
running: true,
view_items: ~"",
stmts: ~""
};
do rl::complete |line, suggest| {
if line.starts_with(":") {
suggest(~":clear");
suggest(~":exit");
suggest(~":help");
}
}
while repl.running {
let result = rl::read(repl.prompt);
if result.is_none() {
break;
}
let line = result.get();
if line.is_empty() {
io::println(~"()");
loop;
}
rl::add_history(line);
if line.starts_with(~":") {
let full = line.substr(1, line.len() - 1);
let split = full.split_char(' ');
let len = split.len();
if len > 0 {
let cmd = split[0];
if !cmd.is_empty() {
let args = if len > 1 {
do vec::view(split, 1, len - 1).map |arg| {
*arg
}
} else { ~[] };
run_cmd(&mut repl, in, out, cmd, args);
loop;
}
}
}
let result = do task::try |copy repl| {
run(copy repl, line)
};
if result.is_ok() {
repl = result.get();
}
}
}

19
src/rusti/wrapper.rs Normal file
View File

@ -0,0 +1,19 @@
#[allow(ctypes)];
#[allow(heap_memory)];
#[allow(implicit_copies)];
#[allow(managed_heap_memory)];
#[allow(non_camel_case_types)];
#[allow(non_implicitly_copyable_typarams)];
#[allow(owned_heap_memory)];
#[allow(path_statement)];
#[allow(structural_records)];
#[allow(unrecognized_lint)];
#[allow(unused_imports)];
#[allow(vecs_implicitly_copyable)];
#[allow(while_true)];
extern mod std;
fn print<T>(result: T) {
io::println(fmt!("%?", result));
}