Go to file
Yuichi Nishiwaki 7c5fb70e73 mark invalid flag 2014-09-24 15:59:35 +09:00
include publish continuation internal APIs 2014-09-24 15:34:46 +09:00
README.md update readme 2014-09-21 15:43:09 +09:00
blob.c remove unused helper functions 2014-09-21 18:05:43 +09:00
bool.c first commit 2014-08-25 13:38:09 +09:00
boot.c implement parameterize 2014-09-15 15:49:04 +09:00
char.c remove pic_error 2014-09-16 23:43:15 +09:00
codegen.c remove pic_error 2014-09-16 23:43:15 +09:00
cont.c publish continuation internal APIs 2014-09-24 15:34:46 +09:00
data.c first commit 2014-08-25 13:38:09 +09:00
debug.c print backtrace to stderr 2014-09-19 17:11:59 +09:00
dict.c remove dictionary-map and dictionary-for-each 2014-09-21 16:26:56 +09:00
error.c mark invalid flag 2014-09-24 15:59:35 +09:00
eval.c flatten the library hierarchy (again) 2014-09-08 19:38:19 +09:00
file.c refactor error object 2014-09-17 00:29:17 +09:00
gc.c spill out continuation type to extra data type family 2014-09-18 22:25:06 +09:00
init.c import (picrin base) to (picrin user) by default 2014-09-17 04:00:03 +09:00
lib.c Fix a bug due to the operator precedence of C. 2014-09-19 18:28:55 +09:00
load.c flatten the library hierarchy (again) 2014-09-08 19:38:19 +09:00
macro.c remove pic_error 2014-09-16 23:43:15 +09:00
number.c remove pic_error 2014-09-16 23:43:15 +09:00
pair.c inline pic_car and pic_cdr 2014-09-17 01:07:25 +09:00
port.c remove pic_error 2014-09-16 23:43:15 +09:00
proc.c remove pic_error 2014-09-16 23:43:15 +09:00
read.c refactor error object 2014-09-17 00:29:17 +09:00
record.c record_new -> make_record 2014-09-12 19:49:58 +09:00
state.c compact struct pic_jmpbuf 2014-09-18 14:50:01 +09:00
string.c spill out string mutators 2014-09-21 15:32:55 +09:00
symbol.c s/pic_abort/pic_panic/g 2014-09-17 01:02:27 +09:00
system.c str_new -> make_str 2014-09-12 19:52:49 +09:00
time.c flatten the library hierarchy (again) 2014-09-08 19:38:19 +09:00
var.c no export current-dynamic-environment 2014-09-16 00:22:54 +09:00
vector.c implement vector-map, vector-for-each, string-map, string-for-each 2014-09-19 18:16:28 +09:00
vm.c [bugfix] don't refer to env storage when accessing non-captured variable 2014-09-18 14:14:09 +09:00
write.c update xhash (orderd map) 2014-09-16 22:38:58 +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.

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.