Front page | perl.cvs.parrot |
Postings from December 2008
[svn:parrot] r33759 - in trunk/languages/lua: . src/lib
From:
fperrad
Date:
December 10, 2008 04:52
Subject:
[svn:parrot] r33759 - in trunk/languages/lua: . src/lib
Message ID:
20081210125246.211DDCBA89@x12.develooper.com
Author: fperrad
Date: Wed Dec 10 04:52:45 2008
New Revision: 33759
Modified:
trunk/languages/lua/luac2pir.pir
trunk/languages/lua/src/lib/luaperl.pir
Log:
[Lua] pdd22io
- more FileHandle
- refactor exception handling
Modified: trunk/languages/lua/luac2pir.pir
==============================================================================
--- trunk/languages/lua/luac2pir.pir (original)
+++ trunk/languages/lua/luac2pir.pir Wed Dec 10 04:52:45 2008
@@ -35,10 +35,9 @@
if argc != 2 goto USAGE
progname = shift argv
filename = shift argv
+ push_eh _handler
content = load_file(filename)
- unless content goto L1
.local pmc script
- push_eh _handler
new $P0, 'LuaBytecode'
script = $P0.'undump'(content)
.local string gen_pir
@@ -46,18 +45,16 @@
save_pir(gen_pir, filename)
pop_eh
end
+ USAGE:
+ printerr "Usage: parrot luac2pir.pir filename\n"
+ exit -1
_handler:
.local pmc e
.local string msg
.get_results (e)
msg = e
- print msg
- print "\n"
- L1:
+ say msg
end
- USAGE:
- printerr "Usage: parrot luad.pir filename\n"
- exit -1
.end
.sub 'load_file' :anon
@@ -68,37 +65,44 @@
push_eh _handler
content = fh.'readall'(filename)
pop_eh
- if content goto L1
- $S0 = err
- print "Can't slurp '"
- print filename
- print "' ("
- print $S0
- print ")\n"
- L1:
- _handler:
.return (content)
+ _handler:
+ .local pmc e
+ .get_results (e)
+ $S0 = "Can't slurp '"
+ $S0 .= filename
+ $S0 .= "' ("
+ $S1 = err
+ $S0 .= $S1
+ $S0 .= ")\n"
+ e = $S0
+ rethrow e
.end
-.sub 'save_pir' :anon
+.sub 'save_pir'
.param string gen_pir
.param string filename
.local string output
.local pmc fh
+ fh = new 'FileHandle'
output = concat filename, '.pir'
- fh = open output, '>'
- if fh goto L1
- $S0 = err
- print "Can't open '"
- print output
- print "' ("
- print $S0
- print ")\n"
- goto L2
- L1:
- print fh, gen_pir
- close fh
- L2:
+ push_eh _handler
+ fh.'open'(output, 'w')
+ pop_eh
+ fh.'print'(gen_pir)
+ fh.'close'()
+ .return ()
+ _handler:
+ .local pmc e
+ .get_results (e)
+ $S0 = "Can't open '"
+ $S0 .= output
+ $S0 .= "' ("
+ $S1 = err
+ $S0 .= $S1
+ $S0 .= ")\n"
+ e = $S0
+ rethrow e
.end
.include 'languages/lua/src/lib/luabytecode.pir'
Modified: trunk/languages/lua/src/lib/luaperl.pir
==============================================================================
--- trunk/languages/lua/src/lib/luaperl.pir (original)
+++ trunk/languages/lua/src/lib/luaperl.pir Wed Dec 10 04:52:45 2008
@@ -53,43 +53,49 @@
.param string code
.param string filename
.local pmc fh
- fh = open filename, '>'
- if fh goto L1
- $S0 = err
- print "Can't open '"
- print filename
- print "' ("
- print $S0
- print ")\n"
- goto L2
- L1:
- print fh, code
- close fh
- L2:
+ fh = new 'FileHandle'
+ push_eh _handler
+ fh.'open'(filename, 'w')
+ pop_eh
+ fh.'print'(code)
+ fh.'close'()
+ .return ()
+ _handler:
+ .local pmc e
+ .get_results (e)
+ $S0 = "Can't open '"
+ $S0 .= filename
+ $S0 .= "' ("
+ $S1 = err
+ $S0 .= $S1
+ $S0 .= ")\n"
+ e = $S0
+ rethrow e
.end
.sub 'load_script' :anon
.param string filename
- .local pmc pio
+ .local pmc fh
.local string content
- pio = new 'ParrotIO'
+ fh = new 'FileHandle'
push_eh _handler
- content = pio.'readall'(filename)
+ content = fh.'readall'(filename)
pop_eh
- if content goto L1
- $S0 = err
- print "Can't slurp '"
- print filename
- print "' ("
- print $S0
- print ")\n"
- L1:
- _handler:
.return (content)
+ _handler:
+ .local pmc e
+ .get_results (e)
+ $S0 = "Can't slurp '"
+ $S0 .= filename
+ $S0 .= "' ("
+ $S1 = err
+ $S0 .= $S1
+ $S0 .= ")\n"
+ e = $S0
+ rethrow e
.end
-
.sub 'compile_file' :anon
.param string filename
.const string out = 'luac.out'
@@ -105,18 +111,22 @@
$S0 .= out
$I0 = spawnw $S0
.local string pir
+ push_eh _handler
pir = load_script($S1)
- if pir goto L1
- $P0 = new 'ParrotIO'
- $S0 = $P0.'readall'(out)
- unlink(out) # cleaning up the temporary file
- die $S0
- L1:
+ pop_eh
unlink(out) # cleaning up the temporary file
.local pmc pir_comp
pir_comp = compreg 'PIR'
$P0 = pir_comp(pir)
.return ($P0)
+ _handler:
+ .local pmc e
+ .get_results (e)
+ $P0 = new 'FileHandle'
+ $S0 = $P0.'readall'(out)
+ printerr $S0
+ unlink(out) # cleaning up the temporary file
+ rethrow e
.end
-
[svn:parrot] r33759 - in trunk/languages/lua: . src/lib
by fperrad