ref: 8b143c8c4ecc3f2b61742a89e9a0b7f8d65edc9a cdaniels.net/src/assets/tclslides.md -rw-r--r-- 1.4 KiB
8b143c8cCharles Daniels added tcl slides 9 months ago

#TCL, C, FFI, and You

Charles Daniels

SuperComputing 2019, Denver CO

Slides: http://cdaniels.net/talks.html

Code: https://github.com/charlesdaniels/teaching-learning/

Real project: https://github.com/HeRCLab/nocsim

#What is TCL

  • Tool Command Language
  • Interpreted, garbage-collected
  • Origins in 1988
  • Of tk/tkinter fame
  • Imagine the best of shell & Python
  • Easy to embed, and to embed things in
  • FFI from C to Python via tkinter
  • Everything is a string

#Who is using TCL

  • Embedded systems
    • Lightweight, few dependencies
  • EDA toolchains
    • Xilinx Vivado
    • Intel Quartus
    • Mentor Graphics ModelSim
  • FlightAware

#Why TCL?

  • Same skills script tools you already know
  • Easy to integrate with existing C/C++ code
    • And others...
  • Easy to embed in existing C/C++ applications
    • And others...
  • Rich standard library
  • Tk for GUIs!

#C $\leftrightarrow$ TCL FFI In a Nutshell

  • Wrap standard C functions & Tcl_CreateObjCommand()
  • Run TCL from C with Tcl_Eval()
  • Link variables with Tcl_LinkVar()
  • Read/write variables with Tcl_GetVar() / Tcl_SetVar()

#C $\leftrightarrow$ Pitfalls

  • "Legacy" API uses strings for everything, lots of existing code / docs
    • New code should use "object" API
  • Reference counting
    • Careful when re-using pointers
  • Create a package, don't embed an interpreter
    • If you can

#Questions, Comments, Concerns, etc.