{"id":202,"date":"2009-06-13T10:59:31","date_gmt":"2009-06-13T08:59:31","guid":{"rendered":"http:\/\/www.coolbasic.com\/blog\/?p=202"},"modified":"2009-06-13T10:59:31","modified_gmt":"2009-06-13T08:59:31","slug":"coolbasic-intermediate-language","status":"publish","type":"post","link":"https:\/\/www.coolbasic.com\/blog\/2009\/06\/13\/coolbasic-intermediate-language\/","title":{"rendered":"CoolBasic Intermediate Language"},"content":{"rendered":"<p>Perhaps the title of the previous blog entry could\u2019ve been better thought out. For some reason, I keep reading it wrong &#8220;IL logic is gone&#8221;, and I\u2019m not sure if I\u2019m the only one \ud83d\ude42 . In addition, &#8220;program logic&#8221; is a term that\u2019s basically the less technical alternative to &#8220;algorithm&#8221;. In the previous post, I was referring to how the execution bounces between &#8220;labels&#8221; generated by program flow control structures such as conditions and loops. Anyways, for today\u2019s post I also have news about Intermediate Language, only this time I actually mean how separate lines are executed expression-wise (which also can be referred to as &#8220;logic&#8221;).<\/p>\n<p>I have now almost finished those necessary functions that are responsible for generating the high-level instructions from each line of the original source code. This is essentially the base for &#8220;Byte code&#8221; that is used by runtime interpreters. The order of tokens, in CoolBasic Intermediate Language, is fixed so that they can be processed and calculated very efficiently at runtime. You can learn more about <strong>postfix notation<\/strong> in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Reverse_Polish_notation\">this wiki article<\/a>. <\/p>\n<p>The following CoolBasic code:<\/p>\n<pre name=\"code\" class=\"cb\">Module M\n\tFunction R()\n\t\tDim i As Integer\n\t\ti *= i + (6 \/ i) - i * 2\n\tEndFunction\nEndModule<\/pre>\n<p>&#8230; will compile into:<\/p>\n<pre>.method public shared m.r ()\n{\n.size 4\nIL_000002: ldloc     m.r.i\nIL_000003: ldloc     m.r.i\nIL_000004: ldc.i4    6\nIL_000005: ldloc     m.r.i\nIL_000006: div       \nIL_000007: add       \nIL_000008: ldloc     m.r.i\nIL_000009: ldc.i4    1\nIL_000010: shl       \nIL_000011: sub       \nIL_000012: mul       \nIL_000013: stloc     m.r.i\nIL_000014: ldc.i4    0\n           IL_prog_6_end:\nIL_000016: ret       \n}<\/pre>\n<p>Operator data type pairs don\u2019t show there, but those are to be determined later. Please also notice that this is not a complete program. I merely wanted to give you a demonstration that CoolBasic Intermediate Language generation is quite mature already. You can also see some code optimization in this example. However, there\u2019s much more into it than simply performing binary shifts instead of multiplication or division in certain situations. The CoolBasic compiler is able to generate the equivalent IL from almost any language feature now.<\/p>\n<p>IL generation from expressions also means that most if not all of the error messages (and so error checks) are done, and that every statement has reached their final design. During this time I have fixed quite a lot of bugs, none of which has proved to be overwhelming enough to compel me to come up with a work-around. There\u2019s also been some bigger challenges such as property behavior with the direct assign operators (+=, -= etc), field access with long dot notation paths, constructor calls, and IL generation for special operators (to be revealed later). Minor and small problems usually take only minutes to solve, but bigger ones can take up several hours until I come up with a solution of some sort. Looking back, those &#8220;difficult&#8221; problems have solved quite nicely, and now that I think of all the benefits I\u2019ve gained thanks to them, there\u2019s no gum code into it after all.<\/p>\n<p>In addition to technical coding, I\u2019ve also established the new www-portal framework I\u2019m experimenting with. CoolBasic web page will feature lots of dynamic content in the future, maybe even some kind of a publishing interface for admins. I\u2019m also thinking of ways to bind this dynamic content to the development environment. As a small side-note I\u2019ve also spent some time on new icon candidates for CoolBasic files, and at least the Vista versions look quite nice already.<\/p>\n<p>The next blog entry will in all probability be just an announcement of two things: for one, of me having finished IL generation entirely. About the second I don&#8217;t want to talk about yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perhaps the title of the previous blog entry could\u2019ve been better thought out. For some reason, I keep reading it wrong &#8220;IL logic is gone&#8221;, and I\u2019m not sure if I\u2019m the only one \ud83d\ude42 . In addition, &#8220;program logic&#8221; is a term that\u2019s basically the less technical alternative to &#8220;algorithm&#8221;. In the previous post, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[5,8],"_links":{"self":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/202"}],"collection":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":0,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}