2020-08-21 19:10:33 +02:00
|
|
|
# All entities in JAPL are objects. Currently, this module serves more
|
|
|
|
# as a logical root rather than an actual implementation, but it will
|
|
|
|
# be needed in the future when more and more default methods are added
|
|
|
|
# to objects, without having to add a (possibly redundant) implementation
|
|
|
|
# into each specific file in the types directory
|
2020-08-15 11:27:04 +02:00
|
|
|
import strutils
|
|
|
|
import strformat
|
|
|
|
|
2020-08-21 19:10:33 +02:00
|
|
|
|
2020-08-13 23:39:26 +02:00
|
|
|
type
|
|
|
|
ObjectTypes* = enum
|
2020-08-21 19:10:33 +02:00
|
|
|
STRING, EXCEPTION, FUNCTION,
|
|
|
|
CLASS, MODULE
|
2020-08-13 23:39:26 +02:00
|
|
|
Obj* = ref object of RootObj
|
2020-08-21 19:10:33 +02:00
|
|
|
kind*: ObjectTypes
|
2020-08-13 23:39:26 +02:00
|
|
|
|
|
|
|
|
2020-08-21 19:10:33 +02:00
|
|
|
func objType*(obj: Obj): ObjectTypes =
|
2020-08-14 08:25:05 +02:00
|
|
|
return obj.kind
|
|
|
|
|
|
|
|
|
2020-08-23 12:10:08 +02:00
|
|
|
method stringify*(obj: Obj): string {.base.} =
|
2020-08-21 19:10:33 +02:00
|
|
|
result = "<object (built-in type)>"
|
2020-08-13 23:39:26 +02:00
|
|
|
|
|
|
|
|
2020-08-23 12:10:08 +02:00
|
|
|
method typeName*(obj: Obj): string {.base.} =
|
|
|
|
result = &"<class '{($obj.kind).toLowerAscii()}'>"
|
|
|
|
|
|
|
|
|
|
|
|
method isFalsey*(obj: Obj): bool {.base.} =
|
|
|
|
result = false
|
|
|
|
|
|
|
|
|
|
|
|
method valuesEqual*(a: Obj, b: Obj): bool {.base.} =
|
|
|
|
result = a.kind == b.kind
|