-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwast.lisp
executable file
·77 lines (63 loc) · 1.88 KB
/
wast.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;#!/usr/local/bin/sbcl --script
;;;; Hey, Emacs, this is a -*- Mode: Lisp; Syntax: Common-Lisp -*- file!
;;;;
;;;; Lisp isn't a language, it's a building material.
;;;; -- Alan Kay
;;;;
;;;; Name: wast.lisp
;;;;
;;;; Started: Wed Mar 31 17:36:02 2021
;;;; Modifications:
;;;;
;;;; Purpose:
;;;;
;;;;
;;;;
;;;; Calling Sequence:
;;;;
;;;;
;;;; Inputs:
;;;;
;;;; Outputs:
;;;;
;;;; Example:
;;;;
;;;; Notes:
;;;;
;;;;
(load "/home/slytobias/lisp/packages/test.lisp")
(defpackage :wast (:use :common-lisp :test))
(in-package :wast)
(define-symbol-macro i32 (unsigned-byte 32))
(defmacro module ((func . body) (export . table))
(let ((functions '()))
(destructuring-bind (name &rest code) body
(multiple-value-bind (params code) (get-params code)
(multiple-value-bind (result code) (get-result code)
(acons name `#'(lambda ,params ,code) functions)))) ))
(defun get-params (code)
(labels ((params (code result)
(if (paramp (first code))
(params (rest code) (cons (rest (first code)) result))
(values (nreverse result) code))))
(params code '())))
(defun paramp (expr)
(and (consp expr)
(symbolp (first expr))
(string= (symbol-name (first expr)) (symbol-name 'param))))
(defun get-result (code)
(labels ((result (code result)
(if (resultp (first code))
(result (rest code) (cons (rest (first code)) result))
(values (nreverse result) code))))
(result code '())))
(defun resultp (expr)
(and (consp expr)
(symbolp (first expr))
(string= (symbol-name (first expr)) (symbol-name 'result))))
;; (module
;; (func $how_old (param $year_now i32) (param $year_born i32) (result i32)
;; get_local $year_now
;; get_local $year_born
;; i32.sub)
;; (export "how_old" (func $how_old)))