[Parrot-users] Hacking the interactive method of the HLL Compiler

Jay Emerson jayemerson at gmail.com
Wed Jul 6 21:31:57 UTC 2011


I stole the method interactive PIR code from HLLCompiler.pir,
verbatim; I wrapped it into NQP inside of Compiler.pm, shown below.
When I try to build, I get the following error.  Advice?  The problem
seems to be the line "    $I0 = is_cclass .CCLASS_NEWLINE, $S1, 0
"

Andrew throught it was a parse error because is_class_i isn't an
opcode, but almost all of this was just copied directly.  I'm probably
just not overriding the HLLCompiler interactive method in the right
way? I must be doing something silly.

jay at bayesman:~/Desktop/SVN/Q/nqr$ parrot setup.pir
"/usr/local/bin/parrot" -o nqr/nqr.pbc src/nqr.pir
error:imcc:The opcode 'is_cclass_i' (is_cclass<1>) was not found.
Check the type and number of the arguments
	in file 'src/gen_compiler.pir' line 155
	included from 'src/nqr.pir' line 1
exit status: 256
command: "/usr/local/bin/parrot" -o nqr/nqr.pbc src/nqr.pir

-----------------
# Compiler.pm, where most of the code inside the interactive method
comes straight from HLLCompiler.pir.

class nqr::Compiler is HLL::Compiler;

INIT {

    nqr::Compiler.language('nqr');
    nqr::Compiler.parsegrammar(nqr::Grammar);
    nqr::Compiler.parseactions(nqr::Actions);
    nqr::Compiler.commandline_banner("Not Quite R for Parrot VM.\n");
    nqr::Compiler.commandline_prompt('> ');
}

method interactive(*%adverbs) {
  return Q:PIR {
    .local pmc adverbs
    adverbs = find_lex '%adverbs'                           # Changed
to get the arguments in?
    #.param pmc adverbs         :slurpy :named
    .local string target, encoding
    target = adverbs['target']
    target = downcase target

    # on startup show the welcome message
    $P0 = self.'commandline_banner'()
    $P1 = getinterp
    $P2 = $P1.'stderr_handle'()
    $P2.'print'($P0)

    .local pmc stdin
    .local int has_readline
    $P0 = getinterp
    stdin = $P0.'stdin_handle'()
    encoding = adverbs['encoding']
    if encoding == 'fixed_8' goto interactive_loop
    unless encoding goto interactive_loop
    stdin.'encoding'(encoding)
  interactive_loop:
    .local pmc code
    unless stdin goto interactive_end

    .local string prompt
    prompt = '> '
    $P0 = self.'commandline_prompt'()
    $I0 = defined $P0
    unless $I0 goto have_prompt
    prompt = $P0
  have_prompt:

    ##  display a prompt ourselves if readline isn't present
  interactive_read:
    code = stdin.'readline_interactive'(prompt)
    if null code goto interactive_end
    unless code goto interactive_loop
    code = concat code, "\n"
    push_eh interactive_trap
    $P0 = self.'eval'(code, adverbs :flat :named)
    pop_eh
    if null $P0 goto interactive_loop
    unless target goto interactive_loop
    if target == 'pir' goto target_pir
    self.'dumper'($P0, target, adverbs :flat :named)
    goto interactive_loop
  target_pir:
    say $P0
    goto interactive_loop
  interactive_trap:
    get_results '0', $P0
    pop_eh
    $S0 = $P0
    if $S0 == '' goto have_newline
    $S1 = substr $S0, -1, 1
    $I0 = is_cclass .CCLASS_NEWLINE, $S1, 0
    if $I0 goto have_newline
    $S0 = concat $S0, "\n"
  have_newline:
    print $S0
    goto interactive_loop
  interactive_end:
    .return ()
  };
}




-- 
John W. Emerson (Jay)
Associate Professor of Statistics
Department of Statistics
Yale University
http://www.stat.yale.edu/~jay


More information about the Parrot-users mailing list