picrin/extlib/benz
Yuichi Nishiwaki 4d18610a79 refine error messages 2015-06-27 17:50:03 +09:00
..
include don't malloc duplicated cstring 2015-06-26 02:32:59 +09:00
README.md change pic_open interface 2015-06-26 02:13:48 +09:00
attr.c add pic_reg 2015-06-09 18:31:46 +09:00
blob.c replace none with undef 2015-06-09 16:34:45 +09:00
bool.c use khash in equal? impl 2015-06-25 06:44:45 +09:00
boot.c refine error messages 2015-06-27 17:50:03 +09:00
char.c Add 'extlib/benz/' from commit '569b1ace02e6a066b21f94dff23c4e01b8748bf0' 2015-01-03 06:31:37 +00:00
codegen.c refine error messages 2015-06-27 17:50:03 +09:00
cont.c [bugfix] don't compare continuation objects by pointers. They may be 2015-06-23 03:14:00 +09:00
data.c cleanup 2015-06-24 01:13:18 +09:00
debug.c print error irritants 2015-06-20 02:34:00 +09:00
dict.c fix dictionary conviersion procedures 2015-06-25 22:29:27 +09:00
error.c use pic_malloc and pic_free in file.c 2015-06-19 02:05:56 +09:00
eval.c eval procedure now takes environment object for the second argument 2015-06-16 22:51:49 +09:00
file.c file.h is now stdio.h-free 2015-06-19 05:14:18 +09:00
gc.c don't malloc duplicated cstring 2015-06-26 02:32:59 +09:00
lib.c use khash for dictionary impl 2015-06-25 05:56:15 +09:00
load.c [bugfix] port leaks 2015-06-26 23:45:56 +09:00
macro.c use khash for env 2015-06-25 07:26:48 +09:00
number.c use pic_malloc and pic_free in file.c 2015-06-19 02:05:56 +09:00
pair.c s/rXXX/uXXX/g 2015-06-15 02:30:05 +09:00
port.c [bugfix] port should be closed properly 2015-06-26 23:06:52 +09:00
proc.c optimize var implementation 2015-06-08 22:28:17 +09:00
read.c [bugfix] port leaks 2015-06-26 23:45:56 +09:00
record.c fix #230 2015-06-19 23:34:12 +09:00
reg.c use khash for registers 2015-06-25 07:14:29 +09:00
state.c refine error messages 2015-06-27 17:50:03 +09:00
string.c use pic_malloc and pic_free in file.c 2015-06-19 02:05:56 +09:00
symbol.c don't malloc duplicated cstring 2015-06-26 02:32:59 +09:00
undef.c let undefined be public API 2015-06-09 16:19:57 +09:00
var.c use registries for parameter table 2015-06-09 18:36:39 +09:00
vector.c replace none with undef 2015-06-09 16:34:45 +09:00
vm.c refine error messages 2015-06-27 17:50:03 +09:00
write.c fix benz's issue 29 2015-06-25 22:33:17 +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(pic_default_allocf, 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(pic_default_allocf, 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.