aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/working/asm.ey8
-rw-r--r--interpreter/ElymasAsm.pm51
-rw-r--r--interpreter/ElymasSys.pm6
-rw-r--r--interpreter/ElymasX86.pm11
4 files changed, 62 insertions, 14 deletions
diff --git a/examples/working/asm.ey b/examples/working/asm.ey
new file mode 100644
index 0000000..87d7c7a
--- /dev/null
+++ b/examples/working/asm.ey
@@ -0,0 +1,8 @@
+sys .asm /asm defv
+
+4096 asm .alloc /e defv
+
+195 e .base asm .poke
+
+e .base asm .execute
+e .free
diff --git a/interpreter/ElymasAsm.pm b/interpreter/ElymasAsm.pm
new file mode 100644
index 0000000..63b7803
--- /dev/null
+++ b/interpreter/ElymasAsm.pm
@@ -0,0 +1,51 @@
+package ElymasAsm;
+
+use strict;
+use warnings;
+
+use Elymas;
+use ACME::Bare::Metal;
+
+our $asm = {
+ 'alloc' => [sub {
+ my ($data) = @_;
+
+ my $size = popInt($data);
+ my $block = ACME::Bare::Metal::allocate($size);
+
+ my $scope; $scope = \{
+ 'base' => [$block, 'int', 'passive'],
+ 'size' => [$size, 'int', 'passive'],
+ 'free' => [sub {
+ my ($data) = @_;
+
+ ACME::Bare::Metal::deallocate($$scope->{'base'}->[0], $$scope->{'size'}->[0]);
+ }, ['func', 'sys .asm .free'], 'active'],
+ };
+
+ push @$data, [enstruct($$scope)];
+ }, ['func', 'sys .asm .alloc'], 'active'],
+ 'poke' => [sub {
+ my ($data, $scope) = @_;
+
+ my $addr = popInt($data);
+ my $value = popInt($data);
+
+ ACME::Bare::Metal::poke($addr, $value);
+ }, ['func', 'sys .asm .poke', ['int', 'int'], []], 'active'],
+ 'peek' => [sub {
+ my ($data, $scope) = @_;
+
+ my $addr = popInt($data);
+ my $value = ACME::Bare::Metal::peek($addr);
+
+ push @$data, [$value, 'int'];
+ }, ['func', 'sys .asm .peek', ['int'], ['int']], 'active'],
+ 'execute' => [sub {
+ my ($data, $scope) = @_;
+
+ my $addr = popInt($data);
+
+ ACME::Bare::Metal::execute($addr);
+ }, ['func', 'sys .asm .execute'], 'active'],
+};
diff --git a/interpreter/ElymasSys.pm b/interpreter/ElymasSys.pm
index becc4d0..d403bd6 100644
--- a/interpreter/ElymasSys.pm
+++ b/interpreter/ElymasSys.pm
@@ -4,14 +4,14 @@ use strict;
use warnings;
use Elymas;
-use ElymasX86;
+use ElymasAsm;
use POSIX;
my $rwmask = &POSIX::O_RDONLY | &POSIX::O_WRONLY | &POSIX::O_RDWR;
our $sys = {
'file' => [sub {
- my ($data) = @_;
+ my ($data, $scope) = @_;
my $file = createFile(-1, &POSIX::O_RDONLY);
push @$data, [enstruct($file)];
@@ -20,7 +20,7 @@ our $sys = {
'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'],
- 'x86' => [enstruct($ElymasX86::x86), 'passive'],
+ 'asm' => [enstruct($ElymasAsm::asm), 'passive'],
};
sub createFile {
diff --git a/interpreter/ElymasX86.pm b/interpreter/ElymasX86.pm
deleted file mode 100644
index f825fdd..0000000
--- a/interpreter/ElymasX86.pm
+++ /dev/null
@@ -1,11 +0,0 @@
-package ElymasX86;
-
-use strict;
-use warnings;
-
-use Elymas;
-use ACME::Bare::Metal;
-
-our $x86 = {
- #FIXME
-};