Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / locative.scm
Last active August 29, 2015 14:27
locative in scheme
(define (make-locative accessor modifier)
(cons accessor modifier))
(define (locative-ref loc)
((car loc)))
(define (locative-set! loc value)
((cdr loc) value))
(set! (setter locative-ref) locative-set!) ; srfi-17: generalized set!
@nyuichi
nyuichi / monadic-peg.scm
Last active August 29, 2015 14:25
peg in scheme
(import (scheme base)
(scheme write)
(gauche partcont))
(define-syntax PEG:reify
(syntax-rules ()
((_ expr)
(reset (PEG:unit expr)))))
(define (PEG:reflect x)
#include <iostream>
#include <type_traits>
#include <typeinfo>
#include <typeindex>
template<typename T> struct Key;
template<> struct Key<int> { static constexpr std::size_t value = 0; };
template<> struct Key<float> { static constexpr std::size_t value = 1; };
template<typename T, typename U>
[yuichi@joestar build]$ find .. -name "*.[ch]" | xargs grep "[^_a-z]\\(realloc\\|malloc\\|free\\|calloc\\)("
../extlib/benz/include/picrin/xhash.h: x->buckets = realloc(x->buckets, (x->size + 1) * sizeof(xh_entry *));
../extlib/benz/include/picrin/xhash.h: free(x->buckets);
../extlib/benz/include/picrin/xhash.h: e = malloc(x->voffset + x->vwidth);
../extlib/benz/include/picrin/xhash.h: free(q);
../extlib/benz/include/picrin/xhash.h: free(q);
../extlib/benz/include/picrin/xhash.h: free(e);
../extlib/benz/include/picrin/xhash.h: free(x->buckets);
../extlib/benz/include/picrin.h: free(ptr);
../extlib/benz/include/picrin.h: return realloc(ptr, size);
[yuichi@joestar build]$ make -C ../etc nm
git show -s --format=%H; echo '****'; clang -shared -pedantic -Wno-overlength-strings -ansi -D"PIC_ENABLE_FLOAT=0" -D"PIC_ENABLE_LIBC=0" -fno-stack-protector -o libbenz.dylib -I../extlib/benz/include ../extlib/benz/*.c; nm -u libbenz.dylib
3d52d56c067d2731921529b0f2443629201523d6
****
dyld_stub_binder
[yuichi@*** build]$ nm -u lib/libpicrin.dylib
__DefaultRuneLocale
__Exit
___assert_rtn
___bzero
___maskrune
___memset_chk
___snprintf_chk
___stack_chk_fail
___stack_chk_guard
PIC_INLINE int
xvfprintf(xFILE *stream, const char *fmt, va_list ap)
{
int flags, width, precision, length;
enum {
ALT = 1,
ZERO = 2,
LEFT = 4,
SIGN = 8,
SPACE = 16
まず、nominalな継承関係はないので、ここでの継承関係とはクラス<A>と<B>の包含関係が
A \subset B
であることします。ようするに
(instanceof? x A) => (instanceof? x B)
みたいな感じですね。これを実現するためにクラス間の継承関係を*あとづけ*できるようにします。
(import (picrin foreign))
(define libm (foreign-library "libm.so.6"))
(define cosh (foreign-function libm "cosh" (list double) double))
(define sinh (foreign-function libm "sinh" (list double) double))
(define libc (foreign-library "libc.so.6"))
(define tm (foreign-struct int 'tm_sec
; = class system =
(define-library (picrin class)
(import (scheme base))
(define-record-type class-type
(make-class membership)
class?
(membership class-membership))