Skip to content

Commit cdaa8d9

Browse files
Fixed a number of different bugs to do with code geenration. Code generation is mostly functional now with the notable exception of generic methods.
1 parent 9e28c40 commit cdaa8d9

File tree

678 files changed

+689
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

678 files changed

+689
-352
lines changed

Diff for: ArgonWorks.xcodeproj/xcuserdata/vincent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+20-36
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
3131
startingColumnNumber = "9223372036854775807"
3232
endingColumnNumber = "9223372036854775807"
33-
startingLineNumber = "3052"
34-
endingLineNumber = "3052"
33+
startingLineNumber = "3071"
34+
endingLineNumber = "3071"
3535
landmarkName = "parseAssignmentBlock(into:)"
3636
landmarkType = "7">
3737
</BreakpointContent>
@@ -174,8 +174,8 @@
174174
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
175175
startingColumnNumber = "9223372036854775807"
176176
endingColumnNumber = "9223372036854775807"
177-
startingLineNumber = "1472"
178-
endingLineNumber = "1472"
177+
startingLineNumber = "1470"
178+
endingLineNumber = "1470"
179179
landmarkName = "parseType()"
180180
landmarkType = "7">
181181
</BreakpointContent>
@@ -196,22 +196,6 @@
196196
landmarkType = "7">
197197
</BreakpointContent>
198198
</BreakpointProxy>
199-
<BreakpointProxy
200-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
201-
<BreakpointContent
202-
uuid = "EDA7D06D-F3CF-4E00-B1DD-F4BE40A9EEDA"
203-
shouldBeEnabled = "Yes"
204-
ignoreCount = "0"
205-
continueAfterRunningActions = "No"
206-
filePath = "ArgonWorks/Expressions/SlotExpression.swift"
207-
startingColumnNumber = "9223372036854775807"
208-
endingColumnNumber = "9223372036854775807"
209-
startingLineNumber = "103"
210-
endingLineNumber = "103"
211-
landmarkName = "emitCode(into:using:)"
212-
landmarkType = "7">
213-
</BreakpointContent>
214-
</BreakpointProxy>
215199
<BreakpointProxy
216200
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
217201
<BreakpointContent
@@ -254,8 +238,8 @@
254238
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
255239
startingColumnNumber = "9223372036854775807"
256240
endingColumnNumber = "9223372036854775807"
257-
startingLineNumber = "1325"
258-
endingLineNumber = "1325"
241+
startingLineNumber = "1323"
242+
endingLineNumber = "1323"
259243
landmarkName = "parseSuperclassReferences(for:at:with:)"
260244
landmarkType = "7">
261245
</BreakpointContent>
@@ -334,8 +318,8 @@
334318
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
335319
startingColumnNumber = "9223372036854775807"
336320
endingColumnNumber = "9223372036854775807"
337-
startingLineNumber = "836"
338-
endingLineNumber = "836"
321+
startingLineNumber = "834"
322+
endingLineNumber = "834"
339323
landmarkName = "parseImport()"
340324
landmarkType = "7">
341325
</BreakpointContent>
@@ -396,8 +380,8 @@
396380
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
397381
startingColumnNumber = "9223372036854775807"
398382
endingColumnNumber = "9223372036854775807"
399-
startingLineNumber = "715"
400-
endingLineNumber = "715"
383+
startingLineNumber = "713"
384+
endingLineNumber = "713"
401385
landmarkName = "parseOperator(_:)"
402386
landmarkType = "7">
403387
</BreakpointContent>
@@ -437,32 +421,32 @@
437421
<BreakpointProxy
438422
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
439423
<BreakpointContent
440-
uuid = "4F47959A-A313-40EE-995D-30E3B16C6357"
441-
shouldBeEnabled = "Yes"
424+
uuid = "91DCA0D3-55D3-4E82-B087-7989D0F0BC8C"
425+
shouldBeEnabled = "No"
442426
ignoreCount = "0"
443427
continueAfterRunningActions = "No"
444-
filePath = "ArgonWorks/Blocks/LoopBlock.swift"
428+
filePath = "ArgonWorks/Expressions/InvocationExpression.swift"
445429
startingColumnNumber = "9223372036854775807"
446430
endingColumnNumber = "9223372036854775807"
447-
startingLineNumber = "70"
448-
endingLineNumber = "70"
431+
startingLineNumber = "170"
432+
endingLineNumber = "170"
449433
landmarkName = "emitCode(into:using:)"
450434
landmarkType = "7">
451435
</BreakpointContent>
452436
</BreakpointProxy>
453437
<BreakpointProxy
454438
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
455439
<BreakpointContent
456-
uuid = "A1A60E38-C3E9-4E1B-8C30-F6A43ABE2C06"
457-
shouldBeEnabled = "Yes"
440+
uuid = "BD2978EF-C0CA-44CE-A0E9-7F0AE7EFE239"
441+
shouldBeEnabled = "No"
458442
ignoreCount = "0"
459443
continueAfterRunningActions = "No"
460444
filePath = "ArgonWorks/Compiler and Phases/Parser.swift"
461445
startingColumnNumber = "9223372036854775807"
462446
endingColumnNumber = "9223372036854775807"
463-
startingLineNumber = "2976"
464-
endingLineNumber = "2976"
465-
landmarkName = "parseLoopConstraints()"
447+
startingLineNumber = "2545"
448+
endingLineNumber = "2545"
449+
landmarkName = "parseIdentifierTerm()"
466450
landmarkType = "7">
467451
</BreakpointContent>
468452
</BreakpointProxy>

