diff options
| author | Drahflow <drahflow@gmx.de> | 2013-12-22 17:05:46 +0100 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2013-12-22 17:05:46 +0100 |
| commit | 0bce2aecb9fddcacbd7353bcdc0c69703ed49e52 (patch) | |
| tree | f3e0e48ef874ebd0ef5d5fed90e41ca8f806214e | |
| parent | 95129aebebc6f2552a600e443db4a207412f5f5b (diff) | |
read now universally returns (undecoded) string
| -rw-r--r-- | compiler/elymasLexer.ey | 2 | ||||
| -rw-r--r-- | compiler/standardClient.ey | 2 | ||||
| -rw-r--r-- | interpreter/ElymasSys.pm | 53 |
3 files changed, 4 insertions, 53 deletions
diff --git a/compiler/elymasLexer.ey b/compiler/elymasLexer.ey index 2929285..411e7ad 100644 --- a/compiler/elymasLexer.ey +++ b/compiler/elymasLexer.ey @@ -43,7 +43,7 @@ { /input defv "" { - 4096 input .readstr cat + 4096 input .read cat _ "" streq not } { { _ "([^\\n]*)\\n(.*)" regex } { -102 -- TOKINT TOKSTR TOKID elymas .tokenize { diff --git a/compiler/standardClient.ey b/compiler/standardClient.ey index 2d62826..b92d5a4 100644 --- a/compiler/standardClient.ey +++ b/compiler/standardClient.ey @@ -428,7 +428,7 @@ } /writeall deff { =*f "" ==buffer { - buffer 4096 read cat =buffer # FIXME interpreter API should also have .read defined as returning string + buffer 4096 read cat =buffer buffer "" streq not } { buffer "\n" str .split ==lines diff --git a/interpreter/ElymasSys.pm b/interpreter/ElymasSys.pm index 9cb07d4..ad79b02 100644 --- a/interpreter/ElymasSys.pm +++ b/interpreter/ElymasSys.pm @@ -71,56 +71,8 @@ sub createFile { my $ret = POSIX::read($$scope->{' fd'}->[0], $buf, $count); die "read failed: $!" unless defined $ret; - $buf = [map { [ord, 'int'] } split //, $buf]; - - push @$data, [$buf, ['array', '[]', [['range', 0, $#{$buf}]], ['int']]]; - }, ['func', 'sys .file .read'], 'active'], - 'readall' => [sub { - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $count = popInt($data); - - my $buf = []; - while($count) { - my $readbuf; - my $ret = POSIX::read($$scope->{' fd'}->[0], $readbuf, $count); - die "read failed: $!" unless defined $ret; - - $buf = [@$buf, map { [ord, 'int'] } split //, $readbuf]; - $count -= $ret; - } - - push @$data, [$buf, ['array', '[]', [['range', 0, $#{$buf}]], ['int']]]; - }, ['func', 'sys .file .read'], 'active'], - 'readstr' => [sub { - # FIXME: give the file an encoding and respect it here, buffering half-characters if needed - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $count = popInt($data); - - my $buf; - my $ret = POSIX::read($$scope->{' fd'}->[0], $buf, $count); - die "read failed: $!" unless defined $ret; - push @$data, [$buf, 'string']; - }, ['func', 'sys .file .readstr'], 'active'], - 'write' => [sub { - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $buf = popArray($data); - $buf = join '', map { chr($_->[0]) } @$buf; - - my $ret = POSIX::write($$scope->{' fd'}->[0], $buf, length $buf); - die "write failed: $!" unless defined $ret; - - push @$data, [$ret, 'int']; - }, ['func', 'sys .file .write'], 'active'], + }, ['func', 'sys .file .read'], 'active'], 'writeall' => [sub { my ($data) = @_; @@ -135,8 +87,7 @@ sub createFile { $buf = substr($buf, $ret); } }, ['func', 'sys .file .writeall'], 'active'], - 'writestr' => [sub { - # FIXME: give the file an encoding and respect it here + 'write' => [sub { my ($data) = @_; die "file not open" if $$scope->{' fd'}->[0] == -1; |
