picrin/extlib/benz
Yuichi Nishiwaki 1fbc38fe55 serializable code representation 2016-02-05 21:53:25 +09:00
..
include serializable code representation 2016-02-05 21:53:25 +09:00
README.md change pic_open interface 2015-06-26 02:13:48 +09:00
blob.c never use size_t 2015-08-26 19:04:27 +09:00
bool.c Fix for equal? bug #312 2015-12-27 21:27:26 -05:00
boot.c Fix cond to conform to R7RS 'If the selected ⟨clause⟩ contains only the ⟨test⟩ and no ⟨expression⟩s, then the value of the ⟨test⟩ is returned as the result.' 2016-01-23 16:14:11 -05:00
char.c never use size_t 2015-08-26 19:04:27 +09:00
codegen.c serializable code representation 2016-02-05 21:53:25 +09:00
cont.c never use size_t 2015-08-26 19:04:27 +09:00
data.c Reduce size of data object by removing unused dict field 2016-01-15 23:44:07 -05:00
debug.c pic_intern_cstr -> pic_intern 2015-07-13 08:16:04 +09:00
dict.c never use size_t 2015-08-26 19:04:27 +09:00
error.c never use size_t 2015-08-26 19:04:27 +09:00
eval.c eval procedure now takes environment object for the second argument 2015-06-16 22:51:49 +09:00
file.c Add benz compile time hooks PIC_DOUBLE_TO_CSTRING and PIC_CSTRING_TO_DOUBLE 2016-01-08 23:06:14 -05:00
gc.c manage ireps using reference count 2016-02-05 00:31:57 +09:00
lib.c never use size_t 2015-08-26 19:04:27 +09:00
load.c pic_load_port -> pic_load 2015-07-13 08:20:07 +09:00
macro.c move pic_resolve to macro.c 2016-02-05 21:01:36 +09:00
number.c Fix c99 style comment 2016-01-10 15:05:35 -05:00
pair.c more efficient arguments processing in pic_apply 2015-08-26 21:52:20 +09:00
port.c never use size_t 2015-08-26 19:04:27 +09:00
proc.c add irep->ints 2016-02-05 21:41:20 +09:00
read.c Fix issue #322 string->number should never signal error 2016-01-10 14:56:44 -05:00
record.c don't use @@type property 2015-08-11 01:34:45 +09:00
reg.c Use pic_eq_p to compare pic_values; move reverse lookup out of khash.h 2015-12-27 10:11:47 -05:00
state.c manage ireps using reference count 2016-02-05 00:31:57 +09:00
string.c fix indent 2016-01-09 23:29:36 +09:00
symbol.c never use size_t 2015-08-26 19:04:27 +09:00
var.c remove pic_proc_name (for a moment) 2015-06-27 19:02:18 +09:00
vector.c more efficient arguments processing in pic_apply 2015-08-26 21:52:20 +09:00
vm.c serializable code representation 2016-02-05 21:53:25 +09:00
write.c never use size_t 2015-08-26 19:04:27 +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.