summary refs log tree commit diff stats
path: root/compiler/lowerings.nim
blob: 2cf641d9331bab0352504a437f52d09deaf11d25 (plain) (blame)
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
#
#
#           The Nimrod Compiler
#        (c) Copyright 2014 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements common simple lowerings.

const
  genPrefix* = ":tmp"         # prefix for generated names

import ast, types, idents, magicsys

proc newTupleAccess*(tup: PNode, i: int): PNode =
  result = newNodeIT(nkBracketExpr, tup.info, tup.typ.skipTypes(
                     abstractInst).sons[i])
  addSon(result, copyTree(tup))
  var lit = newNodeIT(nkIntLit, tup.info, getSysType(tyInt))
  lit.intVal = i
  addSon(result, lit)

proc addVar*(father, v: PNode) = 
  var vpart = newNodeI(nkIdentDefs, v.info, 3)
  vpart.sons[0] = v
  vpart.sons[1] = ast.emptyNode
  vpart.sons[2] = ast.emptyNode
  addSon(father, vpart)

proc newAsgnStmt(le, ri: PNode): PNode =
  result = newNodeI(nkAsgn, le.info, 2)
  result.sons[0] = le
  result.sons[1] = ri

proc lowerTupleUnpacking*(n: PNode; owner: PSym): PNode =
  assert n.kind == nkVarTuple
  let value = n.lastSon
  result = newNodeI(nkStmtList, n.info)

  var temp = newSym(skTemp, getIdent(genPrefix), owner, value.info)
  temp.typ = skipTypes(value.typ, abstractInst)
  incl(temp.flags, sfFromGeneric)

  var v = newNodeI(nkVarSection, value.info)
  v.addVar(newSymNode(temp))
  result.add(v)
  
  result.add newAsgnStmt(newSymNode(temp), value)
  for i in 0 .. n.len-3:
    result.add newAsgnStmt(n.sons[i], newTupleAccess(value, i))
ef='#n74'>74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116




                                                                          
                        












                                      
                                    



                                    

                               

                        
                         




                                   
                     
                           

                       
                         
                         


                               

                                
                                

                                        




                              

                         






                                    
                                    
         
                     
                            
         
                     

                            

                     

                            























                                      
                                                        




                                                                  
                                      

                                            








                                           
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tower</title>
    <style>
        body {
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #f0f0f0;
        }
        .game-container {
            position: relative;
            display: flex;
            gap: 20px;
            align-items: flex-start;
        }
        #gameCanvas {
            border: 2px solid #333;
            background-color: white;
            position: relative;
            flex-shrink: 0;
        }
        .tower-palette {
            width: 160px;
            background: white;
            border: 2px solid #333;
            padding: 10px;
            display: flex;
            flex-direction: column;
            gap: 5px;
            flex-shrink: 0;
        }
        .tower-option {
            width: 140px;
            height: 75px;
            cursor: grab;
            position: relative;
            display: flex;
            flex-direction: row;
            gap: 10px;
            align-items: center;
            justify-content: flex-start;
            padding: 5px;
        }
        .tower-option:active {
            cursor: grabbing;
        }
        .tower-preview {
            width: 25px;
            height: 25px;
            flex-shrink: 0;
        }
        .tower-info {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            gap: 2px;
            font-family: sans-serif;
        }
        .tower-name {
            font-size: 16px;
        }
        .tower-cost {
            font-size: 12px;
            color: #000000;
        }
        .tower-ammo {
            font-size: 12px;
            color: #000000;
        }
        .start-button {
            margin-top: 20px;
            padding: 10px;
            background-color: #2ecc71;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
        }
        .start-button:hover {
            background-color: #27ae60;
        }
        .start-button:disabled {
            background-color: #95a5a6;
            cursor: not-allowed;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <div class="tower-palette">
            <!-- Tower options populated dynamically -->
        </div>
        <canvas id="gameCanvas" width="600" height="600"></canvas>
    </div>
    
    <!-- Core game modules -->
    <script src="js/path.js"></script>
    <script src="js/mechanics.js"></script>
    <script src="js/uiHandlers.js"></script>
    
    <!-- Rendering modules -->
    <script src="js/renderer.js"></script>
    
    <!-- Game state and main loop -->
    <script src="js/gameState.js"></script>
    <script src="js/game.js"></script>
</body>
</html>