perl.cvs.mod_parrot
[Top] [All Lists]

[svn:mod_parrot] r353 - in mod_parrot/trunk: . lib/ModParrot/HLL

Subject: [svn:mod_parrot] r353 - in mod_parrot/trunk: . lib/ModParrot/HLL
From: jhorwitz@xxxxxxxxxxxx
Date: Tue, 24 Jun 2008 10:48:18 -0700 (PDT)
Newsgroups: perl.cvs.mod_parrot

Author: jhorwitz
Date: Tue Jun 24 10:48:18 2008
New Revision: 353

Added:
   mod_parrot/trunk/lib/ModParrot/HLL/lolcode.pir
Modified:
   mod_parrot/trunk/Makefile.in

Log:
take a stab at mod_lolcode


Modified: mod_parrot/trunk/Makefile.in
==============================================================================
--- mod_parrot/trunk/Makefile.in        (original)
+++ mod_parrot/trunk/Makefile.in        Tue Jun 24 10:48:18 2008
@@ -46,6 +46,7 @@
        lib/ModParrot/HLL/pir \
        lib/ModParrot/HLL/perl6 \
        lib/ModParrot/HLL/plumhead \
+       lib/ModParrot/HLL/lolcode \
        lib/ModParrot/HLL/nqp
 
 all: gen-src $(SRC_DIR)/mod_parrot.la

Added: mod_parrot/trunk/lib/ModParrot/HLL/lolcode.pir
==============================================================================
--- (empty file)
+++ mod_parrot/trunk/lib/ModParrot/HLL/lolcode.pir      Tue Jun 24 10:48:18 2008
@@ -0,0 +1,129 @@
+# $Id$
+
+# Copyright (c) 2008 Jeff Horwitz
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.namespace [ 'ModParrot'; 'HLL'; 'lolcode' ]
+
+.sub __onload :anon :load
+    load_bytecode 'languages/lolcode/lolcode.pbc'
+    load_bytecode 'CGI/QueryHash.pbc'
+    $P0 = new 'Hash'
+    set_hll_global 'lolcode_registry', $P0
+.end
+
+.sub load
+    .param string file
+    .local pmc registry
+    .local string source
+
+    registry = get_hll_global 'lolcode_registry'
+    $I0 = exists registry[file]
+    if $I0 goto load_from_registry
+    $P0 = open file, '<'
+    source = $P0.'slurp'(0)
+    close $P0
+    $P1 = compreg 'lolcode'
+    $P2 = $P1.'compile'(source)
+    registry[file] = $P2
+    goto return_code
+  load_from_registry:
+    $P2 = registry[file]
+  return_code:
+    .return($P2)
+.end
+
+#.sub config
+
+# response handler
+.sub handler
+    .param pmc ctx
+    .param pmc handler_name
+    .local string script_path
+    .local string output
+    .local string key
+    .local pmc r
+    .local pmc ap_const
+    .local pmc interp
+    .local pmc code
+    .local pmc query_parse
+    .local pmc query
+    .local pmc q_iter
+    .local int status
+
+    # get apache constants
+    ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
+
+    # get the request_rec object
+    r = ctx.'request_rec'()
+
+    # get the interpreter object
+    interp = ctx.'interp'()
+    script_path = r.'filename'()
+
+    push_eh report_error
+        code = load(script_path)
+    pop_eh
+
+    # set default content type
+    r.'content_type'("text/html")
+
+    # get the query string and store as the global 'ARGZ'
+    $S0 = r.'args'()
+    $P0 = new 'String'
+    $P0 = $S0
+    set_hll_global 'ARGZ', $P0
+
+    # additionally, store each arg as a global, uppercasing the names
+    # XXX lolcode bombs out when you use a variable that hasn't been declared
+    #     or isn't set here.  caveat developer!
+    unless $P0 goto query_loop_end
+    query_parse = get_hll_global [ 'CGI'; 'QueryHash' ], 'parse'
+    query = new 'Hash'
+    query = query_parse($S0)
+    q_iter = new 'Iterator', query
+  query_loop:
+    key = shift q_iter
+    unless key goto query_loop_end
+    $P0 = query[key]
+    $S0 = key
+    $S1 = upcase $S0
+    r.log_rerror('lolcode', 0, 0, $S1)
+    set_hll_global $S1, $P0
+    goto query_loop
+  query_loop_end:
+
+    interp.'capture_stdout'(1)
+    push_eh report_error
+        status = code()
+    pop_eh
+    output = interp.'dump_stdout'()
+    interp.'capture_stdout'(0)
+    r.'puts'(output)
+    status = 0
+    goto return_status
+
+  report_error:
+    get_results '0,0', $P0, $S0
+    $S1 = script_path
+    concat $S1, ": "
+    concat $S1, $S0
+    $I0 = ap_const['APLOG_ERR']
+    r.'log_rerror'(script_path, 0, $I0, $S1)
+    status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
+
+  return_status:
+    # return status code
+    .return(status)
+.end

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:mod_parrot] r353 - in mod_parrot/trunk: . lib/ModParrot/HLL, jhorwitz <=