Commit a0409631 authored by Gregory Casamento's avatar Gregory Casamento
Browse files

Add transforms and modify main to pull out uneeded code. Implement Compiler class.

parent 6138a3ff
......@@ -80,6 +80,7 @@
14BECB8C1A4C8DA000C0522A /* ObjCASTTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB8B1A4C8DA000C0522A /* ObjCASTTransform.m */; };
14BECB901A4C8E0000C0522A /* Compiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB8F1A4C8E0000C0522A /* Compiler.m */; };
14BECB931A4C9BD700C0522A /* ASTTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB921A4C9BD700C0522A /* ASTTransform.m */; };
14BECB961A4DBB3800C0522A /* ObjCMainFunctionDeclaration.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB951A4DBB3800C0522A /* ObjCMainFunctionDeclaration.m */; };
14C83C9E1A29809400A10D94 /* Lexer.m in Sources */ = {isa = PBXBuildFile; fileRef = 14C83C931A29809400A10D94 /* Lexer.m */; };
14C83C9F1A29809400A10D94 /* Regex.m in Sources */ = {isa = PBXBuildFile; fileRef = 14C83C951A29809400A10D94 /* Regex.m */; };
/* End PBXBuildFile section */
......@@ -249,6 +250,8 @@
14BECB8F1A4C8E0000C0522A /* Compiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Compiler.m; sourceTree = "<group>"; };
14BECB911A4C9BD700C0522A /* ASTTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTTransform.h; sourceTree = "<group>"; };
14BECB921A4C9BD700C0522A /* ASTTransform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASTTransform.m; sourceTree = "<group>"; };
14BECB941A4DBB3800C0522A /* ObjCMainFunctionDeclaration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCMainFunctionDeclaration.h; sourceTree = "<group>"; };
14BECB951A4DBB3800C0522A /* ObjCMainFunctionDeclaration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjCMainFunctionDeclaration.m; sourceTree = "<group>"; };
14C83C861A29809400A10D94 /* AST.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AST.h; sourceTree = "<group>"; };
14C83C921A29809400A10D94 /* Lexer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Lexer.h; sourceTree = "<group>"; };
14C83C931A29809400A10D94 /* Lexer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Lexer.m; sourceTree = "<group>"; };
......@@ -350,6 +353,8 @@
143C35271A38A52F004DBA61 /* ObjCVariableDeclaration.m */,
143C35281A38A52F004DBA61 /* ObjCWhileStatement.h */,
143C35291A38A52F004DBA61 /* ObjCWhileStatement.m */,
14BECB941A4DBB3800C0522A /* ObjCMainFunctionDeclaration.h */,
14BECB951A4DBB3800C0522A /* ObjCMainFunctionDeclaration.m */,
);
path = ObjC;
sourceTree = "<group>";
......@@ -623,6 +628,7 @@
143C34D61A343DCA004DBA61 /* DictionaryType.m in Sources */,
143C353F1A38A52F004DBA61 /* ObjCPostfixOperator.m in Sources */,
143C34D71A343DCA004DBA61 /* FunctionType.m in Sources */,
14BECB961A4DBB3800C0522A /* ObjCMainFunctionDeclaration.m in Sources */,
143C35421A38A52F004DBA61 /* ObjCStatementNode.m in Sources */,
143C34C21A34051C004DBA61 /* StatementsNode.m in Sources */,
143C34EC1A3852E6004DBA61 /* NSString+Extension.m in Sources */,
......
//
// ObjCMainFunctionDeclaration.h
// phoenix
//
// Created by Gregory Casamento on 12/26/14.
// Copyright (c) 2014 indie. All rights reserved.
//
#import "ObjCFunctionDeclaration.h"
@interface ObjCMainFunctionDeclaration : ObjCFunctionDeclaration
@end
//
// ObjCMainFunctionDeclaration.m
// phoenix
//
// Created by Gregory Casamento on 12/26/14.
// Copyright (c) 2014 indie. All rights reserved.
//
#import "ObjCMainFunctionDeclaration.h"
#import "ObjCParenthesizedExpression.h"
#import "ObjCStatementsNode.h"
@implementation ObjCMainFunctionDeclaration
- (id)initWithBody: (ASTNode *)body
{
// ObjCPar
// ObjCParenthesizedExpression *signature = [[ObjCParenthesizedExpression alloc] initWithExpression:expr];
return [self initWithName:@"main" signature:nil body:body];
}
@end
......@@ -2,6 +2,7 @@
#import "ASTContext.h"
@implementation ObjCStatementsNode
- (NSString *)toCode
{
if (self.firstStatement)
......@@ -39,4 +40,5 @@
return result;
}
@end
......@@ -8,6 +8,7 @@
#import "Compiler.h"
#import "Lexer.h"
#import "ASTContext.h"
#import "AST.h"
#import "bridge.h"
......@@ -23,6 +24,8 @@
prefix = pfx;
[prefix retain];
[ASTNode setPrefix:prefix];
ctx = [[ASTContext alloc] init];
}
return self;
}
......
......@@ -7,7 +7,28 @@
//
#import "ObjCASTTransform.h"
#import "ObjCStatementsNode.h"
#import "ObjCStatementNode.h"
#import "ObjCMainFunctionDeclaration.h"
@implementation ObjCASTTransform
- (ASTNode *)transform
{
[super transform];
ObjCMainFunctionDeclaration *main = [[ObjCMainFunctionDeclaration alloc] init];
ObjCStatementsNode *item = (ObjCStatementsNode *)resultantTree;
// ObjCStatementsNode *item = (ObjCStatementsNode *)[root next];
ObjCStatementsNode *valid = nil;
while ((valid = item) != nil)
{
ObjCStatementNode *current = (ObjCStatementNode *)[valid current];
ASTNode *func = [current statement];
NSLog(@"NODE: %@",func);
item = (ObjCStatementsNode *)[valid next];
}
return resultantTree;
}
@end
......@@ -19,20 +19,12 @@ int main(int argc, const char * argv[]) {
return 0;
}
*/
ctx = [[ASTContext alloc] init];
NSString *fileName = nil;
// fileName = @"/tmp/webkit.swift";
fileName = @"/tmp/hello.swift";
// fileName = [NSString stringWithUTF8String:argv[1]];
NSString *sourceCode = [NSString stringWithContentsOfFile:fileName
encoding:NSUTF8StringEncoding
error:NULL];
NSString *imports = @"import Foundation\nimport AppKit\n";
sourceCode = [imports stringByAppendingString:sourceCode];
Compiler *compiler = [[Compiler alloc] initWithSourceCode:sourceCode
andPrefix:@"ObjC"];
Compiler *compiler = [[Compiler alloc] initWithContentsOfFile:fileName
andPrefix:@"ObjC"];
[compiler compile];
NSString *outputCode = [compiler output];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment