Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit fb5ad8c
Show file tree
Hide file tree
Showing 78 changed files with 4,741 additions and 0 deletions.
Binary file added 9781430244585.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions Ch02/Ch02.sln
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch02", "Ch02\Ch02.csproj", "{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{225CCADB-3B25-4C8D-9650-8362100C30CB}"
ProjectSection(SolutionItems) = preProject
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Ch02/Ch02/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
58 changes: 58 additions & 0 deletions Ch02/Ch02/Ch02.csproj
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E32B30B-F05C-4ABA-AA90-2EB02682FDF0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ch02</RootNamespace>
<AssemblyName>Ch02</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
92 changes: 92 additions & 0 deletions Ch02/Ch02/Program.cs
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ch02
{
public class CustomEventSource : EventSource
{
public class Keywords
{
public const EventKeywords Loop = (EventKeywords)1;
public const EventKeywords Method = (EventKeywords)2;
}

[Event(1, Level=EventLevel.Verbose, Keywords=Keywords.Loop, Message="Loop {0} iteration {1}")]
public void LoopIteration(string loopTitle, int iteration)
{
WriteEvent(1, loopTitle, iteration);
}
[Event(2, Level=EventLevel.Informational, Keywords=Keywords.Loop, Message="Loop {0} done")]
public void LoopDone(string loopTitle)
{
WriteEvent(2, loopTitle);
}
[Event(3, Level=EventLevel.Informational, Keywords=Keywords.Method, Message="Method {0} done")]
public void MethodDone([CallerMemberName] string methodName = null)
{
WriteEvent(3, methodName);
}
}

class Program
{
private static CustomEventSource log;

static void SomeMethod()
{
for (int i = 0; i < 10; ++i)
{
Thread.Sleep(50);
log.LoopIteration("MainLoop", i);
}
log.LoopDone("MainLoop");
Thread.Sleep(100);
log.MethodDone();
}

static int InstrumentedMethod(int param)
{
List<int> evens = new List<int>();
for (int i = 0; i < param; ++i)
{
if (i % 2 == 0)
evens.Add(i);
}
return evens.Count;
}

static void Main(string[] args)
{
string theLock = "TheLock";
for (int i = 0; i < 10; ++i)
{
int copy = i;
ThreadPool.QueueUserWorkItem(_ =>
{
lock (theLock)
{
Thread.Sleep(100);
Console.WriteLine("Thread pool thread #{0} done", copy);
}
});
}
Console.ReadLine();

Console.WriteLine(InstrumentedMethod(178));

string manifest = EventSource.GenerateManifest(typeof(CustomEventSource), Assembly.GetExecutingAssembly().Location);
File.WriteAllText("Ch02.man", manifest);
Console.ReadLine();
log = new CustomEventSource();
SomeMethod();
}
}
}
36 changes: 36 additions & 0 deletions Ch02/Ch02/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Ch02")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ch02")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("253d2a49-38dc-4490-9d97-8e1b64cd3466")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added Ch02/FileExplorer.exe
Binary file not shown.
Binary file added Ch02/FileExplorer.pdb
Binary file not shown.
38 changes: 38 additions & 0 deletions Ch02/JackCompiler/HelloWorld.jack
@@ -0,0 +1,38 @@
class Main {
function Array initNumbers() {
var Array numbers;
let numbers = Array.new(5);
let numbers[0] = 13;
let numbers[1] = 14;
let numbers[2] = 41;
let numbers[3] = 97;
let numbers[4] = 101;
return numbers;
}
function void main() {
var Array numbers;
var int i, j;
var boolean prime;
let numbers = Main.initNumbers();
let j = 0;
while (j < 5) {
let i = 2;
let prime = true;
while (i < numbers[j] & prime) {
if (numbers[j] % i = 0) {
do System.printInt(numbers[j]);
do System.print(" is composite.");
do System.println();
let prime = false;
}
let i = i + 1;
}
if (prime) {
do System.printInt(numbers[j]);
do System.print(" is prime.");
do System.println();
}
let j = j + 1;
}
}
}
Binary file added Ch02/JackCompiler/JackCompiler.Compiler.dll
Binary file not shown.
Binary file added Ch02/JackCompiler/JackCompiler.Compiler.pdb
Binary file not shown.
Binary file added Ch02/JackCompiler/JackCompiler.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions Ch02/JackCompiler/JackCompiler.exe.config
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
Binary file added Ch02/JackCompiler/JackCompiler.pdb
Binary file not shown.
Binary file added Ch02/JackCompiler/Microsoft.Contracts.dll
Binary file not shown.
51 changes: 51 additions & 0 deletions Ch02/JackCompiler/TestProgram.jack
@@ -0,0 +1,51 @@

class Main {
field int i;
field String j;
static Array k;
field int h;
constructor Main new() {
let i = 5;
return this;
}
method void meth() {
let h = 0;
}
function void main() {
var Array i;
var int j;
var Rational r;
let j = 1;
let i = Main.new();
let i[j] = 5/12*(i[0]-63);
while (i[0] < j) {
let i[0] = i[0] + 1;
}
if (i[0] >= (j + 10)) {
let i[0] = 1;
} else {
let i[0] = 0;
}
let k = 0;
do Memory.free(i);

do System.print("2+3*5 = ");
do System.printInt(2+3*5);
do System.println();

do System.print("Enter a number: ");
let j = System.readInt();
let j = j * j;
do System.println();
do System.print("Your number squared is: ");
do System.printInt(j);
do System.println();

let r = Rational.new(5,j);
do System.print("Is the rational valid? ");
do System.printInt(r.isValid());
do System.println();

return;
}
}
14 changes: 14 additions & 0 deletions Ch02/JackCompiler/TestProgram2.jack
@@ -0,0 +1,14 @@

class Rational {
field int nom;
field int denom;

constructor Rational new(int n, int d) {
let nom = n;
let denom = d;
return this;
}
method boolean isValid() {
return !(denom = 0);
}
}
Binary file added Ch02/JackCompiler_Analyzed.vsps
Binary file not shown.
Binary file added Ch02/MemoryLeak.exe
Binary file not shown.
20 changes: 20 additions & 0 deletions Ch03/Ch03.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ch03", "Ch03\Ch03.csproj", "{D5EDFED7-A732-4BF7-82D1-371AE6511157}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D5EDFED7-A732-4BF7-82D1-371AE6511157}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5EDFED7-A732-4BF7-82D1-371AE6511157}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5EDFED7-A732-4BF7-82D1-371AE6511157}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5EDFED7-A732-4BF7-82D1-371AE6511157}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Ch03/Ch03/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

0 comments on commit fb5ad8c

Please sign in to comment.