Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -58,17 +58,18 @@ cp tcc/libtcc.a tcc4tcl-static.new.a $(AR) rcu tcc4tcl-static.new.a tcc4tcl.o -$(RANLIB) tcc4tcl-static.new.a mv tcc4tcl-static.new.a tcc4tcl-static.a -install: $(TARGET) pkgIndex.tcl $(srcdir)/tcc4tcl.tcl tcc/libtcc1.a $(shell echo $(srcdir)/tcc/include/*) $(shell echo $(srcdir)/tcc/win32/lib/*.c) $(srcdir)/headers.awk $(srcdir)/patch-headers.sh +install: $(TARGET) pkgIndex.tcl $(srcdir)/tcc4tcl.tcl $(srcdir)/tcc4critcl.tcl tcc/libtcc1.a $(shell echo $(srcdir)/tcc/include/*) $(shell echo $(srcdir)/tcc/win32/lib/*.c) $(srcdir)/headers.awk $(srcdir)/patch-headers.sh $(INSTALL) -d "$(DESTDIR)$(PACKAGE_INSTALL_DIR)" $(INSTALL) -d "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/lib" $(INSTALL) -d "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/include" $(INSTALL) -m 0755 $(TARGET) "$(DESTDIR)$(PACKAGE_INSTALL_DIR)" $(INSTALL) -m 0644 pkgIndex.tcl "$(DESTDIR)$(PACKAGE_INSTALL_DIR)" $(INSTALL) -m 0644 $(srcdir)/tcc4tcl.tcl "$(DESTDIR)$(PACKAGE_INSTALL_DIR)" + $(INSTALL) -m 0644 $(srcdir)/tcc4critcl.tcl "$(DESTDIR)$(PACKAGE_INSTALL_DIR)" $(INSTALL) -m 0644 tcc/libtcc1.a "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/lib" $(INSTALL) -m 0644 $(shell echo $(srcdir)/tcc/win32/lib/*.c) "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/lib" $(INSTALL) -m 0644 $(shell echo $(srcdir)/tcc/include/*) "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/include" @if ! echo "_WIN32" | $(CPP) $(CPPFLAGS) - | grep '^_WIN32$$' >/dev/null; then \ echo cp -r $(srcdir)/tcc/win32/include/* "$(DESTDIR)$(PACKAGE_INSTALL_DIR)/include/"; \ @@ -89,11 +90,11 @@ test: test.tcl rm -rf __TMP__ $(MAKE) install tcllibdir=$(shell pwd)/__TMP__ -if [ "$(PACKAGE_VERSION)" = '@@VERS@@' ]; then cd __TMP__/* && ( \ - for file in tcc4tcl.tcl pkgIndex.tcl; do \ + for file in tcc4tcl.tcl tcc4critcl.tcl pkgIndex.tcl; do \ sed 's/@@VERS@@/0.0/g' "$${file}" > "$${file}.new"; \ cat "$${file}.new" > "$${file}"; \ rm -f "$${file}.new"; \ done \ ); fi Index: pkgIndex.tcl.in ================================================================== --- pkgIndex.tcl.in +++ pkgIndex.tcl.in @@ -1,1 +1,2 @@ package ifneeded tcc4tcl @PACKAGE_VERSION@ [list source [file join $dir tcc4tcl.tcl]] +package ifneeded critcl 0 [list source [file join $dir tcc4critcl.tcl]] ADDED tcc4critcl.tcl Index: tcc4critcl.tcl ================================================================== --- tcc4critcl.tcl +++ tcc4critcl.tcl @@ -0,0 +1,114 @@ +#! /usr/bin/env tclsh + +package require tcc4tcl + +namespace eval ::critcl {} + +proc ::critcl::_allocateHandle {} { + if {![info exists ::critcl::handle]} { + set ::critcl::handle [::tcc4tcl::new] + } + + return $::critcl::handle +} + +apply {{} { + foreach {proc args} { + ccode code + ccommand {command argList body} + } { + set argslist "" + foreach arg $args { + append argslist " \$$arg" + } + set argslist [string range $argslist 1 end] + + proc ::critcl::${proc} $args [string map [list @@PROC@@ $proc @@ARGSLIST@@ $argslist] { + set handle [::critcl::_allocateHandle] + + uplevel #0 [list $handle @@PROC@@ @@ARGSLIST@@] + }] + } +}} + +proc ::critcl::ccode {code} { + set handle [::critcl::_allocateHandle] + + tailcall $handle ccode $code +} + +proc ::critcl::_go {handle} { + $handle go + + if {$handle != $::critcl::handle} { + error "out of sync" + } + + unset -nocomplain ::critcl::handle +} + +proc ::critcl::ccommand {command argList body} { + set handle [::critcl::_allocateHandle] + + set command [::tcc4tcl::lookupNamespace $command] + + $handle ccommand $command $argList $body + + set body { + set args [uplevel 1 set args] + + ::critcl::_go $handle + + tailcall $command {*}$args + } + + proc $command args [list apply [list {handle command} $body] $handle $command] +} + +proc ::critcl::cproc {command argList resultType body} { + set handle [::critcl::_allocateHandle] + + set command [::tcc4tcl::lookupNamespace $command] + + $handle cproc $command $argList $resultType $body + + set body { + set args [uplevel 1 set args] + + ::critcl::_go $handle + + + tailcall $command {*}$args + } + + proc $command args [list apply [list {handle command} $body] $handle $command] +} + +proc ::critcl::cheaders {header} { + set handle [::critcl::_allocateHandle] + + $handle ccode "#include \"$header\"" +} + +proc ::critcl::csources {file} { + set handle [::critcl::_allocateHandle] + + # Locate file relative to current script + set file [file join $::critcl::dir $file] + + set fd [open $file] + $handle ccode [read $fd] + close $fd +} + +proc ::critcl::cflags args { + set handle [::critcl::_allocateHandle] + $handle process_command_line [join $args " "] +} + +proc ::critcl::ldflags args { + set handle [::critcl::_allocateHandle] + $handle process_command_line [join $args " "] +} + +package provide critcl 0 Index: test.tcl ================================================================== --- test.tcl +++ test.tcl @@ -225,6 +225,17 @@ $handle go if {[testCCommand] ne "OKAY"} { error "\[testCCommand\] Invalid result" } +# Critcl test +package require -exact critcl 0 +critcl::ccode { +#define test 1234 +} + +critcl::cproc test14 {int x} int { + return(x + test); +} +puts "Test14: [test14 3]" + exit 0