forked from Mirror/wren
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:
@ -1 +1 @@
|
||||
class Subclass is Class {} // expect runtime error: Subclass cannot inherit from Class.
|
||||
class Subclass is Class {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Class'.
|
||||
|
||||
@ -5,4 +5,4 @@ var ClosureType
|
||||
ClosureType = Fn.new { IO.print(a) }.type
|
||||
}
|
||||
|
||||
class Subclass is ClosureType {} // expect runtime error: Subclass cannot inherit from Fn.
|
||||
class Subclass is ClosureType {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Fn'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is Fiber {} // expect runtime error: Subclass cannot inherit from Fiber.
|
||||
class Subclass is Fiber {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Fiber'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is Fn {} // expect runtime error: Subclass cannot inherit from Fn.
|
||||
class Subclass is Fn {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Fn'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is List {} // expect runtime error: Subclass cannot inherit from List.
|
||||
class Subclass is List {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'List'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is Map {} // expect runtime error: Subclass cannot inherit from Map.
|
||||
class Subclass is Map {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Map'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Foo is 123 {} // expect runtime error: Must inherit from a class.
|
||||
class Foo is 123 {} // expect runtime error: Class 'Foo' cannot inherit from a non-class object.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is Range {} // expect runtime error: Subclass cannot inherit from Range.
|
||||
class Subclass is Range {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Range'.
|
||||
|
||||
@ -1 +1 @@
|
||||
class Subclass is String {} // expect runtime error: Subclass cannot inherit from String.
|
||||
class Subclass is String {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'String'.
|
||||
|
||||
@ -22,5 +22,3 @@ bar.method(1, 2) // expect: bar
|
||||
bar.method(1, 2, 3) // expect: foo
|
||||
bar.method(1, 2, 3, 4) // expect: bar
|
||||
bar.override // expect: bar
|
||||
|
||||
// TODO: Prevent extending built-in types.
|
||||
|
||||
Reference in New Issue
Block a user