URL:
https://svn.lrde.epita.fr/svn/scool/trunk
ChangeLog:
2008-03-01 Maxime van Noppen <yabo(a)lrde.epita.fr>
Migrate from SCOOP to Milena
* Makefile: Remove.
* pp-cxx-ng: New.
* scoolt-ng: New.
* pp-cxx/CxxProgram.str: Remove any.hh and find_exact.hh from generated code.
* pp-cxx/CxxType.str: Fix typo.
* scoolt/Decl.str: Remove the static stuff.
pp-cxx-ng/CxxDecl.meta | 1
pp-cxx-ng/CxxDecl.str | 90 ++++++++++++++++++
pp-cxx-ng/CxxExp.str | 31 ++++++
pp-cxx-ng/CxxFun.meta | 1
pp-cxx-ng/CxxFun.str | 69 +++++++++++++
pp-cxx-ng/CxxId.meta | 1
pp-cxx-ng/CxxId.str | 12 ++
pp-cxx-ng/CxxProgram.meta | 1
pp-cxx-ng/CxxProgram.str | 15 +++
pp-cxx-ng/CxxStm.meta | 1
pp-cxx-ng/CxxStm.str | 8 +
pp-cxx-ng/CxxType.meta | 1
pp-cxx-ng/CxxType.str | 25 +++++
pp-cxx-ng/Makefile.am | 21 ++++
pp-cxx-ng/pp-cxx.meta | 1
pp-cxx-ng/pp-cxx.str | 6 +
pp-cxx/CxxProgram.str | 5 -
pp-cxx/CxxType.str | 2
scoolt-ng/Access.str | 15 +++
scoolt-ng/Decl.str | 229 ++++++++++++++++++++++++++++++++++++++++++++++
scoolt-ng/Exp.str | 21 ++++
scoolt-ng/Makefile.am | 21 ++++
scoolt-ng/Program.str | 8 +
scoolt-ng/Stm.str | 21 ++++
scoolt-ng/Tools.str | 29 +++++
scoolt-ng/Type.str | 32 ++++++
scoolt-ng/scoolt.str | 184 ++++++++++++++++++++++++++++++++++++
scoolt/Decl.str | 39 +++----
28 files changed, 866 insertions(+), 24 deletions(-)
Index: trunk/src/Makefile (deleted)
===================================================================
Index: trunk/src/pp-cxx/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx/CxxProgram.str (revision 49)
+++ trunk/src/pp-cxx/CxxProgram.str (revision 50)
@@ -8,8 +8,9 @@
CxxProgram(l) ->
V vs=1 [
V vs=0 [
- "#include <stc/any.hh>"
- "#include <stc/find_exact.hh>"
+ // FIXME: includes
+ //"#include <stc/any.hh>"
+ //"#include <stc/find_exact.hh>"
]
V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
]
Index: trunk/src/pp-cxx/CxxType.str
===================================================================
--- trunk/src/pp-cxx/CxxType.str (revision 49)
+++ trunk/src/pp-cxx/CxxType.str (revision 50)
@@ -19,7 +19,7 @@
CxxTypeToAbox:
Typename -> S("typename")
- /* These function are actually macros */
+ /* These functions are actually macros */
CxxTypeToAbox:
CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [
~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ]
")"]
Index: trunk/src/pp-cxx-ng/CxxProgram.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxDecl.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxFun.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.str (revision 50)
@@ -0,0 +1,69 @@
+module CxxFun
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxStm CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0
+ [
+ H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ] "(" H hs=1 [
~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args, body) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf] "(" H hs=1 [
~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")"
+ ]
+ V vs=0 is=2
+ [
+ "{"
+ ~*<map(CxxStmToAbox <+ CxxTopLevelToAbox)>body
+ ]
+ "}"
+ ]
+
+ CxxTopLevelToAbox:
+ CxxTypedef(t, idf) ->
+ H hs=0 [ H hs=1 [ "typedef" ~<CxxTypeToAbox> t ~S(idf)] ";" ]
+
+ CxxArgDefToAbox:
+ (t, idf) ->
+ H hs = 1
+ [
+ ~<CxxTypeToAbox>t
+ ~<CxxIdToAbox>idf
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [h|tail] ] ->
+ [
+ H hs=1 [
+ H hs=0 [
+ ~<sub>e
+ ~S(sep)
+ ]
+ ~<CxxListToAbox(sub|sep)> [h|tail]
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [] ] ->
+ [
+ H hs=0 [
+ ~<sub>e
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [] ->
+ [ H [] ]
+
Index: trunk/src/pp-cxx-ng/pp-cxx.str
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.str (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.str (revision 50)
@@ -0,0 +1,6 @@
+module pp-cxx
+
+imports Cxx Box libstratego-lib CxxProgram
+
+strategies
+ pp-cxx = io-wrap(CxxProgramToAbox)
Index: trunk/src/pp-cxx-ng/CxxId.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.str (revision 50)
@@ -0,0 +1,12 @@
+module CxxId
+
+imports Cxx Box libstratego-lib
+
+rules
+
+ CxxIdToAbox:
+ x -> S(x)
+ where not(<?CxxScope(_, _)> x)
+
+ CxxIdToAbox:
+ CxxScope(idf1, idf2) -> H hs=0 [ ~<CxxIdToAbox>idf1 "::"
~<CxxIdToAbox>idf2 ]
Index: trunk/src/pp-cxx-ng/CxxExp.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxExp.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxExp.str (revision 50)
@@ -0,0 +1,31 @@
+module CxxExp
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxExpToAbox:
+ CxxInt(i) -> S(i)
+
+ CxxExpToStr:
+ CxxInt(i) -> i
+
+ CxxExpToStr:
+ CxxSum(e1, e2) -> <concat-strings> [<CxxExpToStr> e1, " + ",
<CxxExpToStr> e2]
+
+ CxxExpToStr:
+ x -> x
+ where <is-string> x
+
+ /*
+ * Handle the CxxKeyword ctor.
+ * TODO: Generalize the type of exp.
+ */
+ CxxExpToAbox:
+ CxxKeyword(idf, exp) -> S(<concat-strings> [idf, " ",
<CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ CxxAffect(idf, exp) -> S(<concat-strings> [idf, " = ",
<CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ x -> S(x)
Index: trunk/src/pp-cxx-ng/CxxType.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxStm.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.str (revision 50)
@@ -0,0 +1,8 @@
+module CxxStm
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxStmToAbox:
+ CxxExpStm(e) -> <CxxExpToAbox> e
Index: trunk/src/pp-cxx-ng/CxxFun.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.str (revision 50)
@@ -0,0 +1,15 @@
+module CxxProgram
+
+imports Cxx Box libstratego-lib CxxDecl CxxFun
+
+rules
+
+ CxxProgramToAbox:
+ CxxProgram(l) ->
+ V vs=1 [
+ V vs=0 [
+ "#include <stc/any.hh>"
+ "#include <stc/find_exact.hh>"
+ ]
+ V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
+ ]
Index: trunk/src/pp-cxx-ng/CxxDecl.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.str (revision 50)
@@ -0,0 +1,90 @@
+module CxxDecl
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ l ->
+ V vs=1 [
+ ~*<map(CxxTopLevelToAbox)>l
+ ]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf
] ";"]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf, v) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t
~<CxxIdToAbox>idf "=" ~<CxxExpToAbox> v] ";"]
+
+ CxxTopLevelToAbox:
+ CxxArrayDecl(t, idf, n) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox> t
~<CxxIdToAbox> idf] "[" ~<CxxExpToAbox> n "]"
";" ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxComment(txt) ->
+ H hs=1 [ "//" ~S(txt) ]
+
+// FIXME: MERGE!!!
+
+ CxxBodyToAbox:
+ CxxPublic(b) -> V is=2 [ "public:" V [ ~*<map(CxxTopLevelToAbox)> b
] ]
+
+ CxxBodyToAbox:
+ CxxProtected(b) -> V is=2 [ "private:" V [
~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxBodyToAbox:
+ CxxPrivate(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)>
b ] ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents, body) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox> idf ]
+ ~<CxxParentsToAbox> parents
+ ]
+ V vs=0 is=2 [ "{" V vs=1 [ ~*<map (CxxBodyToAbox)> body ] ]
+ H hs=0 [ "}" ";" ]
+ ]
+
+ CxxParamsToAbox:
+ [] -> H []
+
+ CxxParamsToAbox:
+ params -> H hs=1 [ "template" "<"
~<CxxListToAbox(CxxParamToAbox|",")> params ">" ]
+ where not(<?[]> params)
+
+ CxxParamToAbox:
+ (t, idf) -> H hs = 1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ]
+
+ CxxParentsToAbox:
+ [] -> H []
+
+ CxxParentsToAbox:
+ parents -> H hs=1 [ ":"
~<CxxListToAbox(CxxParentToAbox|",")>parents ]
+ where not(<?[]> parents)
+
+ CxxParentToAbox:
+ (modifier, t) ->
+ H hs=1 [ ~S(modifier) ~<CxxTypeToAbox>t ]
Index: trunk/src/pp-cxx-ng/pp-cxx.meta
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.meta (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxId.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/Makefile.am
===================================================================
--- trunk/src/pp-cxx-ng/Makefile.am (revision 0)
+++ trunk/src/pp-cxx-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = pp-cxx
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = pp-cxx
+
+nodist_pp_cxx_SOURCES = pp-cxx.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/pp-cxx-ng/CxxType.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.str (revision 50)
@@ -0,0 +1,25 @@
+module CxxType
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxTypeToAbox:
+ CxxType(idf) -> <CxxIdToAbox> idf
+
+ CxxTypeToAbox:
+ CxxRefType(t) -> H hs=0 [ ~<CxxTypeToAbox> t "&" ]
+
+ CxxTypeToAbox:
+ CxxType(idf, params) -> H hs=0 [ ~<CxxIdToAbox> idf "<"
~<CxxListToAbox(CxxTypeToAbox|",")> params ">" ]
+
+ CxxTypeToAbox:
+ CxxConstType(t) -> H [ "const" ~<CxxTypeToAbox> t]
+
+ CxxTypeToAbox:
+ Typename -> S("typename")
+
+ /* These function are actually macros */
+
+ CxxTypeToAbox:
+ CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [
~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ]
")"]
Index: trunk/src/pp-cxx-ng/CxxStm.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/scoolt/Tools.str
===================================================================
Index: trunk/src/scoolt/Decl.str
===================================================================
--- trunk/src/scoolt/Decl.str (revision 49)
+++ trunk/src/scoolt/Decl.str (revision 50)
@@ -79,10 +79,9 @@
ConstDec([], idf, cs, Class) ->
CxxClassDecl(
[(Typename, "T")],
- nidf,
+ idf,
[]
)
- where <conc-strings> (idf, "_") => nidf
/*
* Root Class declaration
@@ -90,23 +89,24 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class, ClassVal(v)) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
- [(Typename, "T")],
- nidf,
+ [(Typename, "E")],
+ idf,
[
- (
+ /*(
"public",
CxxType(CxxScope("stc", "any"),
[CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
- )
+ )*/
+ // FIXME: Add a way to specify if a root class should inherit from Object or not
],
<map (AccessToCxx)> v
//[]
)
]
- where <SclNewIdf>idf => nidf
- ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+ where
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
/*
* Final Class declaration
@@ -114,11 +114,11 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class(p), v) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
params,
- nidf,
+ idf,
[
(
"public",
@@ -132,24 +132,21 @@
; if
(
<one(?"final")> specs
- ; !idf => nidf
- ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
- )
- <+ (
- <SclNewIdf>idf => nidf
- ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf),
CxxType("T")]))>cxxp => parent
+ ; <AddTemplate(|CxxType(idf))> cxxp => parent
)
+ <+
+ <AddTemplate(|CxxType("E"))> cxxp => parent
then
if <one(?"final")> specs then
- rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf,
" is final."])
+ rules(IsFinal: CxxType(idf) -> <concat-strings> [idf, " is
final."])
; ![] => params
else
- rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf,
[T]))
- ; ![(Typename, "T")] => params
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
+ ; ![(Typename, "E")] => params
end
else
say(!<concat-strings> [idf, " cannot inherit from ",
<CxxTypeToIdf> cxxp])
- ; if <CxxTypeToStcError> cxxp => error then
+ ; if <IsFinal> cxxp => error then
say(!error)
else
say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not
exist."])
Index: trunk/src/scoolt-ng/Exp.str
===================================================================
--- trunk/src/scoolt-ng/Exp.str (revision 0)
+++ trunk/src/scoolt-ng/Exp.str (revision 50)
@@ -0,0 +1,21 @@
+module Exp
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ ExpToCxx:
+ Int(i) -> CxxInt(i)
+
+ ExpToCxx:
+ Var(v) -> v
+
+ ExpToCxx:
+ Sum(e1, e2) -> CxxSum(<ExpToCxx> e1, <ExpToCxx> e2)
+
+ ExpToCxx:
+ Affect(Var(v), e) -> CxxAffect(v, <ExpToCxx> e)
+ where <debug> e
+
+ ExpToCxx:
+ Cxx(s) -> s
Index: trunk/src/scoolt-ng/Tools.str
===================================================================
--- trunk/src/scoolt-ng/Tools.str (revision 0)
+++ trunk/src/scoolt-ng/Tools.str (revision 50)
@@ -0,0 +1,29 @@
+module Tools
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ SclNewIdf:
+ idf -> <conc-strings> (idf, "_")
+
+ CxxTypeToIdf:
+ CxxType(idf) -> idf
+ where <is-string> idf
+
+strategies
+
+ NewCount =
+ rules(count_:- _)
+
+ Count =
+ if count_ => res then
+ rules(count_:- _)
+ ; rules(count_: _ -> <sum> (res, 1))
+ else
+ rules(count_: _ -> 1)
+ end
+ ; count_
+
+ GetCount =
+ count_ <+ !0
Index: trunk/src/scoolt-ng/Access.str
===================================================================
--- trunk/src/scoolt-ng/Access.str (revision 0)
+++ trunk/src/scoolt-ng/Access.str (revision 50)
@@ -0,0 +1,15 @@
+module Access
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool
+
+rules
+
+ AccessToCxx:
+ Accessblock(Public, l) -> CxxPublic(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Private, l) -> CxxPrivate(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Protected, l) -> CxxProtected(<map (DeclToCxx)> l)
+
Index: trunk/src/scoolt-ng/Type.str
===================================================================
--- trunk/src/scoolt-ng/Type.str (revision 0)
+++ trunk/src/scoolt-ng/Type.str (revision 50)
@@ -0,0 +1,32 @@
+module Type
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ IsScalar:
+ t -> t
+ where
+ (
+ <eq> (t, "char")
+ <+ <eq> (t, "bool")
+ <+ <eq> (t, "short")
+ <+ <eq> (t, "int")
+ <+ <eq> (t, "float")
+ <+ <eq> (t, "double")
+ )
+
+ TypeToCxx:
+ Var(x) -> CxxType(x)
+
+ TypeToCxx:
+ RefType(t) -> CxxRefType(<TypeToCxx> t)
+
+ // Constify + Referencify a type
+ TypeToConstRefCxx:
+ Var(t) -> CxxConstType(CxxRefType(CxxType(t)))
+ where
+ (
+ <is-string> t
+ ; <not (IsScalar)> t
+ )
Index: trunk/src/scoolt-ng/Makefile.am
===================================================================
--- trunk/src/scoolt-ng/Makefile.am (revision 0)
+++ trunk/src/scoolt-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = scoolt
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0 --asfix
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = scoolt
+
+nodist_scoolt_SOURCES = scoolt.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/scoolt-ng/Stm.str
===================================================================
--- trunk/src/scoolt-ng/Stm.str (revision 0)
+++ trunk/src/scoolt-ng/Stm.str (revision 50)
@@ -0,0 +1,21 @@
+module Stm
+
+imports libstratego-lib Cxx Type Exp AsFix Scool
+
+rules
+
+ StmToCxx:
+ ExpStm(e) -> CxxExpStm(<ExpToCxx> e)
+ where <debug> e
+
+ /* Handle the 'return' statement */
+ StmToCxx:
+ Return(e) -> CxxExpStm(CxxKeyword("return", <ExpToCxx> e))
+
+ StmToCxx:
+ VarDec([], idf, t, i) -> <DeclToCxx> VarDec([], idf, t, i)
+ where <debug> idf
+
+ StmToCxx:
+ x -> <DeclToCxx> x
+ where <debug> x
Index: trunk/src/scoolt-ng/scoolt.str
===================================================================
--- trunk/src/scoolt-ng/scoolt.str (revision 0)
+++ trunk/src/scoolt-ng/scoolt.str (revision 50)
@@ -0,0 +1,184 @@
+module scoolt
+
+imports libstratego-lib Cxx Program AsFix Scool
+
+strategies
+
+ scoolt = io-wrap(ProgramToCxx)
+
+
+
+/*
+ t-Program:
+ Program(l) -> Cxx(<collect-vtypes> l, <map(t-Decl)> l)
+
+
+
+ t-Decl:
+ VarDec(i, t) -> CxxVarDec(<t-Type> t, i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ VarDec(i, t, v) -> CxxVarDec(<t-Type> t, i, <t-Exp> v)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxVarDec(CxxConsType(<t-Type> t), i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t, v) -> CxxVarDec(CxxConsType(<t-Type> t), i, <t-Exp>
v)
+ where not(<?Var("type")> t)
+
+
+
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxEscape(<concat-strings> ["/", "/
virtual typedef /abstract/ ", i, ";"] )
+ where <?Var("type")> t
+
+ t-Decl: // FIXME : vvvvvv
+ ConsDec(_, i, t, Var(v)) -> CxxEscape(<concat-strings> ["/",
"/ virtual typedef ", v, " ", i, ";"] )
+ where <?Var("type")> t
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class, ClassVal(l)) ->
[CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic,
CxxTemplateType(CxxScope("stc", "any"), "E"),
<map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)]
where <conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) ->
[CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic,
CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l),
CxxTypedef(CxxTemplateType(newname, "itself"), name)] where
<conc-strings> (name, "_") => newname;
<not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent)) ->
[CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic,
CxxTemplateType(<t-r-Type> parent, "E"), []),
CxxTypedef(CxxTemplateType(newname, "itself"), name)] where
<conc-strings> (name, "_") => newname;
<not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class) -> [CxxClassDec([CxxTemplateArg("E")],
newname, CxxPublic, CxxTemplateType(CxxScope("stc", "any"),
"E"), []), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where
<conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) ->
[CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic,
CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l),
CxxTypedef(CxxTemplateType(newname, "itself"), name)] where
<conc-strings> (name, "_") => newname
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) ->
+ [CxxClassDec (
+ newname,
+ CxxPublic,
+ CxxTemplateType(<t-r-Type> parent, newname),
+ <map(t-ABlock)> l
+ ),
+ CxxTypedef(newname, name)
+ ]
+ where <conc-strings> (name, "_") => newname;
<one(?"final")> qualifiers
+
+ t-ABlock:
+ Accessblock(acc, decs) -> CxxAccessBlock(<t-ASpecifier> acc,
<map(t-Decl)> decs)
+
+ t-ASpecifier:
+ Public -> CxxPublic
+
+ t-ASpecifier:
+ Private -> CxxPrivate
+
+ t-Decl:
+ FunDec(_, name, args, ret, body) -> CxxFunDec(<t-Type> ret, name,
<map(t-Arg)> args, <map(t-Stm + t-Decl)> body)
+
+
+ t-Decl:
+ BiFunDec(qualifiers, name, s-args, args, rettype, body) ->
+ CxxOverloadingCase( name,
+ CxxInt(index),
+ <t-StaticCond>s-args,
+ <t-Type>rettype,
+ <map(t-Arg)>args,
+ <map(t-Stm + t-Decl)>body
+ )
+ where
+ <one(?"overloading")> qualifiers
+ ; if not(<index-over> name) then
+// say(!"first"); debug
+ !1 => index
+ ; rules(index-over: name -> 2)
+ else
+// say(!"not first"); debug
+ <index-over> name => index
+ ; rules(index-over: name -> <add>(index, 1))
+ end
+
+
+
+ t-Arg:
+ (name, type, guard) -> <t-Arg> (name, type)
+
+ t-Arg:
+ (name, type) -> (<t-Type> type, name)
+
+
+
+ t-Type:
+ Var(n) -> n
+
+ t-r-Type:
+ Var(n) -> <conc-strings> (n, "_")
+
+ t-Exp:
+ Int(n) -> CxxInt(n)
+
+ t-Exp:
+ Mul(e1, e2) -> CxxMul(<t-Exp> e1, <t-Exp> e2)
+
+ t-Exp:
+ Var(n) -> CxxVar(n)
+
+ t-Exp:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-Stm:
+ Return(e) -> CxxReturn(<t-Exp> e)
+
+ t-Decl:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-StaticCond:
+ [] -> CxxStaticTrue
+
+ t-StaticCond:
+ [h|[]] -> <t-StaticCond> h
+
+ t-StaticCond:
+ [h|t] -> CxxStaticAnd(<t-StaticCond> h, <t-StaticCond> t)
+ where not(<?[]>t)
+
+ t-StaticCond:
+ (idf, type, Guard(guard)) -> <t-StaticCond> guard
+
+ t-StaticCond:
+ (idf, type) -> CxxStaticTrue
+
+ t-StaticCond:
+ Eq(e1, e2) -> CxxStaticEq(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Or(e1, e2) -> CxxStaticOr(<t-StaticCond> e1, <t-StaticCond> e2)
+
+ t-StaticCond:
+ Inf(e1, e2) -> CxxStaticIsA(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Var("true") -> CxxStaticTrue
+
+ t-StaticCond:
+ Var("false") -> CxxStaticFalse
+
+
+
+ strategies
+
+ collect-vtypes =
+ collect(?ConsDec(attr, _, Var("type")); where
(<one(?"decl")> attr) )
+ ; map(?ConsDec(_, <id>, _))
+ ; make-set
+
+
+*/
Index: trunk/src/scoolt-ng/Decl.str
===================================================================
--- trunk/src/scoolt-ng/Decl.str (revision 0)
+++ trunk/src/scoolt-ng/Decl.str (revision 50)
@@ -0,0 +1,229 @@
+module Decl
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool Access
+
+rules
+
+ /*
+ * Variable declaration.
+ * Grammar: "var" idf ":" t ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t) -> CxxDecl(<TypeToCxx> t, idf)
+
+ /*
+ * Array declaration.
+ * Grammar: "var" idf ":" "array" "[" t
"," n "]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t, n])) ->
+ <if <eq> ("array", st) then
+ ! CxxArrayDecl(<TypeToCxx> t, idf, <ExpToCxx> n)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Buffer declaration.
+ * Grammar: "var" idf ":" "buffer" "[" t
"]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t])) ->
+ <if <eq> ("buffer", st) then
+ ! CxxDecl(CxxType(CxxScope("std", "vector"), [<TypeToCxx>
t]), idf)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Variable declaration with initialisation.
+ * Grammar: "var" idf ":" t ":=" v ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t, v) -> CxxDecl(<TypeToCxx> t, idf, <ExpToCxx> v)
+
+ UnVar:
+ Var(x) -> x
+
+ /*
+ * Constant declaration.
+ * Grammar: idf ":" t ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, t) ->
+ <if <eq> ("type", <UnVar> t) then
+ ! CxxDecl(<TypeToCxx> t, idf)
+ else
+ ! CxxDecl(CxxConstType(<TypeToCxx> t), idf)
+ end>
+ where not(<?Class> t)
+
+ /*
+ * Constant declaration with initialisation.
+ * Grammar: idf ":" t "=" v ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, t, v) -> CxxDecl(CxxConstType(<TypeToCxx> t), idf,
<ExpToCxx> v)
+ where not(<?Class> t)
+
+ DeclToCxx:
+ ConstDec(["decl"], idf, cs, FunType(args, ret)) -> CxxFun([],
<TypeToCxx> ret, idf, <map (ArgDefToCxx)> args)
+
+ /*
+ * Root Class predeclaration
+ * Grammar: idf ":" "class" ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class) ->
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ []
+ )
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Root Class declaration
+ * Grammar: specs idf ":" "class" "=" "{" v
"}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class, ClassVal(v)) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ [
+ (
+ "public",
+ CxxType(CxxScope("stc", "any"),
[CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
+ )
+ ],
+ <map (AccessToCxx)> v
+ //[]
+ )
+ ]
+ where <SclNewIdf>idf => nidf
+ ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+
+ /*
+ * Final Class declaration
+ * Grammar: final idf ":" "class" "=" "{" v
"}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class(p), v) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ params,
+ nidf,
+ [
+ (
+ "public",
+ parent
+ )
+ ],
+ [] // fixme
+ )
+ ]
+ where <TypeToCxx> p => cxxp
+ ; if
+ (
+ <one(?"final")> specs
+ ; !idf => nidf
+ ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
+ )
+ <+ (
+ <SclNewIdf>idf => nidf
+ ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf),
CxxType("T")]))>cxxp => parent
+ )
+ then
+ if <one(?"final")> specs then
+ rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf,
" is final."])
+ ; ![] => params
+ else
+ rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf,
[T]))
+ ; ![(Typename, "T")] => params
+ end
+ else
+ say(!<concat-strings> [idf, " cannot inherit from ",
<CxxTypeToIdf> cxxp])
+ ; if <CxxTypeToStcError> cxxp => error then
+ say(!error)
+ else
+ say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not
exist."])
+ end
+ end
+
+ /*
+ * Handle class declarations with inheritance
+ * Grammar: idf ":" "class" "<" parent ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class(parent)) -> CxxClassDecl([], idf, [("public",
<TypeToCxx> parent)])
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t
"=" "{" body "}"
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, body) -> CxxFun([], <TypeToCxx> t, idf,
<map(ArgDefToCxx)> args, <map(StmToCxx)> body)
+ //where <debug> body
+ //FunDec([], idf, args, t, body) -> <AddParameters(|<GetCount> 0)>
CxxFun([], <TypeToCxx> t, idf, nargs, <map(StmToCxx)>body)
+ //where <NewCount; map(ArgDefToCxx)>args => nargs
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t
"=>" Exp
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, ExpStm(body)) -> CxxFun([], <TypeToCxx> t, idf,
<map(ArgDefToCxx)> args, [<StmToCxx> Return(body)])
+ //where <debug> body
+
+ DeclToCxx:
+ StaticFunDec(l, idf, params, Class(), body) -> CxxClassDecl(<map
(ParamToCxx)> params, idf, [], <map (AccessToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, body) -> CxxFun(<map (ParamToCxx)> params,
<TypeToCxx> t, idf, <map (ArgDefToCxx)> args, <map (StmToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, ExpStm(body)) -> CxxFun(<map (ParamToCxx)>
params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, [<StmToCxx>
Return(body)])
+
+ ParamToCxx:
+ (idf, Var(t), wclause) ->
+ <if <eq> (t, "type") then
+ ! (CxxType("class"), idf)
+ else
+ ! (CxxType(t), idf)
+ end>
+
+ ArgDefToCxx:
+ (idf, t) -> (<TypeToConstRefCxx <+ TypeToCxx> t, idf)
+ //(idf, t) -> (<TypeToCxx; try(CxxTypeToStc(|CxxType(p-idf)))> t, idf)
+ //where <concat-strings; SclNewIdf> ["T", <Count; int-to-string>
0] => p-idf
+
+ ArgDefToCxx:
+ FunArg(idf, t) -> <ArgDefToCxx> (idf, t)
+
+ AddTypedef(|specs, idf):
+ [x] -> [x, CxxTypedef(CxxType(<SclNewIdf>idf,
[CxxType(CxxScope("stc", "itself"))]), idf)]
+ where <not(one(?"abstract"))> specs
+
+ AddClassComment(|idf):
+ l -> [CxxComment(<concat-strings> ["Class ", idf])|l]
+
+ AddParameters(|n):
+ CxxFun(p, t, idf, args, body) -> CxxFun(<Parameters(|n)> p, t, idf, args,
body)
+ //where <debug> n
+
+ Parameters(|n):
+ l -> <Parameters(|<subt>(n, 1))>[(Typename, idf)|l]
+ where <not(?0)> n
+ ; <concat-strings; SclNewIdf> ["T", <int-to-string> n]
=> idf
+
+ Parameters(|n):
+ l -> l
+ where <?0> n
Index: trunk/src/scoolt-ng/Program.str
===================================================================
--- trunk/src/scoolt-ng/Program.str (revision 0)
+++ trunk/src/scoolt-ng/Program.str (revision 50)
@@ -0,0 +1,8 @@
+module Program
+
+imports libstratego-lib Cxx Decl AsFix Scool
+
+rules
+
+ ProgramToCxx:
+ Program(l) -> CxxProgram(<map(DeclToCxx)> l)
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)