#215 What is FCode?

tactics Wed 30 Apr 2008

I keep seeing references to "fcode" in the compiler source. Is that a Fan-specific intermediate code? Or is it an existing technology? How does fcode fit into the compilation process?

brian Wed 30 Apr 2008

The compiler outputs a pod file which is a zip file containing fcode. For scripts this zip file is just a memory buffer. Fcode is essentially Fan bytecode which is portable between the Java and .NET runtimes. Then at runtime the Java or .NET runtime takes the fcode and emits Java bytecode or .NET IL. There are two main advantages to having the intermediate fcode:

  1. a single pod file is portable between the Java and .NET runtime
  2. we avoid fragile base class issues with mixins, because don't actually implement the "mixin routers" until load time

The compiler process is summarized as:

  1. parse source into AST
  2. manipulate/check/normalize the AST thru the series of steps
  3. convert AST to fcode in CodeAsm

The pod is a normal zip file which contains:

  1. a pod.def for the pod's meta-data
  2. a def file for each of the literals (Int, Duration, etc) - these files are very similar the const pool in a Java classfile
  3. an fcode file for each type with the field/method definitions

You can use fanp to disassemble the fcode to see what it looks like.

Hope that provides a good summary! Please let me know if you'd further details.

Login or Signup to reply.