Author: kjs
Date: Thu Feb 21 11:24:15 2008
New Revision: 25942

Added:
   trunk/languages/c99/src/builtins/
   trunk/languages/c99/src/builtins/say.pir   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/languages/c99/c99.pir

Log:
[c99]
-update main file
-add builtins file and directory
-update MANIFEST

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Thu Feb 21 11:24:15 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools\dev\mk_manifest_and_skip.pl Thu Feb 21 19:18:22 2008 UT
+# generated by tools\dev\mk_manifest_and_skip.pl Thu Feb 21 19:22:54 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -1165,6 +1165,7 @@
 languages/c99/src/CPP_ASTGrammar.tg                         [c99]
 languages/c99/src/CPP_PASTNodes.pir                         [c99]
 languages/c99/src/CPP_PGE2AST.pir                           [c99]
+languages/c99/src/builtins/say.pir                          [c99]
 languages/c99/src/c99.pg                                    [c99]
 languages/c99/src/c99_PGE.pir                               [c99]
 languages/c99/src/parser/actions.pm                         [c99]

Modified: trunk/languages/c99/c99.pir
==============================================================================
--- trunk/languages/c99/c99.pir (original)
+++ trunk/languages/c99/c99.pir Thu Feb 21 11:24:15 2008
@@ -1,247 +1,71 @@
-=head1 NAME
+=head1 TITLE
 
-c99 -- A parser for c99 
+c99.pir - A C99 compiler.
 
-=head1 SYNOPSIS
+=head2 Description
 
-  $ ./parrot languages/c99/c99.pir code.c
+This is the base file for the C99 compiler.
 
-=head1 DESCRIPTION
+This file includes the parsing and grammar rules from
+the src/ directory, loads the relevant PGE libraries,
+and registers the compiler under the name 'C99'.
 
-  c99 is a PGE parser running on Parrot.
+=head2 Functions
+
+=over 4
+
+=item onload()
+
+Creates the C compiler using a C<PCT::HLLCompiler>
+object.
 
 =cut
 
-.HLL 'c99', 'c99_group'
-.include 'errors.pasm'
-.include 'library/dumper.pir'
+.namespace [ 'C99::Compiler' ]
 
-.sub _main :main
-    .param pmc args
-    
-    errorson .PARROT_ERRORS_PARAM_COUNT_FLAG
-    
-    load_bytecode 'PGE.pbc'
-    load_bytecode 'dumper.pbc'
-    load_bytecode 'PGE/Dumper.pbc'
-    load_bytecode 'PGE/Text.pbc'
-    load_bytecode 'Getopt/Obj.pbc'
-    
-    print "Parrot C99 Compiler\n"
-
-    load_bytecode 'languages/c99/src/c99_PGE.pbc'
-    load_bytecode 'languages/c99/src/CPP_PGE2AST.pbc'
-    load_bytecode 'languages/c99/src/CPP_PASTNodes.pbc'
-    load_bytecode 'languages/c99/src/CPP_AST2Constants.pbc'
-    #load_bytecode 'languages/c99/src/CPP_POST.pbc'
-    #load_bytecode 'languages/c99/src/CPP_PGE2AST.pbc'
-    #load_bytecode 'languages/c99/src/CPP_AST2OST.pbc'
-    #load_bytecode 'languages/c99/src/CPP_OST2PIR.pbc'
-
-    .local pmc _dumper
-    .local pmc getopts
-    .local pmc opts
-    .local string arg0
-    _dumper = get_root_global [ 'parrot' ], '_dumper'
-    arg0 = shift args
-    getopts = new 'Getopt::Obj'
-    getopts.'notOptStop'(1)
-    push getopts, 'target=s'
-    push getopts, 'constants'
-    opts = getopts.'get_options'(args)
-
-    $S0 = opts['help']
-    if $S0 goto usage
-    .local int constants
-    constants = opts['constants']
-
-
-    .local int stopafter
-    .local string dump
-    .local string target
-    .local int dump_src_early
-    .local int dump_pge
-    .local int dump_ast
-    .local int dump_constants
-    
-    .local pmc c99_compiler
-    .local string filename
-    .local string source
-    
-    stopafter = 10
-    dump_src_early = 1
-    dump_pge = 1
-    dump_ast = 1
-    dump_constants = 1
-
-   c99_compiler = compreg 'C99'
-    
-    $I0 = elements args
-    if $I0 > 0 goto file_arg
-
-  stdin_arg:
-    .local pmc stdin
-    filename = "STDIN"
-    stdin = getstdin
-    push stdin, 'utf8'
-    # enable interactive readline if possible
-    $I0 = stdin.'set_readline_interactive'(1)
-
-  stdin_read_loop:
-    .local string stmt
-    stmt = stdin.'readline'('c99> ')
-    unless stmt goto end
-    #bsr c99_eval
-    goto stdin_read_loop
-
-  file_arg:
-    filename = args[1]
-    source = slurp_file(filename)
-    goto compile_it
-
-  usage:
-    print "usage: c99.pbc [-o output] [file]\n"
-    end
-
-  compile_it:
-    .local pmc parse_tree
-    .local pmc start_rule
-    
-    unless dump_src_early goto after_src_dump_early
-    print "\n\nSource dump:\n"
-    print source
-  after_src_dump_early:
-
-    start_rule = get_root_global [ 'parrot'; 'C99::Grammar'], 
'translation_unit'
-    start_rule = get_root_global [ 'parrot'; 'C99::Grammar'], 
'prereprocessing_file'
-    parse_tree = start_rule(source, 'grammar'=> 'C99::Grammar')
-
-    # Verify the parse was successful
-    $I0 = parse_tree.__get_bool()
-    unless $I0 goto err_parse_fail
-
-    unless dump_pge goto after_pge_dump
-    print "Parse succeeded: C99 PGE parse tree dump:\n"
-    _dumper(parse_tree, "C99 PGE Parse Tree Dump")
-  after_pge_dump:
-    eq stopafter, 1, end
-    
-    # "Traverse" the parse tree
-    .local pmc grammar
-    .local pmc astbuilder
-    .local pmc ast
-    grammar = new 'C99::CPP::ASTGrammar'
-    astbuilder = grammar.apply(parse_tree)
-    ast = astbuilder.get('result')
-    $I0 = defined ast
-    unless $I0 goto err_no_ast 
-
-    unless dump_ast goto after_ast_dump
-    print "\n\nAST tree dump:\n"
-    _dumper(ast)
-    #ast.'dump'()
-  after_ast_dump:
-    eq stopafter, 2, end
-    
-  unless constants goto after_constants_dump
-    # "Traverse" the parse tree
-    .local pmc grammar
-    .local pmc constantsbuilder
-    .local pmc constants_out
-    grammar = new 'C99::CPP::Constants::ConstantsGrammar'
-    constantsbuilder = grammar.apply(ast)
-    constants_out = constantsbuilder.get('root')
-    $I0 = defined constants_out
-    unless $I0 goto err_no_constants
-
-    unless dump_constants goto after_constants_dump
-    print "\n\nConstants dump:\n"
-    print constants_out
-    print "\n"
-  after_constants_dump:
-    eq stopafter, 2, end
-
-    exit 0
-
-
-  err_parse_fail:
-    print "Parse failed on "
-    print filename
-    print "\n"
-    exit -1
-
-  err_no_ast:
-    print "Unable to construct AST.\n"
-    exit -2
-
-  err_no_constants:
-    print "Unable to construct Constants.\n"
-    exit -2
-
-  err_no_ost:
-    print "Unable to construct OST.\n"
-    exit -3
-
-  err_no_pir:
-    print "Unable to construct PIR.\n"
-    exit -4
+.loadlib 'c99_group'
 
