// basic checks (only for checking name conflicts) public void CheckCommonNamesConflicts(string name, int line, int column) { if (Classes.ContainsKey(name) || Routines.ContainsKey(name) || Fields.ContainsKey(name) || ImportedModules.Contains(name) || ModuleData.Name == name) { ThrowConflictNameException(ModuleData.File, line, column); } }
public bool HasSideEffects(ZilObject expr) { // only forms can have side effects if (!(expr is ZilForm form)) { return(false); } // malformed forms are errors anyway if (!(form.First is ZilAtom head)) { return(false); } Debug.Assert(form.Rest != null); // some instructions always have side effects var zversion = Context.ZEnvironment.ZVersion; var argCount = form.Rest.Count(); if (ZBuiltins.IsBuiltinWithSideEffects(head.Text, zversion, argCount)) { return(true); } // routines are presumed to have side effects if (Routines.ContainsKey(head)) { return(true); } // other instructions could still have side effects if their arguments do return(form.Rest.Any(HasSideEffects)); }
void PrepareLateRoutineBuilders() { // builders for routines (again, in case any were added during compilation, e.g. by a PROPSPEC) foreach (var routine in Context.ZEnvironment.Routines) { Debug.Assert(routine.Name != null); if (!Routines.ContainsKey(routine.Name)) { Routines.Add(routine.Name, Game.DefineRoutine( routine.Name.Text, routine.Name == Context.ZEnvironment.EntryRoutineName, (routine.Flags & RoutineFlags.CleanStack) != 0)); } } }
bool CouldModifyGlobal([NotNull] ZilObject expr, [NotNull] ZilAtom globalAtom) { if (!(expr is ZilListBase list)) { return(false); } if (list is ZilForm && list.First is ZilAtom atom) { if ((atom.StdAtom == StdAtom.SET || atom.StdAtom == StdAtom.SETG) && list.Rest?.First == globalAtom) { return(true); } if (Routines.ContainsKey(atom)) { return(true); } } return(list.Any(zo => CouldModifyGlobal(zo, globalAtom))); }
void GenerateRoutineCode() { // compile routines IRoutineBuilder mainRoutine = null; foreach (var routine in Context.ZEnvironment.Routines) { var entryPoint = routine.Name == Context.ZEnvironment.EntryRoutineName; Debug.Assert(routine.Name != null); Debug.Assert(Routines.ContainsKey(routine.Name)); var rb = Routines[routine.Name]; try { using (DiagnosticContext.Push(routine.SourceLine)) { BuildRoutine(routine, rb, entryPoint, Context.TraceRoutines); } } catch (ZilError ex) { // could be a compiler error, or an interpreter error thrown by macro evaluation Context.HandleError(ex); } rb.Finish(); if (entryPoint) { mainRoutine = rb; } } if (mainRoutine == null) { throw new CompilerError(CompilerMessages.Missing_GO_Routine); } }
bool VariableNameInUse([NotNull] ZilAtom atom) { return(Locals.ContainsKey(atom) || TempLocalNames.Contains(atom) || Globals.ContainsKey(atom) || SoftGlobals.ContainsKey(atom) || Constants.ContainsKey(atom) || Objects.ContainsKey(atom) || Routines.ContainsKey(atom)); }