Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 492aa92

Browse files
committed
Fix various thinkos, and remove the parse method grabbed from PCT::HLLCompiler, since it's overridden in the hll-compiler cheats anyway. This gets us through the build again, without depending on PCT::HLLCompiler.
1 parent dafce7f commit 492aa92

File tree

1 file changed

+17
-130
lines changed

1 file changed

+17
-130
lines changed

src/HLL/Compiler.pm

Lines changed: 17 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class HLL::Compiler {
1919
has $!compiler_progname;
2020
has $!language;
2121

22-
# XXX WTF was this for? Sets an attribute on a type object?
23-
#INIT {
24-
# HLL::Compiler.language('parrot');
25-
#}
26-
2722
method BUILD() {
2823
@!stages := pir::split(' ', 'parse past post pir evalpmc');
2924
@!cmdoptions := pir::split(' ', 'e=s help|h target=s dumper=s trace|t=s encoding=s output|o=s combine version|v stagestats');
@@ -236,29 +231,29 @@ class HLL::Compiler {
236231
}
237232

238233
method stages(@value?) {
239-
if pir::defined(@value) {
234+
if +@value {
240235
@!stages := @value;
241236
}
242237
@!stages;
243238
}
244239

245-
method parsegrammar($value?) {
246-
if pir::defined($value) {
247-
$!parsegrammar := $value;
240+
method parsegrammar(*@value) {
241+
if +@value {
242+
$!parsegrammar := @value[0];
248243
}
249244
$!parsegrammar;
250245
}
251246

252-
method parseactions($value?) {
253-
if pir::defined($value) {
254-
$!parseactions := $value;
247+
method parseactions(*@value) {
248+
if +@value {
249+
$!parseactions := @value[0];
255250
}
256251
$!parseactions;
257252
}
258253

259-
method astgrammar($value?) {
260-
if pir::defined($value) {
261-
$!astgrammar := $value;
254+
method astgrammar(*@value) {
255+
if +@value {
256+
$!astgrammar := @value[0];
262257
}
263258
$!astgrammar;
264259
}
@@ -556,121 +551,6 @@ class HLL::Compiler {
556551
};
557552
}
558553

559-
method parse($source, *%adverbs) {
560-
Q:PIR {
561-
.local pmc source, adverbs, parsegrammar, top
562-
source = find_lex '$source'
563-
adverbs = find_lex '%adverbs'
564-
565-
.local string tcode
566-
tcode = adverbs['transcode']
567-
unless tcode goto transcode_done
568-
.local pmc tcode_it
569-
$P0 = split ' ', tcode
570-
tcode_it = iter $P0
571-
tcode_loop:
572-
unless tcode_it goto transcode_done
573-
tcode = shift tcode_it
574-
push_eh tcode_fail
575-
$I0 = find_encoding tcode
576-
$S0 = source
577-
$S0 = trans_encoding $S0, $I0
578-
assign source, $S0
579-
pop_eh
580-
goto transcode_done
581-
tcode_fail:
582-
pop_eh
583-
goto tcode_loop
584-
transcode_done:
585-
586-
.local string target
587-
target = adverbs['target']
588-
target = downcase target
589-
590-
parsegrammar = self.'parsegrammar'()
591-
$I0 = can parsegrammar, 'TOP'
592-
unless $I0 goto parsegrammar_string
593-
top = find_method parsegrammar, 'TOP'
594-
goto have_top
595-
parsegrammar_string:
596-
$S0 = typeof parsegrammar
597-
eq $S0, 'NameSpace', parsegrammar_ns
598-
$P0 = self.'parse_name'(parsegrammar)
599-
$S0 = pop $P0
600-
$P1 = get_hll_global $P0, $S0
601-
$I0 = can $P1, 'TOP'
602-
unless $I0 goto parsegrammar_ns_string
603-
top = find_method $P1, 'TOP'
604-
goto have_top
605-
parsegrammar_ns_string:
606-
$P0 = self.'parse_name'(parsegrammar)
607-
top = get_hll_global $P0, 'TOP'
608-
unless null top goto have_top
609-
goto err_notop
610-
parsegrammar_ns:
611-
top = parsegrammar['TOP']
612-
unless null top goto have_top
613-
err_notop:
614-
self.'panic'('Cannot find TOP regex in ', parsegrammar)
615-
have_top:
616-
.local pmc parseactions, action
617-
null action
618-
if target == 'parse' goto have_action
619-
parseactions = self.'parseactions'()
620-
$I0 = isa parseactions, ['Undef']
621-
if $I0 goto have_action
622-
## if parseactions is a protoobject, use it directly
623-
$I0 = isa parseactions, 'P6protoobject'
624-
if $I0 goto action_exact
625-
## if parseactions is a Class or array, make action directly from that
626-
$I0 = isa parseactions, 'Class'
627-
if $I0 goto action_make
628-
$I0 = isa parseactions, 'NameSpace'
629-
if $I0 goto action_namespace
630-
$I0 = does parseactions, 'array'
631-
if $I0 goto action_make
632-
## if parseactions is not a String, use it directly.
633-
$I0 = isa parseactions, 'String'
634-
if $I0 goto action_string
635-
action_exact:
636-
action = parseactions
637-
goto have_action
638-
action_namespace:
639-
$P0 = get_class parseactions
640-
action = new $P0
641-
goto have_action
642-
action_string:
643-
## Try the string itself, if that fails try splitting on '::'
644-
$P0 = get_class parseactions
645-
unless null $P0 goto action_make
646-
$S0 = parseactions
647-
parseactions = split '::', $S0
648-
push_eh err_bad_parseactions
649-
$P0 = get_class parseactions
650-
if null $P0 goto err_bad_parseactions
651-
pop_eh
652-
action_make:
653-
action = new parseactions
654-
have_action:
655-
.local pmc match
656-
match = top(source, 'grammar' => parsegrammar, 'action' => action)
657-
unless match goto err_failedparse
658-
.return (match)
659-
660-
err_no_parsegrammar:
661-
self.'panic'('Missing parsegrammar in compiler')
662-
.return ()
663-
err_failedparse:
664-
self.'panic'('Failed to parse source')
665-
.return ()
666-
err_bad_parseactions:
667-
pop_eh
668-
$P0 = self.'parseactions'()
669-
self.'panic'('Unable to find action grammar ', $P0)
670-
.return ()
671-
};
672-
}
673-
674554
method past($source, *%adverbs) {
675555
Q:PIR {
676556
.local pmc source, adverbs
@@ -753,3 +633,10 @@ class HLL::Compiler {
753633
}
754634

755635
}
636+
637+
# Set up compiler for "Parrot" language.
638+
INIT {
639+
my $pl := HLL::Compiler.new();
640+
$pl.BUILD();
641+
$pl.language('parrot');
642+
}

0 commit comments

Comments
 (0)