picrin/lib
Yuichi Nishiwaki ac0adda263 update Makefile 2017-04-15 03:35:18 +09:00
..
ext make default-environment a zero-ary procedure 2017-04-15 02:56:31 +09:00
include add PIC_USE_CALLCC flag 2017-04-15 01:53:43 +09:00
Makefile update Makefile 2017-04-15 03:35:18 +09:00
README.md update READMEs 2017-03-29 08:11:20 +09:00
blob.c calculate object size from type 2017-04-12 13:18:06 +09:00
bool.c reimplement macro expander in scheme 2017-04-04 15:05:34 +09:00
char.c redefine value constructors/destructors as inline functions 2017-03-29 07:58:08 +09:00
cont.c cleanup 2017-04-15 02:48:20 +09:00
data.c calculate object size from type 2017-04-12 13:18:06 +09:00
debug.c remove pic_get_backtrace 2017-04-09 15:28:09 +09:00
dict.c calculate object size from type 2017-04-12 13:18:06 +09:00
error.c add PIC_USE_CALLCC flag 2017-04-15 01:53:43 +09:00
gc.c add file ops 2017-04-15 02:13:39 +09:00
khash.h add value.h 2017-03-29 07:11:27 +09:00
load.c add PIC_USE_FILE and PIC_USE_READ flags 2017-04-15 01:06:33 +09:00
number.c bootstrap 2017-04-14 23:40:07 +09:00
object.h bootstrap 2017-04-14 23:40:07 +09:00
pair.c calculate object size from type 2017-04-12 13:18:06 +09:00
port.c update Makefile 2017-04-15 03:35:18 +09:00
proc.c add PIC_USE_CALLCC flag 2017-04-15 01:53:43 +09:00
record.c calculate object size from type 2017-04-12 13:18:06 +09:00
state.c cleanup 2017-04-15 02:48:20 +09:00
state.h bootstrap 2017-04-14 23:40:07 +09:00
string.c calculate object size from type 2017-04-12 13:18:06 +09:00
symbol.c calculate object size from type 2017-04-12 13:18:06 +09:00
var.c bugfix: initial value of parameter must be registered to the top 2017-04-02 01:13:03 +09:00
vector.c calculate object size from type 2017-04-12 13:18:06 +09:00
weak.c bootstrap 2017-04-14 23:40:07 +09:00

README.md

libpicrin

libpicrin 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, libpicrin only contains some C files and headers and this README file. To embed, you only need to copy the files into the project and add include dir to the include path.

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

Example

#include <stdio.h>

#include "picrin.h"
#include "picrin/extra.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(pic, expr)) {
      break;
    }

    pic_printf(pic, "~s\n", pic_eval(pic, expr, "picrin.user"));
  }

  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"
#include "picrin/extra.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(pic, 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, libpicrin'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

libpicrin 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 libpicrin 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 from symbol to object.

Authors

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

LICENSE

Copyright (c) 2013-2017 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.