Skip to content

Managed Expression Evaluator Sample

Patrick Nelson edited this page Sep 9, 2015 · 14 revisions

To demonstrate integration of a .NET language with the debugger, this repo contains a sample compiler named Iris as well as a .NET Expression Evaluator (EE).

Browsing the Sample

The sample compiler and EE are in the "Iris" directory at the root of the repo. This folder contains several subdirectories:

Directory Description
FrontEndTest Contains unit tests focused on the front end parts of the Iris compiler. These tests can be run from within Visual Studio using "Test Explorer" or outside of Visual Studio by using MSTest.
ic This project is a command line driver for the Iris compiler.
IrisCompiler This project builds a .dll containing the code for the compiler itself. This .dll is referenced by the command line driver as well as the EE component
IrisExtension This is a vsix (Visual Studio Extension) project containing all of the EE components as well as some registration information for the Iris language and EE. We'll go into more detail of IrisExtension below...
IrisRuntime This is the runtime .dll referenced by Iris programs. It currently only contains two methods. One method is used by the compiler to initialize string arrays. The other is the implementation of rand.
Programs This folder contains sample programs written in the Iris language as well as a .cmd file for building them

Building the Sample

  1. First clone the repository (or a fork of the repo) to your local machine.

  2. Open Visual Studio and add the package source to get System.Reflection.Metadata

  3. Go to Tools -> NuGet Package Manager -> Package Manager Settings.

  4. On the left side, select "Package Sources"

  5. Add a new Package Source with these settings:

    Name: "myget.org CoreFx"

    Source: "https://www.myget.org/F/dotnet-corefx"

  6. Save your settings. You should now be able to build Iris.sln.

  7. Open and build Iris.sln in Visual Studio

Running the Sample

First you'll want an Iris program to debug. The Iris/Programs directory contains a sample program named TicTacToe.iris. We'll use that program to try out the debugger.

To build TicTacToe.iris:

  1. Open a command prompt
  2. cd to /Iris/Programs
  3. Run "build.cmd"

Following these steps should have created TicTacToe.exe and TicTacToe.pdb. We can now try debugging TicTacToe.exe. To do that follow these steps:

  1. Open Iris.sln in Visual Studio (if you don't already have it loaded)
  2. Set IrisExtension as the Startup Project
  3. Right click on IrisExtension and select "Properties"
  4. Select the "Debug" tab
  5. Select "Start External Program".
  6. For "External Program" enter "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" (or whatever the correct path is for your Visual Studio install"
  7. For "Command Line Arguments" enter "/rootsuffix Exp"
  8. You can now run the Visual Studio with the Extension using Ctrl-F5 (or F5 if you want to debug the debugger).
  9. From the new Visual Studio you just started, select "Open Project or Solution".
  10. Navigate to and open the TicTacToe.exe you built above.
  11. In the project properties, make sure the debugger is "Managed (v4.5 v4.0)"
  12. Push F10 (step)
  13. This should automatically open TicTacToe.iris and you'll be stopped at the "begin" of the main block.

Some things to try with the sample:

  1. Notice that you can set breakpoints, step, and the variable inspection windows are working (Autos window and DataTips require a language service so they will not do anything).
  2. Also notice that advanced features of the debugger such as Set Next Statement, Step into Specific, and Conditional Breakpoints are all available and are flavored in the Iris language.
  3. It's also possible to modify values in the Watch and Locals windows when it's allowed by the compiler.

Implementation of IrisExtension

Clone this wiki locally