Author: bernhard
Date: Wed Nov  2 12:15:57 2005
New Revision: 9723

Added:
   trunk/languages/m4/examples/eval.pir
      - copied, changed from r9719, trunk/languages/m4/examples/eval.imc
Removed:
   trunk/languages/m4/examples/eval.imc
Modified:
   trunk/MANIFEST
   trunk/build_tools/parrotdef.pl
   trunk/config/gen/makefiles/m4.in
   trunk/languages/m4/src/builtin.pir
   trunk/languages/m4/src/eval.c
   trunk/languages/m4/t/basic/012_eval.t
   trunk/languages/m4/t/builtins/010_sysval.t
Log:
'Parrot m4' integer expression evaluation is no longer
a mini compiler. Having a plain "it" NCI function is much 
more simple, but also less interesting.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Wed Nov  2 12:15:57 2005
@@ -1107,7 +1107,7 @@ languages/m4/doc/freezing.pod           
 languages/m4/doc/operation.pod                    [m4]
 languages/m4/doc/running.pod                      [m4]
 languages/m4/examples/README                      [m4]
-languages/m4/examples/eval.imc                    [m4]
+languages/m4/examples/eval.pir                    [m4]
 languages/m4/examples/hello.m4                    [m4]
 languages/m4/examples/nesting.m4                  [m4]
 languages/m4/examples/only_T7_0.frozen            [m4]

Modified: trunk/build_tools/parrotdef.pl
==============================================================================
--- trunk/build_tools/parrotdef.pl      (original)
+++ trunk/build_tools/parrotdef.pl      Wed Nov  2 12:15:57 2005
@@ -252,7 +252,6 @@ my @funcnames = qw(

        Parrot_make_COW_reference

        Parrot_switch_to_cs

        PackFile_Segment_new_seg

-       PF_create_default_segs

 );

 push @funcnames, "PMCNULL      DATA";

 push @funcnames, "Parrot_base_vtables  DATA";


Modified: trunk/config/gen/makefiles/m4.in
==============================================================================
--- trunk/config/gen/makefiles/m4.in    (original)
+++ trunk/config/gen/makefiles/m4.in    Wed Nov  2 12:15:57 2005
@@ -23,7 +23,7 @@ LD_SHARE_FLAGS = ${ld_share_flags} # e.g
 #INVERSE_CONDITIONED_LINE(parrot_exe_def):LIBPARROT      =
 
 # some constants
-M4_EVAL_COMPILER_SO = 
..${slash}..${slash}runtime${slash}parrot${slash}dynext${slash}m4_eval_compiler${share_ext}
+M4_EVALUATE_SO = 
..${slash}..${slash}runtime${slash}parrot${slash}dynext${slash}m4_evaluate${share_ext}
 #CONDITIONED_LINE(has_gnu_m4):USE_GNU_M4 = --use-gnu-m4
 #INVERSE_CONDITIONED_LINE(has_gnu_m4):USE_GNU_M4 = 
 
@@ -51,12 +51,12 @@ help:
 test: build
        cd .. && $(PERL) -I../lib m4/t/harness $(USE_GNU_M4)
 
-build: $(M4_EVAL_COMPILER_SO) m4.pbc 
+build: $(M4_EVALUATE_SO) m4.pbc 
 
 m4.pbc: src/m4.pir
        $(PARROT) -o m4.pbc src/m4.pir 
 
-$(M4_EVAL_COMPILER_SO): src/eval.c
+$(M4_EVALUATE_SO): src/eval.c
        $(CC) $(CFLAGS) $(CC_SHARED) $(DEBUG) $(WARN) -c src/eval.c
        $(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) ${ld_out}$@ eval$(O) $(LIBPARROT)
 
@@ -79,7 +79,7 @@ t/*/*.parrot_out \
 t/*/*.gnu_out \
 t/*/*.imc \
 t/*/*.pir \
