buzz-language / buzz Goto Github PK
View Code? Open in Web Editor NEW๐จโ๐ buzz, A small/lightweight statically typed scripting language
Home Page: https://buzz-lang.dev
License: MIT License
๐จโ๐ buzz, A small/lightweight statically typed scripting language
Home Page: https://buzz-lang.dev
License: MIT License
Keep docblocks in AST so we can reuse it to generate documentation:
|| This is a cool utility object
object MyObject {
|| Says hello
|| @param name To whom you say hello
fun sayHello(str name) > void -> print("hello {name}"),
}
Implement coroutines
import "lib/std";
fun main() > void {
| Async call, creates a new routine (new VM instance), count is not yet executed
rti<str, num> counter = async count(10);
| A routine is over when a OP_RETURN as been executed
while (!counter.over()) {
print("counter is {resume counter}");
}
assert(counter.over(), message: "Routine should be over now");
| await either runs the routine until completion or get the return value of a terminated routine
| if the function yields but is never resumed when we reach the await, yields value are dismissed (?)
print(await counter);
}
| returns str, yields num
fun count(num n) > str > num {
for (num i = 0; i < n; i = i + 1) {
| error or yield is ignored if not called with a async call?
yield i;
}
return "Counting is done!";
}
| optional default value is always null
fun myFunction(str name = "Joe", num? age) > str {
if (age != null) {
return "{name} is {age}";
}
return "{name} is ageless";
}
| valid calls
myFunction();
myFunction("John");
myFunction(age: 12);
Default arguments for native call
We show code from the entry point script rather than the revelant script
When exported, a function should capture global it uses.
Right now we juste take the whole script globals for the ride.
This would not be needed if we do https://github.com/buzz-language/buzz/issues/215
Right now we continue parsing/codegen after reporting errors and almost always end up crashing buzz.
Go over each error reporting and see how it must be handled: either stopping everything or providing enough details so buzz does not crash going forward.
Special method that will be called when the object is collected:
object File {
| ...
fun collect() {
this.close();
}
}
string.utf8Len(str string) > num
string.codepoint(num index) > str
| Do something complex
| @param str input - something to do complex things with
| @return something complex
fun complex(str input) > str {
| ...
}
New type that can hold on pointer to something outside the VM (like Lua's userdata).
Generational GC
Forbid use of break
outside of a loop
Right now if there's a catch that don't match the error is still considered caught
num hello = 42;
num bonjour = 42; | -> should be the same constant
String are not concerned since they are interned.
Zig-like defer
keyword that will execute an expression just before exiting the current function.
fun main() > void {
File file = File.open("hello", mode: FileMode.read);
defer file.close();
|...
}
next(X key) > X
: returns next key after key
(used by foreach
)remove(X key)
> X: removes entry under key
and returns itsize() > num
: returns number of entries in the mapkeys()
: returns list of the map keysvalues()
: return list of the map valuesDebug metadata and api
First class types
type myType = <str>;
fun handleAnything(any value) -> typeOf(value) == myType;
typeof
operatorEdge cases:
MyObject
to be a type, but it's not. It's a reference to the value ObjObject
. So user whishing to get the MyObject
type would have to do: typeof MyObject
.ObjTypeDef
at runtime so we don't need the typeof
operator to get its type.Protocol
whose runtime representation is also an ObjTypeDef
Special type wrapping an opaque pointer
math.abs
math.acos
math.asin
math.atan
math.ceil
math.cos
math.deg
math.exp
math.floor
math.log
math.max
math.min
math.pi
math.rad
math.random
math.sin
math.sqrt
math.tan
Map subscript should return null if key does not exists.
object A {
const num assignedOnce;
}
append(X value)
: append new element to end of listlen
: returns length of listnext(num index) > ?num
: returns next index in list after index
or null
if end of list is reached (used by foreach
)remove(num index)
: remove element at index
and shifts itemssub(num start, num? len) > [X]
indexOf(X element) > num?
join(str? separator) > str
stdin
, stderr
, stdout
File
File.open
File.close
File.readAll
File.readLine
File.write
File.read(num n) > ?str
: reads n
bytes, returns null
if EOF
Be able to provide default value to function arguments:
fun myFunction(str hello = "world") { ... }
pat pattern = _^hello$_;
pat pattern = "^with a string$";
pat
methods are:
pattern.match(str subject) > [str]
: Returns the first match and eventual capturespattern.matchAll(str subject) > [[str]]
: Returns all matches and capturespattern.replace(str subject, str replacement) > str
: Replaces first match with replacement
pattern.replaceAll(str subject, str replacement) > str
: Replaces all matches with replacement
str
methods:
string.match(pat pattern) > [str]
: same as pattern.match
string.matchAll(pat pattern) > [str]
: same as pattern.matchAll
string.replace(pat pattern) > [str]
: same as pattern.replace
string.replaceAll(pat pattern) > [str]
: same as pattern.replaceAll
string.match
and pattern.match
should return iterators.fun delta(num mul) > obj{ num x, num y } {
return .{
x = 10 * mul,
y = 12 * mul,
};
}
obj{ num x, num y } newPoint = delta(10);
Should not allow methods or static fields.
assert(bool condition, str message)
print(str message)
parseNumber
runFile(str path)
: runs file in a separate VM statelist[1..10] == list.sub(1,10);
[int] myRange = 1..10;
foreach (int i in 1..10) {
| ...
}
๐จโ๐ buzz A small/lightweight typed scripting language written in Zig
usage: buzz [options] [command] script.buzz [args]
Available options are:
--dump Dump bytecode
--dump-ast Dump AST tree
--debug Show debug logs
--debug-stack Dump stack after each executed bytecode
--debug-gc Show GC related logs
--debug-current-instruction Show bytecode being executed
--debug-perf Show time to parse, codegen and run the script
--debug-stop-on-report Stop compiling on the first encountered error
Available commands are:
version Print version number and exit
test Run test blocks in the provided script
run (default) Run script
Placeholder system can't handle every case so we're forced to do 2 passes:
len() > num
sub(num start, num len) > str
indexOf(str needle) > num?
split(str separator) > [str]
byte(num at) > num
os.time()
: epoch time in msos.env(str key) > str
: returns env variable named key
os.execute([str] command) > num
: execute command and return its exit codeos.tmpDir() > str
: returns path to system temp directoryos.tmpFilename() > str
: returns a temporary file name in system tmp diros.exit(num exitCode) > void
: exits program with exitCode
At codegen, we don't have access to the ParseNode
which holds the default arguments nodes.
Right now they are functions so we can't do:
fun hello() > bool {
willFail() catch {
| here we return from this catch clause instead of returning from the enclosing function
default -> return false;
}
return true;
}
MyObj{}.bound is Function() > bool
-> MyObj{}.bound is Function(MyObj) > bool
fs.cwd() > str
: returns current directory absolute pathfs.mkDir(str path)
: creates directory path
fs.rm(str path)
: deletes directory or file at path
fs.move(str from, str to)
: moves/renames file at from
to to
fs.ls(str path) > [str]
: list files under path
dylib
, .a
and .dll
Tail calls
Right now this does not work:
import "lib/std.buzz";
Function(str) > void p = print;
REPL
This should be valid:
fun hello() > bool {
if (condition) {
return true;
} else {
throw "an error";
}
}
Would allow for instance, to have more complex function default parameters
fun iCanFail() > !num {
| ...
}
Be able to export something when declaring it like so:
export num exportMe = 42;
Or: require main
to always be fun main([str] args) > num
.
Something similar to https://github.com/SwiftyJSON/SwiftyJSON
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.