blob: 5428dce74fc70eed543f041ca935838d9e03b9df [file] [log] [blame]
swissChilibed80922021-04-13 21:58:05 -07001;;; scratch.s -- ideas for how code generation will work
2
3 ;; (defun lisp-function (A B)
4 ;; (let ((local-var (whatever)))
5 ;; (whatever local-var (something-else 4))))
6 ;;
7 ;; This means the stack looks like this:
8 ;; B_value
9 ;; B_tag
10 ;; A_value
11 ;; A_tag
12 ;; result pointer
13 ;; return pointer <---- esp
14lisp_function:
15 push ebp ; Now ebp can be used as an offset
16 mov ebp, esp
17 sub esp, 16 ; 1 var, 1 temporary
18
19 ;; Now, call `whatever' with no arguments
20 ;; For now we will do no register allocation, so don't even
21 ;; bother saving anything.
22 lea eax, [ebp - 8]
23 push eax ; Return address
24 call whatever
25
26 ;; Now we need to evaluate (something-else 4) and store it in a
27 ;; temporary variable.
28 ;; First set up the literal 4
29 push 4 ; The value
30 push 0x20000000 ; Type tag and length
31 ;; Then set up the return address
32 lea eax, [ebp - 16]
33 push eax
34 call something_else ; Result stored in temporary
35
36 ;; Next function: `whatever'
37 push [ebp - 12] ; The temporary
38 push [ebp - 16]
39 push [ebp - 8] ; The variable
40 push [ebp - 4]
41 push [ebp + 4] ; The function's return address
42 call whatever
swissChilica107a02021-04-14 12:07:30 -070043
44 mov esp, ebp ; Finally clean up
45 pop ebp
swissChilibed80922021-04-13 21:58:05 -070046 ret