* Initial version of pascal-to-javascript converter

git-svn-id: trunk@27474 -
This commit is contained in:
michael 2014-04-05 09:06:05 +00:00
parent ee20ecfcf2
commit 0c50662156
9 changed files with 5614 additions and 0 deletions

8
.gitattributes vendored
View File

@ -6167,6 +6167,14 @@ packages/pasjpeg/src/jquant1.pas svneol=native#text/plain
packages/pasjpeg/src/jquant2.pas svneol=native#text/plain
packages/pasjpeg/src/jutils.pas svneol=native#text/plain
packages/pasjpeg/src/pasjpeg.pas svneol=native#text/plain
packages/pastojs/Makefile svneol=native#text/plain
packages/pastojs/Makefile.fpc svneol=native#text/plain
packages/pastojs/fpmake.pp svneol=native#text/plain
packages/pastojs/src/fppas2js.pp svneol=native#text/plain
packages/pastojs/tests/tcconverter.pp svneol=native#text/plain
packages/pastojs/tests/testpas2js.lpi svneol=native#text/plain
packages/pastojs/tests/testpas2js.pp svneol=native#text/plain
packages/pastojs/todo.txt svneol=native#text/plain
packages/paszlib/Makefile svneol=native#text/plain
packages/paszlib/Makefile.fpc svneol=native#text/plain
packages/paszlib/Makefile.fpc.fpcmake svneol=native#text/plain

2577
packages/pastojs/Makefile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,89 @@
#
# Makefile.fpc for running fpmake
#
[package]
name=pastojs
version=2.7.1
[require]
packages=fcl-js fcl-passrc fpmkunit
[install]
fpcpackage=y
[default]
fpcdir=../..
[prerules]
FPMAKE_BIN_CLEAN=$(wildcard ./fpmake$(SRCEXEEXT))
ifdef OS_TARGET
FPC_TARGETOPT+=--os=$(OS_TARGET)
endif
ifdef CPU_TARGET
FPC_TARGETOPT+=--cpu=$(CPU_TARGET)
endif
LOCALFPMAKE=./fpmake$(SRCEXEEXT)
[rules]
# Do not pass the Makefile's unit and binary target locations. fpmake uses it's own.
override FPCOPT:=$(filter-out -FU%,$(FPCOPT))
override FPCOPT:=$(filter-out -FE%,$(FPCOPT))
# Compose general fpmake-parameters
ifdef FPMAKEOPT
FPMAKE_OPT+=$(FPMAKEOPT)
endif
FPMAKE_OPT+=--localunitdir=../..
FPMAKE_OPT+=--globalunitdir=..
FPMAKE_OPT+=$(FPC_TARGETOPT)
FPMAKE_OPT+=$(addprefix -o ,$(FPCOPT))
FPMAKE_OPT+=--compiler=$(FPC)
FPMAKE_OPT+=-bu
.NOTPARALLEL:
fpmake: fpmake.pp
$(FPCFPMAKE) fpmake.pp $(FPMAKE_SKIP_CONFIG) $(addprefix -Fu,$(COMPILER_FPMAKE_UNITDIR)) $(FPCMAKEOPT) $(OPT)
all: fpmake
$(LOCALFPMAKE) compile $(FPMAKE_OPT)
smart: fpmake
$(LOCALFPMAKE) compile $(FPMAKE_OPT) -o -XX -o -CX
release: fpmake
$(LOCALFPMAKE) compile $(FPMAKE_OPT) -o -dRELEASE
debug: fpmake
$(LOCALFPMAKE) compile $(FPMAKE_OPT) -o -dDEBUG
# If no fpmake exists and (dist)clean is called, do not try to build fpmake, it will
# most often fail because the dependencies are cleared.
# In case of a clean, simply do nothing
ifeq ($(FPMAKE_BIN_CLEAN),)
clean:
else
clean:
$(FPMAKE_BIN_CLEAN) clean $(FPMAKE_OPT)
endif
# In case of a distclean, perform an 'old'-style distclean. This to avoid problems
# when the package is compiled using fpcmake prior to running this clean using fpmake
ifeq ($(FPMAKE_BIN_CLEAN),)
distclean: $(addsuffix _distclean,$(TARGET_DIRS)) fpc_cleanall
else
distclean:
ifdef inUnix
{ $(FPMAKE_BIN_CLEAN) distclean $(FPMAKE_OPT); if [ $$? != "0" ]; then { echo Something wrong with fpmake exectable. Remove the executable and call make recursively to recover.; $(DEL) $(FPMAKE_BIN_CLEAN); $(MAKE) fpc_cleanall; }; fi; }
else
$(FPMAKE_BIN_CLEAN) distclean $(FPMAKE_OPT)
endif
-$(DEL) $(LOCALFPMAKE)
endif
cleanall: distclean
install: fpmake
ifdef UNIXHier
$(LOCALFPMAKE) install $(FPMAKE_OPT) --prefix=$(INSTALL_PREFIX) --baseinstalldir=$(INSTALL_LIBDIR)/fpc/$(FPC_VERSION) --unitinstalldir=$(INSTALL_UNITDIR)
else
$(LOCALFPMAKE) install $(FPMAKE_OPT) --prefix=$(INSTALL_BASEDIR) --unitinstalldir=$(INSTALL_UNITDIR)
endif
# distinstall also installs the example-sources
distinstall: fpmake
ifdef UNIXHier
$(LOCALFPMAKE) install $(FPMAKE_OPT) --prefix=$(INSTALL_PREFIX) --baseinstalldir=$(INSTALL_LIBDIR)/fpc/$(FPC_VERSION) --unitinstalldir=$(INSTALL_UNITDIR) -ie
else
$(LOCALFPMAKE) install $(FPMAKE_OPT) --prefix=$(INSTALL_BASEDIR) --unitinstalldir=$(INSTALL_UNITDIR) -ie
endif

