/// <summary> /// Compiles the block to the given context with the given parameters /// </summary> /// <param name="context"></param> /// <param name="callParameters"></param> public void Compile(LinkContext context, ParentheticGroup callParameters) { Contract.Requires(context != null); Contract.Requires(callParameters != null); // groupify the contents of the block Group groupedBlock = (Group)GroupedBlock.Read(this.Tokens.GetEnumerator()); // there should be 4 items in the group: // 0: inline keyword // 1: identifier token // 2: parenthetical containing the parameter list // 3: code block // just compile the code for now groupedBlock.Items.ElementAt(3).Compile(context); }
/// <summary> /// Reads a group that begins with this token /// </summary> /// <param name="enumerator"></param> /// <returns></returns> public override GroupItem ReadGroupItem(IEnumerator <Token> enumerator) { // we're currently pointing at our own position; move past it switch (Symbol) { case Symbol.LeftCurlyBracket: return(CurlyBracketGroup.Read(enumerator)); case Symbol.LeftParen: return(ParentheticGroup.Read(enumerator)); case Symbol.RightCurlyBracket: case Symbol.RightParen: throw new CompileException(Error.UnexpectedSymbol); default: return(base.ReadGroupItem(enumerator)); } }
/// <summary> /// Compiles the invocation of the invokable item with the given name, using the /// given parameters. /// </summary> /// <param name="identifier">the name of the invokable item</param> /// <param name="callParameters">the parameters</param> public void CompileInvocation(IdentifierToken identifier, ParentheticGroup callParameters) { Contract.Requires(callParameters != null); Contract.Requires(identifier != null); // find the block Block invokableBlock = GetBlock(identifier); if (invokableBlock is InlineBlock) { ((InlineBlock)invokableBlock).Compile(this, callParameters); } else if (jsModule.IsFunctionName(identifier.Identifier)) { byte[] generatedCode = jsModule.EvaluateByteArray(identifier + callParameters.ToString()); this.LinkedModule.AppendCode(generatedCode); } else { throw new CompileException(Error.IdentifierIsNotInvokable, identifier); } }