-$(M4_EVAL_COMPILER_SO) 
+$(M4_EVALUATE_SO) 
 
 realclean: clean
        $(RM_RF) Makefile

Copied: trunk/languages/m4/examples/eval.pir (from r9719, 
trunk/languages/m4/examples/eval.imc)
==============================================================================
--- trunk/languages/m4/examples/eval.imc        (original)
+++ trunk/languages/m4/examples/eval.pir        Wed Nov  2 12:15:57 2005
@@ -13,40 +13,33 @@ See languages/m4/Makefile on how to gene
 
 .sub 'example' :main
 
-    print "Trying to load shared library 'm4_eval_compiler'.\n"
-    print "Let the init function of the library register the compiler.\n"
-    .local pmc m4_eval_compiler_lib
-    m4_eval_compiler_lib = loadlib "m4_eval_compiler"
-    if m4_eval_compiler_lib goto GET_COMPILER
-       printerr "Could not load 'm4_eval_compiler'.\n"     
+    print "Trying to load shared library 'm4_evaluate'.\n"
+    .local pmc m4_evaluate_lib
+    m4_evaluate_lib = loadlib "m4_evaluate"
+    if m4_evaluate_lib goto LOAD_FUNCTION
+       printerr "Could not load 'm4_evaluate'.\n"     
        end
 
-GET_COMPILER:
-    print "Trying to get the registered compiler.\n"
-    .local pmc m4_eval_compiler
-    m4_eval_compiler = compreg "m4_eval_compiler"
-    if m4_eval_compiler goto COMPILE_CODE
-       printerr "Could not get the compiler.\n"     
+LOAD_FUNCTION:
+    print "Trying to load function 'm4_evaluate'.\n"
+    .local pmc m4_evaluate
+    m4_evaluate = dlfunc m4_evaluate_lib, "m4_evaluate", "it"
+    if m4_evaluate goto EVALUATE_CODE
+       printerr "Could not load m4_evaluate.\n"     
        end
 
-COMPILE_CODE:
+EVALUATE_CODE:
     .local string expression
     expression = '1 + 1 * 117'
     print "Evaluating expression: "
     print expression
     print "\n"
-    .local pmc compiled_code
-    compiled_code = m4_eval_compiler( expression )
-    if compiled_code goto INVOKE_COMPILED_CODE
-       printerr "Could not get the compiler.\n"     
-       end
+    .local int value 
+    ( value ) = m4_evaluate( expression )
 
 INVOKE_COMPILED_CODE:
-    print "Invoking compiled code, and receive returned expression\n"
-    .local int evaluated_expression
-    ( evaluated_expression ) = compiled_code()
     print "evaluated: "
-    print evaluated_expression
+    print value
     print "\n"
-    end
+
 .end

Modified: trunk/languages/m4/src/builtin.pir
==============================================================================
--- trunk/languages/m4/src/builtin.pir  (original)
+++ trunk/languages/m4/src/builtin.pir  Wed Nov  2 12:15:57 2005
@@ -7,7 +7,7 @@ builtin.pir - builtin and user defined m
 =head2 DESCRIPTION
 
 Copyright:  2004 Bernhard Schmalhofer.  All Rights Reserved.
-CVS Info:   $Id$
+SVN Info:   $Id$
 History:    Ported from GNU m4 1.4
 References: http://www.gnu.org/software/m4/m4.html
 
@@ -576,17 +576,17 @@ Integer arithmetics.
   .param pmc state
   .param pmc arguments
 
-  # get compiler
-  .local pmc m4_eval_compiler
-  m4_eval_compiler = compreg "m4_eval_compiler"
+  # load shared library
+  .local pmc m4_evaluate_lib
+  m4_evaluate_lib = loadlib "m4_evaluate"
 
   # compile code and run it
   .local string expression
   expression = arguments[0]
-  .local pmc compiled_code
-  compiled_code = compile m4_eval_compiler, expression
   .local int evaluated_expression