View File

@ -0,0 +1,40 @@
{$ifndef ALLPACKAGES}
{$mode objfpc}{$H+}
program fpmake;
uses fpmkunit;
Var
P : TPackage;
T : TTarget;
begin
With Installer do
begin
{$endif ALLPACKAGES}
P:=AddPackage('pastojs');
{$ifdef ALLPACKAGES}
P.Directory:=ADirectory;
{$endif ALLPACKAGES}
P.Version:='2.7.1';
P.OSes := AllOses;
P.Dependencies.Add('fcl-js');
P.Dependencies.Add('fcl-passrc');
P.Author := 'Free Pascal development team';
P.License := 'LGPL with modification, ';
P.HomepageURL := 'www.freepascal.org';
P.SourcePath.Add('src');
P.SupportBuildModes := [bmOneByOne];
P.Options.Add('-S2h');
T:=P.Targets.AddUnit('fppas2js.pp');
{$ifndef ALLPACKAGES}
Run;
end;
end.
{$endif ALLPACKAGES}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="Pascal to Javascript converter tests"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="FPCUnitConsoleRunner"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
</Item2>
</RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="testpas2js.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="testpas2js"/>
</Unit0>
<Unit1>
<Filename Value="tcconverter.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="tcconverter"/>
</Unit1>
<Unit2>
<Filename Value="../src/fppas2js.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fppas2js"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../src"/>
</SearchPaths>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,39 @@
{
This file is part of the Free Component Library (FCL)
Copyright (c) 2014 by Michael Van Canneyt
Unit tests runner for Pascal-to-Javascript converter class.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
program testpas2js;
{$mode objfpc}{$H+}
uses
Classes, consoletestrunner, tcconverter, fppas2js;
type
TMyTestRunner = class(TTestRunner)
protected
end;
var
Application: TMyTestRunner;
begin
DefaultFormat:=fPlain;
DefaultRunAllTests:=True;
Application := TMyTestRunner.Create(nil);
Application.Initialize;
Application.Title:='Pascal to Javascript converter tests';
Application.Run;
Application.Free;
end.

81
packages/pastojs/todo.txt Normal file
View File

@ -0,0 +1,81 @@
Things that need to be done:
Var Arguments:
Procedure A(var B : integer);
begin
B:=123;
end;
Var
C : Integer;
begin
C:=456;
A(C);
end.
Callee, assume reference (needs examining arguments):
function a(b) {
b.r:=123;
}
Caller side: generate a temp object var
var c = 0;
c=456;
var c$123 = {r : c};
try {
a(c$123);
} finally {
c=c$123.r;
}
Advantage: no transformations needed.
Disadvantage: try/finally needed in case callee (a) throws an exception.
Caller side: allocate variable as object from the very start.
var
c = {r: 0};
c.r=123;
a(c);
Overloads:
----------
Function A(S : String) : String;
Function A(I : Integer) : String;
Add suffix:
function a$1(s) {
}
function a$2(i) {
}
when calling overloaded version, we need to determine which one needs to be
called.
Object model:
-------------
2 Possibilities:
- Use Javascript Objects, java class model using prototype
Disadvantages:
"this" is rather 'confused' in javascript,
use of constructor ?
delegation (procedure of object), event handlers ? (and this!)
- Roll our own in a flat model, explicitly passing self.
TMyClass = Class
Function MyFunction(S : string);
end;
Defines a class. Class is an object
Var TMyClass = {
$_ClassName : "TMyClass",
$_ParentClass : "TObject",
myfunction : function (Self,s) {
}
}
A:=TMyClass.Create()
needs some helper magic:
A:=TMyClass.Create($NewClassInstance(TMyClass))
Disadvantage: not using javascript classes, how to import external javascript objects ?