First pass at implementing foreign classes.

Most of the pieces are there:

- You can declare a foreign class.
- It will call your C function to provide an allocator function.
- Whenever a foreign object is created, it calls the allocator.
- Foreign methods can access the foreign bytes of an object.
- Most of the runtime checking is in place for things like subclassing
  foreign classes.

There is still some loose ends to tie up:

- Finalizers are not called.
- Some of the error-handling could be better.
- The GC doesn't track how much memory a marked foreign object uses.
This commit is contained in:
Bob Nystrom
2015-08-15 12:07:53 -07:00
parent 7a79b8fac6
commit 48bdbc7745
33 changed files with 720 additions and 119 deletions
@@ -0,0 +1,9 @@
foreign class Foo {
bar {
// Can't read a field.
IO.print(_bar) // expect error
// Or write one.
_bar = "value" // expect error
}
}
@@ -0,0 +1,7 @@
class Foo {
method() {
_field = "value"
}
}
foreign class Bar is Foo {} // expect runtime error: Foreign class 'Bar' may not inherit from a class with fields.
@@ -0,0 +1,2 @@
// Missing "class".
foreign blah A {} // expect error