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

Commit

Permalink
[HLLGrammar]: Move lexical subs to top for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 28, 2009
1 parent 6f44564 commit a785048
Showing 1 changed file with 66 additions and 65 deletions.
131 changes: 66 additions & 65 deletions src/HLL/Actions.pm
@@ -1,5 +1,71 @@
class HLL::Actions;

sub string_to_int($src, $base) {
Q:PIR {
.local pmc src
.local string src_s
src = find_lex '$src'
src_s = src
.local int base, pos, eos, result
$P0 = find_lex '$base'
base = $P0
pos = 0
eos = length src_s
result = 0
str_loop:
unless pos < eos goto str_done
.local string char
char = substr src_s, pos, 1
if char == '_' goto str_next
.local int digitval
digitval = index "00112233445566778899AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", char
if digitval < 0 goto err_base
digitval >>= 1
if digitval > base goto err_base
result *= base
result += digitval
str_next:
inc pos
goto str_loop
err_base:
src.'panic'('Invalid radix conversion of "', char, '"')
str_done:
%r = box result
};
}

sub ints_to_string($ints) {
Q:PIR {
.local string result
result = ''
.local pmc ints, ints_it
ints = find_lex '$ints'
$I0 = does ints, 'array'
unless $I0 goto ints_1
ints_it = iter ints
ints_loop:
unless ints_it goto ints_done
$P0 = shift ints_it
$I0 = $P0.'ast'()
$S0 = chr $I0
concat result, $S0
goto ints_loop
ints_1:
$I0 = ints.'ast'()
result = chr $I0
ints_done:
%r = box result
};
}

sub isaPAST($x) {
Q:PIR {
$P0 = find_lex '$x'
$I0 = isa $P0, ['PAST';'Node']
%r = box $I0
}
}
method EXPR($/, $key?) {
unless $key { return 0; }
my $past := $<OPER>.peek_ast;
Expand Down Expand Up @@ -116,68 +182,3 @@ method escape:sym<oct>($/) {
make ints_to_string( $<octint> ?? $<octint> !! $<octints><octint> );
}

sub string_to_int($src, $base) {
Q:PIR {
.local pmc src
.local string src_s
src = find_lex '$src'
src_s = src
.local int base, pos, eos, result
$P0 = find_lex '$base'
base = $P0
pos = 0
eos = length src_s
result = 0
str_loop:
unless pos < eos goto str_done
.local string char
char = substr src_s, pos, 1
if char == '_' goto str_next
.local int digitval
digitval = index "00112233445566778899AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", char
if digitval < 0 goto err_base
digitval >>= 1
if digitval > base goto err_base
result *= base
result += digitval
str_next:
inc pos
goto str_loop
err_base:
src.'panic'('Invalid radix conversion of "', char, '"')
str_done:
%r = box result
};
}

sub ints_to_string($ints) {
Q:PIR {
.local string result
result = ''
.local pmc ints, ints_it
ints = find_lex '$ints'
$I0 = does ints, 'array'
unless $I0 goto ints_1
ints_it = iter ints
ints_loop:
unless ints_it goto ints_done
$P0 = shift ints_it
$I0 = $P0.'ast'()
$S0 = chr $I0
concat result, $S0
goto ints_loop
ints_1:
$I0 = ints.'ast'()
result = chr $I0
ints_done:
%r = box result
};
}

sub isaPAST($x) {
Q:PIR {
$P0 = find_lex '$x'
$I0 = isa $P0, ['PAST';'Node']
%r = box $I0
}
}

0 comments on commit a785048

Please sign in to comment.