Skip to content

Instantly share code, notes, and snippets.

hll := 'nqp';
code := 'Q:PIR { say $S0 };';
sa[ 0] := '.sub "" :anon';
sa[ 1] := ' .param string hll';
sa[ 2] := ' .param string code';
sa[ 3] := ' ';
sa[ 4] := ' $P0 = compreg hll';
sa[ 5] := ' unless_null $P0, compile';
sa[ 6] := ' load_language "nqprx"';
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parrot/embed.h"
#include "parrot/extend.h"
Parrot_String create_string(Parrot_Interp interp, const char *name)
{
return Parrot_new_string(interp, name, strlen(name), (const char *) NULL, 0)
procedure TDrvParrot.write(outStream: TFileStream);
var
pbc: String;
len: cardinal;
begin
pbc := Parrot_str_to_cstring(interp, out_pbc);
len := Parrot_str_byte_length(interp, out_pbc);
writeln(len);
outStream.write(PChar(pbc)^, len)
end;
.sub comp
.param string hll
.param string code
$P0 = compreg hll
unless_null $P0, compile
load_language "nqprx"
$P0 = compreg "NQP-rx"
compile:
$P1 = $P0."compile"(code)
$P1 = $P1()
make: `lorito' is up to date.
real 0m0.009s
user 0m0.010s
sys 0m0.000s
{atrodo@lorito}> perl lasm.pl < t/00_sanity.t > t/00_sanity.lor
{atrodo@lorito}> prove -e ./lorito t/00_sanity.lor
t/00_sanity.lor .. ok
All tests successful.
Files=1, Tests=4, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.00 cusr 0.01 csys = 0.05 CPU)
Result: PASS
{atrodo@lorito}> prove -v -e ./lorito t/00_sanity.lor

Lorito

Below, you will find my braindump of Lorito after having written a Lorito prototype. I will try and go through each Lorito page on the parrot wiki and explain my differences and the important points of each page.

Lorito

LoritoPurpose

@atrodo
atrodo / gist:650578
Created October 28, 2010 03:38
Less magic == More magic
What I learned from trying to implement Lorito, especially things that were underspecified, in as unorganized mess as
possible.
I learned a few things. First, a simple VM is pretty easy. Really, it's a SMOP task. And fun. I had just enough
guidance, especially from allison's 20 opcode email, to make something that resembled usable.
Second, there might have be some assumptions in place that I may not have realized. Parrot is a large beast that has quite
a bit of history. Most of which, I haven't had the introduction to that others might have. To me, Parrot is a CISC VM
that has it's hundreds of instructions defined by PASM/PIR with 4 registers, the last, PMCs, are rather magical and
apparently, C.
@atrodo
atrodo / lorito_braindump.pod
Created December 10, 2010 14:49
lorito braindump

lorito braindump

atrodo's brain

1 - context is the new interp
  - context contains the PC, INSP regs, other stuff as needed (outPC, ehPC, payload, parentContext)
    I<I like this idea. To what I've done, the context/interp definition has changed.  The interp
      is the core that runs the code, but really, all the guts are in the context.>
    - there's no goto.  You assign to the PC
      I<I'm not sure how this would work.  Will the PC have a special register, or would there be
{atrodo@squaak}> ./installable_squaak --target=parse t/00-sanity.t
"parse" => PMC 'Regex;Match' => "x = 42\n" @ 0 {
<statementlist> => PMC 'Regex;Match' => "x = 42\n" @ 0 {
<stat_or_def> => ResizablePMCArray (size:1) [
PMC 'Regex;Match' => "x = 42\n" @ 0 {
<statement> => PMC 'Regex;Match' => "x = 42\n" @ 0 {
<assignment> => PMC 'Regex;Match' => "x = 42\n" @ 0 {
<primary> => PMC 'Regex;Match' => "x " @ 0 {
<identifier> => PMC 'Regex;Match' => "x" @ 0 {
<ident> => PMC 'Regex;Match' => "x" @ 0