Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 54 lines (45 sloc) 1.288 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
.sub '' :anon :load :init
    load_bytecode 'HLL.pbc'
    load_bytecode 'P6Regex.pbc'
.end

.include 'gen_grammar.pir'
.include 'gen_actions.pir'
.include 'gen_jst.pir'
.include 'gen_past2jst.pir'
.include 'gen_jst2java.pir'
.include 'gen_jst2jasm.pir'
.loadlib 'io_ops'

.sub 'main' :main
    .param pmc args

    # Do we have an argument saying we're compiling the setting?
    $P0 = new ['Integer']
    .lex '$*COMPILING_NQP_SETTING', $P0
    $S0 = args[2]
    if $S0 != '--setting' goto not_setting
    $P0 = 1
  not_setting:
    
    .local pmc g, a, pastcomp, jstcomp
    g = get_hll_global ['JnthnNQP'], 'Grammar'
    a = get_hll_global ['JnthnNQP'], 'Actions'
    pastcomp = get_hll_global 'PAST2JSTCompiler'

    $S0 = args[2]
    if $S0 == '--jasm' goto jasm
    jstcomp = get_hll_global 'JST2JavaCompiler'
    goto comp_done
  jasm:
    jstcomp = get_hll_global 'JST2JASMCompiler'
  comp_done:
    
    .local string filename, file
    .local pmc fh
    filename = args[1]
    fh = open filename, 'r'
    fh.'encoding'('utf8')
    file = fh.'readall'()
    fh.'close'()
    
    .local pmc match, ast, jst, compiled
    match = g.'parse'(file, 'actions'=>a)
    ast = match.'ast'()
    jst = pastcomp.'compile'(ast)

    compiled = jstcomp.'compile'(jst)
    say compiled
.end
Something went wrong with that request. Please try again.