public static Atom TableImportAll(Atom args, Context context) { Atom dict = (Atom)args?.value; Context dictionary = GetDictionary(dict); ContextUtils.ImportAllSymbols(dictionary, context); return(null); }
private static Atom Require(Atom args, Context context) { BombardoModule currentModule = modulesStack_.Peek(); Atom path = args.atom; if (path.type != AtomType.String && path.type != AtomType.Symbol) { throw new ArgumentException("argument must be string or symbol!"); } string file = FSUtils.LookupModuleFile(programPath_, currentModule.currentPath, AllNames.MODULES_FOLDER, (string)path.value); if (file == null) { throw new ArgumentException("file not found!"); } // Lifting exception up to first file BombardoModule module = ExecuteFile(file, false); Atom result = module.GetModuleResult(); Atom rest = args.next; if (rest != null && rest.IsPair()) { Atom command = rest.atom; if (!command.IsSymbol()) { throw new ArgumentException(string.Format("Unexpected symbol '{0}'!", command)); } switch ((string)command.value) { case AllNames.MODULE_REQUIRE_AS: Atom name = rest.next?.atom; if (name == null || !name.IsSymbol()) { throw new ArgumentException(string.Format("Unexpected symbol '{0}'!", name)); } context.Define((string)name.value, result); break; case AllNames.MODULE_REQUIRE_IMPORT: string[] nameList = CommonUtils.ListToStringArray(rest.next, "REQUIRE"); ContextUtils.ImportSymbols((Context)result.value, context, nameList); break; case AllNames.MODULE_REQUIRE_IMPORT_ALL: ContextUtils.ImportAllSymbols((Context)result.value, context); break; default: throw new ArgumentException(string.Format("Unexpected symbol '{0}'!", command)); } } else { string name = Path.GetFileNameWithoutExtension((string)path.value); context.Define(name, result); } return(result); }