18 ms·
Berry is a ultra-lightweight dynamically typed embedded scripting language
- geenat 3y agohttps://hyperscript.org/ https://hyperscript.org/
- deleted 3y ago[deleted]
- ryanschaefer 3y agoVery cool language, but it doesn’t seem to have anything to do with the purpose of the language in the original post. Can this be used in embedded systems too?
- ginko 3y agoI guess the main questions I'd have would be: What's the performance & memory usage compared to Lua? How sandboxable is it? Can you run untrusted code through it?
- loa_in_ 3y agoYou can't run untrusted code because by default code can open and write to the filesystem. Sandboxing is up to the application. For sandboxing wasm is a good alternative.
- qznc 3y agoRemoving the API for file access would be easy. Limiting compute time is the harder thing.
- norir 3y agoYes, it is very easy to remove the entire standard library from lua. Could compute time be handled with signal handlers in at least some cases? If not, one (admittedly somewhat hard) option is to write a small lua to lua compiler that injects yields into loops and recursive function calls.
- sweetjuly 3y agoLimiting compute is trivial on any modern operating system. On Linux you can create a second supervisor thread, block on a mutex with a timeout, and then if you timed out before acquiring the mutex you can just tgkill the runner thread. On BSDs it's even easier since you can just hand the runner thread port to your supervisor thread and, after you timeout, you can just set RIP/PC to whatever location you want without having to screw around with signals.
- foobazgt 3y agoI'd love to better understand what you're describing. Thread-level compute limits generally seem like they need to be managed in some sort of cooperative fashion, otherwise you end up with the possibility of dangling locks and other kinds of corruption on forcible termination. What signal are you sending to the running thread? What's the handler look like? How does that translate to terminating the thread? How do you do this forcibly (without cooperation from user code)? Schemes that I have seen look more like generating/ instrumenting polling/checkpoints into user code.
- loa_in_ 3y agoYou let it operate on a copy of the input data and check integrity afterwards. If it doesn't reach a valid state you discard it as failed/corrupted.
- foobazgt 3y agoThere are many pieces of process global runtime state that can get corrupted that are irrelevant to the input data. You can get lucky and sometimes avoid corruption, but eventually you're going to hit something important like leaving a libc heap allocator mutex locked when you kill a thread in the middle of an allocation.
- lelanthran 3y agoHe's describing killing a thread using a watchdog. This doesn't limit compute power of the thread. It's an all or nothing approach; either the thread runs or is killed, which doesn't work (as you point out) for all circumstances where you want to limit the amount of compute pwr a thread can use.
- JTyQZSnP3cQGa8B 3y agoThe comparison with Lua is the most interesting to me. Most companies I worked for used Python as a shitty proxy or CLI tool, but I never could recommend Lua due to its confusing OO system (meta tables??) If this language is a valid alternative with a simple struct and a basic constructor, I may recommend it to remove all the Python scripts and their dependencies.
- zdragnar 3y agoHaving a lot of experience wrangling prototypes in JS was a nice benefit to my first forays into lua, though I wrote more functional code than OO anyway. Honestly, off by one errors due to indexing was a lot harder to shake than getting used to meta tables.
- runlaszlorun 3y agoI’m assuming that the indexing off by one errors were due to Lua 1-based indexing? If so, was it due to you being used to 0-based indexing or something else? Just curious. I’ve been kicking around some attempts to make programming simpler (though hopefully no less powerful) for casual programmers. Lua’s 1-based indexing gets a lot of critiques and, while I haven’t written a ton of Lua, can’t help but think that the critiques are due to us all being used to 0-based indexing. Which is a valid critique, especially for a scripting language, but one that applies less to novices.
- deleted 3y ago[deleted]
- norir 3y agoThis is somewhat inefficient but zero indexed strings can easily be simulated in lua: local array = function(backing) local res = { len = function() return #backing end } setmetatable(res, { __index = function(_, k) return backing[k + 1] end, __newindex = function(_, k, v) backing[k + 1] = v end }) return res end local x = array { 1, 2, 3 } print(x[0]) -- 1 x[1] = 5 x[x.len()] = 6 for i = 0, x.len() - 1 do print(x[i]) end -- 1\n5\n3\n6
- deadf00d 3y agoAn native thread management with an `async` keyword would really make it stand out from Lua for game engine uses.
- demi56 3y agoI wouldn’t call that “stand out” especially when it comes to game engines, game engines are very complex and they are all different from implementations to their algorithms having a native thread management keyword does more worries than stand out
- RunningDroid 3y agoNote that Berry is used by Tasmota: https://tasmota.github.io/docs/Berry/ https://tasmota.github.io/docs/Berry/
- 22c 3y agoTasmota looks interesting. Interested to hear your thoughts on it if you've tried it or have compared it to toit/jaguar?
- blinkingled 3y agoI use Tasmota on a couple smart wifi plugs and apart from it being very reliable and doing what it says I don't have any development experience with it. But isn't toit a language and jaguar an app as opposed to Tasmota being a complete firmware that merely includes Berry as the runtime?
- 22c 3y agoYes the nomenclature is a bit confusing but I believe toit is the SDK/platform/firmware(?), toitlang is the language, and jaguar is the CLI tool used to bundle/deploy it all onto a device. As far as I can tell, the combination of all three of the above is the equivalent to tasmota + tasmotizer + berry? I guess what I am asking for is how does developing on the ESP32 when using toitlang + toit SDK compare to issuing commands against Tasmota using berry?
- blinkingled 3y agoThat makes much more sense. Naming continues to be a hard computer science problem :)
- MrBuddyCasino 3y agoThis looks like a language optimized for embedded use. It looks well designed and documented, and doesn’t do anything stupid or unexpected. The syntax is pleasantly minimalist and tasteful. I‘ll definitely keep it in mind for my next ESP32 project.
- MarkMarine 3y agoI will use it right now, I’ve been messing with my ESP-32 dev kits for some flashy Halloween decorations, and I’m excited to try this out. I agree, it looks great for the niche it’s in, especially since it’s doing things that I don’t really think have an analog in any other language.
- traverseda 3y agoI think the thing I'd miss most from python if I was using this is multiple-inheritance. Not even necessarily true multiple inheritance, but at least some kind of mixin.
- rollcat 3y agoClass-based inheritance is IMHO overrated. Most of the time you're interested in specific behavior (what is the area under this shape?), rather than some abstract taxonomy (is square a specialized rect or is rect a generalized square?). Composition and interfaces tend to produce less convoluted designs, and the most obnoxious problem with multiple inheritance ("diamonds") has to be explicitly addressed at the call site, rather than by meditating on the globally-determined method resolution order.
- runlaszlorun 3y agoHow do feel about prototypical inheritance and/or mixins as an alternative? I sorta feel like the component in the Entity/Component/System model that’s been getting popular in gaming drifts into the same territory as well though I’ve never written games.
- reactordev 3y agoECS is different. Systems coordinate entities, entities have components, some of them can be behaviors, some of them are not (vertex data). You would need to provide something that a component can inherit to derive that it’s a behavior. Unity does this by calling it a MonoBehavior (not Mono as in singular, mono as in Mono runtime, the name stuck). Having an ECBS system: one could model all the permutations as described while keeping code concise, shareable, and non-repeatable. Unity is really an ECBS. Inheritance vs non is as old as OOP vs functional. Each has their place, each has their pros and cons. Having functional components and behavior traits attached to object inheritance based entity nodes is probably the best of all composition. Entities can get more and more complex with inheritance chains (further classifying what components can be attached), components can include behaviors, data, events/triggers, sub-components. Behaviors (triggering events or waiting for) is where your game logic would mostly reside.
- i_am_a_squirrel 3y agoTheir marketing page loaded absurdly fast
- deleted 3y ago[deleted]
- bwanab 3y agoThere's got to be an xkcd strip on the trajectory of computer languages: 1. Starts out fast, compact and lightweight. 2. Bugs and corner-cases get fixed. 3. Features demanded by users get added. 4. No longer fast, compact or lightweight.
- deleted 3y ago[deleted]
- xonix 3y agoTrue. Probably, only AWK is an exception.
- vitiral 3y agoAnd Lua
- runlaszlorun 3y agoI’d think this actually applies to nearly everything in software and is def a useful thing to keep an eye on. Underemployment for the last 3 years has given me a great opportunity to dive deeper into a lot of CS topics for things we use daily and read (or at least try to read) specs and code bases etc. I’ve come to firmly believe that languages or other open source projects that get popular, usually do so for the things that are in its early versions. For example, the HTTP 0.9 spec is like 1 page. UDP is like 3 pages. I’d seen an article on HN recently (cant remember the name) that described this well. A language or what not starts simply and many jump on the bandwagon. Then starts adding incremental features, none of which are difficult to incrementally learn for existing users but the footprint of the product keeps expanding. C++, Javascript, Web APIs, graphics languages like OpenGL all are examples in my eye. The fact that our system (broadly speaking) incentivizes inventing something ‘new’ rather than fixing or simplifying an existing something certainly exacerbates this.
- carapace 3y agoWhen I try to explain this to non-programmers I often use this metaphor: Imagine that you enjoy mountain climbing, but the act of climbing the mountain causes more mountain to rise above you. That's what we see in software development: a runaway process of elaboration and ever-increasing complexity and levels of abstraction.
- Sytten 3y agoIt would be very nice to provide bindings to other languages. We use quickjs from rust and it works pretty well, you can provide what you want to the VM so it can run untrusted code.
- runlaszlorun 3y agoMan, this looks great. And, personally, I think this is some of the best documentation I’ve seen. Kudos to those who put it together! I love the “short manual” for experienced devs to quickly get a sense of the language. And I wasn’t familiar with Tasmota before but def will be looking for an excuse to try it on a project.
- nine_k 3y agoA surprisingly rich feature set for a 40-KB runtime: a VM with GC that runs a Python/Ruby lookalike language, supporting procedural, OO, or functional styles. From the cursory look, seems pretty ergonomic to write. What stood out for me is the ability to pre-create constant objects and put them mostly into ROM, so that the RAM is only used for the actually mutable data. This is something you can't have with MicroPython or Lua, AFAICT, and this makes a lot of difference in MCUs where ROM / flash is plentiful, and RAM is scarce.
- snops 3y agoYou can "freeze" micropython modules and have them saved in flash with Micropython, where flash only stores the precompiled bytecode. If your module contains stored data in the form of an immutable object, like a string or bytes(), it will be read straight out of flash without copying to RAM first. This needs you to run some code on a desktop computer to perform the freezing though. https://docs.micropython.org/en/latest/reference/constrained.html https://docs.micropython.org/en/latest/reference/constrained...
- mikepurvis 3y agoAny serious build setup for an MCU firmware is going to have steps like this in, generating code and saving blobs of this and that. Though I guess part of the pitch for micropython is being able to iterate without a flash step every time. Possibly addressed by having your dev boards fitted with a version of the MCU with enough RAM to run it all that way.
- matt_trentini 3y agoJust to be clear, not just data but bytecode will also be executed from flash too.
- tomcam 3y agoI have to admit, I went back to the site after reading your description. I find it much more comprehensive and appealing than the home page.
- paulclinger 3y ago
- CharlesW 3y agoWhat are some reasons this is interesting when great embedded JavaScript/TypeScript runtimes (like Moddable's XS, which runs on microcontrollers with as little as 32 KB RAM) exist?
- jlnho 3y ago1) If you use Berry, you won't have to write JavaScript
- c0wb0yc0d3r 3y agoHaving only looked at both projects and not using either, to me there are 2 standout features berry has over xs. 1. It appears straight forward to add native functionality to berry. 2. Berry has the ability to compile code to ROM. Maybe xs has that functionality too, but I don't see it anywhere in the top levels of it's docs. One thing I see missing from the berry docs is the debugging process. That could be a rather significant drawback of it isn't easy.
- rcarmo 3y agoLooks nice. I'm still rather partial to uLisp (http://www.ulisp.com http://www.ulisp.com), but it's great to see this. Erm... Berry good :)
- uticus 3y agomicrocontroller options are interesting, also Forths (https://github.com/tabemann/zeptoforth https://github.com/tabemann/zeptoforth)
- happens 3y agoI'd love something exactly like this, but with less paradigms and statically typed, for use as a configuration language. I've used several projects requiring non-trivial configuration that, instead of requiring you to write hundreds of lines of yaml, simply let you write Lua or Starlark/python, which feels so much better to me. I'm always missing autocompletion and reflection though. There doesn't seem to be a good candidate for this, pretty much all small embeddable scripting languages are dynamically typed...
- mst 3y agoI've been thinking along these lines but more 'strongly validated' than statically typed in the sense that you'd be better off being able to load the entire config and then produce a list of problems (and should be able to offer good editor support if done correctly). Though https://dhall-lang.org/ https://dhall-lang.org/ demonstrates that you can statically type quite a lot of configuration to great advantage, which appears to be programmatically embeddable in multiple languages per https://docs.dhall-lang.org/howtos/How-to-integrate-Dhall.html https://docs.dhall-lang.org/howtos/How-to-integrate-Dhall.ht...
- spacechild1 3y agoNo coroutines :-(
- zoom6628 3y agoMost MCU code I've seen targets single core single thread especially that for hard real-time. Maybe the author can outline more of the thinking behind coroutines, fibres or green threads or whatever they considered. In a real time if you have callbacks triggered by physical events that may offer more certainty than coroutines doing stuff that might finish, sometime.
- spacechild1 3y ago> Most MCU code I've seen targets single core single thread That's actually a good fit for coroutines! Cooperative multi-tasking can be very useful in single-threaded environments; it's basically syntactic sugar for a state machine. Lua has had coroutines since 2003, so I'd be curious why Berry chose to omit them.
- skiars 3y ago[dead]
- vitiral 3y agoSeems cool, has a lot of the Vibe of Lua but with bit-twiddling types
- dvdkon 3y agoThis looks nice, especially the small runtime. One nitpick: Why not "if" expressions, or even "for" expressions? Ternary operators aren't something any new language should copy. It might even reduce parser code.
- influxmoment 3y agoDon't care for the way they do exceptional handling. Make errors part of the type system
- tomcam 3y agoCan you ELI 5?
- maleldil 3y agoHandle errors using exceptions (like most languages today, e.g. C++, Java, Python) vs errors as values (e.g. Rust, Go, Haskell). The type system (especially for Rust and Haskell) forces you to always handle the error, or you have a compilation error. With some syntactic sugar (? in Rust, do notation in Haskell), you can be as concise as exception-based languages.
- tomcam 3y agoOK a lot of pieces just dropped in the place with your explanation. I’ve never heard it said so compactly before.
- Borg3 3y agoHmm, written in C99 :) Thats super cool, considered its very new language. It can even run on my ancient toaster ;) I will keep an eye on that project. For now im happy with old Ruby.
- Pxtl 3y agoIt looks neat. But the goals sound very similar to venerable old Lua. I wonder what Berry has to set it apart from Lua, besides a few of Lua's idiosyncratic language decisions that come from its age.
- nightowl_games 3y agoIs there a standard approach to making native stack traces capable of marking stack frames with the name of the scripted function? Like when you get a crash or use a cpu profiler, is it possible to interleave native and script stack traces?
- 0x6461188A 3y agoIf like me you like to look at examples of code to get a feel for the language, take a look at https://github.com/berry-lang/berry/tree/master/examples https://github.com/berry-lang/berry/tree/master/examples
- germandiago 3y agoAny chance Berry has something like generators or function resumption of some kind? I usually use scripting in interactive stuff such as games.
- skiars 3y ago[dead]
- alberth 3y agoOff topic: Any good resources on how to create your own language? (eg syntax, compilation, etc)
- c0wb0yc0d3r 3y agoIt's not a tutorial by any means, but the openwrt project has been working on ucode[0]. Tiny JavaScript-like interpreter. It's pretty small. You might be able to glean insight. Presumably the source for this project would be insightful as well. It appears like there is more code for berry script compared to ucode though. [0]: https://github.com/jow-/ucode https://github.com/jow-/ucode
- TeaDude 3y agoBob Nystrom's Crafting Interpreters is generally well regarded these days although I'm unaware of any of the classic "so you want to build a programming language" texts.
- t-3 3y agoThere are more than a few books and tutorials on how to write parsers and compilers and PL theory, but I know of none on how to go about actually designing a language from scratch. Perhaps most new languages can be considered slight variations on earlier languages, so there's not much point when you're almost certainly using one of ~6 styles with slight modifications? I got started on my own little project by writing "ideal" programs and then working backwards and defining the syntax and vocabulary, then writing and reworking again ad nauseam.
- antifa 3y agoI wonder if anyone is forking love2D to use berry instead of/in addition to Lua?