~swisschili/bluejay

ref: 6d02af472f6ce87ea50ff24aa77f88928dbf31bc bluejay/src/lisp/scratch.s -rw-r--r-- 1.2 KiB
6d02af47swissChili Add detailed error reporting, remove panics 10 months ago
                                                                                
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
;;; scratch.s -- ideas for how code generation will work

	;; (defun lisp-function (A B)
	;;   (let ((local-var (whatever)))
	;;     (whatever local-var (something-else 4))))
	;; 
	;; This means the stack looks like this:
	;; B_value
	;; B_tag
	;; A_value
	;; A_tag
	;; result pointer
	;; return pointer     <---- esp 
lisp_function:
	push ebp					; Now ebp can be used as an offset
	mov ebp, esp
	sub esp, 16					; 1 var, 1 temporary

	;; Now, call `whatever' with no arguments
	;; For now we will do no register allocation, so don't even
	;; bother saving anything.
	lea eax, [ebp - 8]
	push eax					; Return address
	call whatever

	;; Now we need to evaluate (something-else 4) and store it in a
	;; temporary variable.
	;; First set up the literal 4
	push 4 						; The value
	push 0x20000000				; Type tag and length
	;; Then set up the return address
	lea eax, [ebp - 16] 
	push eax
	call something_else			; Result stored in temporary

	;; Next function: `whatever'
	push [ebp - 12]				; The temporary
	push [ebp - 16]
	push [ebp - 8]				; The variable
	push [ebp - 4]
	push [ebp + 4]				; The function's return address
	call whatever

	mov esp, ebp 				; Finally clean up
	pop ebp
	ret