Go to file
Yuichi Nishiwaki 5b7f5ad1f9 Squashed 'extlib/benz/' changes from 414f790..057b5f2
057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol
c91f6cd [bugfix] build failure in debug mode
b1849c4 pic_sym is not a pointer
e353b07 s/pic_sym/pic_sym_ptr/g
a11fb91 [bugfix] irep->name is missed to mark
1820a25 [bugfix] wrong type specified for cxt->syms
b8d2b8e better error messages against invalid use of auxiliary syntax
d9ade33 mark only interned symbols and some specisl uninterned symbols
da2217b move symbol constants to pic_state
78b035b [bugfix] pic_intern must count up reference of the return value
bbdc663 rename internal object
ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g
1af32d1 improve error message
dd09fbf don't malloc in pic_interned_p
7f51070 turn on GC
7460e81 add gc on/off flag
f3742db move symbol-related macros to symbol.h
ded6759 remove pic_sym_value
ec97d07 remove pic_symbol_value
28bd059 heap symbol seems working (with GC stopped)
e0d6fe9 change pic_intern interface
6750693 remove pic_ungensym
4ea7d3c add irep->syms
ede7a99 use dictionary for senv->map
b3cb50c use dictionaries for temporary import table
fc698b5 use dictionary for rec->data
1b814d4 use dictionary for lib->exports
7ae1af4 use dictionaries for pic->globals and pic->macros
74f9979 remove 'struct pic_macro'. define-syntax spec is changed.
86136c5 some procedures are moved to contrib/
da99761 gather all includes of standard headers into picrin.h
7df8d77 add dictionary-map and dictionary-for-each
b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure
f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys

git-subtree-dir: extlib/benz
git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 17:44:06 +09:00
include Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
README.md add single line comments about attribute and dictionary 2014-09-25 12:17:06 +09:00
attr.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
blob.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
bool.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
boot.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
char.c revert: argc must be size_t type 2014-09-27 20:17:02 +09:00
codegen.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
cont.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
data.c first commit 2014-08-25 13:38:09 +09:00
debug.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
dict.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
error.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
eval.c flatten the library hierarchy (again) 2014-09-08 19:38:19 +09:00
gc.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
init.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
lib.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
load.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
macro.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
number.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
pair.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
port.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
proc.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
read.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
record.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
state.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
string.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
symbol.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
var.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
vector.c revert: argc must be size_t type 2014-09-27 20:17:02 +09:00
vm.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00
write.c Squashed 'extlib/benz/' changes from 414f790..057b5f2 2015-01-20 17:44:06 +09:00

README.md

Benz

Benz is a super tiny scheme interpreter intended to be embedded in other applications such as game engine and network server. It provides a subset language of R7RS with several useful extensions. By default, Benz just contains some C files and headers and this README file. In embedding, you only need to copy the files into the project and add include dir to the include path.

Originally, Benz used to be the core component of Picrin Scheme. They are currently maintained at separate repositories.

Example

#include <stdio.h>

#include "picrin.h"

/* Simple REPL program */

int
main(int argc, char *argv[])
{
  pic_state *pic;
  pic_value expr;

  pic = pic_open(argc, argv, NULL);

  while (1) {
    printf("> ");

    expr = pic_read(pic, pic_stdin(pic));

    if (pic_eof_p(expr)) {
      break;
    }

    pic_printf(pic, "~s\n", pic_eval(pic, expr, pic->lib));
  }

  pic_close(pic);

  return 0;
}

More Example

Function binding is also easy. pic_defun defines a scheme procedure converting from a C function. In the native function, callee arguments can be taken with pic_get_args. pic_get_args gets arguments according to the format string. If actual arguments does not match a number or incompatible types, it will raise an exception.

#include "picrin.h"

int fact(int i) {
  return i == 1 ? 1 : i * fact(i - 1);
}

pic_value factorial(pic_state *pic) {
  int i;

  pic_get_args(pic, "i", &i);

  return pic_int_value(fact(i));
}

int
main(int argc, char *argv[])
{
  pic_state *pic = pic_open(argc, argv, NULL);

  pic_defun(pic, "fact", factorial); /* define fact procedure */

  pic_load_cstr(pic, "(display (fact 10))");

  pic_close(pic);

  return 0;
}

Language

All procedures and syntaces are exported from a single library named (picrin base). The complete list is found at https://gist.github.com/wasabiz/344d802a2340d1f734b7 .

call/cc

Full continuation has many problems in embbeding into applications. By default, Benz's call/cc operator does not support continuation that can handle re-entering (it only supports escape continuations). To remove this restriction, please use an add-on provided from Picrin Scheme's repository.

Strings

Benz utilize rope data structure to implement string type. Thanks to the implementation, string-append is guaranteed to be done in a constant time (so do string-copy, when ascii-only mode is enabled). In return for that, strings in benz are immutable by default. It does not provide mutation API (string-set!, string-copy! and string-fill! in R7RS). This restriction can be also removed with an add-on in Picrin Scheme's repository.

Dictionaries

Dictionary is a hash table object. Its equivalence is tested with equal? procedure.

Attribute

Benz has an facility to get or set metadata to any heap object.

Authors

See https://github.com/picrin-scheme/benz and https://github.com/picrin-scheme/picrin for details.

LICENSE

Copyright (c) 2013-2014 Yuichi Nishiwaki and other picrin contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.