// left OPERATOR right style expressions // the most common form of expressions // for things like 1 + 3 #region lValueOperatorrValueCalls internal void genericExpVisitor(YarnSpinnerParser.ExpressionContext left, YarnSpinnerParser.ExpressionContext right, int op) { Visit(left); Visit(right); // TODO: temp operator call compiler.Emit(ByteCode.CallFunc, tokens[op].ToString()); }
// operatorEquals style operators, eg += // these two should only be called during a SET operation // eg << set $var += 1 >> // the left expression has to be a variable // the right value can be anything #region operatorEqualsCalls // generic helper for these types of expressions internal void opEquals(string varName, YarnSpinnerParser.ExpressionContext expression, int op) { // Get the current value of the variable compiler.Emit(ByteCode.PushVariable, varName); // run the expression Visit(expression); // Stack now contains [currentValue, expressionValue] // now we evaluate the operator // op will match to one of + - / * % compiler.Emit(ByteCode.CallFunc, tokens[op].ToString()); // Stack now has the destination value // now store the variable and clean up the stack compiler.Emit(ByteCode.StoreVariable, varName); compiler.Emit(ByteCode.Pop); }
internal void generateClause(string jumpLabel, YarnSpinnerParser.StatementContext[] children, YarnSpinnerParser.ExpressionContext expression) { string endOfClauseLabel = compiler.RegisterLabel("skipclause"); // handling the expression (if it has one) // will only be called on ifs and elseifs if (expression != null) { Visit(expression); compiler.Emit(ByteCode.JumpIfFalse, endOfClauseLabel); } // running through all of the children statements foreach (var child in children) { Visit(child); } compiler.Emit(ByteCode.JumpTo, jumpLabel); if (expression != null) { compiler.Emit(ByteCode.Label, endOfClauseLabel); compiler.Emit(ByteCode.Pop); } }