<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>WebAssembly on Jefferson Oliveira</title><link>https://jeffersonmourak.com/tags/webassembly/</link><description>Recent content in WebAssembly on Jefferson Oliveira</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>All content provided by this website are my own opinons and beliefs and are distrubuted under the &lt;br/></copyright><lastBuildDate>Tue, 12 May 2026 08:27:04 -0201</lastBuildDate><atom:link href="https://jeffersonmourak.com/tags/webassembly/index.xml" rel="self" type="application/rss+xml"/><item><title>Pleasure to meet you, circ!</title><link>https://jeffersonmourak.com/blog/circ-en/</link><pubDate>Tue, 12 May 2026 08:27:04 -0201</pubDate><guid>https://jeffersonmourak.com/blog/circ-en/</guid><category domain="https://jeffersonmourak.com/tags/compilers/">Compilers</category><category domain="https://jeffersonmourak.com/tags/languages/">Languages</category><category domain="https://jeffersonmourak.com/tags/webassembly/">WebAssembly</category><category domain="https://jeffersonmourak.com/tags/dsl/">DSL</category><category>Compiler</category><category>Zig</category><description>&lt;p>Hey y&amp;rsquo;all! If you&amp;rsquo;ve been following the fundamentals of computing series here, you&amp;rsquo;ve noticed those little widgets. You can click them, toggle the switches, watch the LEDs light up, peek at the circuit topology. Today I want to tell you what&amp;rsquo;s actually running in them, because I made it.&lt;/p>
&lt;p>It&amp;rsquo;s called &lt;code>circ&lt;/code>. It&amp;rsquo;s a small language for describing digital circuits, and a compiler that turns the description into something your browser can run. First of all I want you to understand this isn&amp;rsquo;t a serious systems language (&lt;em>yet&lt;/em>), and I believe it&amp;rsquo;s great for this blog but not ready for production. For now it exists for the sole purpose of having the circuits here &lt;em>actually work&lt;/em>, instead of being static drawings or handcrafted simulators.&lt;/p></description><content:encoded><![CDATA[<p>Hey y&rsquo;all! If you&rsquo;ve been following the fundamentals of computing series here, you&rsquo;ve noticed those little widgets. You can click them, toggle the switches, watch the LEDs light up, peek at the circuit topology. Today I want to tell you what&rsquo;s actually running in them, because I made it.</p>
<p>It&rsquo;s called <code>circ</code>. It&rsquo;s a small language for describing digital circuits, and a compiler that turns the description into something your browser can run. First of all I want you to understand this isn&rsquo;t a serious systems language (<em>yet</em>), and I believe it&rsquo;s great for this blog but not ready for production. For now it exists for the sole purpose of having the circuits here <em>actually work</em>, instead of being static drawings or handcrafted simulators.</p>
<h2 id="how-it-reads">How it reads</h2>
<p>I think the best way to introduce a language is to let you look at it. Here&rsquo;s a half-adder written in <code>.circ</code>:</p>
<pre tabindex="0"><code>input a, b

xor s(a=a, b=b)
and c(a=a, b=b)

output sum(in=s.out)
output carry(in=c.out)
</code></pre><p>That&rsquo;s the whole file. You declare your inputs, you instantiate gates and give them names, you wire each gate&rsquo;s ports to the signals that drive them, and you declare which signals leave through the outputs. Doesn&rsquo;t it read a little like a recipe? <em>Take two inputs. Combine <code>a</code> and <code>b</code> with an XOR, call it <code>s</code>. Combine the same two with an AND, call it <code>c</code>. Send <code>s.out</code> to the <code>sum</code> output, <code>c.out</code> to the <code>carry</code>.</em> That&rsquo;s it.</p>
<p>The primitives are deliberately tiny: <code>input</code>, <code>output</code>, <code>and</code>, <code>not</code>, <code>wire</code>, <code>led</code>. Six things. Everything else is built from those.</p>
<p>And here&rsquo;s a detail I&rsquo;m a little smug about: the built-in gates <code>or</code>, <code>nand</code>, <code>nor</code>, <code>xor</code>, <code>xnor</code> are themselves written in <code>.circ</code>. The compiler&rsquo;s entire &ldquo;standard library&rdquo; is five tiny files that look exactly like the one above. When you write <code>xor s(a=a, b=b)</code>, the compiler quietly pulls in a five-line file that defines XOR in terms of AND, OR, and NAND. The language is small enough to be its own standard library, and that makes me unreasonably happy.</p>
<h2 id="where-it-came-from">Where it came from</h2>
<p><code>circ</code> didn&rsquo;t start as a language. It started as me wanting to draw circuits.</p>
<p>I&rsquo;d been writing this series for a while, and every circuit in every post was a static SVG I&rsquo;d hand-drawn or coaxed out of a TypeScript renderer I kept patching. The drawings worked, but they were <em>just drawings</em>. You couldn&rsquo;t toggle a switch and watch the LED change. You couldn&rsquo;t ask &ldquo;what does this circuit <em>do</em>, exactly?&rdquo; and get an answer. They were illustrations of computers, not computers.</p>
<p>Around the same time I bought <a href="https://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p"><em>The Elements of Computing Systems</em></a>, and this book hexed me (pun intended) with the curse of curiosity, which led me right into <a href="https://www.nand2tetris.org/"><em>Nand to Tetris</em></a>. In it, you build everything from a single NAND gate, in a tiny language called HDL, and every component you write actually runs. The combination of &ldquo;describe a circuit in a few lines&rdquo; and &ldquo;now press play and watch it work&rdquo; is how circuits should feel when you&rsquo;re learning about them. So I wanted that, for this blog, for you. The widgets in the posts you&rsquo;ve already read are the result.</p>
<p>The name is the most boring part of the story: <code>circ</code> is short for circuit (<em>I am not a poet, sorry.</em>)</p>
<h2 id="the-two-things-i-love-most">The two things I love most</h2>
<p>Once the compiler started working, two things fell out of it that I didn&rsquo;t expect to love as much as I do.</p>
<p>The first is that <code>circ</code> can draw itself. Hand it a circuit and it&rsquo;ll produce an ASCII schematic, complete with rounded corners, fan-out dots, and wires that detour politely around gates that sit in their way. Here&rsquo;s the half-adder from earlier, rendered by the compiler itself:</p>
<pre tabindex="0"><code>╭───╮     ╭───╮         ╭───────╮
│ a ├○─●─▶┤   │ ╭──────▶┤ carry │
╰───╯  │  │AND├○╯       ╰───────╯
      ╭┼─▶┤   │
      ││  ╰───╯
      ││
╭───╮ ││  ╭───────╮     ╭─────╮
│ b ├○●╰─▶┤       │ ╭──▶┤ sum │
╰───╯ │   │[xor:s]├○╯   ╰─────╯
      ╰──▶┤       │
          ╰───────╯
</code></pre><p>The second is that <code>circ</code> can tabulate itself. Hand it the same file and ask for <code>--truth-table</code>, and you get:</p>
<table>
  <thead>
      <tr>
          <th>a</th>
          <th>b</th>
          <th>sum</th>
          <th>cout</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>0</td>
          <td>0</td>
          <td>0</td>
          <td>0</td>
      </tr>
      <tr>
          <td>1</td>
          <td>0</td>
          <td>1</td>
          <td>0</td>
      </tr>
      <tr>
          <td>0</td>
          <td>1</td>
          <td>1</td>
          <td>0</td>
      </tr>
      <tr>
          <td>1</td>
          <td>1</td>
          <td>0</td>
          <td>1</td>
      </tr>
  </tbody>
</table>
<p>That&rsquo;s the beauty of it: using only 5 lines you have a circuit description, a picture of itself, and proof that it does what it claims. Every interactive widget in every post of this series has been <code>circ</code> doing this quietly in the background, three times over. Once to render the schematic you see, once to run the simulation when you toggle a switch, once to prove the gates behave the way I said they would.</p>
<h2 id="until-we-meet-again">Until we meet again</h2>
<p>That&rsquo;s just the surface of it. There&rsquo;s a parser, a resolver, a validator with stable error codes, a tiny WebAssembly runtime that the compiler embeds inside every artifact so the whole thing runs in your browser without needing any toolchain on your machine. But those are stories for other days.</p>
<p>If you want to dig deeper, the language has a home of its own at <a href="https://circ-lang.org/">circ-lang.org</a>, with the full reference and more examples than I could fit here.</p>
<p>For now, the next time you click on a widget in one of these posts, you&rsquo;ll know what you&rsquo;re looking at. It&rsquo;s <code>circ</code>. Pleasure to meet you.</p>
<h3 id="special-thanks">Special thanks</h3>
<p>Before we say goodbye, I want to give a special shoutout to <a href="https://clarete.li/">@clarete</a>. He is the brain behind <a href="https://clarete.li/langlang/">langlang</a>, the parser generator that powers this language. He has been hammering my ears about langlang for years and I couldn&rsquo;t be more proud of what he has done.</p>
<h2 id="references">References</h2>
<ul>
<li><a href="https://github.com/jeffersonmourak/circ-compiler"><code>circ-compiler</code> on GitHub</a></li>
<li><a href="https://circ-lang.org/">circ-lang.org</a>, the language reference and examples</li>
<li><a href="https://ziglang.org/">Zig</a></li>
<li><a href="https://clarete.li/langlang/">langlang</a>, the PEG parser generator that builds the <code>.circ</code> grammar</li>
<li><a href="https://www.nand2tetris.org/">From Nand to Tetris</a></li>
</ul>
]]></content:encoded></item><item><title>Prazer, circ!</title><link>https://jeffersonmourak.com/blog/circ/</link><pubDate>Tue, 12 May 2026 08:27:04 -0200</pubDate><guid>https://jeffersonmourak.com/blog/circ/</guid><category domain="https://jeffersonmourak.com/tags/compiladores/">Compiladores</category><category domain="https://jeffersonmourak.com/tags/linguagens/">Linguagens</category><category domain="https://jeffersonmourak.com/tags/webassembly/">WebAssembly</category><category domain="https://jeffersonmourak.com/tags/dsl/">DSL</category><category>Zig</category><description>&lt;p>Olá pessoal, tudo bom? Se vocês têm acompanhado a série de fundamentos da computação aqui, com certeza notaram aqueles circuitinhos. Dá pra clicar neles, mexer nos interruptores, ver os LEDs acendendo, espiar a topologia do circuito. Hoje eu quero contar o que de verdade está rodando neles, porque fui eu que fiz.&lt;/p>
&lt;p>Ele se chama &lt;code>circ&lt;/code>. É uma linguagem pra descrever circuitos digitais, e um compilador que transforma essa descrição em algo que o seu navegador consegue rodar. Antes de mais nada, quero deixar claro: isso não é uma linguagem séria de sistemas (&lt;em>ainda&lt;/em>), e eu acredito que é ótima pra esse blog mas não está pronta pra produção. Por enquanto ela existe pelo único motivo de fazer os circuitos daqui &lt;em>funcionarem de verdade&lt;/em>, em vez de serem desenhos estáticos ou simuladores feitos na mão.&lt;/p></description><content:encoded><![CDATA[<p>Olá pessoal, tudo bom? Se vocês têm acompanhado a série de fundamentos da computação aqui, com certeza notaram aqueles circuitinhos. Dá pra clicar neles, mexer nos interruptores, ver os LEDs acendendo, espiar a topologia do circuito. Hoje eu quero contar o que de verdade está rodando neles, porque fui eu que fiz.</p>
<p>Ele se chama <code>circ</code>. É uma linguagem pra descrever circuitos digitais, e um compilador que transforma essa descrição em algo que o seu navegador consegue rodar. Antes de mais nada, quero deixar claro: isso não é uma linguagem séria de sistemas (<em>ainda</em>), e eu acredito que é ótima pra esse blog mas não está pronta pra produção. Por enquanto ela existe pelo único motivo de fazer os circuitos daqui <em>funcionarem de verdade</em>, em vez de serem desenhos estáticos ou simuladores feitos na mão.</p>
<h2 id="aprendendo-a-ler">Aprendendo a ler</h2>
<p>Eu acho que a melhor forma de apresentar uma linguagem é deixar você olhar pra ela. Aqui está um meio-somador (<em>half-adder</em>) escrito em <code>.circ</code>:</p>
<pre tabindex="0"><code>input a, b

xor s(a=a, b=b)
and c(a=a, b=b)

output sum(in=s.out)
output carry(in=c.out)
</code></pre><p>É o arquivo inteiro. Você declara as suas entradas, instancia as portas e dá um nome pra elas, conecta as portas de cada uma aos sinais que as alimentam, e declara quais sinais saem pelas saídas. Não parece um pouco com uma receita? <em>Pegue duas entradas. Combine <code>a</code> e <code>b</code> com um XOR, chame de <code>s</code>. Combine as mesmas duas com um AND, chame de <code>c</code>. Mande <code>s.out</code> pra saída <code>sum</code>, e <code>c.out</code> pra <code>carry</code>.</em> É isso.</p>
<p>As primitivas são propositalmente minúsculas: <code>input</code>, <code>output</code>, <code>and</code>, <code>not</code>, <code>wire</code>, <code>led</code>. Seis coisas. Todo o resto é construído a partir delas.</p>
<p>E aqui vai um detalhe do qual eu me orgulho um pouco: as portas <code>or</code>, <code>nand</code>, <code>nor</code>, <code>xor</code>, <code>xnor</code> também são escritas em <code>.circ</code>. A &ldquo;biblioteca padrão&rdquo; inteira do compilador são cinco arquivos que se parecem exatamente com o de cima. Quando você escreve <code>xor s(a=a, b=b)</code>, o compilador silenciosamente puxa um arquivo de cinco linhas que define XOR em termos de AND, OR e NAND. A linguagem é pequena o suficiente pra ser a sua própria biblioteca padrão, e isso pra mim é fascinante.</p>
<h2 id="senta-que-lá-vem-história">Senta que lá vem história</h2>
<p><code>circ</code> não começou como uma linguagem. Começou como eu querendo desenhar circuitos.</p>
<p>Eu vinha escrevendo essa série há um tempo, e todo circuito de todo post era um SVG estático que eu tinha desenhado na mão ou arrancado de um renderizador em TypeScript que eu não parava de remendar. Os desenhos funcionavam, mas eram <em>só desenhos</em>. Você não podia mexer numa chave e ver o LED mudar. Você não podia perguntar &ldquo;o que esse circuito <em>faz</em>, exatamente?&rdquo; e receber uma resposta. Eram ilustrações de computadores, não computadores.</p>
<p>Mais ou menos na mesma época eu comprei o <a href="https://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p"><em>The Elements of Computing Systems</em></a>, e esse livro explodiu minha cabeça e me levou direto pro <a href="https://www.nand2tetris.org/"><em>Nand to Tetris</em></a>. Nele, você constrói tudo a partir de uma única porta NAND, numa linguagenzinha chamada HDL, e cada componente que você escreve realmente roda. A combinação de &ldquo;descreva um circuito em poucas linhas&rdquo; e &ldquo;agora aperte play e veja funcionar&rdquo; é como deveria ser quando você está aprendendo sobre circuitos. Então eu quis isso, pra esse blog, pra você. Os widgets dos posts que você já leu são o resultado.</p>
<p>O nome é a parte mais sem graça da história: <code>circ</code> é abreviação de <em>circuit</em> (<em>não sou poeta, desculpa.</em>)</p>
<h2 id="as-cerejas-do-bolo">As cerejas do bolo</h2>
<p>Assim que o compilador começou a funcionar, duas coisas saíram dele que eu não esperava amar tanto quanto amo.</p>
<p>A primeira é que o <code>circ</code> consegue se desenhar. Entrega um circuito pra ele e ele produz um esquema em ASCII, completo com cantos arredondados, pontos de fan-out, e fios que desviam educadamente das portas que estão no caminho. Aqui está o meio-somador de antes, renderizado pelo próprio compilador:</p>
<pre tabindex="0"><code>╭───╮     ╭───╮         ╭───────╮
│ a ├○─●─▶┤   │ ╭──────▶┤ carry │
╰───╯  │  │AND├○╯       ╰───────╯
      ╭┼─▶┤   │
      ││  ╰───╯
      ││
╭───╮ ││  ╭───────╮     ╭─────╮
│ b ├○●╰─▶┤       │ ╭──▶┤ sum │
╰───╯ │   │[xor:s]├○╯   ╰─────╯
      ╰──▶┤       │
          ╰───────╯
</code></pre><p>A segunda é que o <code>circ</code> consegue se tabular. Entrega o mesmo arquivo pra ele e peça <code>--truth-table</code>, e você recebe:</p>
<table>
  <thead>
      <tr>
          <th>a</th>
          <th>b</th>
          <th>sum</th>
          <th>cout</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>0</td>
          <td>0</td>
          <td>0</td>
          <td>0</td>
      </tr>
      <tr>
          <td>1</td>
          <td>0</td>
          <td>1</td>
          <td>0</td>
      </tr>
      <tr>
          <td>0</td>
          <td>1</td>
          <td>1</td>
          <td>0</td>
      </tr>
      <tr>
          <td>1</td>
          <td>1</td>
          <td>0</td>
          <td>1</td>
      </tr>
  </tbody>
</table>
<p>Essa é a beleza da coisa: usando só 5 linhas você tem a descrição do circuito, uma imagem dele mesmo, e a prova de que ele faz o que diz que faz. Cada widget interativo de cada post dessa série tem sido o <code>circ</code> fazendo isso silenciosamente no fundo, três vezes seguidas. Uma vez pra renderizar o esquema que você vê, uma vez pra rodar a simulação quando você mexe numa chave, e uma vez pra provar que as portas se comportam do jeito que eu disse que iam se comportar.</p>
<h2 id="até-a-próxima">Até a próxima</h2>
<p>Isso é só a superfície. Tem um parser, um resolvedor, um validador com códigos de erro estáveis, um pequeno runtime em WebAssembly que o compilador injeta dentro de cada artefato pra que tudo rode no seu navegador sem precisar de toolchain nenhum na sua máquina. Mas essas são histórias pra outros dias.</p>
<p>Se quiser se aprofundar, a linguagem tem um site só pra ela em <a href="https://circ-lang.org/">circ-lang.org</a>, com a referência completa e mais exemplos do que coube aqui.</p>
<p>Por enquanto, da próxima vez que você clicar num widget em um desses posts, você vai saber o que está vendo. É o <code>circ</code>. Prazer em te conhecer.</p>
<h3 id="agradecimentos-especiais">Agradecimentos especiais</h3>
<p>Antes de nos despedirmos, eu quero dar um agradecimento especial pro <a href="https://clarete.li/">@clarete</a>. Ele é o cérebro por trás do <a href="https://clarete.li/langlang/">langlang</a>, o gerador de parsers que dá vida pra essa linguagem. Ele vem martelando meus ouvidos sobre o langlang há anos, e eu não poderia estar mais orgulhoso do que ele construiu.</p>
<h2 id="referências">Referências</h2>
<ul>
<li><a href="https://github.com/jeffersonmourak/circ-compiler"><code>circ-compiler</code> no GitHub</a></li>
<li><a href="https://circ-lang.org/">circ-lang.org</a>, a referência da linguagem e exemplos</li>
<li><a href="https://ziglang.org/">Zig</a></li>
<li><a href="https://clarete.li/langlang/">langlang</a>, o gerador de parser PEG que constrói a gramática do <code>.circ</code></li>
<li><a href="https://www.nand2tetris.org/">From Nand to Tetris</a></li>
</ul>
]]></content:encoded></item></channel></rss>