├── .gitignore ├── bench ├── .gitignore ├── try.sl ├── stack1.sl ├── stack2.sl ├── task.sl ├── fib2.sl ├── stack1.py ├── fib1.sl ├── bench.py ├── fib1.py ├── try.py ├── fib3.py └── task.py ├── logo.png ├── src ├── snabl │ ├── sym.cpp │ ├── try.cpp │ ├── file.hpp │ ├── repl.hpp │ ├── libs │ │ ├── abc.hpp │ │ └── abc.cpp │ ├── runtime_error.cpp │ ├── async.hpp │ ├── pos.hpp │ ├── lambda.cpp │ ├── target.cpp │ ├── macro.cpp │ ├── ptrs.hpp │ ├── types.hpp │ ├── types │ │ ├── time.hpp │ │ ├── meta.cpp │ │ ├── meta.hpp │ │ ├── time.cpp │ │ ├── error.hpp │ │ ├── file.hpp │ │ ├── rwfile.hpp │ │ ├── error.cpp │ │ ├── float.hpp │ │ ├── nil.hpp │ │ ├── async.hpp │ │ ├── lambda.hpp │ │ ├── bool.hpp │ │ ├── async.cpp │ │ ├── sym.hpp │ │ ├── file.cpp │ │ ├── byte.hpp │ │ ├── char.hpp │ │ ├── nil.cpp │ │ ├── i64.hpp │ │ ├── iter.hpp │ │ ├── float.cpp │ │ ├── lambda.cpp │ │ ├── sym.cpp │ │ ├── byte.cpp │ │ ├── bin.hpp │ │ ├── bool.cpp │ │ ├── stack.hpp │ │ ├── enum.hpp │ │ ├── str.hpp │ │ ├── iter.cpp │ │ ├── char.cpp │ │ ├── enum.cpp │ │ ├── i64.cpp │ │ ├── stack.cpp │ │ ├── bin.cpp │ │ └── str.cpp │ ├── iter.cpp │ ├── stack.hpp │ ├── try.hpp │ ├── timer.hpp │ ├── timer.cpp │ ├── var.hpp │ ├── def.hpp │ ├── fmt.hpp │ ├── stack.cpp │ ├── iter.hpp │ ├── user_error.hpp │ ├── cmp.hpp │ ├── target.hpp │ ├── state.hpp │ ├── time.hpp │ ├── call.cpp │ ├── call.hpp │ ├── runtime_error.hpp │ ├── scope.hpp │ ├── atype.cpp │ ├── macro.hpp │ ├── lambda.hpp │ ├── std.hpp │ ├── type.hpp │ ├── fmt.cpp │ ├── task.hpp │ ├── repl.cpp │ ├── state.cpp │ ├── fimp.hpp │ ├── sym.hpp │ ├── parser.hpp │ ├── error.hpp │ ├── mpool.hpp │ ├── bset.hpp │ ├── lib.cpp │ ├── func.hpp │ ├── fimp.cpp │ ├── lib.hpp │ ├── atype.hpp │ ├── ptr.hpp │ ├── box.hpp │ ├── env.cpp │ ├── form.hpp │ ├── parser.cpp │ ├── op.hpp │ ├── form.cpp │ ├── env.hpp │ └── op.cpp ├── tests.hpp ├── tests.cpp └── main.cpp ├── CMakeLists.txt ├── LICENSE.txt ├── todo.org ├── tests └── all.sl ├── README.md └── logo.svg /.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | build 3 | -------------------------------------------------------------------------------- /bench/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codr4life/snabl/HEAD/logo.png -------------------------------------------------------------------------------- /src/snabl/sym.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/sym.hpp" 2 | 3 | namespace snabl { 4 | } 5 | -------------------------------------------------------------------------------- /bench/try.sl: -------------------------------------------------------------------------------- 1 | 10000 bench: ( 2 | 10 times: ( 3 | try: (42 throw!) 4 | drop! 5 | ) 6 | ) ms say -------------------------------------------------------------------------------- /bench/stack1.sl: -------------------------------------------------------------------------------- 1 | 10000 bench: { 2 | [] let: lst 3 | 100 times: (@lst [] push) 4 | 100 times: (@lst pop) 5 | } ms say -------------------------------------------------------------------------------- /bench/stack2.sl: -------------------------------------------------------------------------------- 1 | 10000 bench: ( 2 | [] 3 | 100 times: (dup! [] push) 4 | 100 times: (dup! pop) 5 | drop! 6 | ) ms say -------------------------------------------------------------------------------- /bench/task.sl: -------------------------------------------------------------------------------- 1 | 10000 bench: ( 2 | task: (100 times: yield!) 3 | task: (100 times: yield!) 4 | 100 times: yield! 5 | ) ms say -------------------------------------------------------------------------------- /src/tests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_TESTS_HPP 2 | #define SNABL_TESTS_HPP 3 | 4 | namespace snabl { 5 | void all_tests(); 6 | } 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /bench/fib2.sl: -------------------------------------------------------------------------------- 1 | 10000 bench: ( 2 | 20 0 1 &( 3 | rswap! switch:, 4 | 0? sdrop! 5 | 1? drop!, 6 | -- rswap! dup! rot! + recall! 7 | ) call! drop! 8 | ) ms say -------------------------------------------------------------------------------- /src/snabl/try.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/env.hpp" 2 | #include "snabl/try.hpp" 3 | 4 | namespace snabl { 5 | Try::Try(Env &env, ops::Try &op): prev(env._try()), op(op), state(env) { } 6 | } 7 | -------------------------------------------------------------------------------- /bench/stack1.py: -------------------------------------------------------------------------------- 1 | from bench import bench 2 | 3 | def test(): 4 | lst = [] 5 | for _ in range(100): lst.append([]) 6 | for _ in range(100): lst.pop() 7 | 8 | print(int(bench(10000))) 9 | -------------------------------------------------------------------------------- /bench/fib1.sl: -------------------------------------------------------------------------------- 1 | func: tail-fib { 2 | let: (n a b) 3 | 4 | @n switch:, 5 | 0? @a 6 | 1? @b, 7 | -- @b dup! @a + recall! 8 | } 9 | 10 | 10000 bench: (20 0 1 tail-fib drop!) ms say -------------------------------------------------------------------------------- /bench/bench.py: -------------------------------------------------------------------------------- 1 | from timeit import Timer 2 | 3 | setup = 'gc.enable(); from __main__ import test' 4 | 5 | def bench(reps): 6 | Timer('test()', setup).timeit(reps) 7 | return Timer('test()', setup).timeit(reps)*1000 8 | -------------------------------------------------------------------------------- /bench/fib1.py: -------------------------------------------------------------------------------- 1 | from bench import bench 2 | 3 | def fib(n, a, b): 4 | return a if n == 0 else b if n == 1 else fib(n-1, b, a+b) 5 | 6 | def test(): 7 | fib(20, 0, 1) 8 | 9 | print(int(bench(10000))) 10 | -------------------------------------------------------------------------------- /bench/try.py: -------------------------------------------------------------------------------- 1 | from bench import bench 2 | 3 | def test(): 4 | for _ in range(10): 5 | try: 6 | raise 42 7 | except Exception as e: 8 | pass 9 | 10 | print(int(bench(10000))) 11 | -------------------------------------------------------------------------------- /src/snabl/file.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_FILE_HPP 2 | #define SNABL_FILE_HPP 3 | 4 | #include "snabl/ptrs.hpp" 5 | 6 | namespace snabl { 7 | using File = fstream; 8 | using FilePtr = Ptr; 9 | } 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/snabl/repl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_REPL_HPP 2 | #define SNABL_REPL_HPP 3 | 4 | #include "snabl/std.hpp" 5 | 6 | namespace snabl { 7 | struct Env; 8 | 9 | void repl(Env &env, istream &in, ostream &out); 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/snabl/libs/abc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_LIB_ABC_HPP 2 | #define SNABL_LIB_ABC_HPP 3 | 4 | #include "snabl/lib.hpp" 5 | 6 | namespace snabl::libs { 7 | struct Abc: Lib { 8 | Abc(Env &env); 9 | void init(); 10 | }; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /bench/fib3.py: -------------------------------------------------------------------------------- 1 | from bench import bench 2 | 3 | def fib(n): 4 | a, b = 0, 1 5 | 6 | for _ in range(n): 7 | a, b = b, a 8 | b += a 9 | 10 | return b 11 | 12 | def test(): 13 | fib(20) 14 | 15 | print(int(bench(10000))) 16 | -------------------------------------------------------------------------------- /src/snabl/runtime_error.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/env.hpp" 2 | #include "snabl/runtime_error.hpp" 3 | 4 | namespace snabl { 5 | RuntimeError::RuntimeError(Env &env, const string &msg): 6 | Error(), run_msg(msg), pos(env.pos()), stack(env.task->stack) { } 7 | } 8 | -------------------------------------------------------------------------------- /src/snabl/async.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_ASYNC_HPP 2 | #define SNABL_ASYNC_HPP 3 | 4 | #include "snabl/box.hpp" 5 | #include "snabl/ptr.hpp" 6 | 7 | namespace snabl { 8 | using Async = future>; 9 | using AsyncPtr = Ptr; 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/snabl/pos.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_POS_HPP 2 | #define SNABL_POS_HPP 3 | 4 | #include "snabl/std.hpp" 5 | #include "snabl/types.hpp" 6 | 7 | namespace snabl { 8 | struct Pos { 9 | I64 row, col; 10 | Pos(I64 row, I64 col): row(row), col(col) { } 11 | }; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/snabl/lambda.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/env.hpp" 2 | #include "snabl/lambda.hpp" 3 | 4 | namespace snabl { 5 | void Lambda::call(Env &env, Pos pos) const { 6 | if (vars) { env.begin_scope(*vars); } 7 | env.begin_call(*this, pos, env.pc()); 8 | env.jump(start_pc); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/snabl/target.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/scope.hpp" 2 | #include "snabl/target.hpp" 3 | 4 | namespace snabl { 5 | Target::Target(Scope *parent_scope, PC start_pc, I64 end_pc): 6 | start_pc(start_pc), end_pc(end_pc) { 7 | if (parent_scope) { vars.emplace(parent_scope->vars.vals); } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /bench/task.py: -------------------------------------------------------------------------------- 1 | from bench import bench 2 | 3 | def test(): 4 | def task(): 5 | for _ in range(100): yield 6 | 7 | t1, t2, t3 = task(), task(), task() 8 | 9 | for _ in range(100): 10 | next(t1) 11 | next(t2) 12 | next(t3) 13 | 14 | print(int(bench(10000))) 15 | -------------------------------------------------------------------------------- /src/snabl/macro.cpp: -------------------------------------------------------------------------------- 1 | #include "snabl/macro.hpp" 2 | 3 | namespace snabl { 4 | Macro::Macro(Lib &lib, Sym id, const Imp &imp): Def(id), lib(lib), imp(imp) { } 5 | 6 | void Macro::call(Forms::const_iterator &in, 7 | Forms::const_iterator end, 8 | Env &env) { imp(in, end, env); } 9 | } 10 | -------------------------------------------------------------------------------- /src/snabl/ptrs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_PTRS_HPP 2 | #define SNABL_PTRS_HPP 3 | 4 | #include "snabl/ptr.hpp" 5 | #include "snabl/std.hpp" 6 | #include "snabl/types.hpp" 7 | 8 | namespace snabl { 9 | using BinPtr = Ptr; 10 | using StrPtr = Ptr; 11 | 12 | struct Op; 13 | using PC = Op *; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/snabl/types.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_TYPES_HPP 2 | #define SNABL_TYPES_HPP 3 | 4 | #include "snabl/std.hpp" 5 | 6 | namespace snabl { 7 | using Byte = uint8_t; 8 | using Bin = vector; 9 | using Char = char; 10 | using Float = long double; 11 | using I64 = int64_t; 12 | using Str = string; 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/snabl/types/time.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SNABL_TYPE_TIME_HPP 2 | #define SNABL_TYPE_TIME_HPP 3 | 4 | #include "snabl/time.hpp" 5 | 6 | namespace snabl { 7 | struct TimeType: Type