Diff for: ArgonWorks/Blocks/Block.swift

+42-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import Foundation
99

1010
public class Block:NSObject,NamingContext,NSCoding
1111
{
12+
public var enclosingClass: Class?
13+
{
14+
return(self.parent.enclosingClass)
15+
}
16+
1217
public var hasInlineReturnBlock: Bool
1318
{
1419
var aBlock = self.lastBlock
@@ -81,11 +86,6 @@ public class Block:NSObject,NamingContext,NSCoding
8186
fatalError("Attempt to remove a symbol n a block")
8287
}
8388

84-
public var firstInitializer: Initializer?
85-
{
86-
return(self.parent.firstInitializer)
87-
}
88-
8989
public func setSymbol(_ symbol: Symbol,atName: Name)
9090
{
9191
self.parent.setSymbol(symbol,atName: atName)
@@ -235,7 +235,43 @@ public class Block:NSObject,NamingContext,NSCoding
235235

236236
public func lookup(name: Name) -> Symbol?
237237
{
238-
self.parent.lookup(name: name)
238+
if name.isRooted
239+
{
240+
if name.count == 1
241+
{
242+
return(nil)
243+
}
244+
if let start = self.lookup(label: name.first)
245+
{
246+
if name.count == 2
247+
{
248+
return(start)
249+
}
250+
if let symbol = start.lookup(name: name.withoutFirst)
251+
{
252+
return(symbol)
253+
}
254+
}
255+
}
256+
if name.isEmpty
257+
{
258+
return(nil)
259+
}
260+
else if name.count == 1
261+
{
262+
if let symbol = self.lookup(label: name.first)
263+
{
264+
return(symbol)
265+
}
266+
}
267+
else if let start = self.lookup(label: name.first)
268+
{
269+
if let symbol = start.lookup(name: name.withoutFirst)
270+
{
271+
return(symbol)
272+
}
273+
}
274+
return(nil)
239275
}
240276

241277

Diff for: ArgonWorks/Blocks/InitializerBlock.swift

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import Foundation
99

1010
public class InitializerBlock: Block
1111
{
12-
public override var firstInitializer: Initializer?
13-
{
14-
return(self.initializer)
15-
}
16-
1712
private let initializer: Initializer
1813

1914
public init(initializer: Initializer)

Diff for: ArgonWorks/Blocks/LoopBlock.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import Foundation
99

1010
public class LoopBlock: Block
1111
{
12-
private let startExpressions: Array<Expression>
13-
private let endExpression: Expression
14-
private let updateExpressions: Array<Expression>
12+
public var startExpressions: Array<Expression>!
13+
public var endExpression: Expression!
14+
public var updateExpressions: Array<Expression>!
1515

16+
override init()
17+
{
18+
super.init()
19+
}
20+
1621
init(start: Array<Expression>,end: Expression,update: Array<Expression>)
1722
{
1823
self.startExpressions = start
@@ -82,6 +87,6 @@ public class LoopBlock: Block
8287
try expression.emitCode(into: buffer,using: using)
8388
}
8489
try self.endExpression.emitCode(into: buffer,using: using)
85-
buffer.append(nil,"BRF",self.endExpression.place,.none,.label(label))
90+
buffer.append(nil,"BRLT",.none,.none,.label(label))
8691
}
8792
}

Diff for: ArgonWorks/Blocks/SelectBlock.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,16 @@ public class SelectBlock: Block
6565
let endLabel = buffer.nextLabel()
6666
for when in whenBlocks
6767
{
68-
let temp = buffer.nextTemporary()
6968
if aClass.isPrimitiveClass && !aClass.isStringClass
7069
{
71-
buffer.append(nextWhen,"CMPW",self.value.place,when.condition.place,temp)
70+
buffer.append(nextWhen,"CMPW",self.value.place,when.condition.place,.none)
7271
}
7372
else
7473
{
75-
buffer.append(nextWhen,"CMPO",self.value.place,when.condition.place,temp)
74+
buffer.append(nextWhen,"CMPO",self.value.place,when.condition.place,.none)
7675
}
7776
nextWhen = buffer.nextLabel()
78-
buffer.append(nil,"BRNEQ",temp,.none,.label(nextWhen!))
77+
buffer.append(nil,"BRNEQ",.none,.none,.label(nextWhen!))
7978
try when.emitCode(into: buffer,using: generator)
8079
buffer.append(nil,"BR",.none,.none,.label(endLabel))
8180
}

Diff for: ArgonWorks/Code Generation/T3ABuffer.swift

+42-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import Foundation
99

1010
public class T3ABuffer: NSObject,NSCoding,Collection
1111
{
12+
public var hasPendingLabel: Bool
13+
{
14+
self.pendingLabel.isNotNil
15+
}
16+
1217
public var count: Int
1318
{
1419
return(self.instructions.count)
@@ -79,6 +84,10 @@ public class T3ABuffer: NSObject,NSCoding,Collection
7984

8085
public func append(lineNumber: Int)
8186
{
87+
guard self.currentOffset > 0 && !self.instructions[self.currentOffset - 1].operand1.isInteger(lineNumber) else
88+
{
89+
return
90+
}
8291
self.append(nil,"LINE",.literal(.integer(Argon.Integer(lineNumber))),.none,.none)
8392
}
8493

@@ -89,18 +98,45 @@ public class T3ABuffer: NSObject,NSCoding,Collection
8998

9099
public func append(_ label: T3ALabel? = nil,_ opcode: String,_ operand1: T3AInstruction.Operand,_ operand2: T3AInstruction.Operand,_ result: T3AInstruction.Operand)
91100
{
92-
if self.pendingLabel.isNotNil && label.isNotNil
101+
if opcode != "LINE" && opcode != "CMT"
102+
{
103+
if self.pendingLabel.isNotNil && label.isNotNil
104+
{
105+
fatalError("Clash of the labels - pending label is not nil and so is incoming label")
106+
}
107+
else if label.isNotNil
108+
{
109+
self.pendingLabel = label
110+
}
111+
}
112+
var instruction: T3AInstruction
113+
if opcode == "LINE" || opcode == "CMT"
93114
{
94-
fatalError("Clash of the labels - pending label is not nil and so is incoming label")
115+
instruction = T3AInstruction(nil,opcode,operand1,operand2,result)
95116
}
96-
else if label.isNotNil
117+
else
97118
{
98-
self.pendingLabel = label
119+
instruction = T3AInstruction(self.pendingLabel,opcode,operand1,operand2,result)
99120
}
100-
let instruction = T3AInstruction(self.pendingLabel,opcode,operand1,operand2,result)
101121
instruction.offset = currentOffset
102122
self.currentOffset += 1
103123
self.instructions.append(instruction)
104-
self.pendingLabel = nil
124+
if opcode != "LINE" && opcode != "CMT"
125+
{
126+
self.pendingLabel = nil
127+
}
128+
}
129+
130+
public func appendEntry(temporaryCount: Int)
131+
{
132+
self.append("PUSH",.framePointer,.none,.none)
133+
self.append("MOV",.stackPointer,.none,.framePointer)
134+
self.append("SUB",.stackPointer,.literal(.integer(Argon.Integer(8*temporaryCount))),.stackPointer)
135+
}
136+
137+
public func appendExit()
138+
{
139+
self.append("MOV",.framePointer,.stackPointer,.none)
140+
self.append("POP",.framePointer,.none,.none)
105141
}
106142
}

0 commit comments

Comments
 (0)