aboutsummaryrefslogtreecommitdiff
path: root/interpreter/ElymasSys.pm
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2012-12-14 12:15:40 +0100
committerDrahflow <drahflow@gmx.de>2012-12-14 12:15:40 +0100
commitf20e50a4e3ac3aeeac84358a68c253358f213667 (patch)
treeefed2b2c51fec59a0fae8f59845afa1b520e0204 /interpreter/ElymasSys.pm
parent26c5b2be3918e7e27f9ae0616f3a3a629190b19c (diff)
Compiler Tokenizer working
Diffstat (limited to 'interpreter/ElymasSys.pm')
-rw-r--r--interpreter/ElymasSys.pm15
1 files changed, 15 insertions, 0 deletions
diff --git a/interpreter/ElymasSys.pm b/interpreter/ElymasSys.pm
index 09e3f71..7e6d1b9 100644
--- a/interpreter/ElymasSys.pm
+++ b/interpreter/ElymasSys.pm
@@ -18,6 +18,7 @@ our $sys = {
'in' => [enstruct(createFile(0, &POSIX::O_RDONLY)), 'passive'],
'out' => [enstruct(createFile(1, &POSIX::O_WRONLY)), 'passive'],
'err' => [enstruct(createFile(2, &POSIX::O_WRONLY)), 'passive'],
+ 'argv' => [[map { [$_, 'string'] } @ARGV[1 .. $#ARGV]], ['array', 'sys .argv', ['range', 0, $#ARGV - 1], ['string']], 'passive'],
};
sub createFile {
@@ -91,6 +92,20 @@ sub createFile {
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 .writestr'], 'active'],
'write' => [sub {
my ($data) = @_;