Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / prime-bench.jsx
Last active August 29, 2015 13:56
indirect threading vs dispatching by tail-calls
class _Main {
static function main (args : string[]) : void {
function * prime () : number {
NEXT:
for (var n = 2; true; ++n) {
for (var m = 2; m * m <= n; ++m) {
if (n % m == 0)
continue NEXT;
}
yield n;
.text
.align 2
.globl printf2
printf2:
# %r3 void *fmt
# %r14 const char *fmt
# %r15 void *ap
# %r16 char c
# %r17 char *str
$ make run
warn: redefining variable: wr-lst@1734
warn: redefining variable: pp-expr@1773
warn: redefining variable: pp-call@1774
warn: redefining variable: pp-list@1772
warn: redefining variable: pp-down@1775
warn: redefining variable: pp-general@1776
warn: redefining variable: tail2@1825
warn: redefining variable: tail3@1826
warn: redefining variable: indent-general@1778
/*
* C-side API
*/
struct my_data {
// blah blah blah
};
struct my_data *
create_my_data ()
type false_t = { any : 'a.'a };;
type 'a not_t = 'a -> false_t;;
type ('a,'b) and_t = 'a * 'b;;
type ('a,'b) or_t = L of 'a | R of 'b;;
(* ('a->'b)->('b->'c)->('a->'c) *)
let f1 f g x = g (f x);;
(define-library (lib)
(import (scheme base))
(define foo 1)
(export foo))
(define-library (lib2)
(import (scheme base))
; たとえばこんなライブラリがあったとして…
(define-library (my lib)
(import (scheme base))
(define foo 1)
(define bar 2)
(export foo)
(export (rename bar baz)))
(dictionary . plist)
(dictionary? obj)
(dictionary-ref dict key)
(dictionary-set! dict key value)
(dictionary-has? dict key)
(dictionary-delete dict key)
(dictionary-size dict)
; conversions
(dictionary->plist dict)
; Thinking of reader macros for a while, I found that
; `in-library` can be the silver bullet of it.
(define-library (foo)
(import (picrin keyword)) ; it is assumed that (picrin keyword) exports a reader syntax :foo.
; here you can do everything but using keyword syntax like :foo, because
; import of (picrin keyword) is processed after the top level expression `(define-library ...)` has
; fully read.
.align 2
.globl prod
prod:
lda $30, -16($30)
stq $26, 0($30)
stq $15, 8($30)
mov $30, $15
xor $0, $0, $0
for: