Permalink
Browse files

Cleanup and refactor for class support

git-svn-id: https://svn.parrot.org/parrot/trunk/languages/cardinal@14634 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 65db6cf commit 4cfaaf2f4d087463022306424956e4da1000da64 @tewk tewk committed Sep 17, 2006
Showing with 360 additions and 104 deletions.
  1. +22 −0 cardinal.pir
  2. +17 −0 src/AST2OST.pir
  3. +13 −4 src/ASTGrammar.tg
  4. +14 −37 src/OST2PIR.pir
  5. +122 −28 src/OSTGrammar.tg
  6. +29 −4 src/PAST.pir
  7. +65 −29 src/PIRGrammar.tg
  8. +78 −2 src/POST.pir
View
@@ -131,6 +131,7 @@ compiler, see:
dump_pir = 1
dump_src_early = 1
dump_src = 1
+ execute_debug = 1
stopafter = 0
after_dump_all:
@@ -270,6 +271,10 @@ compiler, see:
after_pir_dump:
eq stopafter, 4, end
+ # dump pir to file
+ $S0 = concat filename, ".pir.out"
+ _spew_file($S0, pir)
+
# Execute
unless execute_debug goto execute_only
print "\n\nExecution Result:\n"
@@ -331,6 +336,23 @@ compiler, see:
end
.end
+.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
+.end
+
=head1 LICENSE
Copyright (c) 2005 The Perl Foundation
View
@@ -12,6 +12,7 @@
addattribute $P0, 'past_scope_stack'
addattribute $P0, 'BEGIN_blocks'
addattribute $P0, 'END_blocks'
+ addattribute $P0, 'namespaces'
.return ()
error:
print "Cardinal::OSTGrammar class not found\n"
@@ -76,3 +77,19 @@ error:
end:
.return (stack)
.end
+
+.sub 'push_namespace' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .local pmc stack
+ stack = self.'attr'('namespaces', 0, 0)
+ $I0 = defined stack
+ if $I0 goto test_value
+ stack = new .ResizablePMCArray
+ stack = self.'attr'('namespaces', stack, 1)
+ test_value:
+ unless has_value goto end
+ push stack, value
+ end:
+ .return (stack)
+.end
View
@@ -732,8 +732,16 @@ transform result (Cardinal::Grammar::lang_statements) :language('PIR') {
function_name = tree.get('result', $P0, 'Cardinal::Grammar::function_name')
$P0 = self.'top_scope_stack'()
+ $S0 = $P0.'blocktype'()
+ .local string function_blocktype
+
+ function_blocktype = 'function'
+ unless $S0 == 'class' goto is_function
+ function_blocktype = 'method'
+ is_function:
+
function = new 'Cardinal::PAST::Block'
- function.'init'('node'=>node, 'name'=>function_name, 'blocktype'=>'function', 'outer'=>$P0)
+ function.'init'('node'=>node, 'name'=>function_name, 'blocktype'=>function_blocktype, 'outer'=>$P0)
$P0 = node['function_prototype_arg_list']
self.'add_to_current_block'(function_name, function)
@@ -772,7 +780,7 @@ transform result (Cardinal::Grammar::lang_statements) :language('PIR') {
unless $I0 goto err_no_tree
$P0 = node['class_path']
child = tree.get('result', $P0, 'Cardinal::Grammar::class_path')
- class_block.'add_child'(child)
+ class_block.'class_path'(child)
$I0 = defined node['superclass']
@@ -932,13 +940,13 @@ transform result (Cardinal::Grammar::function_name) :language('PIR') {
transform result (Cardinal::Grammar::class_path) :language('PIR') {
.local pmc result
.local pmc child
- result = new 'Cardinal::PAST::Op'
+ result = new 'Cardinal::PAST::ClassPath'
result.'init'('node'=>node, 'name'=>'class_path')
$I0 = defined node['starting_colons']
unless $I0 goto atoms
$P0 = node['starting_colons']
- #result.'starting_colons'(1)
+ result.'starting_colons'(1)
atoms:
$I0 = defined node['atom']
@@ -959,6 +967,7 @@ transform result (Cardinal::Grammar::class_path) :language('PIR') {
$I0 = defined node['class_name']
unless $I0 goto err_no_tree
$S0 = node['class_name']
+ result.'add_child'($S0)
.return (result)
View
@@ -8,7 +8,8 @@
if $I0 == 0 goto error
$P0 = getclass 'Cardinal::PIRGrammar'
addattribute $P0, 'scope_stack'
- addattribute $P0, 'sub_stack'
+ addattribute $P0, 'subs'
+ addattribute $P0, 'namespaces'
.return ()
error:
print "Cardinal::PIRGrammar class not found\n"
@@ -30,41 +31,6 @@ error:
.return (value)
.end
-.sub 'add_sub' :method
- .param pmc subcode
- $P0 = self.'sub_stack'()
- push $P0, subcode
- .return ()
-.end
-
-.sub 'gen_subs' :method
- $S0 = ""
- $P0 = self.'sub_stack'()
- .local pmc iter
- iter = new .Iterator, $P0
- iter_loop:
- unless iter goto iter_end
- $P0 = shift iter
- $S1 = $P0
- $S0 .= $S1
- goto iter_loop
- iter_end:
- .return ($S0)
-.end
-
-.sub 'sub_stack' :method
- .param pmc attr :optional
- .param int has_attr :opt_flag
- .local pmc value
- value = self.'attr'('sub_stack', attr, has_attr)
- $I0 = defined value
- if $I0 goto end
- value = new .ResizablePMCArray
- value = self.'attr'('sub_stack', value, 1)
- end:
- .return (value)
-.end
-
.sub 'scope_stack' :method
.param pmc attr :optional
.param int has_attr :opt_flag
@@ -78,9 +44,20 @@ error:
.return (value)
.end
+.sub 'push_scope_stack' :method
+ .param pmc value
+ $P0 = self.'scope_stack'()
+ push $P0, value
+.end
+
+.sub 'pop_scope_stack' :method
+ $P0 = self.'scope_stack'()
+ pop $P1, $P0
+.end
+
.sub 'top_scope_stack' :method
.local pmc value
- value = self.'attr'('scope_stack', $P0, 0)
+ value = self.'scope_stack'()
$I0 = elements value
unless $I0 goto end
$I0 -= 1
Oops, something went wrong.

0 comments on commit 4cfaaf2

Please sign in to comment.