This commit is contained in:
DieMyst 2023-06-09 10:51:29 +02:00
parent 7410765606
commit c298dc2275
14 changed files with 84 additions and 20 deletions

View File

@ -1,6 +1,6 @@
-Dfile.encoding=UTF8
-Xms1G
-Xmx6G
-Xmx16G
-XX:ReservedCodeCacheSize=500M
-XX:+TieredCompilation
-XX:+UseParallelGC

View File

@ -2,6 +2,7 @@ import {
Aqua,
Call,
Path,
AquaConfig
} from "@fluencelabs/aqua-api/aqua-api.js";
const aquaPath = new Path("test.aqua")
@ -9,8 +10,11 @@ const aquaPath = new Path("test.aqua")
const args = {num: 42}
const call = new Call("getNumber(num)", args, aquaPath)
const inputPath = new Path("test.aqua")
// compile call
const compilationResult = await Aqua.compile(call, [])
const compilationResult = await Aqua.compile(inputPath, [], new AquaConfig("info", [], false, false, "typescript"))
/*
@ -29,4 +33,5 @@ export class CompilationResult {
// get function definition, that describes types of arguments and results of a function
// and AIR script
const {funcDef, script} = compilationResult.functionCall
console.log(compilationResult.generatedSources)

View File

@ -9,13 +9,19 @@
"version": "1.0.0",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/aqua-api": "0.10.4"
"@fluencelabs/aqua-api": "file:/../aqua-api-npm"
}
},
"../aqua-api-npm": {
"version": "0.11.0",
"license": "Apache-2.0",
"devDependencies": {
"@fluencelabs/fluence": "0.28.0"
}
},
"node_modules/@fluencelabs/aqua-api": {
"version": "0.10.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-api/-/aqua-api-0.10.4.tgz",
"integrity": "sha512-mBT/ht0mVcGqBfkrnQw9E/tqIW3RNOCDhNwjra9X5WI/TRlztU3G8Vn/odVn6YTpZWJeDwn1qN1VgLoS3VkASA=="
"resolved": "../aqua-api-npm",
"link": true
}
}
}

View File

@ -10,6 +10,6 @@
"type": "module",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/aqua-api": "0.10.4"
"@fluencelabs/aqua-api": "file:/../aqua-api-npm"
}
}

View File

@ -1,9 +1,7 @@
module Import3 declares *
import "import1"
import "import2"
export foo_bar
use "export.aqua"
func foo_bar() -> string, string:
z <- FooBars.foo()
<- z, FooBars.DECLARE_CONST2
func transitive() -> string, string:
result1 <- runFrom1()
result2 <- runFrom2()
<- result1, result2

View File

@ -0,0 +1,8 @@
import "inside/somelib"
service A(""):
call(s: string) -> string
func runFrom1() -> string:
res <- version()
<- A.call(res)

View File

@ -0,0 +1,5 @@
service Some(""):
callee(s: string) -> string
func version() -> string:
<- Some.callee("11111111")

View File

@ -0,0 +1,8 @@
import "inside/somelib"
service B(""):
bzzzz(s: string) -> string
func runFrom2() -> string:
res <- version()
<- B.bzzzz(res)

View File

@ -0,0 +1,5 @@
service Some(""):
callee(s: string) -> string
func version() -> string:
<- Some.callee("222222222")

View File

@ -24,7 +24,12 @@ object Test extends IOApp.Simple {
_ <- AquaPathCompiler
.compileFilesTo[IO](
Path("./aqua-src/antithesis.aqua"),
List(Path("./aqua")),
List(
Path("./aqua-src/testImport1"),
Path("./aqua-src/testImport2"),
Path("./aqua-src/testImport1/insideLib1"),
Path("./aqua-src/testImport2/insideLib2")
),
Option(Path("./target")),
TypeScriptBackend(false, "IFluenceClient$$"),
TransformConfig(wrapWithXor = false),

View File

@ -67,6 +67,13 @@ class AquaCompiler[F[_]: Monad, E, I: Order, S[_]: Comonad, C: Monoid: Picker](
.mapValues(ctx(_))
.collect { case (fn, Some(fc)) => fn -> fc }
.toMap
println("======================")
println("imports: " + imports)
println("for: " + mod.imports)
println("from: " + mod.id)
println("======================")
val header = mod.body.head
// To manage imports, exports run HeaderHandler
headerHandler

View File

@ -23,6 +23,8 @@ class AquaFileSources[F[_]: AquaIO: Monad: Files: Functor](
) extends AquaSources[F, AquaFileError, FileModuleId] with Logging {
private val filesIO = implicitly[AquaIO[F]]
private val importFromAbs = importFrom.map(_.absolute.normalize)
override def sources: F[ValidatedNec[AquaFileError, Chain[(FileModuleId, String)]]] =
filesIO.listAqua(sourcesPath).flatMap {
case Validated.Valid(files) =>
@ -57,9 +59,15 @@ class AquaFileSources[F[_]: AquaIO: Monad: Files: Functor](
val validatedPath = Validated.fromEither(Try(Path(imp)).toEither.leftMap(FileSystemError.apply))
validatedPath match {
case Validated.Valid(importP) =>
importFromAbs.sortBy { importPath =>
}
println(s"importP: $importP")
println(s"resolveImport from '$from' import '$imp'")
println(s"importFrom: $importFromAbs with ${from.file.parent}")
// if there is no `.aqua` extension, than add it
filesIO
.resolve(importP, importFrom.prependedAll(from.file.parent))
.resolve(importP, importFromAbs.prependedAll(from.file.parent))
.bimap(NonEmptyChain.one, FileModuleId(_))
.value
.map(Validated.fromEither)

View File

@ -32,7 +32,16 @@ object Test extends IOApp.Simple {
case Validated.Invalid(errs) =>
errs.map(System.err.println): Unit
case Validated.Valid(res) =>
res.map(println): Unit
res.foreach {
case (_, a) => a.foreach(_.values.toList.map {
context =>
println("import tokens:")
println(context.importTokens)
println("locations:")
println(context.locations)
})
}
}
_ <- IO.println("Compilation ends in: " + (System.currentTimeMillis() - start) + " ms")
} yield ()

View File

@ -92,7 +92,7 @@ case class RawContext(
)
.map(StructType(name, _))
override def toString: String = s"module: $module\ndeclares: $declares\nexports: $exports"
override def toString: String = s"module: $module, declares: $declares, exports: $exports"
}
object RawContext {