glcase.sl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. % GSN 10-FEB-83 12:56
  2. % Compile code for Case statement.
  3. (DE GLDOCASE (EXPR)
  4. (PROG
  5. (SELECTOR SELECTORTYPE RESULT TMP RESULTTYPE TYPEOK ELSECLAUSE TMPB)
  6. (SETQ TYPEOK T)
  7. (SETQ TMP (GLPUSHEXPR (LIST (CADR EXPR))
  8. NIL CONTEXT T))
  9. (SETQ SELECTOR (CAR TMP))
  10. (SETQ SELECTORTYPE (CADR TMP))
  11. (SETQ EXPR (CDDR EXPR))
  12. % Get rid of of if present
  13. (COND ((MEMQ (CAR EXPR)
  14. '(OF Of of))
  15. (SETQ EXPR (CDR EXPR))))
  16. A
  17. (COND
  18. ((NULL EXPR)
  19. (RETURN (LIST (GLGENCODE (CONS 'SELECTQ
  20. (CONS SELECTOR (ACONC RESULT ELSECLAUSE))))
  21. RESULTTYPE)))
  22. ((MEMQ (CAR EXPR)
  23. '(ELSE Else
  24. else))
  25. (SETQ TMP (GLPROGN (CDR EXPR)
  26. CONTEXT))
  27. (SETQ ELSECLAUSE (COND ((CDAR TMP)
  28. (CONS 'PROGN
  29. (CAR TMP)))
  30. (T (CAAR TMP))))
  31. (SETQ EXPR NIL))
  32. (T
  33. (SETQ TMP (GLPROGN (CDAR EXPR)
  34. CONTEXT))
  35. (SETQ
  36. RESULT
  37. (ACONC RESULT
  38. (CONS (COND
  39. ((ATOM (CAAR EXPR))
  40. (OR (AND (SETQ TMPB (GLSTRPROP SELECTORTYPE
  41. 'VALUES
  42. (CAAR EXPR)
  43. NIL))
  44. (CADR TMPB))
  45. (CAAR EXPR)))
  46. (T (MAPCAR (CAAR EXPR)
  47. (FUNCTION
  48. (LAMBDA (X)
  49. (OR (AND (SETQ TMPB (GLSTRPROP
  50. SELECTORTYPE
  51. 'VALUES
  52. X NIL))
  53. (CADR TMPB))
  54. X))))))
  55. (CAR TMP))))))
  56. % If all the result types are the same, then we know the result of the
  57. % Case statement.
  58. (COND (TYPEOK (COND ((NULL RESULTTYPE)
  59. (SETQ RESULTTYPE (CADR TMP)))
  60. ((EQUAL RESULTTYPE (CADR TMP)))
  61. (T (SETQ TYPEOK NIL)
  62. (SETQ RESULTTYPE NIL)))))
  63. (cond (expr (SETQ EXPR (CDR EXPR)) ))
  64. (GO A)))