compc.lsp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (global '(s!:c_name s!:c_file s!:lisp_name s!:lisp_file))
  2. (dm c!:printf (u) (list 'c!:printf1 (cadr u) (cons 'list (cddr u))))
  3. (de c!:printf1 (fmt args)
  4. (prog (a c)
  5. (setq fmt (explode2 fmt))
  6. (prog nil
  7. !G67 (cond ((not fmt) (return nil)))
  8. (progn
  9. (setq c (car fmt))
  10. (setq fmt (cdr fmt))
  11. (cond
  12. ((and (equal c '!\) (equal (car fmt) 'n))
  13. (progn (terpri) (setq fmt (cdr fmt))))
  14. ((and (equal c '!\) (equal (car fmt) 'q))
  15. (progn (princ '!") (setq fmt (cdr fmt))))
  16. ((equal c '!%)
  17. (progn
  18. (setq c (car fmt))
  19. (setq fmt (cdr fmt))
  20. (setq a (car args))
  21. (setq args (cdr args))
  22. (cond
  23. ((equal c 'v)
  24. (cond
  25. ((flagp a 'c!:live_across_call)
  26. (progn
  27. (princ "stack[")
  28. (princ (minus (get a 'c!:location)))
  29. (princ "]")))
  30. (t (princ a))))
  31. ((equal c 'a) (prin a))
  32. ((equal c 't) (ttab a))
  33. (t (princ a)))) )
  34. (t (princ c))))
  35. (go !G67))))
  36. (de open_output (name) (open name 'output))
  37. (de s!:cstart (module_name)
  38. (prog (w)
  39. (verbos nil)
  40. (princ "Start of compilation into C for ")
  41. (prin module_name)
  42. (terpri)
  43. (setq w (cons '!" (explodec module_name)))
  44. (setq s!:c_name (compress (append w '(!. c !"))))
  45. (setq s!:lisp_name (compress (append w '(!. l s p !"))))
  46. (setq s!:c_file (open_output s!:c_name))
  47. (setq s!:lisp_file (open_output s!:lisp_name))
  48. (cond ((and s!:c_file s!:lisp_file) (return t)))
  49. (cond (s!:c_file (close s!:c_file)))
  50. (cond (s!:lisp_file (close s!:lisp_file)))
  51. (return nil)))
  52. (de s!:cinit (u)
  53. (prog (o)
  54. (setq o (wrs s!:lisp_file))
  55. (princ "Initform: ")
  56. (prinl u)
  57. (terpri)
  58. (wrs o)))
  59. (de s!:cend nil
  60. (prog nil
  61. (close s!:c_file)
  62. (setq s!:c_file nil)
  63. (close s!:lisp_file)
  64. (setq s!:lisp_file nil)
  65. (return nil)))
  66. (de s!:cgen (name nargs body env)
  67. (prog (w fgg)
  68. (princ "Cgen: ")
  69. (prin name)
  70. (terpri)
  71. (princ "nargs: ")
  72. (prin nargs)
  73. (terpri)
  74. (cond
  75. ((greaterp nargs 10)
  76. (progn
  77. (terpri)
  78. (princ "++++++ Functions with > 10 args or &optional, &rest")
  79. (terpri)
  80. (princ " arge can not be compiled into C")
  81. (terpri)
  82. (return 'failed))))
  83. (prog (l)
  84. (setq l (reverse body))
  85. lab (cond ((null l) (return nil)))
  86. ((lambda (l)
  87. (progn
  88. (prin (car l))
  89. (princ ": ")
  90. (setq w (reverse (cdddr l)))
  91. (cond ((and (not fgg) (greaterp nargs 3)) (setq w (cddr w))))
  92. (setq fgg t)
  93. (prog (x)
  94. (setq x w)
  95. lab (cond ((null x) (return nil)))
  96. ((lambda (x) (progn (princ " ") (prin x))) (car x))
  97. (setq x (cdr x))
  98. (go lab))
  99. (princ " ")
  100. (prin (cadr l))
  101. (terpri)))
  102. (car l))
  103. (setq l (cdr l))
  104. (go lab))))