Ejemplo n.º 1
0
    /// <summary>
    /// Emits a language element.
    /// </summary>
    /// <param name="emitter">The emitter.</param>
    /// <param name="element">The language element.</param>
    /// <param name="exits">The non-exceptiona exit targets.</param>
    /// <returns>Reference to the emitter for method call chaining.</returns>
    private static Emitter Emit(this Emitter emitter, LanguageElement element, Exits exits)
    {
        emitter.At(element.Token);

        if (exits == null)
        {
            var section1 = emitter.Section();          // <- function body
            var section2 = emitter.Section().At(null); // <- default result
            var section3 = emitter.Section().At(null); // <- final cleanup
            var section4 = emitter.Section().At(null); // <- return

            element.Emit(section1, new Exits(section3));
            section2.Emit(Opcode.Null);
            section4.Emit(Opcode.Return);

            return(section1);
        }
        else
        {
            element.Emit(emitter, exits);
            return(emitter);
        }
    }