private bool IsScriptParameter(string expectedReturnType, ParserRuleContext context) { // This script doesn't have parameters. if (_parameterLookup.Count == 0) { return false; } string text = context.GetTextSanitized(); // The script doesn't have a parameter with this name. if (!_parameterLookup.TryGetValue(text, out ParameterInfo info)) { return false; } string returnType = DetermineReturnType(info, expectedReturnType, context); if(returnType is null) { throw new CompilerException($"Failed to determine the return type of the parameter {text}.", context); } ushort returnTypeOpcode = _opcodes.GetTypeInfo(returnType).Opcode; ushort opcode = returnTypeOpcode; // (In)Equality functions are special if(context.Parent.Parent is HS_Gen1Parser.CallContext grandparent) { string funcName = grandparent.callID().GetTextSanitized(); var funcInfo = _opcodes.GetFunctionInfo(funcName); if(funcInfo != null) { if (funcInfo[0].Group == "Equality" || funcInfo[0].Group == "Inequality") { opcode = GetEqualityArgumentOP(returnTypeOpcode); } } } var expression = new ScriptExpression { Index = _currentIndex, Opcode = opcode, ReturnType = returnTypeOpcode, Type = ScriptExpressionType.ParameterReference, Next = DatumIndex.Null, StringOffset = _strings.Cache(info.Name), Value = new LongExpressionValue(info.Opcode), LineNumber = GetLineNumber(context) }; EqualityPush(info.ReturnType); OpenDatumAddExpressionIncrement(expression); return true; }
private bool IsGlobalsReference(string expectedType, ParserRuleContext context) { string text = context.GetTextSanitized(); GlobalInfo globalInfo = _opcodes.GetGlobalInfo(text); IExpressionValue value; // Engine global. if(globalInfo != null) { //ushort[] arr = { 0xFFFF, globalInfo.MaskedOpcode }; value = new LongExpressionValue(0xFFFF, globalInfo.MaskedOpcode); } // Map global. else if(_mapGlobalsLookup.ContainsKey(text)) { globalInfo = _mapGlobalsLookup[text]; value = new LongExpressionValue(globalInfo.Opcode); } // Not a global... else if (expectedType == TypeHelper.GlobalsReference) { throw new CompilerException($"A global reference was expected, but no global with the name \"{text}\" could be found.", context); } else { return false; } string returnType = DetermineReturnType(globalInfo, expectedType, context); ushort returnTypeOpcode = _opcodes.GetTypeInfo(returnType).Opcode; ushort opcode = GetGlobalOpCode(returnTypeOpcode, context); var expression = new ScriptExpression { Index = _currentIndex, Opcode = opcode, ReturnType = returnTypeOpcode, Type = ScriptExpressionType.GlobalsReference, Next = DatumIndex.Null, StringOffset = _strings.Cache(text), Value = value, LineNumber = GetLineNumber(context) }; OpenDatumAddExpressionIncrement(expression); return true; }
private void WriteContext(string level, ParserRuleContext context, CompilerContextAction action) { string innerMessage = $"Line: {context.Start.Line}, {action}: \"{context.GetTextSanitized()}\""; WriteEntry(level, innerMessage); }