public override object VisitEnd_of_init([NotNull] scheme_langParser.End_of_initContext context) { //Add completed init function to scheme CompiledScheme.SetInit(currentFunc); currentFunc = null; VariableManager.EndBlock(); return(base.VisitEnd_of_init(context)); }
public void Init(Object @object, Game game) { //initialize object with this scheme CompiledScheme.Init(@object, game); //call parents foreach (var parent in Parents) { parent.Init(@object, game); } }
/* *** */ public Visitor(Scheme scheme, Config config) { Scheme = scheme; Config = config; Scheme.CompiledScheme = CompiledScheme; bodyFunction = new SchemeFunction("_body"); CompiledScheme.SetBody(bodyFunction); currentFunc = bodyFunction; }
public override object VisitInit_block([NotNull] scheme_langParser.Init_blockContext context) { if (CompiledScheme.GetFunctionByName("init") != null) { Errors.Add(new ErrorDescriptor($"This scheme already contains an init block.", context)); } //Sign start of init block currentFunc = new SchemeFunction("init"); VariableManager.NewBlock(); return(base.VisitInit_block(context)); }
/* CODE BUILDING */ private ObjectVariable CreateVariableFromContext(scheme_langParser.Variable_definitionContext context) { string type = context.variable_type().GetText(); string name = context.variable_name().GetText(); object value = null; if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null) { Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", context)); return(null); } return(new ObjectVariable(type, name, value)); }
public void Construct(Object @object, List <ObjectVariable> parameters, Game game) { if (!IsCompiledValid) { Compile(game.Config); } //construct object based on this scheme CompiledScheme.Construct(@object, parameters, game); //call parents foreach (var parent in Parents) { parent.Construct(@object, parameters, game); } }
public override object VisitBody_variable_definition([NotNull] scheme_langParser.Body_variable_definitionContext context) { //Add predefined variable to scheme var variable_definition = context.variable_definition(); string type = variable_definition?.variable_type()?.GetText(); string name = variable_definition?.variable_name()?.GetText(); if (type == null || name == null) { return(base.VisitBody_variable_definition(context)); } if (!VariableManager.IsTypeValid(type, Config)) { Errors.Add(new ErrorDescriptor($"Type '{type}' is not recognized.", variable_definition.variable_type())); } if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null) { Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", variable_definition.variable_name())); if (variable_definition.EQUALS() != null) { SetNewExpression(1); } return(base.VisitBody_variable_definition(context)); } ObjectVariable variable = new ObjectVariable(type, name, null); if (variable != null) { CompiledScheme.AddVariable(variable); CommandSetVariable cmd = new CommandSetVariable(variable_definition.variable_name().GetText(), GetRegName(0)); currentFunc.AddCommand(cmd); SetNewExpression(1); } return(base.VisitBody_variable_definition(context)); }
public SchemeFunction GetFunctionByName(string functionName) { SchemeFunction matchingFunction = CompiledScheme.GetFunctionByName(functionName); //If given name was not found in this scheme, we try the parents if (matchingFunction == null) { foreach (Scheme parent in Parents) { matchingFunction = parent.GetFunctionByName(functionName); if (matchingFunction != null) { return(matchingFunction); } } } else { return(matchingFunction); } return(null); }
public override object VisitAction_block([NotNull] scheme_langParser.Action_blockContext context) { //Sign start of action string name = context.action_name()?.GetText(); int actionPoints = 0; if (context.action_point() != null) { int.TryParse(context.action_point().GetText(), out actionPoints); } //else //Errors.Add(new ErrorDescriptor("Missing action points")); if (CompiledScheme.GetFunctionByName(name) != null) { Errors.Add(new ErrorDescriptor($"This scheme already contains an action named '{name}'.", context.action_name())); } currentFunc = new SchemeFunction(name, actionPoints); VariableManager.NewBlock(); return(base.VisitAction_block(context)); }