vertexshader256 / cengine   0.0.5

Apache License 2.0 GitHub

Execute C code on the JVM

Scala versions: 2.11

cEngine

C interpreter which runs on the JVM.

Supports:

  • Multi-dimensional arrays
  • Variable arguments
  • Pointer aritmetic
  • Recursion
  • Multilevel pointers
  • Function pointers
  • Unsigned types
  • Memory allocation
  • Structures, enumerations

sbt

libraryDependencies += "com.github.bdwashbu" % "cengine_2.11" % "0.0.5"

Hello world

From the sbt console:

scala> import c.engine.Interpreter._
scala> c"""printf("Hello world!");"""
Hello world!

Dependencies

Test approach:

For all code, standard output of cEngine must exactly match that of gcc. Tested against gcc 5.3.0.

scalatest and sbt-coverage are very helpful.

cEngine was bootstrapped off of java.util.Formatter but it can now execute an embedded version of printf, ee_printf.

ee_printf is found here: https://github.com/bwalex/supermips/blob/master/software/coremark/supermips/ee_printf.c

Debugging

Using d3.js to visualize the AST is very helpful.

cEngine Debugger

Assumptions

All code executed by cEngine can be succesfully compiled with gcc.