aboutsummaryrefslogtreecommitdiff
path: root/interpreter/ElymasSys.pm
diff options
context:
space:
mode:
Diffstat (limited to 'interpreter/ElymasSys.pm')
-rw-r--r--interpreter/ElymasSys.pm58
1 files changed, 58 insertions, 0 deletions
diff --git a/interpreter/ElymasSys.pm b/interpreter/ElymasSys.pm
new file mode 100644
index 0000000..1718060
--- /dev/null
+++ b/interpreter/ElymasSys.pm
@@ -0,0 +1,58 @@
+package ElymasLinux;
+
+use strict;
+use warnings;
+
+use Elymas;
+
+use POSIX ();
+
+our $linux = {
+ 'open' => [sub {
+ my ($data, $scope) = @_;
+
+ my $mode = popInt($data);
+ my $flags = popInt($data);
+ my $pathname = popString($data);
+
+ my $fd = POSIX::open($pathname, $flags, $mode);
+ $fd = -1 unless defined $fd;
+
+ push @$data, [$fd, 'int'];
+ }, ['func', 'linux .open'], 'active'],
+ 'close' => [sub {
+ my ($data, $scope) = @_;
+
+ my $fd = popInt($data);
+
+ my $ret = POSIX::close($fd);
+ $ret = -1 unless defined $ret;
+
+ push @$data, [$ret, 'int'];
+ }, ['func', 'linux .close'], 'active'],
+# 'read' => [sub {
+# my ($data, $scope) = @_;
+#
+# my $count = popInt($data);
+# my $buf = popArray($data);
+# my $fd = popInt($data);
+#
+# my $ret = POSIX::close($fd);
+# $ret = -1 unless defined $ret;
+#
+# push @$data, [$ret, 'int'];
+# }, ['func', 'linux .read'], 'active'],
+};
+
+map { installIntConstant($_) } qw(O_RDONLY O_RDWR O_WRONLY);
+
+sub installIntConstant {
+ my ($name) = @_;
+
+ my $elymasName = $name;
+ $elymasName =~ s/_//g;
+
+ $linux->{$elymasName} = [${$POSIX::{$name}}, 'int', 'passive'];
+}
+
+1;