-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzylogo_Classes.coffee
95 lines (76 loc) · 3.2 KB
/
fizzylogo_Classes.coffee
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class FLClasses extends FLObjects
name: null # a standard JS string
msgPatterns: null # an array of FLLists
methodBodies: null # an array of FLLists
priorities: null # an array of JS Numbers
associativities: null # JS Array
# this is when you create a new class, e.g.
# Number, String, or custom user-made classes.
constructor: (name) ->
super name
@name = name
@flClass = FLClass
@resetInstanceVariables()
# this is useful because then we can compare classes
# (i.e. Number == String)
# using the usual value check
@value = @
if !@isClass()
@name = @constructor.name
@name = @name.substr 2, @name.length - 7
@resetMethods()
# the temp variables contents
# are in the context, not here in the class
# similarly, the instance variables contents
# are in the object, not here in the class
allClasses.push @
rename: (newName) ->
@name = newName
resetMethods: ->
@msgPatterns = []
@methodBodies = []
@priorities = []
@associativities = []
resetInstanceVariables: ->
@instanceVariablesDict = {}
@instanceVariablesDict[ValidIDfromString "class"] = FLClass
# this is when you create a new instance of this class,
# for example a new number or a new string or a new
# object from custom user-made classes.
# as you see, classes are objects.
createNew: (theClass) ->
# turn things like "flNumberClass" into "Number"
#log "class name: " + @name
toBeReturned = new FLObjects theClass
return toBeReturned
addMethod: (signature, methodBody, priority, associativity) ->
#log "adding method " + signature.flToString() + " to: " + @flToString()
#log "sort order: " + signature.sortOrderString()
for i in [0...@msgPatterns.length]
eachSignature = @msgPatterns[i]
#dir eachSignature
if eachSignature.flToString() == signature.flToString()
@msgPatterns[i] = signature
@methodBodies[i] = methodBody
@priorities[i] = priority
@associativities[i] = associativity
if flClassesDebug
log "adding method signature (replacing): " + signature.flToString() + " body: " + methodBody.flToString?()
return
if flClassesDebug
log "adding method signature (appending): " + signature.flToString() + " body: " + methodBody.flToString?()
@msgPatterns.jsArrayPush signature
@methodBodies.jsArrayPush methodBody
@priorities.jsArrayPush priority
@associativities.jsArrayPush associativity
# sort all signatures in order of increasing genericity i.e.
# more generic matches will be done last. See "sortOrderString"
# method for more details.
sortOrderStrings = @msgPatterns.map (elem) -> elem.sortOrderString()
@msgPatterns = sortFirstArrayAccordingToSecond @msgPatterns, sortOrderStrings
@methodBodies = sortFirstArrayAccordingToSecond @methodBodies, sortOrderStrings
@priorities = sortFirstArrayAccordingToSecond @priorities, sortOrderStrings
@associativities = sortFirstArrayAccordingToSecond @associativities, sortOrderStrings
#for i in [0...@msgPatterns.length]
# log "msgPatterns ordered " + sortOrderStrings[i] + " : " + @msgPatterns[i].flToString()
#log "-------------------- "