commit inicial

This commit is contained in:
Pedro de Oliveira 2010-06-04 00:23:50 +01:00
commit 2e74636062
11 changed files with 601 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# Mac OS X Finder and whatnot
.DS_Store
# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
# Generated files
VersionX-revision.h
# build products
build/
*.[oa]
# Other source repository archive directories (protects when importing)
.hg
.svn
CVS
# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/

18
BrainFuck.h Normal file
View File

@ -0,0 +1,18 @@
/* BrainFuck */
#import <Cocoa/Cocoa.h>
@interface BrainFuck : NSObject
{
IBOutlet NSTextView *inputCode;
IBOutlet NSTableView *memoryDisplay;
IBOutlet NSTextView *outputText;
int space[32768];
//int memory[32768];
NSMutableArray *myMemory;
int pc; // Program Counter
}
- (IBAction)run:(id)sender;
- (void)limpaMemoria;
@end

181
BrainFuck.m Normal file
View File

@ -0,0 +1,181 @@
#import "BrainFuck.h"
// Makes an NSArray work as an NSTableDataSource.
@implementation NSMutableArray (NSTableDataSource)
// just returns the item for the right row
- (id)tableView:(NSTableView *) aTableView
objectValueForTableColumn:(NSTableColumn *) aTableColumn
row:(int) rowIndex
{
NSString *returnValue;
if ([[aTableColumn identifier] isEqualToString:@"1"])
returnValue = [NSString stringWithFormat:@"%i", [NSNumber numberWithInt:rowIndex]];
//returnValue = [NSNumber numberWithInt:rowIndex];
if ([[aTableColumn identifier] isEqualToString:@"2"])
returnValue = [self objectAtIndex:rowIndex];
if ([[aTableColumn identifier] isEqualToString:@"3"])
{
NSNumber *valor = [self objectAtIndex:rowIndex];
unichar c = [valor intValue];
NSString *str = [NSString stringWithCharacters: &c length:1];
returnValue = str;
}
return returnValue;
}
// just returns the number of items we have.
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [self count];
}
@end
@implementation BrainFuck
- (void)awakeFromNib
{
pc = 0;
myMemory = [[NSMutableArray alloc] initWithCapacity:32768];
[self limpaMemoria];
// Liga o myMemory ao memoryDisplay
[memoryDisplay setDataSource: myMemory];
}
- (void)limpaMemoria
{
int i;
[myMemory removeAllObjects];
for(i=0; i < 32768; i++)
{
[myMemory addObject:[NSNumber numberWithInt:0]];
//space[i] = 0;
}
[memoryDisplay reloadData];
}
- (IBAction)run:(id)sender
{
[self limpaMemoria];
int spointer = 1,mpointer;
int i,len,kl;
NSString *codigo = [[inputCode textStorage] string];
NSMutableString *curChar;
for(i = 0; i < [codigo length]; i++) {
//NSLog(@"%c", [codigo characterAtIndex:i]);
space[spointer] = [codigo characterAtIndex:i];
spointer++;
}
len = spointer;
spointer = 0;
mpointer = 0;
for (spointer = 0; spointer < len; spointer++)
{
curChar = @"";
NSNumber *memPos = [myMemory objectAtIndex:mpointer];
unichar c = [memPos intValue];
NSString *str;
NSAttributedString *string;
NSTextStorage *storage;
//NSLog(@"#%i - '%c', MemPos: %i, MemVal: %d", spointer, space[spointer], mpointer, [memPos intValue]);
switch(space[spointer])
{
/* Increment pointer value */
case '+':
[myMemory replaceObjectAtIndex:mpointer withObject:
[NSNumber numberWithInt:[memPos intValue]+1]];
//memory[mpointer]++;
break;
/* Decrement pointer value */
case '-':
[myMemory replaceObjectAtIndex:mpointer withObject:
[NSNumber numberWithInt:[memPos intValue]-1]];
//memory[mpointer]--;
break;
/* Increment pointer */
case '>':
mpointer++;
break;
/* Decrement pointer */
case '<':
mpointer--;
break;
/* Print current pointer value */
case '.':
/*
curChar = [NSMutableString stringWithFormat:@"%c",[memPos charValue]];
NSLog(@"BENFICA: %S\n",curChar);
outputT = [outputText stringValue];
outputT = [NSMutableString stringWithFormat:@"%s%s",outputT,curChar];
[outputText setStringValue:curChar];
//[this stringWithFormat:@"%c" , [memPos charValue]];
NSLog(@"\nViva o MEU BENFICA: %@\n",curChar);
//[outputText insertText:curChar];
//[outputText setNeedsDisplay:YES];
//[outputText displayIfNeeded];
*/
//NSNumber *valor = [self objectAtIndex:rowIndex];
str = [NSString stringWithCharacters: &c length:1];
string = [[NSAttributedString alloc] initWithString:str];
storage = [outputText textStorage];
[storage beginEditing];
[storage appendAttributedString:string];
[storage endEditing];
//putchar(memory[mpointer]);
break;
/* Read value and store in current pointer */
case ',':
//memory[mpointer] = getchar();
break;
/* Start loop */
case '[':
//if (memory[mpointer] == 0) {
if ([memPos intValue] == 0)
{
/* Find matching ] */
spointer++;
/* If kl == 0 and space[pointer] == ']' we found
* the matching brace */
while (kl > 0 || space[spointer] != ']')
{
if (space[spointer] == '[') kl++;
if (space[spointer] == ']') kl--;
/* Go in right direction */
spointer++;
}
}
break;
/* End loop */
case ']':
//if (memory[mpointer] != 0) {
if ([memPos intValue] != 0)
{
/* Find matching [ */
spointer--;
while (kl > 0 || space[spointer] != '[')
{
if (space[spointer] == '[') kl--;
if (space[spointer] == ']') kl++;
/* Go left */
spointer--;
}
spointer--;
}
break;
}
[memoryDisplay selectRow: mpointer byExtendingSelection: NO];
[memoryDisplay reloadData];
}
}
@end

