Skip to content

Instantly share code, notes, and snippets.

MIZUTANI Tociyuki tociyuki

Block or report user

Report or block tociyuki

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tociyuki
tociyuki / so-er-expand.scm
Created Mar 28, 2018
Explicit renaming macro expander for scheme with Dybvig's syntax-object
View so-er-expand.scm
; explicit renaming macro expander
; Hanson-Bawden alias as Dybvig syntax-object.
(use util.match)
(define so-macro-proc-environment (interaction-environment))
(define so-unique-id-counter 0)
(define (so-reset-unique-id-counter) (set! so-unique-id-counter 0))
(define (so-expand form env)
@tociyuki
tociyuki / rsc-rules.scm
Last active Mar 24, 2018
SRFI 149 syntax-rules for rsc-expand.scm
View rsc-rules.scm
; SRFI 149 syntax rules
; for rsc-expand.scm
; https://gist.github.com/tociyuki/83f6a4523618e6f843549feb9186cafa
(define (sc-length* x)
(if (not (pair? x))
0
(let loop ((x x) (xx (cdr x)) (c 1))
(cond
((eq? x xx) (error "cyclic list"))
@tociyuki
tociyuki / so-rules.scm
Last active Mar 24, 2018
SRFI 149 syntax-rules for syntax object expander
View so-rules.scm
; SRFI 149 syntax rules
; for so-expand.scm
; https://gist.github.com/tociyuki/420306242e66f6ead2c3bd3d1be0b2f6
(define (so-syntax-vector? x) (vector? (so-unwrap-syntax x)))
(define (so-syntax-vector->list x) (vector->list (so-unwrap-syntax x)))
(define (so-syntax-list->vector x) (list->vector (so-syntax-map identity x)))
(define (so-syntax-length* x)
(define (strip x)
@tociyuki
tociyuki / so-expand.scm
Last active Mar 23, 2018
Dybvig's syntax object based low level hygienic macro expander for core scheme
View so-expand.scm
; low level hygienic macro expander
; This experimental implementation stands on the Kent Dibvig's
; syntax objects expander.
(define so-macro-proc-environment (interaction-environment))
(define so-unique-id-counter 0)
(define (so-reset-unique-id-counter) (set! so-unique-id-counter 0))
(define (so-expand x template-id)
(so-expand-form (so-datum->syntax template-id x)))
@tociyuki
tociyuki / rsc-expand.scm
Last active Mar 24, 2018
Hanson-Bawden syntactic closures hygienic macro expander for tiny scheme core language
View rsc-expand.scm
; syntactic closures based on
; Alan Bawden, Jonathan Rees, ``Syntactic Closures'', 1988
; Chris Hanson, ``A Syntactic Closures Macro Facility'', 1991
; William Clinger, ``Hygienic Macros Through Explicit Renaming'', 1991
(use util.match)
(define sc-macro-proc-environment (interaction-environment))
(define sc-unique-id-counter 0)
(define (sc-reset-unique-id-counter) (set! sc-unique-id-counter 0))
@tociyuki
tociyuki / cr-er-expand.scm
Last active Feb 28, 2018
Clinger-Rees explicit renamimg hygienic macro expander for tiny scheme core language
View cr-er-expand.scm
; explicit renaming macro based on
; W. Clinger, J. Rees, ``Macros That Work'', 1991
; W. Clinger, ``Hygienic Macros Through Explicit Renaming'', 1991
(use util.match)
(define cr-macro-proc-environment (interaction-environment))
(define cr-unique-id-counter 0)
(define (cr-reset-unique-id-counter) (set! cr-unique-id-counter 0))
@tociyuki
tociyuki / sc-expand.scm
Last active Feb 28, 2018
syntactic-closures hygienic macro expander for tiny scheme core language
View sc-expand.scm
; syntactic-closures based on
; Alan Bawden, Jonathan Rees ``Syntactic Closures'', 1988
(use util.match)
(define sc-macro-proc-environment (interaction-environment))
(define sc-unique-id-counter 0)
(define (sc-reset-unique-id-counter) (set! sc-unique-id-counter 0))
; Expander
@tociyuki
tociyuki / kffd-expand.scm
Last active Jan 17, 2018
KFFD hygienic macro expander for tiny scheme core language
View kffd-expand.scm
; historical hygienic macro expander for tiny scheme based on
; E. Kohlbecker, D. Friedman, M. Felleisen, and B. Duba
; ``Hygienic Macro Expansion'', 1986
(use util.match)
(use srfi-69)
(define get #f)
(define put #f)
(let ((dict (make-hash-table equal?)))
@tociyuki
tociyuki / vm-3imp-stack-flat.scm
Created Dec 24, 2017
Stack-based Flat-Closure compile/VM from 3imp to Gauche 0.9.5
View vm-3imp-stack-flat.scm
; Historical Stack-based Flat-Closure compiler/VM of core Scheme
;
; ported to Gauche 0.9.5 from
; R. Kent Dybvig ``Three Implementation Models for Scheme'' (1987), Chapter 4
;
; changes:
;
; 1. reversal vector stack: #( s <-- push; pop --> s ).
; stack pointer s starts from (vector-length stack).
; i-th element in the frame f is (vector-ref stack (+ f i)).
@tociyuki
tociyuki / yydecode-json.cpp
Last active Nov 2, 2017
JSON decoder in C++11 based on N. Wirth's table-driven top-down parsing technique
View yydecode-json.cpp
#include <string>
#include <vector>
#include <unordered_map>
#include <cctype>
#include <utility>
// for example: (the handle of a string data at box.m_string[i]) == i + T_STRING
enum {
T_NUMBER = 0x10000000L, T_STRING = 0x20000000L, T_OBJECT = 0x30000000L,
T_ARRAY = 0x40000000L, T_NULL = 0x50000000L, T_TRUE = 0x60000000L,
You can’t perform that action at this time.