Coder Social home page Coder Social logo

picrin-scheme / picrin Goto Github PK

View Code? Open in Web Editor NEW
412.0 24.0 34.0 9.72 MB

lightweight scheme interpreter

License: MIT License

C 22.37% Makefile 0.40% Scheme 73.15% Shell 0.42% TeX 3.44% Emacs Lisp 0.07% Perl 0.15%
interpreter scheme-interpreter c scheme

picrin's Introduction

The project is in hiatus and being archived soon...

Build Status Docs Status

Picrin is a lightweight R7RS scheme implementation written in pure C89. It contains a reasonably fast VM, an improved hygienic macro system, useful contribution libraries, and simple but powerful C interface.

  • R7RS compatible
  • Reentrant design (all VM states are stored in single global state object)
  • Bytecode interpreter
  • Direct threaded VM
  • Internal representation by nan-boxing (available only on x64)
  • Conservative call/cc implementation (VM stack and native c stack can interleave)
  • Exact GC (simple mark and sweep, partially reference count)
  • String representation by rope
  • Hygienic macro transformers (syntactic closures, explicit and implicit renaming macros)
  • Extended library syntax

Documentation

See http://picrin.readthedocs.org/

Homepage

Currently picrin is hosted on Github. You can freely send a bug report or pull-request, and fork the repository.

https://github.com/picrin-scheme/picrin

Build

Just type make in the project root directory. You will find an executable binary newly created at bin/ directory.

$ make

When you are building picrin on x86_64 system, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail).

Install

make install target is provided. By default it installs picrin binary into /usr/local/bin/.

$ make install

Since picrin does not use autoconf, if you want to specify the install directory, pass the custom path to make via command line argument.

$ make install prefix=/path/to/dir

Requirement

To build Picrin Scheme from source code, some external libraries are required:

  • perl
  • regex.h of POSIX.1
  • libedit (optional)

Make command automatically turns on optional libraries if available. Picrin is mainly developed on Mac OS X and only tested on OS X or Ubuntu 14.04+. When you tried to run picrin on other platforms and found something was wrong with it, please send us an issue.

Authors

See AUTHORS

picrin's People

Contributors

dcurrie avatar hiromu avatar hopkinsr avatar johngtait avatar keens avatar ktakashi avatar lassik avatar leon-vv avatar nyuichi avatar okuoku avatar omasanori avatar stibear avatar syohex avatar wtokuno avatar zeptometer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

picrin's Issues

export bug?

I'm writing SRFI-9 (Defining Record Types).
https://gist.github.com/stibear/8982207
If export "define-record-type" only,

compilation error: unbound variable define-record-field

So I wrote (export define-record-type define-record-field), though I didn't export define-record-field.

I think this is export's bug. What do you think?

repl shows strange message?

According to @stibear, repl seems show some strange message when defining below function.

I expect this is caused by readline, but further research is required.