View File

@ -0,0 +1,275 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 42;
objects = {
/* Begin PBXBuildFile section */
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
C0E62A4C1183FEE0007F9E37 /* BrainFuck.m in Sources */ = {isa = PBXBuildFile; fileRef = C0E62A4B1183FEE0007F9E37 /* BrainFuck.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* BrainFucker_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrainFucker_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* BrainFucker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BrainFucker.app; sourceTree = BUILT_PRODUCTS_DIR; };
C0E62A4A1183FEE0007F9E37 /* BrainFuck.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = BrainFuck.h; sourceTree = "<group>"; };
C0E62A4B1183FEE0007F9E37 /* BrainFuck.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = BrainFuck.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8D11072E0486CEB800E47090 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
C0E62A4A1183FEE0007F9E37 /* BrainFuck.h */,
C0E62A4B1183FEE0007F9E37 /* BrainFuck.m */,
);
name = Classes;
sourceTree = "<group>";
};
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
};
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
isa = PBXGroup;
children = (
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8D1107320486CEB800E47090 /* BrainFucker.app */,
);
name = Products;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* BrainFucker */ = {
isa = PBXGroup;
children = (
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
name = BrainFucker;
sourceTree = "<group>";
};
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
32CA4F630368D1EE00C91783 /* BrainFucker_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
);
name = "Other Sources";
sourceTree = "<group>";
};
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
8D1107310486CEB800E47090 /* Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
);
name = Resources;
sourceTree = "<group>";
};
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8D1107260486CEB800E47090 /* BrainFucker */ = {
isa = PBXNativeTarget;
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "BrainFucker" */;
buildPhases = (
8D1107290486CEB800E47090 /* Resources */,
8D11072C0486CEB800E47090 /* Sources */,
8D11072E0486CEB800E47090 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = BrainFucker;
productInstallPath = "$(HOME)/Applications";
productName = BrainFucker;
productReference = 8D1107320486CEB800E47090 /* BrainFucker.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "BrainFucker" */;
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* BrainFucker */;
projectDirPath = "";
targets = (
8D1107260486CEB800E47090 /* BrainFucker */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8D1107290486CEB800E47090 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8D11072C0486CEB800E47090 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
C0E62A4C1183FEE0007F9E37 /* BrainFuck.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C165DFE840E0CC02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = {
isa = PBXVariantGroup;
children = (
29B97319FDCFA39411CA2CEA /* English */,
);
name = MainMenu.nib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = BrainFucker;
WRAPPER_EXTENSION = app;
ZERO_LINK = YES;
};
name = Debug;
};
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = BrainFucker;
WRAPPER_EXTENSION = app;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "BrainFucker" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4B08A954540054247B /* Debug */,
C01FCF4C08A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "BrainFucker" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}

7
BrainFucker_Prefix.pch Normal file
View File

@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'BrainFucker' target in the 'BrainFucker' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif

Binary file not shown.

17
English.lproj/MainMenu.nib/classes.nib generated Normal file
View File

@ -0,0 +1,17 @@
{
IBClasses = (
{
ACTIONS = {run = id; };
CLASS = BrainFuck;
LANGUAGE = ObjC;
OUTLETS = {
inputCode = NSTextView;
memoryDisplay = NSTableView;
outputText = NSTextView;
};
SUPERCLASS = NSObject;
},
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
);
IBVersion = 1;
}

25
English.lproj/MainMenu.nib/info.nib generated Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>177 125 387 306 0 0 1024 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>213</key>
<string>398 302 228 418 0 0 1024 746 </string>
<key>29</key>
<string>68 251 338 44 0 0 1024 746 </string>
</dict>
<key>IBFramework Version</key>
<string>489.0</string>
<key>IBOpenObjects</key>
<array>
<integer>213</integer>
<integer>21</integer>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>8S165</string>
</dict>
</plist>

Binary file not shown.

30
Info.plist Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.BrainFucker</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

14
main.m Normal file
View File

@ -0,0 +1,14 @@
//
// main.m
// BrainFucker
//
// Created by Pedro de Oliveira on 10/04/24.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}