Commit Graph

23 Commits

Author SHA1 Message Date
K. Lange
04391ebbaa add exit() to repl 2021-01-05 13:43:47 +09:00
K. Lange
a4885833c5 add paste() to repl to disable automatic indentation 2021-01-05 12:53:51 +09:00
K. Lange
49d2a26aa4 repl must reset stack after printing values since they run without a callframe 2021-01-04 17:47:44 +09:00
K. Lange
b676df69da Add method decorators
This required a new approach for handling function arguments.

Methods remain the same: the callee object is on the stack and positioned
to be "argument 0". Non-methods have changed so that "argument 0" is the
first argument, with the function still remaining before that. When a
non-method is called, we track this fact so that we can continue to restore
the stack to the correct height to get rid of the function. This allows
a method decorator to be defined exactly like it would be in Python

def methodDecorator(func):
    def wrappedMethod(instance, someOtherArg):
        print "Do something with the arg:", someOtherArg
        func(instance)

class Foo():
    @methodDecorator
    def func():
        print "I only take an implicit self:", self

let f = Foo()
f.func("but that other arg is needed")
2021-01-03 08:43:32 +09:00
K. Lange
6164c3ebf4 General code cleanup. 2021-01-02 12:21:11 +09:00
K. Lange
f7e1c0da0d Add docstrings, __doc__, and help() 2020-12-30 16:59:21 +09:00
K. Lange
2432135b15 clean up repl highlighter 2020-12-28 21:31:46 +09:00
K. Lange
3ba8025eeb lots of fixups so we can create dicts from the vm 2020-12-28 20:38:26 +09:00
K. Lange
cdcbf6cf54 First pass at module/builtin cleanup 2020-12-28 19:01:28 +09:00
K Lange
5a5c597033 little repl improvements 2020-12-28 11:25:42 +09:00
K Lange
ac15ca117c Clean up some pedantic warning stuff 2020-12-28 11:11:50 +09:00
K. Lange
bbae30b09b fix history scrollback 2020-12-28 14:00:12 +09:00
K. Lange
f62f6f84e2 fix up some bad garbage collections with modules 2020-12-28 13:51:14 +09:00
K. Lange
1d3368861b fix a bunch of compiler stuff 2020-12-28 12:16:44 +09:00
K. Lange
1bae2060eb add fancy repl 2020-12-28 11:37:38 +09:00
K. Lange
8f42695f36 Fix up repl 2020-12-28 10:54:25 +09:00
K. Lange
3bcc5d5530 Synthesized properties and methods for strings 2020-12-28 09:08:35 +09:00
K. Lange
4982881235 that's a lot of stuff and pretty much finishes the book; need to do optimizations 2020-12-27 22:40:35 +09:00
K. Lange
1f754ebc01 not exactly how modules work in Python, but, uh, good enough for us for now 2020-12-27 18:55:52 +09:00
K. Lange
aab01f01f7 Finish up chapter 22, local variables; fix up indentation-based scoping 2020-12-26 18:39:29 +09:00
K. Lange
928047f1db Completed chapter 21, global variables 2020-12-26 16:53:15 +09:00
K. Lange
417637ef21 hash tables (which should work with any object as keys?) and string interning from ch 20 2020-12-26 14:33:34 +09:00
K. Lange
14aeea5f5b through chapter 19 of Crafting Interpreters 2020-12-26 09:32:21 +09:00