1. 1
    1. 2

      There’s a fun and related hobby project that I contributed a bit to here: https://github.com/ybur-yug/gkv

      1. 3

        I use mbasic.facebook.com almost daily and like the speed and simplicity of it and I’m glad to hear it gets some attention, coincidental or not. It wouldn’t surprise me to hear that Facebook engineers read lobsters; after all, it has become pretty famous in the last few years.

        1. 4

          FB engineer checking in, I read lobsters. But I’m on infra, not mbasic.

        1. 1

          method_missing is super slow. You can cache the keys by defining methods dynamically and that might help a little.

          1. 2

            some people won’t like the method_missing (define_method would need to stay in sync with the keys)

            I did a quick benchmark: https://gist.github.com/localhostdotdev/bd97537dcbc4099bc05dd56bccd98cff

            1 000 000 lookups is 0.12s with Hash, and between 0.4s and 1.4s with SimpleHash.

            so something to consider if it becomes a bottleneck.

            edit: thanks a lot, it made me think and I would rather have some future-proof data structures, e.g. I would move this to inherint from Hash, freeze it to be read-only and use define_method instead of method_missing

            1. 1

              Oops, I’m sorry that I missed it! The good news is that you can remove_method too.

              1. 1

                I would also need to generate subclasses as each class would have different methods

                1. 2

                  You can do instance_eval, I think

                  1. 1

                    Oh! thanks, didn’t think of it. tried it and I can’t remove_method (or define_method, I just used def) in an instance_eval, so I would need to redefine and raise a NoMethodError (also I need to check for existing methods).

                    anyway, I’m going to make it a small gem so it’s easier to track the changes and maybe have people contribute (I’m going back to HashWithIndifferentAccess as the Hash approach introduces many possible bugs (and I’m too lazy to reimplement everything correctly)).

                    1. 2

                      I think you can define method in an instance eval. I’ll dig up some of my old code that does part of what your thing does and post it in a comment here.

                      1. 2

                        oh just learned about undef, works well:

                        class A; end; a = A.new; a.instance_eval { def b; 1; end }; a.b; a.instance_eval { undef :b }; a.b rescue "good"
                        => "good"
                        
          1. 2

            Kartik, this is very cool. I’m excited to see you talk about this publicly. Do you have any plans to build mnemonics on top of it? I can’t imagine having to type all of those very machine-specific things when writing assembly programs because I would have to look them up every time.

            Also, I can’t believe you only use “bootstrap” twice on that page.

            1. 4

              Yeah, I definitely plan notational improvements, as I say in a couple of places. For now the priority is to keep it easy to bootstrap :) I wrote about the rationale for the current “bottom-level” notation here.

              Oh, perhaps I should describe how I’ve been putting up with the mnemonics. I have a couple of helpers in my editor (Vim).

              :P opens up the opcodes file from the repo in a split window. (This file just contains the output of subx help opcodes.)

              :G <pattern> opens up a split window with the results of:

              grep -h <pattern> *.subx */*.subx
              

              For example, :G add.*EAX.*imm32 for instructions adding a literal int to EAX.

              I now often find the perfect line to copy over from somewhere else in the repo.

              More details.

            1. 6

              Did you consider using libgit2 in your approach? Why did it not fit your needs?

              1. 20

                Porting is annoying, and ape (the ansi/posix emulation environment) is a separate world that’s no fun to use. It also comes with interoperability caveats and issues when using the native plan9 libraries. Additionally, the things that libgit2 helps with are the things I want to do in shell script. And finally:

                  term% cd git9
                  term% wc -l `{du -a . | awk '/.*\.[chy]$/{print $2}'}
                     108 ./conf.c
                     378 ./fetch.c
                     839 ./fs.c
                     174 ./git.h
                      62 ./objset.c
                     828 ./pack.c
                     264 ./save.c
                     489 ./send.c
                     228 ./util.c
                    3370 total
                

                Compared to:

                  term% cd libgit2
                  term% wc -l `{du -a . | awk '/.*\.[chy]$/{print $2}' }
                      <elided list of ~900 files>
                      270404 total
                

                Even ignoring tests, examples, and external deps:

                  term% wc -l `{du -a . | \
                           awk '/.*\.[chy]$/{print $2}' | \
                           grep -v 'tests|deps|examples' }
                      <elided list of files>
                      138077 total
                

                In other words, depending on how you count, there’s between 1.2% and 2.4% the amount of C code to maintain, update, and understand in this implementation. And sure, this implementation will grow, but it’s likely to stay within the single digit percentages of libgit2’s size.

                1. 1

                  Thank you for your response!

              1. 1

                Sorry, that might be interesting but I won’t read a blog post that requires that I watch a video first. I’m here to read text and graphics, not watch videos. Reading a solution to a problem that is not stated is not interesting. Typing a few lines in intro would take the same place and less effort than linking the youtube video in the first place.

                1. 2

                  You make a fair point. To temporarily tide you over, here is a brief description from Wikipedia: https://en.wikipedia.org/wiki/100_prisoners_problem

                1. 2

                  I use Jekyll for bernsteinbear.com because it’s pretty simple. I am slowly growing frustrated with the large Gem dependency graph and may eventually switch to something with a lower footprint. That being said, I don’t much notice it because GitHub Pages generates everything for me.

                  1. 2

                    Nice post, Taylor!

                    1. 2

                      Thanks, Max! I hope that you’re well. What are you working on these days?

                      1. 1

                        Likewise. I’m working on a runtime at work, which has been interesting, and doing some networking projects at home. I’ll reach out via PM.

                    1. 8

                      So, not seeing the entry for Lua yet, I’ll allow myself to hereby add it! By the way, I first learnt of the language exactly as part of an app where it was used as an application scripting language. I’m amazed by Lua as a language ever since.

                      Other than that, I’m not sure if Red is embeddable as of today; but if not, I believe it could become a really interesting option in this area eventually.

                      Finally, I’m recently learning Nim, and I find it very interesting. As subset of Nim called NimScript can be run in a VM, and can be made embedded in other programs (though it seems it’s not exactly a turn-key solution as of today).

                      1. 9

                        I have been using Lua as well, for about 12 years now. My main reasons are:

                        • The simplicity of the (reference) implementation. Lua is about 16000 lines of C, any experienced programmer can read them and understand how the whole interpreter works. The same cannot be said of most other mainstream languages.

                        • The wonderful language of the design. Nothing in Lua feels like a kludge to me. That is probably because it is designed and implemented by a very restricted core team, and not by committee.

                        • The syntax is not S-expressions. As much as I want to like Lisp, I cannot bring myself to find that syntax pleasant to use in practice.

                        • The ease of embedding it in C and sandboxing it. Some people do not like the Lua - C stack-based API, but to me it is one of the main selling points of the language. I have written bindings for other dynamic languages such as Python and Ruby, and compared to that experience doing the same for Lua is wonderful.

                        And over the years, I have found an extra reason, which is the community. The Lua community is small but great, maybe in part because it is one of the few mainstream languages that does not originate from the Western block (Europe / USA). Because of that, its community is a mix from people from all over the world, from very different industries, who use the language in very different ways. Going to a Lua-related conference such as Lua Workshop is always a great time.

                        1. 4

                          I think that the fact that Lua feels as well designed as it is is because it has had 5+ iterations with few considerations given to backwards compatability. Which isn’t to dog on it, but to more say that it’s had a lot more time to be refined in ways that would have not flown if an early version of Lua had been shipped in web browsers, like JS was.

                          1. 1

                            Completely agreed.

                          2. 2

                            All great points; but your third point reminded me that the unrelenting simplicity of the language does make it a fantastic compilation target. So Lua doesn’t support a s-expression-based syntax out of the box, but it can be added in roughly 1kloc of code without changing the semantics. Prefer syntactically-significant whitespace for some reason? You can do that in a compiler too! (Moonscript unfortunately does add a bunch of new semantics like the class system, which is a huge misfeature IMO, but it’s readily within the grasp of one person to create a moonscript-lite that’s just syntactic.)

                          3. 2

                            The first two links in “can be made” are the same. Was that intentional?

                            1. 2

                              Nope, sorry! The second one should have been: https://github.com/komerdoor/nim-embedded-nimscript. Thanks for asking!

                            2. 1

                              I too use Lua, but at work, it’s more for LPEG (Lua Parser Expression Grammar). It takes a while to get used to it, but I find it much more expressive and powerful than the Lua patterns (or even regex). Not only can an expression be reused as part of another expression, but the resulting code is its own VM (distinct from Lua) that is geared directly for parsing.

                            1. 2

                              I’m working on getting more interesting / bigger scope / more architecture-focused projects at work. I’m new to the company and the team, so I have been primarily doing smaller stuff. Hopefully soon I can take ownership of larger components of the project.

                              For personal projects, I want to start working on my personal library management system.

                              1. 2

                                I will be moving into my new house, which will be exhausting. Then, I would like to either continue work on one of my two slow-moving projects: 1) a distributed mesh messaging network 2) a website for my personal library, so that others may see what books I have and borrow books from me. Ideally this will turn into a thing that anybody can load their libraries into.

                                1. 4

                                  Personal: I’m adding to my bytecode interpreter blog post – virtual frames, name resolution, etc.

                                  Work: Adding some more features to the runtime at work so we have feature parity with upstream.

                                  1. 6

                                    I wrote this to understand bytecode compilers and interpreters. Please let me know what you think!

                                    1. 3

                                      Thanks for the mention at the end :) I haven’t touched that README in awhile, and reading over it reminded me to get cracking on that work!

                                      1. 2

                                        Of course – I am fascinated by your project and would love to find some application for OPy in my life. This was hopefully the first step in doing something related.

                                        1. 1

                                          Cool, feel free to send me any questions about it! There is a public messaging system at https://oilshell.zulipchat.com.

                                          Right now I don’t think OPy is that interesting, aside from being small and hackable. But if I actually manage to compile Oil down to something more efficient and compact with it, then it will be interesting!

                                          Basically “OPy” will be defined as “whatever collection of compiler techniques work for the Oil codebase”. That makes it very concrete and I think a pretty interesting open question. It’s also possible it will fail, but we’ll see :-/

                                          1. 1

                                            Huh, looks like I meant OVM2. I am interested particularly in having a tiny Python bytecode interpreter. Is there anything I could do to help with that?

                                            1. 1

                                              It’s hard for me to think of something specific, since there’s a lot of background knowledge required to answer that question :)

                                              But to be brief, I started the VM, and I would basically accept any patch that makes it run more real Python programs (and which has tests showing that). I mentioned in a blog post that it runs a toy Fibonacci. It doesn’t even implement functions or dictionaries yet, so it’s very basic, and there’s a lot to do.

                                              https://github.com/oilshell/oil/blob/master/ovm2/main.cc

                                              I definitely need help because finishing up OSH and implementing OVM2 is easily a year’s worth of work, and that leaves aside the Oil language. It’s not clear if there’s a good place to jump in, but we can chat about it or feel free to hack around.

                                              I maintain a list of issues for the broader Oil project: https://github.com/oilshell/oil/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22

                                              There are some small issues, as well as some larger ones that don’t require much background on Oil itself but require some knowledge in another area (e.g. fuzzing).

                                    1. 1

                                      I’ve enjoyed working with libtap. It’s small and effective.

                                      1. 9

                                        I read Neal Stephenson’s Anathem and loved it. Blew my mind. It did take a while to get going, though. But totally worth it.

                                        1. 2

                                          Anathem is really wonderful, I would suggest it too.

                                        1. 2

                                          I have a Lenovo T480S running Ubuntu and love it. It’s a beast and it’s pretty light, too!

                                          1. 3

                                            I’ll be starting my second week on my new team. I’m excited to have joined! We’re building a runtime. Can’t wait to learn more about that. As far as technical specifics go, I’ll be adding some metaprogramming builtin functions and some new types.

                                            1. 3

                                              I’m going to make be cooking for a potluck and seeing a good friend who is visiting while interviewing in the area.

                                              1. 1

                                                Why is this tagged release? It looks like it was last worked on last year.

                                                1. 1

                                                  Or php, or vim for that matter…

                                                  1. 2

                                                    I killed the other tags but left in vim because it’s a vi-style editor.

                                                    1. 1

                                                      Oh, I missed that. Thought it was pure acme. Neat!