Kuroko v1.3.0
This is Kuroko, a dynamic, bytecode-compiled, interpreted language with significant whitespace and familiar syntax.
For a complete tutorial and sample code, please visit kuroko-lang.github.io.
If you believe you have discovered a bug in this release, please file an issue report here on Github or join #toaruos
on Libera.chat to discuss the problem.
What's new in 1.3.0
Over 200 commits have been made since 1.2.5, including several major feature additions, bug fixes, and C API improvements.
Major Features
- Optimized method invocations reduce object allocation pressure when calling bound methods.
- Cached method operators eliminate hash lookup costs when using built-in operators.
- More operator overloads including in-place ops (
+=
, etc.), unary+
, infix@
(__matmul__
) - Support for
else
branches infor
,while
,try
for branches to execute upon successful completion. - Relative imports and improved package module support, with a new import resolution strategy.
- Arbitrary precision integers with a new
long
type, using an integrated bigint implementation and with seamless switchover from smallint
s. - Exception contexts and causes when raising within an
except
block or withraise ... from ...
. - Format specs and
=
in f-strings with the addition of__format__
. __setattr__
and__set_name__
methods- Updated
codecs
module
Other Improvements and Bug Fixes
- Added comparator methods for
list
s andtuple
s. - Some loops and iterator operations have been optimized.
- Implemented Python name mangling for private identifiers in classes.
- The compiler now supports concatenating unalike string tokens (f-strings, r-strings, and regular strings).
- Issues with memory allocation tracking that resulted in over-eager garbage collection have been resolved.
- Reallocation of value stacks used in C native functions is now deferred until the function returns.
- Global namespaces are now bound to functions, not codeobjects, and functions objects can be built at runtime from codeobjects combined with appropriate upvalue sources and global tables (either through an instance or dict).
- The compiler now builds expressions directly and the repl will only print the results of expression statements, rather than peeking beyond the top of the stack to find statement values.
- The
dis
module can now be used with-m
to compile and print a disassembly of source inputs, recursively, without running them. - Type hints can now be added to local declarations, and are computed and stored when functions are created in a manner similar to arguments. The keys for these type hints are indexes into the local names table, where the actual names and valid lifetimes on the variables can be found.
- The binding for
**
has been corrected to match Python, binding to the right, so2 ** 3 ** 4
is equivalent to2 ** (3 ** 4)
instead of(2 ** 3) ** 4
. - All global state has been consolidated to the VM state and threadstate objects in the interpreter.
- The scanner and compiler are now reentrant.
- Upvalue capture in generators has been improved.
- When
break
ing orcontinue
ing from within awith
ortry
,__exit__
handlers andfinally:
blocks are now executed correctly. krk_runfile()
now provides the exit frame guaranteeskrk_callfile
provided, makingkrk_callfile
redundant; it has been removed.- A new string formatter has been implemented for
krk_runtimeError
, supporting several common usecases such as printing the type name of an object, directly printingKrkString*
objects, and callingrepr
on arguments. __pow__
is now supported onint
s by default. (float.__pow__
still requiresimport math
to be bound to a libm implementation ofpow()
)
Changes from RC0
let
is now a simple statement and can be chained with semicolons and used in a-c
argument.- Linear-time base conversions for power-of-two string formatting and parsing of
long
s. - Some
math
functions have been changed. - New utility functions,
krk_parseArgs
,krk_pushStringBuilderFormat
, have been added to the C API. File
,BinaryFile
,Directory
are now part offileio
.DYNAMIC_PROPERTY
has been removed from the C API.- The exception hierarchy has been reworked to more closely match Python.
- More accurate conversions between
float
andlog
.
Changelog
- 8043ca2 Pre-hash strings from str(),hex(),oct(),bin() conversions
- 08aa30a Calculate hash while multiplying strings
- b9b60ad Better power-of-two base conversions for parsing/printing longs
- 564a4b3 Parse 'let' declarations as simple statements
- a59b635 tgamma/lgamma should exist on all of these platforms
- 90f6854 Just bind tgamma instead for now; can alias it later
- 6cb3be2 Don't bind 'math.gamma' to libc gamma, we have no idea what that might actually calculate
- d63ab70 Fix dangling pointer to VM value stack in krk_processComplexArguments
- 81c5706 Saturate rather than failing on index bounds in list.insert()
- ab0418f fix missing .0 when printing negative whole floats
- 016e9e4 Use StringBuilders in compiler string parsing
- 0b696fc StringBuilders should be cleared when finished or discarded
- e4f96af Expand KRK_Method, KRK_Function in doxygen docs, instead of old _METHOD, _FUNC
- 9732e01 Drop SCAN_TRACING
- 13d0189 Add an
__options__
import to disable implicit 'self' - e6e63ad Fixup backspace behavior in rline
- 4e791e9 Fix bad return values from
int.__eq__
,float.__eq__
- b9f8f4c Bump serial
- 342ee04 Cleanup krk_disassembleInstruction
- fb57355 Use krk_parseArgs in os module
- 607ac88 Support several int conversions in krk_parseArgs
- db3a628 Expose _protected in util.h, useful elsewhere
- ca981fb Cleanup operators to use a common function
- bdfb0e2 Make paste() a little bit smarter
- de7e32b Cleanup input()
- 7bd6cdf Implement proper float conversions for longs
- 984dea5 ToaruOS has sigaction now
- ad39476 Clean up function, method repring
- 29199c9 And in base objects...
- ca631e0 Use new formatted string builders in various places
- 32c1dba Add krk_stringFromFormat
- a632144 Fix handling of ^C when editing multi-line input
- 6b8d7ee Move StringBuilder functions out of header, into obj_str; add pushStringBuilderFormat
- 6029d50 Fix incorrect handling of tombstones in tableGet_Fast, tableFindString
- f6a5f7f Cleanup exception hierarchy
- 1129323 Trying to build an exception may itself raise an exception
- 5d9d33e The builtins module really should be called 'builtins'
- 879a26f Support rline in the simple-repl and update it to be more like the real one
- 0df346f Don't keep rebuilding class object that tracks compiler state for gc...
- 6d8d33c Move File, BinaryFile, Directory to fileio module
- 0455137 Store fget, fset as direct object pointers if we can
- 8236fb9 Rewrite attribute get/set to fix descriptors; drop DYNAMIC_PROPERTY
- c519298 reorder opcodes since we added EXIT_LOOP
- 71dd3ec Use krk_parseArgs in a few places
- 15fa509 Add krk_parseArgs utility function
- 2387ac6 bytes() can take iterators, int, encode strings (utf-8)
- 0d23254 Replace all uses of PUSH_CHAR in obj_str with string builders
- b0a35fb Attach mode strings to stdin, stdout, stderr objects so they repr correctly
- 85d64e0 _macos_currentThread should always be inlined
- efb73c8 Don't use PRIkrk_int in exception format strings, we can't trust it
- 5190c0c Mark this as rc0
- 2793090 Make deb package versions a bit smarter
- bc413b6 Missing cast when shifting '1' by digit size in obj_long
- b3fbb9c Cleanup old unpackArray things
- 5c469dd clang seems to think this can be uninitialized
- 9bd257e Exceptions raised in 'else' should run 'finally' before raising, not run 'except'
- 2f18ecb Support 'else' block on 'try'
- d6c9602 Properly run
__exit__
, finally on break or continue - d89b023 Support %.*s in exception formatter
- 0a9eeca Cleanup sandbox
- 473f0ba Fix Makefile oops with rpath=$ORIGIN
- 3de86ab Break out 'kuroko' module, expose init functions, and let VM be initialized without modules
- b862060 Minor cleanup of import errors
- 8c387b5 Clean up some C API docs
- 3b770aa Fixup krk_runfile and remove krk_callfile
- 71ab25b Add more exposed API functions to headers
- 74d3b5f Move exception generation into src/exceptions.c
- b5ab2bd Support del on function attributes, since we support get and set
- a0d66aa Serial to 7
- 3b56331 Don't use 'char*' Attribute functions in get/set/delattr
- 26a31b7 Use a custom formatter for krk_runtimeError
- b9c8e36 Don't rely on %s to print messages attached to exceptions
- 9075a58 Fix wrong size of specialMethodNames
- 8fa4a62 serial to 6
- fb014bf Fix up some feature disable flags
- 786457c Fixup typedefs for KrkObj, KrkString
- 7d568a2 Make the compiler reentrant
- 39ed214 Remove global state from debugger
- 73cdaee Get rid of several redundant globals
- b7f81d9 KrkGenericAlias → krk_GenericAlias for symbol name consistency
- dd621b9 Don't let an already-running generator execute
- 4dc3f08 Fix upvalue capture in generators
- 8213430 Close upvalues even if exception exits runtime
- ee86a24 b5
- a580a83 Codecs revisited (#28)
- 79a4a02 Resolve long-standing left/right binding issue with '**'
- b966db7 Bump serial to b4
- 825dbe1 Support type hints on locals
- c739180 Cleanup exported symbols in rline
- eae29dd Avoid unnecesasry type checking in tableGet_fast
- 6eda981 Be more clear on OPERANDS being unsigned
- d027b86 Bump serial, 1.3.0b3
- d73d7bd -m dis should recurse
- e22410d Still need to advance into that string token...
- 77c38ea Only print actual expressions in repl; fix dumb hacks
- a20c89f Support -m dis with a dis.krk pseudomodule
- f8acd8a Fix segfault in syntax error when previous token is synthetic
- b7e1454 int in bytes
- cf4683e
tuple.__mul__
- 56c1bbe Tab-complete builtin module names after 'import', 'from'
- d332688 Bump serial number
- 6e2ba5f Allow functions to be built from codeobjects, upvalues, dict/instance
- 316d121 Bind globals to functions, not codeobjects
- 7dc754a Update outdated comment about enum values for opcodes
- 3472fcf Accept trailing comma in set literal
- ed81bc9 Randomize the opcode table.
- 212efab Consolidate opcode definitions and do not expose the macros in public headers
- ff43e94 Cleanup common method invocation instructions
- 431d347 OP_TEST_ARG
- eeca53e Fix bad argument collection with optional positionals
- 258527e Fill out missing tokens in parse table for debugging; remove TOKEN_ from string names
- be3c8a9 Set release serial, shorten -beta to b
- 15014df Add kuroko.hexversion
- 7193115 Let MAKE_STRING handle the = prefix, after FORMAT_VALUE swaps it around
- feebd6e Emit emit string not MAKE_STRING 0
- a3b2722 Unicode character for fill in
__format__
- 0c10107 Support Unicode strings in argument to str.*strip
- aa97b37 f'{foo=}' should default to !r if no = or !s
- ec6a896 Display textual representation of FORMAT_VALUE type in dis like CPython does
- 391a4d7 Fixup concatenating unalike string tokens in compiler
- e5f4208
str.__format__
- cb1bfa4 Cleanup, fix, break out common format string parsing
- 7d409eb Format spec support in f-strings
- 9230d4f
int.__format__
,long.__format__
with as close to Python semantics as I can be bothered - d8a1861 format() and
object.__format__()
- f1c0af7 Cache
__format__
method - f24cb33 Fixup SET_GLOBAL to use IfExists, no need for delete
- 9b5ce15 Implement Python's identifier mangling
- d00bdda Strings, too...
- 17a6aaf Fix parse error when 'if' ends on a class
- 95c6f17 Remove accidentally committed test file
- 6fa951a Subclass cleanup must use exact key match to not call VM during GC sweep
- ff23dbb Update docs
- c10a457 Rudimentary
__setattr__
support - cf98b93
dict.__eq__
- ae99ce1 set comparisons
- ff19144 Even more correct sequence comparisons...
- 6d59ddb 'inline' on krk_valuesEqual does nothing
- c9b989c Add test for
__set_name__
- 2d8de13 More fixes to tuple comparisons; port to lists
- d601800 list and tuple stuff should use SameOrEqual not just Equal
- 92d8d0e Cleanup, simplify equality operation
- 17772c7 unary + (
__pos__
) - ed52b72 operator @ (
__matmul__
) - 855d342 Support
__set_name__
- 388a649 Perform identity checking before equality checking for table keys
- c49a12e Highlight krk sources as Python on gitlab mirror
- af18b20 Better long printing
- afc522a Replace KRK_METHOD, KRK_FUNC with nicer macros
- 25d5f88 Clean up a bunch of potential type checking issues
- 7ff7c26 Standardize =,is,~,- a bit more; ELF 'protected' on operator functions
- e95cc5d Break out collection builder opcodes into inlinable function
- 9237891 No reason for that callgrind stuff to be a big macro
- ee1420c Use krk_unpackIterable (and a temporary tuple) in OP_UNPACK
- eabe6f9 Cleanup some exposed string functions we don't need
- 3cda8cf Replace macro unpackIterableFast with callback-driven function
- ebe1b02 Remove tupleOf builtin
- 19927ea Stop using tupleOf in codec tools
- a429aa9
tuple.__init__
should not call tupleOf - 31509bc Remove setOf, listOf, dictOf builtins (all unused)
- 87f6c31
tuple.__add__(tuple)
- 8314e4c 'zip' as a class
- 5d77dec Set rpath in tools
- fe4fd1a Retool more things to use utility macros
- 0ae051b Rewrite Exceptions using typechecking method macros
- f86887b Elide : for zero-length
Exception.__str__()
- de0af11 KeyError should repr instead of print because Python does that
- 8b6952d Include module name when printing exception name
- f38a451 Attach and build upon partial tracebacks
- 85ad910 Attach
__cause__
,__context__
to exceptions; support 'raise ... from ...' - 2d26917 Exceptions with no argument should not set it to 'None'
- 3167888 Restore frame pointer correctly on exit due to inner exception
- 1d828ad Bail early if _eq raises an exception
- 33946d8 Break early from exceptions in more list functions
- 9f2791f Describe 'END_FINALLY' handler sentinel in printValueSafe
- 6512720 Revert accidental inclusion of debug prints when print() encounters an exception
- e33a37a Cleanup complex argument parsing
- abd90cc Fixup, complete tuple comparisons
- 150a37f NotImplemented == NotImplemented
- e39628b When returning with an uncaught exception in an inner call, set the stack appropriately
- 2e15653 Add some tuple comparators
- 0b7988c Ensure list.sort doesn't run more comparators with an active exception
- ed9b522 Use absolute stack offset when exiting from a native call
- 2000161 Trim trailing whitespace in string-to-int/long conversions
- a354c4a Fixup int(str) which should default to base 10, and throw exceptions
- 0d28885 Fix that one old test to not go through float()
- e7ca71e Support more special methods in doc generation
- d968a91 Cleanup missed setlice/delslice refs
- 563a2b1 Update version suffix to -beta
- fa452d6 Cleanup macros for BIND_TRIPLET
- 4c5a584 highlight 'long' as a type in rline
- fd7bc2a Internal long inspection methods
- 8c6273c
long.__abs__
- c5fa5cf Fix
__pow__
loop order, missing scratch reg - 5da2708 (-1) ** 0 is in fact 1
- 468fb09 Implement
__pow__
for integers using method described by HAC 14.79, as CPython does - 978f09a Add
set.__xor__
- edc86e2 Rudimentary float operations for longs; definitely more inaccurate than they could be
- c670dd6 Addition long (and int) functions, as per Python
- 1079190 Collect a bunch of digits into a uint64_t first...
- 21cd0c8 typo'd condition for converting negatives
- f61922d long type
- 635dd44 Add method fallbacks for oct,hex,bin,abs,float; move int methods to class
- 82292d0 Optimize 'while True' and 'while 1' at a parse level
- 5e464b3 Upvalue closing only needs to happen once in CLOSE_MANY
- 4b02118 Bind a few new dynamic properties for code objects
- 2314a4e Rudimentary % formatter for strings
- 0e51103
__call__
must be one of these, let's skip the extra jumps and switch... - 92c0d09 Implement
dict.__ior__
- 7d3df0d Cache binary operator methods, support inplace variants
- ed31f1e Try some minor optimizations to function calls
- 3721ebc shift-and-compare is probably better than mask & compare
- 248f54a Pull out attributeUnpack to a separate function because I may want to just get rid of it
- cdcfb63 New '
__options__
' psuedo-module with compile-time changes - b2846c1 (bench) python fasttimer should check for exceptions
- cd25ada Less obtuse list.append() benchmark
- 75e0ec9 Fix up some syntax errors
- 3bfa32a Print ^s for the whole width of a faulting symbol in a syntax error, looks cooler
- 4fd68ec Simplify rewinding infix operators
- 5f3a2b4 Expose
__args__
directly on codeobject - b434930 Add more keywords to the stdlib highlighter
- 5a79f27 Fix incorrect OP_CLOSURE instruction size returned by dis.examine
- 9c25e20 Take the line number from the previously parsed token when build synthetics
- bce9943 (meta) upgrade github codeql workflow
- 48f9d34 Tests for bound method edge cases
- 2e7bf54 Bound methods can be bound to non-function callables
- 55849aa Fix edgecases around expanded calls to bound callables when no stack space is available
- 3bc8d72 Take best-of-ten in most benchmarks, add inner_loop benchmarks
- 1ee63c1 Use a flag to mark classes not subclassable
- 098b316 prevent functions, codeobjects from being initialized; methods can be
- fa2b2c0 Merge flags
- c785b25 kuroko.inspect_value() shows KrkValue byte representation
- b3c693e Disallow subclassing of some core types that are not subclasses of Instance
- 3f0522d Change getsizeof calculations; stack-only values have 0 size
- 2437e73 Bad malloc size in putenv?
- f16083a Pack object type/flags/hash better
- bbfe948 Lambda should be able to accept *args and **kwargs
- 65f7ae3 Simplify cached method things; don't expose the enum in headers
- a41410d Stick 'subclasses' before method cache
- bbf378e Reorder arguments to callNativeOnStack for better fallthrough to native call
- d18b08e Native function args should be const
- 8ade3af Support dir() with no arguments; returns globals only
- ae10f81 Start calling this 1.3
- 285f7cd Fix up path search ordering to be more like CPython; implement
__main__.krk
- a4e2b5c Relative imports
- 3645047 Same for None
- f14ca90 Avoid
NotImplemented.__hash__
resolving toobject.__hash__
and segfaulting - 81e3bb3 Defer freeing pre-grown stacks when using them in native calls
- 1f6afa7 Add new CLOSE_MANY and POP_MANY instructions
- 7dff49c Fix incorrect hashing of classes in fallback added for subclass tracking
- aa67816 Fix bad encoding of large upvalue indexes
- 32b3af5 Unset class bases when doing final free so we don't access potentially-freed subclass tables
- 1ac8f29 Invalidate caches of subclass method pointers when they change in a superclass
- 1c5fc95 Update copyright years, it's been 2022 for a while now
- 3601411 Support step value in range()
- 1acd024 Workaround horrible thread-local performance on macOS (aarch64)
- 74e064c Test case for preceding fix
- b9776ae Revert loop on 'for ... if ...'
- 341fd87 New optimized loop and jump instructions
- 657a02a Reduce recursion overhead when calling objects
- c4b8339 More efficient bool, int comparisons, sometimes
- c38e78e Fast-case
listiterator.__call__
instanceof check - d0c2f8c Cleanup memory size debugger, no need for external hashmap
- cb14875 Catch exceptions early in timeit.timeit
- 4a05219 Support 'else' blocks on for and while loops
- ece7da2 Support = to print f-string expression alongside value
- 78e85ce Support an extensive memory debugging process, if you provide some extra files
- 27278cf Fixup allocation size for bytes literals
- 953e57f Fix two more instances of bad alloc/dealloc pairings
- 73c82e0 Fixup display of gc debug info on 32-bit platforms
- a50cfc6 Fix tracking of memory from instances of objects with allocSize != sizeof(Instance)
- 9b1875d Fix incorrect memory usage tracking of taken strings
- b6e5916 Fix incorrect memory usage tracking of code object line mappings
- 81f78b9 fixup potential leaks when os.exec*() family fails
- 7c4b129 Dict unpacking should only happen on dicts, or we're going to have a bad time
- 396b8c0 Inline string equality check to save overhead of
object.__eq__
call - 5df1469 Optimized method invoke
- d947e1a Add bound method call test to benchmark suite
- f8139f9 Add versions, local Kuroko to benchmark