CPython-Like Builtins
Implemented CPython-Like Built-ins¶
The following built-in functions work similarly to their equivalents in CPython; see the specific functions below for notes
abs(object)¶
- Currently only implemented for int32's or objects convertible to int32's. The
__abs__attribute is not currently supported.
breakpoint()¶
- Drops the user into an interactive SPy debugging session via
spdb, apdb-likedebugging interface for SPy.
dict[keytype, valuetype]()¶
- In SPy,
dictmust always be fully typed and used asdict[keytype, valuetype]., The syntaxdict[keytype, valuetype]()can be used to create a new empty dict of the given types. The simpler syntaxd: dict[keytype, valuetype] = {}can also be used. - Unlike CPython, this does not (currently) accept an Iterable to create a new dict from.
- The implementation (in SPy) of
dictcan be viewed here.
dir(object)¶
- Returns a list of object’s attributes’ names, the names of its class’s attributes, and recursively of the attributes of its class’s base classes.
dir(type)is not currently implemented. - The no-argument form of
dir()(i.e. print local variables) is not currently implemented. Custom__dir__methods on objects are not currently supported.
float(object)¶
- Converts
objectto a float if able.floatis an alias for thef64type.
getattr(obj, name: str)¶
- Return the value of the named attribute of object.
attrmust be blue
hash(object)¶
- Currently implemented for types:
i8,i32,u8,bool,str. - By default, instances of SPy structs are not hashable. As a planned future feature, structs will have auto-generated
__hash__by default, but this is awaiting implementation. Currently, users can implement the__hash__function to permit hashing.
int(object)¶
- Converts
objectto an int if able. Works for number types, as well as strings. - The
inttype is currently an alias toi32. In the future,intwill alias preferred individual types for specific platforms, but currently it is alwaysi32.
len(object)¶
- Return the length (the number of items) in a container
list[type]()¶
- The syntax
list[type]()can be used to create a new empty list of the given type. The simpler syntaxl: list[membertype] = []can also be used. Unlike CPython, this does not (currently) accept an Iterable to create a new list from. - The implementation (in SPy) of
listcan be viewed here.
max(x: i32, y: i32)¶
- Currently only implemented for int32's or objects convertible to int32's.
min(x: i32, y: i32)¶
- Currently only implemented for int32's or objects convertible to int32's.
object¶
objectis implemented as a type, and can be used as a parameter or return type. "Plain" objects (i.e.x = object()) are not supported.
print(obj)¶
- The print function is currently not variadic, in the sense that it only accepts a single argument. The built-in types are special-cased, and SPy can always print blue objects by pre-computing their string representation
range(stop)¶
range(start, stop, step)
-
Creates an iterable set of indices between
startandstop, jumping overstepindices between each. -
The implementation (in SPy) of
rangecan be viewed here.
repr(object)¶
- Returns string containing a printable representation of an object.
setattr(object, name: str, value: obj)¶
- Assigns
valueto the attribute ofobjectnamed byname.attrmust be blue.
slice(stop)¶
slice(start, stop, step=None)
-
Return a slice object representing the items reached when iterating over range(start, stop, step). The start and step arguments default to None.
str(object)¶
- Returns a string version of the object. Selecting an encoding is not currently implemented.
tuple()¶
- The syntax
tuple[t1, t2, ...](val1, val2 ...)can be used to create a new tuple, witht1as the type ofval1, etc. unlike CPython, this does not (currently) accept an Iterable to create a new tuple from. - The implementation (in SPy) of
tuplecan be viewed here.
type(object)¶
- Returns the type (i.e. the dynamic type at runtime) of an object
Not-Implemented CPython Built-ins¶
The following CPython built-ins are not currently implemented in SPy. Each category has a brief note about the current state of that category of object or function - some require additional internal mechanics, others are simply lower priority that other facets of the language to this point.
Async¶
- SPy does not currently have an async story.
-
aiter(), anext()
Iterables and Iterators¶
Iterables and collections are very much an area of active developmen; as their API solidifies, these types of builtins should become more straightforward to implement.
- Generators are not currently supported in SPy.
-
all(), any(), enumerate(), filter(), iter(), map(), next(), reversed(), sorted(), sum(), zip()
Math¶
- Number types beyond int and float are in active development; some of the math functions below are also in active development.
-
divmod(), bin(), hex(), oct(), pow(), round()
Function Types, Introspection and Metaprogramming¶
- The internals of SPy are significantly different from CPython; as such, the road to (and need for) some of these built-ins is less straightforward. Some are also waiting on internal details to solidify prior to implementation.
-
callable(), classmethod(), compile(), delattr(), eval(), exec(), globals(), hasattr(), help(), id(), isinstance(), issubclass(), locals(), property(), super(), vars(). __import__()
Type Conversion¶
- Many of these types are not implemented yet; others are in active development.
-
ascii(), bool(), bytearray(), bytes(), chr(), complex(), format(), frozenset(), memoryview(), ord() set()
I/O¶
- The I/O story is currently a high priority and is in active development.
-
input(), open()