public static bool Check(Core.Session session, Core.DeclFunct funct) { var checker = new FunctTypeChecker(session, funct); checker.Check(); return(checker.foundErrors); }
public ASTParser(Core.Session session, TokenCollection tokenColl, int startToken = 0) { this.readhead = startToken; this.tokenColl = tokenColl; this.session = session; this.insideCondition = new Stack <bool>(); this.insideCondition.Push(false); }
public void PrintToConsole(Core.Session session) { PrintContext(); PrintMessage(); PrintExcerptWithHighlighting(this.kind, this.spans); if (this.innerMessage != null) { this.innerMessage.indentation = this.indentation + " "; this.innerMessage.PrintToConsole(session); } }
public static bool Resolve( Core.Session session, Core.DeclFunct funct, Core.UseDirective[] useDirectives, Grammar.ASTNodeExpr bodyExpr) { var resolver = new FunctBodyResolver(session, funct, useDirectives); resolver.Resolve(bodyExpr); return(resolver.foundErrors); }
private FunctBodyResolver(Core.Session session, Core.DeclFunct funct, Core.UseDirective[] useDirectives) { this.session = session; this.funct = funct; this.useDirectives = useDirectives; this.foundErrors = false; this.localScopeLivenesses = new List<bool>(); for (var i = 0; i < funct.parameterNum; i++) this.localScopeLivenesses.Add(true); }
public AlgebraViewModel() { var pAssembly = Assembly.GetExecutingAssembly(); Name = pAssembly.GetCustomAttribute <AssemblyTitleAttribute>().Title; Version = pAssembly.GetName().Version.ToString(); Description = pAssembly.GetCustomAttribute <AssemblyDescriptionAttribute>().Description; License = pAssembly.GetCustomAttribute <AssemblyCopyrightAttribute>().Copyright; Website = "https://github.com/bugbit/algebra"; Session = new Core.Session(); }
public static ASTNodeDeclGroup Parse(Core.Session session, TokenCollection tokenColl) { try { var astParser = new ASTParser(session, tokenColl); return(astParser.ParseDeclGroup()); } catch (Core.CheckException) { return(null); } }
public CreateElementPanel(Core.Session session) { InitializeComponent(); this.currentSession = session; basis = new List<ITheoryElement>(); TheoryTypeBox.Text = type.ToString(); LinksItemBox.ItemsSource = basis; mod = Mods.Create; LanguageResource.Updated += new Updated(LanguageResource_Updated); FormulationTextBox.Focus(); LanguageResource_Updated(null); }
private FunctBodyResolver(Core.Session session, Core.DeclFunct funct, Core.UseDirective[] useDirectives) { this.session = session; this.funct = funct; this.useDirectives = useDirectives; this.foundErrors = false; this.localScopeLivenesses = new List <bool>(); for (var i = 0; i < funct.parameterNum; i++) { this.localScopeLivenesses.Add(true); } }
public static bool Check(Core.Session session) { var foundErrors = false; var structs = session.GetStructs(); for (var i = 0; i < structs.Count; i++) { var seenStructs = new Stack <int>(); foundErrors |= CheckStruct(session, i, seenStructs); } return(foundErrors); }
public override string GetString(Core.Session session) { var result = "fn("; for (var i = 0; i < this.parameterTypes.Length; i++) { result += this.parameterTypes[i].GetString(session); if (i < this.parameterTypes.Length - 1) { result += ", "; } } return(result + ") -> " + this.returnType.GetString(session)); }
public override string GetString(Core.Session session) { var result = "("; for (var i = 0; i < this.elementTypes.Length; i++) { result += this.elementTypes[i].GetString(session); if (i < this.elementTypes.Length - 1) { result += ", "; } } return(result + ")"); }
public override bool IsZeroSized(Core.Session session) { var anySized = false; for (var i = 0; i < this.elementTypes.Length; i++) { if (!this.elementTypes[i].IsZeroSized(session)) { anySized = false; break; } } return(!anySized); }
public static Core.Type GetDataAccessType( Core.Session session, Core.DeclFunct funct, Core.DataAccess access) { var regAccess = access as Core.DataAccessRegister; if (regAccess != null) { return(funct.registerTypes[regAccess.registerIndex]); } var regField = access as Core.DataAccessField; if (regField != null) { return(GetFieldType( session, GetDataAccessType(session, funct, regField.baseAccess), regField.fieldIndex)); } var regDeref = access as Core.DataAccessDereference; if (regDeref != null) { var innerType = GetDataAccessType(session, funct, regDeref.innerAccess); var innerPtr = innerType as Core.TypePointer; if (innerPtr == null) { return(new Core.TypeError()); } return(innerPtr.pointedToType); } var regDiscard = access as Core.DataAccessDiscard; if (regDiscard != null) { return(Core.TypeTuple.Empty()); } return(new Core.TypeError()); }
private static bool CheckField( Core.Session session, int structIndex, int fieldIndex, Core.Type innerType, Stack <int> seenStructs) { var fieldStruct = innerType as Core.TypeStruct; if (fieldStruct == null) { return(false); } var st = session.GetStruct(structIndex); Core.Name fieldName; st.fieldNames.FindByValue(fieldIndex, out fieldName); session.PushContext( "in struct '" + session.GetStructName(structIndex).GetString() + "', " + "field '" + fieldName.GetString() + "'", st.GetFieldNameSpan(fieldIndex)); var err = false; if (seenStructs.Contains(fieldStruct.structIndex)) { err = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.StructRecursion, "struct recursion", session.GetStruct(fieldStruct.structIndex).GetNameSpan(), st.GetFieldNameSpan(fieldIndex)); } if (!err) { CheckStruct(session, fieldStruct.structIndex, seenStructs); } session.PopContext(); return(err); }
public CreateElementPanel(ITheoryElement element, List<ITheoryElement> basis, Core.Session session, TheoryTree tree) { InitializeComponent(); this.element = element; this.basis = basis; this.currentSession = session; this.type = element.GetTheoryType(); this.tree = tree; TheoryTypeBox.Text = type.ToString(); LinksItemBox.ItemsSource = basis; FormulationTextBox.Text = element.Formulation; TemplateTextBox.Text = element.Template; if (element is Theorem) ProofTextBox.Text = ((Theorem)element).Proof; mod = Mods.Edit; LanguageResource.Updated += new Updated(LanguageResource_Updated); Update(); LanguageResource_Updated(null); }
public static int GetFieldNum( Core.Session session, Core.Type baseType) { var baseStruct = baseType as Core.TypeStruct; if (baseStruct != null) { return(session.GetStruct(baseStruct.structIndex).fieldTypes.Count); } var baseTuple = baseType as Core.TypeTuple; if (baseTuple != null) { return(baseTuple.elementTypes.Length); } return(0); }
public static string Generate(Core.Session session) { var gen = new CGenerator(); gen.session = session; gen.GatherItems(); gen.RegisterStructDependencies(); gen.RegisterFunctDependencies(); var sortedItems = gen.itemGraph.GetTopologicalSort(); var result = ""; result += "typedef char Bool;\n"; result += "typedef int Int;\n"; result += "typedef unsigned int UInt;\n"; result += "\n"; for (var i = 0; i < sortedItems.Count; i++) { var item = sortedItems[i]; switch (item.kind) { case Item.Kind.StructHeader: result += gen.GenerateStructDecl(item.index); break; case Item.Kind.Struct: result += gen.GenerateStructDef(item.index); break; case Item.Kind.FunctHeader: result += gen.GenerateFunctDecl(item.index); break; case Item.Kind.Funct: result += gen.GenerateFunctDef(item.index); break; } } /*result += gen.GenerateFunctDecls() + "\n"; * result += gen.GenerateFunctDefs() + "\n";*/ return(result); }
public static Core.Type GetFieldType( Core.Session session, Core.Type baseType, int fieldIndex) { var baseStruct = baseType as Core.TypeStruct; if (baseStruct != null) { return(session.GetStruct(baseStruct.structIndex).fieldTypes[fieldIndex]); } var baseTuple = baseType as Core.TypeTuple; if (baseTuple != null) { return(baseTuple.elementTypes[fieldIndex]); } return(new Core.TypeError()); }
public static bool GetDataAccessMutability( Core.Session session, Core.DeclFunct funct, Core.DataAccess access) { var regAccess = access as Core.DataAccessRegister; if (regAccess != null) { return(funct.registerMutabilities[regAccess.registerIndex]); } var regField = access as Core.DataAccessField; if (regField != null) { return(GetDataAccessMutability(session, funct, regField.baseAccess)); } var regDeref = access as Core.DataAccessDereference; if (regDeref != null) { var innerType = GetDataAccessType(session, funct, regDeref.innerAccess); var innerPtr = innerType as Core.TypePointer; if (innerPtr == null) { return(false); } if (!innerPtr.mutable) { return(false); } return(true); } return(false); }
public static bool Check(Core.Session session, Core.DeclFunct funct) { var checker = new FunctInitChecker(session, funct); var statusList = new List <InitStatus>(); for (var i = 0; i < funct.registerTypes.Count; i++) { statusList.Add(new InitStatus(i >= 1 && i < funct.parameterNum + 1)); } var segmentVisitCounts = new List <int>(); for (var i = 0; i < funct.segments.Count; i++) { segmentVisitCounts.Add(0); } checker.CheckSegment(0, segmentVisitCounts, statusList); checker.CheckUnusedMutabilities(); return(checker.foundErrors); }
public static Core.Type ResolveStruct( Core.Session session, Grammar.ASTNodeName nameNode, IList <Core.UseDirective> useDirectives, bool mustBeResolved) { var name = NameResolver.Resolve(nameNode); var foundDecls = session.GetDeclsWithUseDirectives(name, nameNode.path.isRooted, useDirectives); if (!session.ValidateSingleDecl(foundDecls, name, nameNode.GetSpan())) { return(new Core.TypeError()); } if (!session.ValidateAsType(foundDecls[0], name, nameNode.GetSpan())) { return(new Core.TypeError()); } return(Core.TypeStruct.Of(foundDecls[0].index)); }
public static Core.Name GetFieldName( Core.Session session, Core.Type baseType, int fieldIndex) { var baseStruct = baseType as Core.TypeStruct; if (baseStruct != null) { Core.Name name; session.GetStruct(baseStruct.structIndex).fieldNames.FindByValue(fieldIndex, out name); return(name); } var baseTuple = baseType as Core.TypeTuple; if (baseTuple != null) { return(Core.Name.FromPath(fieldIndex.ToString())); } return(null); }
public static bool ValidateDataAccess( Core.Session session, Core.DeclFunct funct, Core.DataAccess access) { var regDeref = access as Core.DataAccessDereference; if (regDeref != null) { var innerType = GetDataAccessType(session, funct, regDeref.innerAccess); var innerPtr = innerType as Core.TypePointer; if (innerPtr == null) { session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.CannotDereferenceType, "dereferencing '" + innerType.GetString(session) + "'", access.span); return(false); } } return(true); }
private static bool CheckStruct(Core.Session session, int structIndex, Stack <int> seenStructs) { var st = session.GetStruct(structIndex); var err = false; seenStructs.Push(structIndex); for (var i = 0; i < st.fieldTypes.Count; i++) { err |= CheckField(session, structIndex, i, st.fieldTypes[i], seenStructs); var fieldTuple = st.fieldTypes[i] as Core.TypeTuple; if (fieldTuple != null) { for (var j = 0; j < fieldTuple.elementTypes.Length; j++) { err |= CheckField(session, structIndex, i, fieldTuple.elementTypes[j], seenStructs); } } } seenStructs.Pop(); return(err); }
public static Core.Type ResolveStruct( Core.Session session, Grammar.ASTNodeExprName nameNode, IList <Core.UseDirective> useDirectives, bool mustBeResolved) { var nameConcreteNode = nameNode as Grammar.ASTNodeExprNameConcrete; if (nameConcreteNode == null) { if (mustBeResolved) { session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Expected, "type must be known", nameNode.GetSpan()); } return(new Core.TypeError()); } return(ResolveStruct(session, nameConcreteNode.name, useDirectives, mustBeResolved)); }
public AddPage(Core.Session argSession, ViewModels.IBoard argBoard) { InitializeComponent(); vm.Session = argSession; vm.Board = argBoard; }
public static void LoadSession(Panel parent) { Operation operation = new Operation("Load session"); OperationsHandler.OperationStarts(operation); try { if (session != null) session.LoadData(); else { session = new Protsenko.TheoryEditor.Core.Session(parent, "Default", Protsenko.TheoryEditor.Core.Session.ConstructorMods.Load); } } catch (Exception exc) { Core.Debug.ExceptionHandler.exceptionHandler.Add(exc); } Core.Debug.OperationsHandler.OperationComlete(operation); }
public DeclResolver(Core.Session session) { this.session = session; }
public static void NewSession(Panel parent) { Operation operation = new Operation("New session"); OperationsHandler.OperationStarts(operation); try { if (session == null) session = CreateSession(parent); else { MessageBoxResult result = MessageBox.Show(LanguageResource.currentDictionary["requestSaveSessionAndCreateNew"], LanguageResource.currentDictionary["message"], MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { session.Close(); session = CreateSession(parent); } } SessionAdded(session, new EventArgs()); } catch (Exception exc) { Core.Debug.ExceptionHandler.exceptionHandler.Add(exc); } Core.Debug.OperationsHandler.OperationComlete(operation); }
public override bool IsZeroSized(Core.Session session) { return(false); }
private FunctInitChecker(Core.Session session, Core.DeclFunct funct) { this.session = session; this.funct = funct; this.foundErrors = false; }
public TsunamiViewModel() { Settings.Logger.Inizialize(); _preference = new Models.Preferences(); _torrentList = new ObservableCollection <Models.TorrentItem>(); System.Windows.Data.BindingOperations.EnableCollectionSynchronization(TorrentList, _lock); _sessionStatistic = new SessionStatistics(); IsTsunamiEnabled = false; //_notifyIcon = new Models.NotifyIcon(); _torrentSession = new Core.Session(); CoreLog.Debug("created"); if (System.IO.File.Exists(".session_state")) { var data = System.IO.File.ReadAllBytes(".session_state"); using (var entry = Core.Util.lazy_bdecode(data)) { _torrentSession.load_state(entry); } } CoreLog.Debug("session_state loaded. pausing"); _torrentSession.pause(); Core.SessionSettings ss = _torrentSession.settings(); //ss.connections_limit = 500; // 200 //ss.tick_interval = 250; // 500 //ss.torrent_connect_boost = 20; // 10 //ss.connection_speed = -1; // -1 = 200 ; default 10 //ss.num_want = 400; // 200 //ss.cache_size = -1; // -1 = 1/8 RAM; default 1024 //ss.coalesce_reads = true; // false //ss.coalesce_writes = true; // false string ua = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build.ToString(); ss.user_agent = string.Format(Tsunami.Settings.Application.TSUNAMI_USER_AGENT, ua); log.Debug("using user agent {0}", ss.user_agent); // from qbit torrent ss.upnp_ignore_nonrouters = true; ss.use_dht_as_fallback = false; ss.ssl_listen = 0; // Disable support for SSL torrents for now ss.lazy_bitfields = true; // To prevent ISPs from blocking seeding ss.stop_tracker_timeout = 1; // Speed up exit ss.auto_scrape_interval = 1200; // 20 minutes ss.announce_to_all_trackers = true; // from pref->announceToAllTrackers(); ss.announce_to_all_tiers = true; // from pref->announceToAllTrackers(); ss.auto_scrape_min_interval = 900; // 15 minutes ss.cache_size = -1; ss.cache_expiry = 60; ss.disk_io_read_mode = 0; // enable_os_cache ss.anonymous_mode = false; ss.active_seeds = 3; // MaxActiveUploads ss.dont_count_slow_torrents = false; ss.active_downloads = 3; // MaxActiveDownloads + m_extraLimit ss.active_limit = 5; // MaxActiveTorrents + m_extraLimit ss.active_tracker_limit = -1; ss.active_dht_limit = -1; ss.active_lsd_limit = -1; ss.ignore_limits_on_local_network = true; // Ignore limits on LAN ss.rate_limit_ip_overhead = false; // Include overhead in transfer limits //ss.announce_ip = Utils::String::toStdString(pref->getNetworkAddress()); // IP address to announce to trackers ss.strict_super_seeding = false; // Super seeding ss.half_open_limit = 20; // * Max Half-open connections ss.connections_limit = 500; // * Max connections limit ss.unchoke_slots_limit = -1; // * Global max upload slots ss.enable_incoming_utp = true; // uTP ss.enable_outgoing_utp = true; // uTP ss.rate_limit_utp = true; // uTP rate limiting ss.mixed_mode_algorithm = 0; // prefer_tcp ss.connection_speed = 20; //default is 10 ss.no_connect_privileged_ports = false; ss.seed_choking_algorithm = 1; // fastest_upload ss.apply_ip_filter_to_trackers = false; // FilterTracker _torrentSession.set_settings(ss); // MISSING ENCRYPTION // libt::pe_settings encryptionSettings; (835 of session.cpp) Core.DhtSettings dhts = _torrentSession.get_dht_settings(); //dhts.aggressive_lookups = true; _torrentSession.set_dht_settings(dhts); var alertMask = Core.AlertMask.error_notification | Core.AlertMask.peer_notification | Core.AlertMask.port_mapping_notification | Core.AlertMask.storage_notification | Core.AlertMask.tracker_notification | Core.AlertMask.status_notification | Core.AlertMask.ip_block_notification | Core.AlertMask.progress_notification | Core.AlertMask.stats_notification | Core.AlertMask.dht_notification ; _torrentSession.set_alert_mask(alertMask); _torrentSession.set_alert_callback(HandlePendingAlertCallback); _torrentSession.set_session_callback(HandleAlertCallback); if (Settings.Application.DISPATCHER_INTERVAL < 500) { log.Warn("DISPATCHER_INTERVAL {0} should not be lower than 500", Settings.Application.DISPATCHER_INTERVAL); } _dispatcherTimer.Elapsed += new System.Timers.ElapsedEventHandler(dispatcherTimer_Tick); _dispatcherTimer.Interval = Settings.Application.DISPATCHER_INTERVAL; _dispatcherTimer.Start(); LoadFastResumeData(); _torrentSession.start_natpmp(); _torrentSession.start_upnp(); _torrentSession.start_dht(); _torrentSession.start_lsd(); _torrentSession.resume(); log.Info("created"); //Dht = new Core.AdunanzaDht(); //Dht.start(); //Dht.bootstrap("bootstrap.ring.cx", "4222"); }
public static void DoInference(Core.Session session, Core.DeclFunct funct) { var inferencer = new FunctTypeInferencer(session, funct); inferencer.ApplyRules(); }
private static Core.Session CreateSession(Panel parent) { Core.Session session = null; CreateSessionBox box = CreateSessionBox.Show(); if (box.notcanceled) { session = new Core.Session(parent, box.Name, Protsenko.TheoryEditor.Core.Session.ConstructorMods.New); } else { throw new Exception(LanguageResource.currentDictionary["errorCreationAborted"]); } return session; }
private FunctTypeInferencer(Core.Session session, Core.DeclFunct funct) { this.session = session; this.funct = funct; }
public static void CloseSession() { Operation operation = new Operation("Close session"); OperationsHandler.OperationStarts(operation); try { if (session != null) { operation.Name += " " + session.Name; MessageBoxResult result = MessageBox.Show(LanguageResource.currentDictionary["requestSaveSession"], "?", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { session.SaveData(); } if (result != MessageBoxResult.Cancel) { session.Close(); session = null; SessionDeleted(session, new EventArgs()); } } else throw new Exception(LanguageResource.currentDictionary["errorNotInitializedSession"]); } catch (Exception exc) { Core.Debug.ExceptionHandler.exceptionHandler.Add(exc); } Core.Debug.OperationsHandler.OperationComlete(operation); }
private static void TerminateSaveResume() { _torrentSession.clear_alert_dispatch(); using (var entry = _torrentSession.save_state(0xfffffff)) { var data = Core.Util.bencode(entry); File.WriteAllBytes(".session_state", data); } _torrentSession?.Dispose(); _torrentSession = null; }
public override string GetString(Core.Session session) { return("_"); }