> (define (circular-list? x)
    (and (pair? x)
     (let rec ((lst (cdr x)))
       (cond ((not (pair? lst)) #f)
         ((null? lst) #f)
         ((eq? x lst) #t)
         (else (rec (cdr lst)))))))
* * * * 
.git/        .travis.yml  Makefile     etc/         lib/         t/
.gitignore   AUTHORS      README.md    extlib/      piclib/      tools/
.gitmodules  LICENSE      bin/         include/     src/         
* 
.git/        .travis.yml  Makefile     etc/         lib/         t/
.gitignore   AUTHORS      README.md    extlib/      piclib/      tools/
.gitmodules  LICENSE      bin/         include/     src/         
* 
.git/        .travis.yml  Makefile     etc/         lib/         t/
.gitignore   AUTHORS      README.md    extlib/      piclib/      tools/
.gitmodules  LICENSE      bin/         include/     src/         
compilation error: invalid expression given

optional arguments

I often want to define the function receiving optional arguments.
IMO, it is not necessary, but should be discussed.
How do you feel about it?

inter-referential definition support

In most practical cases interreferential definitions frequently occurs on the source code. Especially reference to undefined global function which will be defined later on the code appears many times.

compilation failure on Arch Linux

$ make
cd src; \
  yacc -d parse.y; \
  lex scan.l
parse.y: 30.1-12: 警告: deprecated directive, use `%pure-parser` [-Wdeprecated] %pure_parser
 ^^^^^^^^^^^^^
flex: Can't use --reentrant or --bison-bridge with -l option
Makefile:24:  recipe for target 'build-lib' failed
$
$ lex --version
2.5.37
$ yacc --version
bison 3.0

object arena handler stack

Unlike mruby picrin create a number of objects in one call (mainly because of the existence of cons). We need another way to manage newly allocated objects in c function just as Rubinius does.

Core dump from REPL

Hi,

I just pulled picrin source from the repo, and after issuing these in REPL:

> (define (range s e) 
     (if (>= s e) 
       (list)
       (cons s (range (+ 1 s) e))))
> (apply + (range 1 10000))

I'm getting core dump. Any idea what can be wrong?

Best, Sanel

regex support

Possible API design:

  • (regex ptrn [flags])
  • (regex-match re txt)
  • (regex-search re txt)
  • (regex-replace re txt)
  • (regex-split re txt)
  • reader syntax: #/.../[gi]

bug in explicit renaming?

I defined hygenic and macro as below, but picrin crashes while expanding this macro. It seems that (rename 'if) in last line cause this bug.

;; crash
(define-syntax myand
  (er-macro-transformer
   (lambda (form rename compare)
     (let ((exprs (cdr form)))
       (if (null? exprs)
       #t
       (let ((test (car exprs))
         (if-true (cons (rename 'myand) (cdr exprs))))
         (list (rename 'if) test if-true  #f)))))))

;; work
(define-syntax badand
  (er-macro-transformer
   (lambda (form rename compare)
     (let ((exprs (cdr form)))
       (if (null? exprs)
       #t
       (let ((test (car exprs))
         (if-true (cons (rename 'badand) (cdr exprs))))
         (list if test if-true  #f)))))))

compilation error on circular-list?

According to @stibear below code does not work on picrin.

(define (circular-list? x)
    (let rec ((lst (cdr x)))
      (cond ((null? lst) #f)
        ((eq? x lst) #t)
        (else (rec (cdr lst))))))
; * * * * compilation error: invalid expression given

compilation error on Arch Linux

$ make
cd src; \
  yacc -d parse.y; \
  flex scan.l
gcc -Wall -g -DDEBUG=1 -O0 -shared src/*.c -o lib/libpicrin.so -I./include -I./extlib -lm
In file included from scan.l:6:0:
y.tab.h:113:21: warning: ‘struct parser_control’ declared inside parameter list [enabled by default]
y.tab.h:113:21: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
/usr/bin/ld: /tmp/ccVEtfJs.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccVEtfJs.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:24: recipe for target 'build-lib' failed
make: *** [build-lib] Error 

cons*がruntime errorする

bin/picrin
> (define (append-reverse rev-head tail)
    (append (reverse rev-head) tail))
* => #f
> (define (cons* x . args)
    (let rec ((acm '()) (x x) (lst args))
      (if (null? lst)
          (append-reverse acm x)
          (rec (cons x acm) (car lst) (cdr lst)))))
* * * * => #f
> (cons* 1)
=> 1
> (cons* 1 2 3 4)
runtime error: invalid application

Bug in `load`

If non-existent library was imported in define-library, symbols which are already bound become unbound.

../test.scm:

(define-library (dummy 0)
    (import (wwq))
)

input and output:

koba-e964@debian-koba-e964-0:~/srcview/picrin$ bin/picrin 
> (+ 2 3)
=> 5
> (import (scheme load))
=> #f
> (load "../test.scm")
=> #<undef>
> (+ 2 3)
error: unbound variable +
> (list 2 3)
error: unbound variable list
> 
koba-e964@debian-koba-e964-0:~/srcview/picrin$ 

er-macro-transformer is broken

Likewise Chibi-scheme, we've currently made use of syntactic closures to implement er/ir-macro-transformer. I however found they are broken because they require identifier? and identifier=? are defined in global scope. In the original algorithm of er/ir-macro, the transformers don't require any helper functions declared, and instead they close all syntactic information in rename and compare functions which will be passed to the transformer.

hygiene problem

Per justinethier/husk-scheme#151 the expression

(let ((unquote 'foo)) `(,'bar)

should expand into (,'bar) or ((unquote (quote bar))). But instead it expands into (bar):

justin@justin-desktop:~/Documents/picrin$ make run
bin/picrin
> (let ((unquote 'foo)) `(,'bar))
=> (bar)

add a library-embedding tool like mrbc in mruby

It would be better if we have a tool to embed the built-in library in libpicrin. mruby already includes such tool, called mrbc. I saw a similar approach in V8 (but it might have changed now).

AFAIK mruby choose byte code as embedding format and V8 did JavaScript source code. Which is better for us?

nested unhygienic macros broken

According to @zeptometer, macroexpander seems broken when unhygienic macros are complicatedly nested

https://gist.github.com/zeptometer/8885494

(destructuring-bind ((a b) . c) '((1 2) 3 4 5) (list a b c))

; expands to

((lambda (evaluated@605)
   ((lambda (evaluated@605)
      ((lambda (a@617)
     (begin ((lambda (evaluated@605)
           ((lambda (b@619)
              (begin
            (begin
              ((lambda (c@620) (begin (list@19 a@617 b@619 c@620)))
               (cdr@9 evaluated@605)))))
            (car@8 evaluated@605)))
         (cdr@9 evaluated@605))))
       (car@8 evaluated@605)))
    (car@8 evaluated@605)))
 (quote ((1 2) 3 4 5)))

A variable evaluated is expanded in a uniform symbol but theoretically must be compiled to each different symbols.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.