<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Asrp Blog</title>
    <description>Blog at A Self-Referential Place</description>
    <link>https://blog.asrpo.com</link>

    <item>
      <title>Flpc internals: model and bootstrapping</title>
      <link>https://blog.asrpo.com/flpc_internals_1_bootstrapping</link>
      <pubDate>Sat Jul  3 16:20:19 2021 +0000</pubDate>
      <description><![CDATA[<p>The <a href="https://github.com/asrp/flpc">Forth Lisp Python Continuum</a> (Flpc) is a small high dynamic programming language I'm making. In these series of posts, I will describe and discuss its inner workings, more or less in the order that they are run when the program starts.</p>

<p>This will hopefully help with others making programming languages and serve as some kind of documentation. Though Flpc was designed to be relatively easy to change,
there is a surprising amount that stayed unchanged since the start of this project, perhaps unfortunately. I'm sure some of this post will still become outdatated and the intended final format is an interactive tutorial to teach you how to recreate Flpc so different design decisions can be made (similar to <a href="https://github.com/asrp/maketheseslides">How to make these slides</a>) but we're still very far from that.</p>

<p>I've recently ported Flpc's C source to <a href="https://nim-lang.org">Nim</a>, which now runs faster than C (when all Nim/underlying C compiler optimization flags are turned on) thanks to folks from the Nim forum.</p>]]></description>
    </item>
    <item>
      <title>Instruction level just-in-time programming</title>
      <link>https://blog.asrpo.com/jit_programming</link>
      <pubDate>Thu May  6 20:39:01 2021 +0000</pubDate>
      <description><![CDATA[<p>Just-in-time programming is a workflow for creating a program top-down, while a program is running. This is typical in Smalltalk environments like <a href="https://squeak.org">Squeak</a>.</p>

<p>In this post, I want to describe an <em>instruction level</em> variant of this.</p>

<p>I think the best way to describe instruction level just-in-time programming (IL-JIT programming) is by showing how it works. I'll start with the classic Fibonacci example (<a href="https://rosettacode.org/wiki/Fibonacci_sequence">Rosetta code has many implementations</a>). We'll implement Fibonacci while evaluating <code>fib(3)</code>.</p>]]></description>
    </item>
    <item>
      <title>Adding a minimal foreign function interface to your language</title>
      <link>https://blog.asrpo.com/minimal_ffi</link>
      <pubDate>Tue Feb  9 20:21:17 2021 +0000</pubDate>
      <description><![CDATA[<p>A foreign function interface (FFI) is a way for one language to call functions from another language.</p>

<p>The most common FFIs are C FFIs where the target language is C.</p>

<p>I just pushed a new version of <a href="https://github.com/asrp/flpc">Flpc</a> where I added a very limited FFI for calling Python. Highlights of some other changes are:</p>]]></description>
    </item>

    <item>
      <title>Speed improvements using hash tables</title>
      <link>https://blog.asrpo.com/hashtables</link>
      <pubDate>Sat May 16 15:11:37 2020 +0000</pubDate>
      <description><![CDATA[<p>I wrote the <a href="https://github.com/asrp/flpc">Forth Lisp Python Continuum</a> (Flpc)'s self hosted compiler in stages. When I completed the parser and gave it larger and larger pieces of its own source code, it was running too slow. I tried many things to speed it up, one that helped was using hash tables.</p>

<p>They helped make dictionaries [names] which can</p>

<p>An example of a dictionary:</p>]]></description>
    </item>
    <item>
      <title>Flpc is now self-hosted</title>
      <link>https://blog.asrpo.com/flpc_is_now_self_hosted</link>
      <pubDate>Sun Apr 19 15:27:47 2020 +0000</pubDate>
      <description><![CDATA[<p>The Forth Lisp Python Continuum (Flpc) can now compile its own source code! Get it from <a href="https://github.com/asrp/flpc">Github</a>.</p>

<p>So instead of</p>
<pre><code>$ python compiler.py file1.flpc file2.flpc file3.flpc &gt; output.f
</code></pre>
<p>you can now run</p>
<pre><code>$ ./flpc precompiled/compiler.f
&gt; push: output.f init_g
&gt; push: file1.flpc compile_file
&gt; push: file2.flpc compile_file
&gt; push: file3.flpc compile_file
</code></pre>
]]></description>
    </item>
    <item>
      <title>Roll your own GUI automation library</title>
      <link>https://blog.asrpo.com/python_gui_automation</link>
      <pubDate>Mon Oct 21 10:37:25 2019 +0000</pubDate>
      <description><![CDATA[<p><a href="http://sikulix.com">Sikuli</a> is a tool for automating repetitive tasks.</p>

<p><img src="guiauto/sikuli-small.png" alt="Screenshot of Sikuli" title="" /></p>

<p>To automate a program, it makes use of screenshots and image recognition to decide where to click and type [automation_methods]. As you can see above, Sikuli uses Python for its script's language (plus rendered image). But under the hood, its implemented in Java and runs Jython. Since nothing Sikuli uses really needs Java, we'll try to implement some GUI automation in pure Python.</p>]]></description>
    </item>
    <item>
      <title>Nand to CPU</title>
      <link>https://blog.asrpo.com/nand2cpu</link>
      <pubDate>Thu Sep 27 20:22:34 2018 +0000</pubDate>
      <description><![CDATA[<p><a href="https://www.nand2tetris.org">Nand to Tetris</a> is a course that teaches you how to build a computer up from nand gates</p>

<p><img src="nand/Nand-gate-en.svg" alt="nand gate" title="" /></p>

<p>and then program Tetris for your computer. <a href="https://www.nandgame.com">Nand game</a> cover the first 3 projects of the course using a nice drag-and-drop interface</p>

<p>Nand game includes a number of (in my opinion) improvements to the presentation. I feel it really lets me get to the crux of the matter quickly.</p>

<p>This post contains solutions to Nand game and therefore Nand to Tetris. Try them first if you haven't already.</p>

<p>One thing I wish I could do in Nand game is to experiment with the CPU designs (rather than just implement an existing design). I quite like their interface but am much quicker (and used to) a text interface. </p>]]></description>
    </item>
    
    <item>
      <title>Making a low level (Linux) debugger, part 3: our first program</title>
      <link>https://blog.asrpo.com/making_a_low_level_debugger_part_3</link>
      <pubDate>Fri Jul  6 14:57:28 2018 +0000</pubDate>
      <description><![CDATA[<p>This continues a series where we make a debugger and live editor for (re)creating assembly and C programs.</p>

<p>In <a href="making_a_low_level_debugger">part 1</a>, we got the assembly parts: read/write registers and memory, single step, single instruction execution, function calls (although not perfect), set/restore breakpoints, memory allocation and examining upcoming instructions.</p>

<p>In <a href="making_a_low_level_debugger_part_2">part 2</a>, we got the C parts: read/write variables using ptrace and memory maps, a C read-eval-print loop (REPL), line numbers from DWARF headers and undo using <code>fork()</code>.</p>

<p>Its now time to actually use our debugger/editor! We'll try to use it to write a C program.</p>]]></description>
    </item>

    <item>
      <title>Making a low level (Linux) debugger part 2: C</title>
      <link>https://blog.asrpo.com/making_a_low_level_debugger_part_2</link>
      <pubDate>Sat Jun 23 01:35:09 2018 +0000</pubDate>
      <description><![CDATA[<p><a href="making_a_low_level_debugger.html">Last time</a>, we started making a debugger and live editor for (re)creating assembly and C programs.</p>

<p>We got all the assembly parts: read/write registers and memory, single step, single instruction execution, function calls (although not perfect), set/restore breakpoints, memory allocation and examining upcoming instructions.</p>

<p>This post will try to do similar things in the C portion. Next time, we'll try using it to make something.</p>]]></description>
    </item>

    <item>
      <title>Making a low level (Linux) debugger</title>
      <link>https://blog.asrpo.com/making_a_low_level_debugger</link>
      <pubDate>Fri Jun 15 02:01:02 2018 +0000</pubDate>
      <description><![CDATA[<p><a href="https://www.gnu.org/s/gdb/">gdb</a> and <a href="https://lldb.llvm.org/">lldb</a> are the best known debuggers to me. While they are both customizable with scripts, there are many times where I'd like have much more control over how my debugger works (both the interactive portion and its internal representation).</p>

<p>Being able to recreate <a href="https://github.com/asrp/flpc">flpc</a> in a more interactive ways is one of these times. In this post, I try to make a debugger from more primitive pieces: the ptrace system call wrapped by the <a href="http://python-ptrace.readthedocs.io/en/latest/gdb.html">python-ptrace library</a>, <a href="https://github.com/eliben/pyelftools">pyelftools</a> and later on, the disassembly library <a href="https://pypi.org/project/distorm3/">distorm3</a>.</p>

<p>Because those debuggers are very large projects, trying to remake them seem daunting. But since I mostly want to debug and live-edit a binary I've created, I don't need maximum compatibility. Simplicity will be favoured over completeness when it seems like a good trade. Hopefully, this post itself exposes enough of the underlying ideas to bridge the gap in case of a slightly different environment and standard.</p>]]></description>
    </item>

    <item>
      <title>Describing animations</title>
      <link>https://blog.asrpo.com/animation</link>
      <pubDate>Tue May  8 02:24:57 2018 +0000</pubDate>
      <description><![CDATA[Flipbooks provide the simplest of animation and the basic principle remain the same with computers.

      <p><img src="anim/Flipbook.jpg" alt="Flipbook from Wikimedia commons" title="" /></p>

      <p>Display a sequence of images fast enough and the eye perceives motion. In this post, I want to look at possible architectures and APIs for an animations library (to potentially be used with <a href="https://github.com/asrp/maketheseslides">Make these slides</a> or plain <a href="https://github.com/asrp/guitktk">guitktk</a>).</p>]]></description>
    </item>
    <item>
      <title>Collaborative software trades</title>
      <link>https://blog.asrpo.com/collaborative_trades</link>
      <pubDate>Fri Apr 27 13:37:58 2018 +0000</pubDate>
      <description><![CDATA[There are many computer programs I'd like to use and modify that do not exist. In this post, I put forth the idea of a (different?) kind of collaboration to achieve this that I've had for a while now.

      <h2>Trades</h2>

      <p>Basically, the idea is to coordinate with a group where each person makes one program and when we are all done, the union contains many programs that each person wants.</p>]]></description>
    </item>
    <item>
      <title>Combining all my github projects into one</title>
      <link>https://blog.asrpo.com/the_plan</link>
      <pubDate>Wed Mar 28 00:39:51 2018 +0000</pubDate>
      <description><![CDATA[<p>I've been making projects <a href="https://github.com/asrp">avaible on Github</a> for a while now. The last one was <a href="https://github.com/asrp/guitktk">guitktk</a>. What I didn't say much about is that all the repositories are intended to form one big project. (Most of them also have uses on their own.)</p>]]></description>
    </item>
    <item>
      <title>Removing polling checks in guitktk</title>
      <link>https://blog.asrpo.com/removing_polling</link>
      <pubDate>Sat Mar  3 23:56:03 2018 +0000</pubDate>
      <description><![CDATA[Updating a rectangular bounding box of a selection was a bit of a hack in <a href="gui_toolkit.html">guitktk</a>: every frame the selection was checked for changes and the rectangle recreated if needed. In this post, I'll show how to remove that check using "formulas" for parameter values.]]></description>
    </item>
    <item>
      <title>Are there any interpreted languages?</title>
      <link>https://blog.asrpo.com/are_there_interpreted_languages</link>
      <pubDate>Thu Feb 22 07:20:46 2018 +0000</pubDate>
      <description><![CDATA[
      <p><strong>Update</strong>: This post got many good comments and useful answers summarized at the very end.</p>

      Or rather, are there any widely used <em>implementations</em> of a popular-enough language that directly interpret ASTs (or similar)? [1] Anything that doesn't compile to assembly to bytecode would do.]]></description>
    </item>
    <item>
      <title>Debugging C like it's Python</title>
      <link>https://blog.asrpo.com/debugging_c_like_python</link>
      <pubDate>Sat Feb 17 19:51:44 2018 +0000</pubDate>
      <description><![CDATA[I use the Python interpreter interactively and <a href="https://docs.python.org/3/library/pdb.html">pdb</a> (as well as <a href="https://github.com/gotcha/ipdb">ipdb</a>) a lot and they let me understand my programs' state and test new things out quickly.

      <p>When writing <a href="https://github.com/asrp/flpc">Flpc</a> in C, I found it a difficult to transition. In this post, I describe how to use <a href="https://www.gnu.org/s/gdb/">gdb</a> to get a similar workflow.</p>]]></description>
    </item>
    <item>
      <title>Adding a new statement to Python's syntax in python_terp</title>
      <link>https://blog.asrpo.com/adding_new_statement</link>
      <pubDate>Sun Feb  4 22:03:22 2018 +0000</pubDate>
      <description><![CDATA[This <a href="https://stackoverflow.com/questions/214881/can-you-add-new-statements-to-pythons-syntax/9108164#9108164">stackoverflow answer</a> [1] shows how to add an <code>until</code> statement to Python. In this post I will show how to do that in <a href="https://github.com/asrp/python_terp">python_terp</a> and how to debug these modifications.]]></description>
    </item>
    <item>
      <title>Another tutorial for writing a Forth interpreter in assembly (Part 3)</title>
      <link>https://blog.asrpo.com/forth_tutorial_part_3</link>
      <pubDate>Sun Oct  8 17:23:49 2017 +0000</pubDate>
      <description><![CDATA[<a href="https://github.com/asrp/forth_tutorial/blob/master/forth22/forth.asm">Direct link to the final (pregenerated) interpreter at the end of this tutorial</a>. Try running
      <pre><code>nasm -f elf64 forth.asm -o forth.o ;and ld forth.o ;and ./a.out &lt; test2.f
</code></pre>

      <p>inside <a href="https://github.com/asrp/forth_tutorial/blob/master/forth22">forth22</a>.</p>]]></description>
    </item>
    <item>
      <title>Another tutorial for writing a Forth interpreter in assembly (Part 2)</title>
      <link>https://blog.asrpo.com/forth_tutorial_part_2</link>
      <pubDate>Wed Oct  4 01:15:12 2017 +0000</pubDate>
      <description><![CDATA[
      <p>With the major part of Forth written in Forth, we can now them in "Forth-style" assembly (using <code>call</code>/<code>ret</code>). We will still have to write all the primitive functions in assembly.</p>]]></description>
    </item>
    <item>
      <title>Another tutorial for writing a Forth interpreter in assembly (Part 1)</title>
      <link>https://blog.asrpo.com/forth_tutorial_part_1</link>
      <pubDate>Wed Oct  4 01:14:47 2017 +0000</pubDate>
      <description><![CDATA[This tutorial will teach you how to make a Forth interpreter in assembly with initial prototype simulators made in Python.]]></description>
    </item>
    <item>
      <title>The chicken or the egg problem in bootstrapping</title>
      <link>https://blog.asrpo.com/bootstrap_chicken_or_egg</link>
      <pubDate>Mon May  8 10:19:35 2017 +0000</pubDate>
      <description><![CDATA[
      <blockquote>
      <p>Which came first? The chicken or the egg?</p>
      </blockquote>
      <p>This post discusses bootstrapping: the first step when trying to make something new. Bootstrapping is needed in many places.</p>]]></description>
    </item>
    <item>
      <title>Making a GUI toolkit</title>
      <link>https://blog.asrpo.com/gui_toolkit</link>
      <pubDate>Mon Apr 17 12:17:45 2017 +0000</pubDate>
      <description><![CDATA[A step is missing between <a href="https://github.com/asrp/pymetaterp">pymetaterp</a>, the (eventual) Python-like interpreter, and <a href="https://github.com/asrp/tkui">tkui</a> the self modifying GUI editor: a GUI toolkit. Tkinter fills that role right now.]]></description>
    </item>
    <item>
      <title>Visual explanation of a Google Codejam 2017 question</title>
      <link>https://blog.asrpo.com/gcj_qual2017</link>
      <pubDate>Sun Apr  9 12:26:14 2017 +0000</pubDate>
      <description><![CDATA[This is the last question from the <a href="https://code.google.com/codejam/contest/3264486/dashboard#s=p3">Google Codejam 2017 qualification round</a>.]]></description>
    </item>
    <item>
      <title>Allowing multiple read-only servers in pyzdb</title>
      <link>https://blog.asrpo.com/pyzdb_multiple_read</link>
      <pubDate>Sat Feb 11 12:53:33 2017 +0000</pubDate>
      <description><![CDATA[I finally changed <a href="https://github.com/asrp/pyzdb">pyzdb</a> to support multiple servers. Actually, multiple read servers with a single write server. This post discusses the design and implementation selected. The pyzdb README now contains an example of how to use it.]]></description>
    </item>
    <item>
      <title>Messing with Python's sort function</title>
      <link>https://blog.asrpo.com/python_sort</link>
      <pubDate>Tue Jan 24 09:52:55 2017 +0000</pubDate>
      <description><![CDATA[There are many interesting things about python's <code>sort</code> function like how its adapts depending on the input, how its stable in-place, how its in other languages and <a href="http://envisage-project.eu/proving-android-java-and-python-sorting-algorithm-is-broken-and-how-to-fix-it/">how it could give the wrong result</a>. This post is about none of those.]]></description>
    </item>
    <item>
      <title>Python list and dict with undo</title>
      <link>https://blog.asrpo.com/undo-redo</link>
      <pubDate>Sun Jan 22 09:21:58 2017 +0000</pubDate>
      <description><![CDATA[I've made some python list and dict with undo and redo so I can play back and forth the operations applied to them. Its on <a href="https://github.com/asrp/undoable">Github</a>.]]></description>
    </item>
  </channel>
</rss>

