{"action":"created","comment":{"url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/comments/191124864","pull_request_review_id":123638253,"id":191124864,"diff_hunk":"@@ -0,0 +1,142 @@\n+﻿using System;\n+using System.Collections.Generic;\n+using System.Linq;\n+using DaedalusCompiler.Dat;\n+\n+namespace DaedalusCompiler.Compilation\n+{\n+    public class DatBuilder\n+    {\n+        private int _currentAddress;\n+        private readonly List<DatSymbol> _symbols;\n+        private readonly List<ExecBlock> _execBlocks;\n+\n+        public DatBuilder(AssemblyBuilder assemblyBuilder)\n+        {\n+            _currentAddress = 0;\n+            _symbols = assemblyBuilder.Symbols;\n+            _execBlocks = assemblyBuilder.ExecBlocks;\n+        }\n+\n+        private int GetSymbolId(DatSymbol symbol)\n+        {\n+            return _symbols.IndexOf(symbol);\n+        }\n+\n+        private Dictionary<string, int> GetLabelToAddressDict(ExecBlock execBlock)\n+        {\n+            Dictionary<string, int> labelToAddress = new Dictionary<string, int>();\n+\n+            foreach (var instruction in execBlock.Body)\n+            {\n+                switch (instruction)\n+                {\n+                    case PushArrayVar _:\n+                    {\n+                        _currentAddress += 6;\n+                        break;\n+                    }\n+\n+                    case JumpToLabel _:\n+                    case SymbolInstruction _:\n+                    case ValueInstruction _:\n+                    {\n+                        _currentAddress += 5;\n+                        break;\n+                    }\n+\n+                    case ParamLessInstruction _:\n+                    {\n+                        _currentAddress += 1;\n+                        break;\n+                    }\n+                    \n+                    \n+\n+                    case AssemblyLabel assemblyLabel:\n+                    {\n+                        labelToAddress[assemblyLabel.Label] = _currentAddress;\n+                        break;\n+                    }\n+                }\n+            }\n+\n+            return labelToAddress;\n+        }\n+\n+        private List<DatToken> GetTokens(ExecBlock execBlock)\n+        {\n+            List<DatToken> tokens = new List<DatToken>();\n+            Dictionary<string, int> labelToAddress = GetLabelToAddressDict(execBlock);\n+\n+            foreach (var instruction in execBlock.Body)\n+            {\n+                if (instruction is AssemblyLabel)\n+                {\n+                    continue;\n+                }\n+                \n+                \n+                int? intParam = null;\n+                byte? byteParam = null;\n+                switch (instruction)\n+                {\n+                    case PushArrayVar pushArrVar:\n+                    {\n+                        intParam = GetSymbolId(pushArrVar.Symbol);\n+                        byteParam = (byte) pushArrVar.Index;\n+                        break;\n+                    }\n+                    case JumpToLabel jumpToLabel:\n+                    {\n+                        intParam = labelToAddress[jumpToLabel.Label];\n+                        break;\n+                    }\n+                    case SymbolInstruction symbolInstruction:\n+                    {\n+                        intParam = GetSymbolId(symbolInstruction.Symbol);\n+                        break;\n+                    }\n+                    case ValueInstruction valueInstruction:\n+                    {\n+                        intParam = (int) valueInstruction.Value;\n+                        break;\n+                    }\n+                    case AddressInstruction addressInstruction: // TODO check if there is any possibility for this\n+                    {\n+                        intParam = addressInstruction.Address;\n+                        break;\n+                    }\n+                }\n+\n+                \n+                string tokenName = instruction.GetType().Name;\n+                if (tokenName.EndsWith(\"ToLabel\"))","path":"src/DaedalusCompiler/Compilation/DatBuilder.cs","position":114,"original_position":114,"commit_id":"bb5621765cf315b6d3746da8807dc807447fb651","original_commit_id":"bb5621765cf315b6d3746da8807dc807447fb651","user":{"login":"arturkasperek","id":6894763,"avatar_url":"https://avatars2.githubusercontent.com/u/6894763?v=4","gravatar_id":"","url":"https://api.github.com/users/arturkasperek","html_url":"https://github.com/arturkasperek","followers_url":"https://api.github.com/users/arturkasperek/followers","following_url":"https://api.github.com/users/arturkasperek/following{/other_user}","gists_url":"https://api.github.com/users/arturkasperek/gists{/gist_id}","starred_url":"https://api.github.com/users/arturkasperek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arturkasperek/subscriptions","organizations_url":"https://api.github.com/users/arturkasperek/orgs","repos_url":"https://api.github.com/users/arturkasperek/repos","events_url":"https://api.github.com/users/arturkasperek/events{/privacy}","received_events_url":"https://api.github.com/users/arturkasperek/received_events","type":"User","site_admin":false},"body":"Please instead compering strings check if instruction is type `JumpToLabel`.","created_at":"2018-05-28T06:54:23Z","updated_at":"2018-05-28T06:55:13Z","html_url":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13#discussion_r191124864","pull_request_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/comments/191124864"},"html":{"href":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13#discussion_r191124864"},"pull_request":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13","id":190821043,"html_url":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13","diff_url":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13.diff","patch_url":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13.patch","issue_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/13","number":13,"state":"open","locked":false,"title":"successfully compiled .DAT file and opened in DecDat","user":{"login":"Kisioj","id":6262202,"avatar_url":"https://avatars3.githubusercontent.com/u/6262202?v=4","gravatar_id":"","url":"https://api.github.com/users/Kisioj","html_url":"https://github.com/Kisioj","followers_url":"https://api.github.com/users/Kisioj/followers","following_url":"https://api.github.com/users/Kisioj/following{/other_user}","gists_url":"https://api.github.com/users/Kisioj/gists{/gist_id}","starred_url":"https://api.github.com/users/Kisioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kisioj/subscriptions","organizations_url":"https://api.github.com/users/Kisioj/orgs","repos_url":"https://api.github.com/users/Kisioj/repos","events_url":"https://api.github.com/users/Kisioj/events{/privacy}","received_events_url":"https://api.github.com/users/Kisioj/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-28T02:14:13Z","updated_at":"2018-05-28T06:55:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a012bba97493a9de3fa8494b0af793fc90f3fece","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13/commits","review_comments_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13/comments","review_comment_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/13/comments","statuses_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/statuses/bb5621765cf315b6d3746da8807dc807447fb651","head":{"label":"Kisioj:DatBuilder-MVP","ref":"DatBuilder-MVP","sha":"bb5621765cf315b6d3746da8807dc807447fb651","user":{"login":"Kisioj","id":6262202,"avatar_url":"https://avatars3.githubusercontent.com/u/6262202?v=4","gravatar_id":"","url":"https://api.github.com/users/Kisioj","html_url":"https://github.com/Kisioj","followers_url":"https://api.github.com/users/Kisioj/followers","following_url":"https://api.github.com/users/Kisioj/following{/other_user}","gists_url":"https://api.github.com/users/Kisioj/gists{/gist_id}","starred_url":"https://api.github.com/users/Kisioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kisioj/subscriptions","organizations_url":"https://api.github.com/users/Kisioj/orgs","repos_url":"https://api.github.com/users/Kisioj/repos","events_url":"https://api.github.com/users/Kisioj/events{/privacy}","received_events_url":"https://api.github.com/users/Kisioj/received_events","type":"User","site_admin":false},"repo":{"id":133282287,"name":"DaedalusCompiler","full_name":"Kisioj/DaedalusCompiler","owner":{"login":"Kisioj","id":6262202,"avatar_url":"https://avatars3.githubusercontent.com/u/6262202?v=4","gravatar_id":"","url":"https://api.github.com/users/Kisioj","html_url":"https://github.com/Kisioj","followers_url":"https://api.github.com/users/Kisioj/followers","following_url":"https://api.github.com/users/Kisioj/following{/other_user}","gists_url":"https://api.github.com/users/Kisioj/gists{/gist_id}","starred_url":"https://api.github.com/users/Kisioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kisioj/subscriptions","organizations_url":"https://api.github.com/users/Kisioj/orgs","repos_url":"https://api.github.com/users/Kisioj/repos","events_url":"https://api.github.com/users/Kisioj/events{/privacy}","received_events_url":"https://api.github.com/users/Kisioj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kisioj/DaedalusCompiler","description":null,"fork":true,"url":"https://api.github.com/repos/Kisioj/DaedalusCompiler","forks_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/forks","keys_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/teams","hooks_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/hooks","issue_events_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/issues/events{/number}","events_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/events","assignees_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/assignees{/user}","branches_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/branches{/branch}","tags_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/tags","blobs_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/statuses/{sha}","languages_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/languages","stargazers_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/stargazers","contributors_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/contributors","subscribers_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/subscribers","subscription_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/subscription","commits_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/contents/{+path}","compare_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/merges","archive_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/downloads","issues_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/issues{/number}","pulls_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/pulls{/number}","milestones_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/milestones{/number}","notifications_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/labels{/name}","releases_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/releases{/id}","deployments_url":"https://api.github.com/repos/Kisioj/DaedalusCompiler/deployments","created_at":"2018-05-13T23:27:55Z","updated_at":"2018-05-27T22:01:56Z","pushed_at":"2018-05-28T02:13:19Z","git_url":"git://github.com/Kisioj/DaedalusCompiler.git","ssh_url":"git@github.com:Kisioj/DaedalusCompiler.git","clone_url":"https://github.com/Kisioj/DaedalusCompiler.git","svn_url":"https://github.com/Kisioj/DaedalusCompiler","homepage":null,"size":518,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dzieje-khorinis:master","ref":"master","sha":"a1723bf4f3ea7394c462fd51dd791585ffd5b8c4","user":{"login":"dzieje-khorinis","id":38348048,"avatar_url":"https://avatars0.githubusercontent.com/u/38348048?v=4","gravatar_id":"","url":"https://api.github.com/users/dzieje-khorinis","html_url":"https://github.com/dzieje-khorinis","followers_url":"https://api.github.com/users/dzieje-khorinis/followers","following_url":"https://api.github.com/users/dzieje-khorinis/following{/other_user}","gists_url":"https://api.github.com/users/dzieje-khorinis/gists{/gist_id}","starred_url":"https://api.github.com/users/dzieje-khorinis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dzieje-khorinis/subscriptions","organizations_url":"https://api.github.com/users/dzieje-khorinis/orgs","repos_url":"https://api.github.com/users/dzieje-khorinis/repos","events_url":"https://api.github.com/users/dzieje-khorinis/events{/privacy}","received_events_url":"https://api.github.com/users/dzieje-khorinis/received_events","type":"Organization","site_admin":false},"repo":{"id":129379933,"name":"DaedalusCompiler","full_name":"dzieje-khorinis/DaedalusCompiler","owner":{"login":"dzieje-khorinis","id":38348048,"avatar_url":"https://avatars0.githubusercontent.com/u/38348048?v=4","gravatar_id":"","url":"https://api.github.com/users/dzieje-khorinis","html_url":"https://github.com/dzieje-khorinis","followers_url":"https://api.github.com/users/dzieje-khorinis/followers","following_url":"https://api.github.com/users/dzieje-khorinis/following{/other_user}","gists_url":"https://api.github.com/users/dzieje-khorinis/gists{/gist_id}","starred_url":"https://api.github.com/users/dzieje-khorinis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dzieje-khorinis/subscriptions","organizations_url":"https://api.github.com/users/dzieje-khorinis/orgs","repos_url":"https://api.github.com/users/dzieje-khorinis/repos","events_url":"https://api.github.com/users/dzieje-khorinis/events{/privacy}","received_events_url":"https://api.github.com/users/dzieje-khorinis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dzieje-khorinis/DaedalusCompiler","description":"Daedalus ( Gothic I & II scripting language ) Compiler to DAT","fork":false,"url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler","forks_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/forks","keys_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/teams","hooks_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/hooks","issue_events_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/events{/number}","events_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/events","assignees_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/assignees{/user}","branches_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/branches{/branch}","tags_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/tags","blobs_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/statuses/{sha}","languages_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/languages","stargazers_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/stargazers","contributors_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/contributors","subscribers_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/subscribers","subscription_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/subscription","commits_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/contents/{+path}","compare_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/merges","archive_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/downloads","issues_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues{/number}","pulls_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls{/number}","milestones_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/milestones{/number}","notifications_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/labels{/name}","releases_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/releases{/id}","deployments_url":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/deployments","created_at":"2018-04-13T09:27:22Z","updated_at":"2018-05-27T22:02:06Z","pushed_at":"2018-05-28T02:14:13Z","git_url":"git://github.com/dzieje-khorinis/DaedalusCompiler.git","ssh_url":"git@github.com:dzieje-khorinis/DaedalusCompiler.git","clone_url":"https://github.com/dzieje-khorinis/DaedalusCompiler.git","svn_url":"https://github.com/dzieje-khorinis/DaedalusCompiler","homepage":"","size":506,"stargazers_count":3,"watchers_count":3,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13"},"html":{"href":"https://github.com/dzieje-khorinis/DaedalusCompiler/pull/13"},"issue":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/13"},"comments":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/dzieje-khorinis/DaedalusCompiler/statuses/bb5621765cf315b6d3746da8807dc807447fb651"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"arturkasperek"}}