{"id":394,"date":"2014-08-16T15:06:49","date_gmt":"2014-08-16T15:06:49","guid":{"rendered":"http:\/\/www.coolbasic.com\/blog\/?p=394"},"modified":"2014-08-16T15:06:49","modified_gmt":"2014-08-16T15:06:49","slug":"very-temporary","status":"publish","type":"post","link":"https:\/\/www.coolbasic.com\/blog\/2014\/08\/16\/very-temporary\/","title":{"rendered":"VERY TEMPORARY"},"content":{"rendered":"<p>Today I\u2019m going to talk about some old stuff. Don\u2019t worry though, most of you haven\u2019t seen it yet. A year ago, at our traditional summer meeting, I demoed some very early and experimental  CoolBasic builds. The reason I want to show code and screens this old, is so that it\u2019s easier to explain about how things have since changed in the future coming blog posts.<\/p>\n<p>Back in 2013 I actually had a working environment that consisted of a code editor, CoolBasic compiler, and a debugging runtime. You could write CoolBasic code, pass it to the compiler and finally execute it. It couldn\u2019t render game graphics or play sounds, but the very basic text input and output was in place. At that time I focused on code execution rather than game libraries. Control structures, strings, arrays, types, operators, all that kind of stuff. As a result, the demo was probably very boring to watch, but hey, at least it was executing something!<\/p>\n<h2>The Compiler<\/h2>\n<p>The compiler was naturally the number one priority to get done. In refreshment, it\u2019s written in C#, running on .NET CLR and Mono, and is a standalone console application so it can be called from anywhere. It wasn\u2019t feature complete back then (for example, Select&#8230;Case was missing,) but it could handle most control structures and generate the final bytecode.<\/p>\n<p>Compilers aren\u2019t very exciting, though. All you need to know is it\u2019s now faster, more feature-rich, and hasn\u2019t got a function limit.<\/p>\n<h2>A VERY TEMPORARY Editor<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_editor.png\" alt=\"The VERY TEMPORARY editor\" \/><\/p>\n<p>Before you go to the forums and start complaining about how awful it looks, mind the window title. Guess why it\u2019s called \u201cVERY TEMPORARY EDITOR\u201d. The caps are intended. This will *not* be the editor that will ship &#8211; don\u2019t worry. I promise.<\/p>\n<p>In short, I just wanted to test <strong>a)<\/strong> how easy it is to integrate the compiler into an IDE, and <strong>b)<\/strong> could I perhaps use <a href=\"http:\/\/avalonedit.net\/\" title=\"AvalonEdit\">AvalonEdit<\/a> as the editing control as opposed to the commercial <a href=\"http:\/\/www.actiprosoftware.com\/products\/controls\/wpf\/syntaxeditor\" title=\"Actipro Syntax Editor\">Actipro SyntaxEditor<\/a>. I\u2019m already quite familiar with the Actipro component (had a chance to use it in a work project) and I know it is the state-of-the-art option, but perhaps that would be a little bit of an overkill for my purposes.<\/p>\n<p>As it turns out, AvalonEdit is just perfect, at least for the starters; I can always upgrade to Actipro later. AvalonEdit offers configurable syntax highlighting out of the box, supports code completion popups, and is generally fairly extendable. Syntax highlighting definition is loaded from an external XML file, and the list of commands provided by the game engine is imported from a special \u201cframework definition file\u201d that I can generate automatically off a compiled executable or DLL (via reflection.)<\/p>\n<p>It was pretty easy to invoke the compiler, have its output written in a textbox, and parse off any errors it would report. All in all, a successful little test editor.<\/p>\n<h2>A VERY TEMPORARY Runtime<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_0.png\" alt=\"The VERY TEMPORARY runtime\" \/><\/p>\n<p>That\u2019s not a real game engine. It\u2019s actually just a normal WPF application powered by the new Cool VES virtual machine.  In fact, the only available commands are <code>Print<\/code>, <code>Input<\/code>, and <code>Timer<\/code> (for benchmarking.) The intention was to establish a simple \u201cconsole\u201d which would provide basic input and output so that I could test that the virtual machine doesn\u2019t corrupt the virtual stack or leak memory at any point.<\/p>\n<p>For this reason there are some debugging features available. At any time, I can click this cute pause button:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_pause\" alt=\"The pause button\" \/><\/p>\n<p>This will halt the virtual machine that\u2019s executing the code. While paused, this UI becomes available:<\/p>\n<h6>Metadata: symbols<\/h6>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_1.png\" alt=\"Debug info: metadata\" \/><\/p>\n<p>This view lists all functions and variables and their types. Symbol information is needed for a number of reasons. Firstly, the debugger can emit more meaningful call stacks when the functions\u2019 names are known. Secondly, the runtime can perform proper clean-up when returning from a function as it knows which resources are stored in heap.<\/p>\n<h6>Bytecode<\/h6>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_2.png\" alt=\"Debug info: disassembled program\" \/><\/p>\n<p>This listing represents the current program in its \u201cdisassembled\u201d form. Here I can see that the program was decoded properly and matches with what the compiler spat out.<\/p>\n<h6>Managed resources<\/h6>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_3.png\" alt=\"Debug info: managed resources\" \/><\/p>\n<p>Remember how <code>LoadImage<\/code> would return a handle that you\u2019d then store into a variable for later use? These handles are called \u201cResources\u201d internally in Cool VES. For more efficient memory management Cool VES keeps a list on what has been loaded. It\u2019s not a real (unmanaged) memory pointer, but a reference to an internal object that also contains metadata of that object.<\/p>\n<p>Interestingly, also <strong>strings<\/strong> are managed resources and they, too have handles that are manipulated every time a string is stored in and consumed off the stack.<\/p>\n<h6>Call stack and locals<\/h6>\n<p><img decoding=\"async\" src=\"http:\/\/www.coolbasic.com\/common\/images\/archives\/2014\/08\/very_temporary_runtime_4.png\" alt=\"Debug info: virtual stack\" \/><\/p>\n<p>If I want to see the low-level state about the executing program, this is the view I\u2019m interested in. I can inspect the values of each variable, for each function within the call stack. This information, of course, would be presented in a more intuitive way in a real debugger.<\/p>\n<p>So that\u2019s how things were a year ago. Nowadays the compiler is pretty much feature complete, and the real code editor is in the works. I also did some engine experiments based on the DirectX10 interface (initially on DX11, but for whatever reason DirectWrite that I use for text rendering isn\u2019t easily usable in it.) More on these topics in future coming posts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I\u2019m going to talk about some old stuff. Don\u2019t worry though, most of you haven\u2019t seen it yet. A year ago, at our traditional summer meeting, I demoed some very early and experimental CoolBasic builds. The reason I want to show code and screens this old, is so that it\u2019s easier to explain about [&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,6,7],"_links":{"self":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/394"}],"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=394"}],"version-history":[{"count":7,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/394\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}