etng-r2/evaluator-base-library.scm
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 216 aa55f1375161
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
216
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     1
(define-macro prim0
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
  (lambda (x env exp)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     3
    (let ((name (cadr x)))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     4
      `(define-global! ',name
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     5
	 (lambda ()
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     6
	   (%assemble () ()
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     7
	     (scheme (,name))))))))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     8
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     9
(define-macro prim1
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    10
  (lambda (x env exp)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    11
    (let ((name (cadr x)))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    12
      `(define-global! ',name
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    13
	 (lambda (a0)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    14
	   (%assemble (a0) (a0)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    15
	     (scheme (,name a0))))))))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    16
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    17
(define-macro prim2
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    18
  (lambda (x env exp)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    19
    (let ((name (cadr x)))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    20
      `(define-global! ',name
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    21
	 (lambda (a0 a1)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    22
	   (%assemble (a0 a1) (a0 a1)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    23
	     (scheme (,name a0 a1))))))))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    24
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    25
(prim1 primitive-eval)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    26
(prim1 read-file)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    27
(prim1 write)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    28
(prim1 newline)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    29
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    30
(prim1 cdr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    31
(prim1 cddr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    32
(prim1 cddar)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    33
(prim1 cdar)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    34
(prim1 cdadr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    35
(prim1 car)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    36
(prim1 cadr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    37
(prim1 caddr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    38
(prim1 cadddr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    39
(prim1 cadar)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    40
(prim1 caar)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    41
(prim1 caadr)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    42
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    43
(prim1 box)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    44
(prim1 unbox)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    45
(prim2 set-box!)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    46
    
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    47
(prim1 length)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    48
(prim2 append)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    49
(prim1 reverse)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    50
(prim2 cons)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    51
(prim2 eq?)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    52
(prim2 =)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    53
(prim1 not)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    54
(prim1 null?)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    55
(prim1 pair?)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    56
(prim1 symbol?)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    57
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    58
(prim0 gensym)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    59
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    60
(define-global! 'map
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    61
  (lambda (f l)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    62
    (if (null? l)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    63
	'()
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    64
	(cons (f (car l))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    65
	      (map f (cdr l))))))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    66
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    67
(define-global! 'for-each
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    68
  (lambda (f l)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    69
    (if (null? l)
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    70
	'ok
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    71
	(begin (f (car l))
aa55f1375161 Switch to using %assemble for primitives.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    72
	       (for-each f (cdr l))))))