
# (find-es "forth" "pforth_and_tcl")
# (find-fline "~/PFORTH/tclpforth.c")
# (find-fline "~/PFORTH/Makefile")

load /home/root/PFORTH/tclpforth.so
# pf_init pforth.dic
pf_init ./tclpforth.dic

proc readfile {fname} {
  set channel [open $fname r]; set bigstr [read $channel]; close $channel
  return $bigstr
}
proc writefile {fname bigstr} {
  set channel [open $fname w]; puts -nonewline $channel $bigstr; close $channel
}


# First way to eval pforth code from Tcl, by storing it in a temporary
# file... This requires some kernel calls, but uses only C functions
# and so will work without a pforth.dic. See the alternative below.
# (find-fline "~/PFORTH/tclpforth.c" "_pf_includefile")
#
proc fdo {bigstr} {
  writefile /tmp/tmp.pforth $bigstr\n
  pf_includefile /tmp/tmp.pforth
}

# Second way to eval pforth code from Tcl.
# Depends on having EVALUATE on the dictionary.
# Overrides the previous definiton.
#
# (find-pffile "quit.fth" ": EVALUATE")
# (find-fline "~/PFORTH/tclpforth.c" "_pf_evaluate")
#
proc fdo {bigstr} {
  pf_evaluate $bigstr
}


# A debugging trick.
# (find-fline "~/TCL/attachgdb")
# (find-es "forth" "pforth_and_tcl")
#
proc attachgdb {progname args} {
  eval exec /home/root/TCL/attachgdb $progname \
    -d /usr/src/pforth-21/csrc -d /home/root/PFORTH $args
}