-  ( evaluated_expression ) = compiled_code()
+  .local pmc m4_evaluate
+  m4_evaluate = dlfunc m4_evaluate_lib, "m4_evaluate", "it"
+  ( evaluated_expression ) = m4_evaluate( expression )
   .local string ret
   ret = evaluated_expression
 

Modified: trunk/languages/m4/src/eval.c
==============================================================================
--- trunk/languages/m4/src/eval.c       (original)
+++ trunk/languages/m4/src/eval.c       Wed Nov  2 12:15:57 2005
@@ -85,8 +85,7 @@ static eval_error          exp_term( eva
 static eval_error          unary_term( eval_token, eval_t * );
 static eval_error          simple_term( eval_token, eval_t * );
 boolean_for_m4             evaluate (const char *, eval_t *);
-PMC *                      compile_m4_arithmetic_expression(Parrot_Interp, 
const char *);
-void                       Parrot_lib_m4_eval_compiler_init(Parrot_Interp , 
PMC* );
+int                        m4_evaluate(void *);
 
 /*--------------------.
 | Lexical functions.  |
@@ -792,14 +791,6 @@ $ make -C examples/compilers/
  * we use init to register the compiler
  */
 
-void
-Parrot_lib_m4_eval_compiler_init(Parrot_Interp interp, PMC* lib)
-{
-    STRING *m4_eval_compiler = const_string(interp, "m4_eval_compiler");
-    Parrot_compreg(interp, m4_eval_compiler, compile_m4_arithmetic_expression);
-}
-
-
 static int
 unescape(char *string)
 {
@@ -825,102 +816,18 @@ unescape(char *string)
 
 
 /*
- * This one is actually generating PBC.
- * First the aritmetic expression is evaluated.
- * Then we generaten a sub, that does nothing but return the result of the 
evaluation.
- * I suppose that is cheating in a confuse way.
+ * This one is called from PIR using NCI with the signature 'it'.
  */
-PMC *
-compile_m4_arithmetic_expression( Parrot_Interp interp, const char *program )
+int 
+m4_evaluate( void *program )
 {
     eval_t value;                        /* will be returned to caller */
-    struct PackFile_ByteCode *new_cs;    /* generated PBC goes there */
-    struct PackFile_ByteCode *old_cs;    /* Continue there, when new_cs is 
finished */
-    opcode_t* program_counter;
-    PMC *sub;
-    parrot_sub_t sub_data;
-    char name[64];
 
     /*
      * The real work is done here
      */
-    evaluate( program, &value );
-
-    /* This is from ast/ast_main.c
-     * What does this do?
-     */
-    /*
-    if (interp->imc_info->last_unit) {
-        imc_info = mem_sys_allocate_zeroed(sizeof(imc_info_t));
-        imc_info->ghash = interp->imc_info->ghash;
-        imc_info->prev = interp->imc_info;
-        interp->imc_info = imc_info;
-    }
-    */
-
-    /* m4_eval_compiler always compiles to interp->code->cur_cs
-     * make new, switch and save old cs
-     */
-    sprintf(name, "EVAL_" INTVAL_FMT, ++interp->code->base.pf->eval_nr);
-    new_cs = PF_create_default_segs(interp, name, 0);
-    old_cs = Parrot_switch_to_cs(interp, new_cs, 0);
-    /* TODO gcc complains interp->imc_info->cur_namespace = NULL: */
-
-    /*
-     * need a packfile segment
-     */
-    /*
-     * alloc byte code mem
-     */
-    new_cs->base.data = mem_sys_allocate(CODE_SIZE * sizeof(opcode_t));
-    new_cs->base.size = CODE_SIZE;
+    evaluate( (const char *)program, &value );
 
-    /*
-     * Generate some bytecode
-     * This is actually simulating the now obsolete calling conventions.
-     * TODO: Let the PIR-compiler generate the PBC
-     */
-    program_counter = new_cs->base.data;
-    /* set the single integer return value */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 5;
-    *program_counter++ = value;
-    /* promise to fill in the counters */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 0;
-    *program_counter++ = 1;
-    /* one integer return value */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 1;
-    *program_counter++ = 1;
-    /* no string return values */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 2;
-    *program_counter++ = 0;
-    /* no PMC return values */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 3;
-    *program_counter++ = 0;
-    /* no numeric return values */
-    *program_counter++ = interp->op_lib->op_code("set_i_ic", 1);
-    *program_counter++ = 4;
-    *program_counter++ = 0;
-    /* invoke the return continuation */
-    *program_counter++ = interp->op_lib->op_code("returncc", 1);
-
-    if (old_cs) {
-        /* restore old byte_code, */
-        (void)Parrot_switch_to_cs(interp, old_cs, 0);
-    }
-    /*
-     * create sub PMC
-     */
-    sub = pmc_new(interp, enum_class_Eval);
-    sub_data = PMC_sub(sub);
-    sub_data->seg = new_cs;
-    sub_data->address = new_cs->base.data;
-    sub_data->end = new_cs->base.data + new_cs->base.size;
-    sub_data->name = string_from_cstring(interp, "m4 eval", 0);
-
-    return sub;
+    return value;
 }
+

Modified: trunk/languages/m4/t/basic/012_eval.t
==============================================================================
--- trunk/languages/m4/t/basic/012_eval.t       (original)
+++ trunk/languages/m4/t/basic/012_eval.t       Wed Nov  2 12:15:57 2005
@@ -10,12 +10,10 @@ use Test::More tests => 1; 
 my $real_out;
 my $parrot    = "cd .. && .$PConfig{slash}parrot$PConfig{exe}";
 
-$real_out     = `$parrot languages/m4/examples/eval.imc 2>&1`; 
+$real_out     = `$parrot languages/m4/examples/eval.pir 2>&1`; 
 is( $real_out, << 'END_OUT', 'single expression' );
-Trying to load shared library 'm4_eval_compiler'.
-Let the init function of the library register the compiler.
-Trying to get the registered compiler.
+Trying to load shared library 'm4_evaluate'.
+Trying to load function 'm4_evaluate'.
 Evaluating expression: 1 + 1 * 117
-Invoking compiled code, and receive returned expression
 evaluated: 118
 END_OUT

Modified: trunk/languages/m4/t/builtins/010_sysval.t
==============================================================================
--- trunk/languages/m4/t/builtins/010_sysval.t  (original)
+++ trunk/languages/m4/t/builtins/010_sysval.t  Wed Nov  2 12:15:57 2005
@@ -7,14 +7,14 @@ use lib "$FindBin::Bin/../../lib", "$Fin
 use Parrot::Config;
 use Parrot::Test tests => 1 + 1;
 
-my $true  = "$PConfig{perl} -e exit(0)";
-my $false = "$PConfig{perl} -e exit(1)";
+my $true  = qq{$PConfig{perl} -e "exit(0)"};
+my $false = qq{$PConfig{perl} -e "exit(1)"};
 
 SKIP:
 {
   skip( "difference between running a process in a fork, or with system()", 1 
);
-  language_output_is( 'm4', <<'CODE', <<'OUT', 'output of "false"' );
-syscmd(`$false`)
+  language_output_is( 'm4', <<"CODE", <<'OUT', 'output of "false"' );
+syscmd(`$false')
 sysval()
 CODE
 
@@ -23,8 +23,8 @@ OUT
 }
 
 {
-  language_output_is( 'm4', <<'CODE', <<'OUT', 'output of "true"' );
-syscmd(`$true`)
+  language_output_is( 'm4', <<"CODE", <<'OUT', 'output of "true"' );
+syscmd(`$true')
 sysval()
 CODE
 

Reply via email to