UNPKG

1.68 kBtext/coffeescriptView Raw
1### clearall =====================================================================
2
3Tags
4----
5scripting, JS, internal, treenode, general concept
6
7
8General description
9-------------------
10
11Completely wipes all variables from the environment.
12
13
14###
15
16
17Eval_clearall = ->
18 do_clearall()
19 push(symbol(NIL))
20
21do_clearall = ->
22 if (test_flag == 0)
23 clear_term()
24
25 do_clearPatterns()
26 clear_symbols()
27 defn()
28 codeGen = false
29
30# clearall from application GUI code
31clearall = ->
32 run("clearall")
33
34# this transformation is done in run.coffee, see there
35# for more info.
36clearRenamedVariablesToAvoidBindingToExternalScope = ->
37 for i in [0...symtab.length]
38 if symtab[i].printname.indexOf("AVOID_BINDING_TO_EXTERNAL_SCOPE_VALUE") != -1
39 # just clear it
40 symtab[i].k = SYM
41 symtab[i].printname = ""
42 binding[i] = symtab[i]
43 isSymbolReclaimable[i] = true
44
45### clear =====================================================================
46
47Tags
48----
49scripting, JS, internal, treenode, general concept
50
51Parameters
52----------
53x
54
55General description
56-------------------
57
58Completely wipes a variable from the environment (while doing x = quote(x) just unassigns it).
59
60###
61
62
63Eval_clear = ->
64 p2 = cdr(p1)
65
66 while (iscons(p2))
67 variableToBeCleared = car(p2)
68 #console.log variableToBeCleared + ""
69
70
71 if (variableToBeCleared.k != SYM)
72 stop("symbol error")
73
74 #console.log "getting binding of " + p.toString()
75 #if p.toString() == "aaa"
76 # debugger
77
78 indexFound = symtab.indexOf(variableToBeCleared)
79 symtab[indexFound].k = SYM
80 symtab[indexFound].printname = ""
81 binding[indexFound] = symtab[indexFound]
82 isSymbolReclaimable[indexFound] = true
83
84
85 p2 = cdr(p2)
86
87 push(symbol(NIL))