-  end:
-    exit 0
-.end
+.sub 'onload' :anon :load :init
+    load_bytecode 'PCT.pbc'
 
-.sub pir_exec
-    .param pmc code
-    .local pmc pir_compiler
-    .local pmc pir_compiled
-    pir_compiler = compreg "PIR"
-    pir_compiled = pir_compiler(code)
-    pir_compiled()
+    $P0 = get_hll_global ['PCT'], 'HLLCompiler'
+    $P1 = $P0.'new'()
+    $P1.'language'('C99')
+    $P1.'parsegrammar'('C99::Grammar')
+    $P1.'parseactions'('C99::Grammar::Actions')
 .end
 
-.sub slurp_file
-    .param string filename
-    .local pmc filehandle
-    filehandle = open filename, "<"
-    unless filehandle goto err_no_file
-    $S1 = read filehandle, 65535
-    close filehandle
-    .return ($S1)
-
-  err_no_file:
-    print "Unable to open file "
-    print filename
-    print "\n"
-    end
-.end
+=item main(args :slurpy)  :main
+
+Start compilation by passing any command line C<args>
+to the C compiler.
 
-.sub spew_file
-    .param string filename
-    .param string contents
-    .local pmc filehandle
-    filehandle = open filename, ">"
-    unless filehandle goto err_no_file
-    print filehandle, contents
-    close filehandle
-    .return ($S1)
-
-  err_no_file:
-    print "Unable to open file "
-    print filename
-    print "\n"
-    end
+=cut
+
+.sub 'main' :main
+    .param pmc args
+
+    $P0 = compreg 'C99'
+    $P1 = $P0.'command_line'(args)
 .end
 
-=head1 LICENSE
 
-Copyright (C) 2005-2008, The Perl Foundation.
+.include 'src/gen_builtins.pir'
+.include 'src/gen_grammar.pir'
+.include 'src/gen_actions.pir'
 
-This is free software; you may redistribute it and/or modify
-it under the same terms as Parrot.
 
-=head1 AUTHOR
+.namespace [ 'C99::Grammar' ]
+
+.sub 'debug'
+    .param pmc match
+    .param pmc arg
+    .param pmc attrs :slurpy
+    printerr arg
+    printerr "\n"
+.end
 
-Kevin Tew <[EMAIL PROTECTED]>
+=back
 
 =cut
 
@@ -249,4 +73,5 @@
 #   mode: pir
 #   fill-column: 100
 # End:
-# vim: expandtab shiftwidth=4 ft=pir:
+# vim: expandtab shiftwidth=4:
+

Added: trunk/languages/c99/src/builtins/say.pir
==============================================================================
--- (empty file)
+++ trunk/languages/c99/src/builtins/say.pir    Thu Feb 21 11:24:15 2008
@@ -0,0 +1,31 @@
+# $Id$
+
+=head1
+
+say.pir -- simple implementation of a say function
+
+=cut
+
+.namespace
+
+.sub 'say'
+    .param pmc args            :slurpy
+    .local pmc iter
+    iter = new 'Iterator', args
+  iter_loop:
+    unless iter goto iter_end
+    $P0 = shift iter
+    print $P0
+    goto iter_loop
+  iter_end:
+    print "\n"
+    .return ()
+.end
+
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
+

Reply via email to