Skip to content

Commit 1f76efa

Browse files
committed
[puts] works again
1 parent 96f655d commit 1f76efa

File tree

6 files changed

+16
-28
lines changed

6 files changed

+16
-28
lines changed

src/Partcl.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ sub MAIN($partcl, $filename) {
2424
my @ARGS := [];
2525
nqp::push(@ARGS, $filename);
2626
my %LEXPAD;
27+
my %*CHANNELS := nqp::hash();
28+
29+
%*CHANNELS<stdout> := nqp::getstdout;
30+
%*CHANNELS<stderr> := nqp::getstderr;
31+
%*CHANNELS<stdin> := nqp::getstdin;
32+
2733
my $compiler := Partcl::Compiler.new();
2834
$compiler.language('Partcl');
2935
$compiler.parsegrammar(Partcl::Grammar);

src/Partcl/commands/fileevent.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ method fileevent(*@args) {
99
self.error("bad event name \"$event\": must be readable or writable");
1010
}
1111

12-
our %CHANNELS;
13-
my $chanObj := %CHANNELS{$channelId};
12+
my $chanObj := %*CHANNELS{$channelId};
1413
if (! nqp::defined($chanObj) ) {
1514
self.error("can not find channel named \"$channelId\"");
1615
}

src/Partcl/commands/gets.pm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
method gets(*@args) {
2-
our %CHANNELS;
3-
42
if +@args < 1 || +@args > 2 {
53
self.error('wrong # args: should be "gets channelId ?varName?"');
64
}

src/Partcl/commands/puts.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ method puts(*@args) {
44
@args.shift; $nl := 0;
55
}
66
my $channelId;
7-
if +@args == 1 {
7+
if nqp::elems(@args) == 1 {
88
$channelId := 'stdout';
99
} else {
1010
$channelId := @args.shift;
1111
}
12-
my $chanObj := _getChannel($channelId);
13-
$chanObj.print(@args[0]);
12+
my $chanObj := %*CHANNELS{$channelId};
13+
$chanObj // nqp::die("can not find channel named \"$channelId\"");
14+
$chanObj := nqp::getstdout;
15+
nqp::printfh($chanObj, @args[0]);
1416
if $nl {
15-
$chanObj.print("\n");
17+
nqp::printfh($chanObj, "\n");
1618
1; # the void print causes trouble elsewise.
1719
}
1820
'';

src/init.pm

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use src::TclLexPad;
22
use src::TclArray;
33

4-
our %CHANNELS_HASH;
5-
64
INIT {
75
# only necessary on parrot?
86
#pir::loadlib__Ps("os");
@@ -21,13 +19,6 @@ INIT {
2119
%GLOBALS<errorCode> := 'NONE';
2220
%GLOBALS<errorInfo> := '';
2321

24-
## cannot merge
25-
##%CHANNELS_HASH := TclLexPad.newpad();
26-
27-
##%CHANNELS_HASH<stdout> := nqp::getstdout;
28-
##%CHANNELS_HASH<stderr> := nqp::getstderr;
29-
##%CHANNELS_HASH<stdin> := nqp::getstdin;
30-
3122
=begin XXX
3223
3324
my %PConfig := pir::getinterp__P()[8]; ## .IGLOBALS_CONFIG_HASH
@@ -49,14 +40,6 @@ INIT {
4940
=end XXX
5041
}
5142

52-
# Get a channel (XXX put into _tcl NS and move to another file)
53-
# This should use the [error] builtin.
54-
sub _getChannel($name) is export {
55-
my $ioObj := %CHANNELS_HASH{$name};
56-
$ioObj // nqp::die("can not find channel named \"$name\"");
57-
return $ioObj;
58-
}
59-
6043
## EXPAND is a helper sub for {*} argument expansion; it probably
6144
## doesn't belong in the global namespace but this is a convenient
6245
## place to test it for now. It takes a string and splits it up

tools/build/Makefile-JVM.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ EXT = jar
3131
COMMANDS = \
3232
src/Partcl/commands/puts.pm \
3333

34-
COMMANDS = \
34+
NYICOMMANDS = \
3535
src/Partcl/commands/after.pm \
3636
src/Partcl/commands/apply.pm \
3737
src/Partcl/commands/array.pm \
@@ -134,13 +134,13 @@ src/Partcl.$(EXT): $(GEN_SOURCES)
134134
src/Partcl/commands.pm: $(COMMANDS) $(HELPERS) src/init.$(EXT) src/TclList.$(EXT) \
135135
src/Partcl/Actions.pm src/Partcl/Compiler.pm src/Partcl/Grammar.pm\
136136
src/Internals.pm
137-
$(ECHO) "use src::init;" > src/Partcl/commands.pm
137+
$(ECHO) "" > src/Partcl/commands.pm
138138
$(ECHO) "use src::TclList;" >> src/Partcl/commands.pm
139139
$(CAT) src/Partcl/Grammar.pm >> src/Partcl/commands.pm
140140
$(CAT) src/Partcl/Actions.pm >> src/Partcl/commands.pm
141141
$(CAT) src/Partcl/Compiler.pm >> src/Partcl/commands.pm
142142
$(ECHO) "class Builtins {" >> src/Partcl/commands.pm
143-
#$(CAT) $(COMMANDS) >> src/Partcl/commands.pm
143+
$(CAT) $(COMMANDS) >> src/Partcl/commands.pm
144144
$(ECHO) "}" >> src/Partcl/commands.pm
145145
$(CAT) src/Internals.pm >> src/Partcl/commands.pm
146146
$(CAT) $(HELPERS) >> src/Partcl/commands.pm

0 commit comments

Comments
 (0)