-
-
Notifications
You must be signed in to change notification settings - Fork 10
Witx parser extension in generator module #71
Conversation
parent 7f427a8 author Javier Cabrera <javierca@kth.se> 1584053392 +0100 committer Javier Cabrera <javierca@kth.se> 1587397289 +0200 Executing binary files Executing text format Adding tracing support Mappping app args to tracer options Starting parameters parsing Forcing entrypoint function name in the cli app Fixing help messages Renaming to cli Removing PublishModule mixing from cli project Listing available functions if no name is provided Listing available functions if no name is provided Update cli/src/InterpreterApp.scala Co-Authored-By: Lucas Satabin <lucas.satabin@gnieh.org> Improving code Wrapping side-effects Changing s name to main Removing test modules Remove pom settings for cil package Use blocker for readig text files Using the standard `Source` class is not safe, as it executes in the calling execution context. Switching to the fs2 interface makes it more stable and better. Fix examples with new text file reading API Removing unnecessary method in Engine.scala Removing missed printf method Reformating Fix examples with new text file reading API Reformating Fixing examples Fix code issues Sorting cli options Sorting cli options WIP Sorting cli options Successful external jar loading Starting parameters parsing Starting parameters parsing Fix fieldName repetition Fix fieldName repetition Adding WITX parser to create WASI interfaces Removing stdlib module Reformatting Adding snapshopt of WASI as package resource Loading types on demand Traversers for types and interfaces Generating boilerplate from witx Isolating the witx-parser
Refactoring and merging in progress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you are refactoring currently, but still have left some comments :)
|
||
|
||
@module | ||
abstract class Module[@effect F[_]](val mem: Memory[IO])(implicit F: Applicative[F]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory should be on the same type effect F
than the module.
{ | ||
val name = "{{{moduleName}}}" | ||
|
||
def tryToExecute(a: => errnoEnum.Value) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method looks like it's WASI specific (errno and friends), and won't make sense outside of this specific use case. I am not sure it is the appropriate place to have this.
override val basicTypeTraverser = { | ||
case (_, t: BasicType) => | ||
t match { | ||
case BasicType.u8 => s"$mem.readByte(${concatOffsets(offset, prev)}).unsafeRunSync()\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really not a fan of having unsafeRunSync
in our code, because they are only there fo IO
, and the library code should not assume it will be an IO
, but some F
having some typeclass (usually Sync
). The Memory
class has unsafe versions of the read/write operations. If you really need to run without effect type (only there for some internal performance reasons), use them instead of this.
|
||
override val enumTypeTraverser = { | ||
case (_, t: EnumType) => | ||
s"object ${t.tpeName}Enum extends Enumeration { \n\t ${t.names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala standard enums are really not good. Can you use enumeratum instead? It is already a dependency of the core Swam module, so you have it here. You can have a look at how I did it in my WASI branch.
@@ -22,7 +22,7 @@ import cats._ | |||
import java.nio.ByteBuffer | |||
|
|||
/** A memory instance that traces all calls to the underlying memory instance. */ | |||
private[runtime] class TracingMemory[F[_]](inner: Memory[F], tracer: Tracer)(implicit F: MonadError[F, Throwable]) | |||
class TracingMemory[F[_]](val inner: Memory[F], tracer: Tracer)(implicit F: MonadError[F, Throwable]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stay internal. It is an implementation detail.
else // else search in path | ||
System | ||
.getenv("PATH") | ||
.split(":") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will raise a NPE if PATH
is not defined. Prefer using the scala sys.env
map with the appropriate get
method, which returns an Option
.
extends BaseWitxType(name, size, pad) | ||
|
||
object BasicType { | ||
case object u8 extends BasicType("u8", 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the size be 1?
|
||
case class Pointer(tpe: BaseWitxType) extends BaseWitxType("Pointer", 4 * tpe.size) // 8 bytes | ||
|
||
class StructType(override val tpeName: String, val fields: Seq[Field]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AST classes should all be case classes
.
/** | ||
*@author Javier Cabrera-Arteaga on 2020-03-18 | ||
*/ | ||
abstract class BaseWitxType(val tpeName: String, val size: Int = 4, val pad: Int = 0) | ||
|
||
abstract class BasicType(name: String, override val size: Int, override val pad: Int = 0) | ||
extends BaseWitxType(name, size, pad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please don't use abstract classes as AST base classes if they are just interfaces, especially if this is to have default values. Avoid this, prefer:
/** | |
*@author Javier Cabrera-Arteaga on 2020-03-18 | |
*/ | |
abstract class BaseWitxType(val tpeName: String, val size: Int = 4, val pad: Int = 0) | |
abstract class BasicType(name: String, override val size: Int, override val pad: Int = 0) | |
extends BaseWitxType(name, size, pad) | |
sealed trait BaseWitxType { | |
val tpeName: String | |
val size: Int | |
val pad: Int | |
} | |
sealed trait BasicType extends BaseWitxType { | |
val name: String | |
} |
@@ -0,0 +1 @@ | |||
mill generator.run -x True -p wasi -i generator/resources/wasi_witx generator/resources/wasi_witx/wasi_snapshot_preview1.witx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this belongs to the Swam repository.
I think this one became obsolete with the WASI implementation. I will close it now. |
Generates Scala boilerplate from witx module definitions