Commit graph

648 commits

Author SHA1 Message Date
joeduffy 11b7880547 Further reshuffle Protobufs; generate JavaScript code
After a bit more thinking, we will create new SDK packages for each
of the languages we wish to support writing resource providers in.
This is where the RPC goo will live, so I have created a new sdk/
directory, moved the Protobuf/gRPC definitions underneath sdk/proto/,
and put the generated code into sdk/go/ and sdk/js/.
2017-02-10 09:28:46 -08:00
joeduffy d67de40cf6 Move Mu library source files underneath src/ directory 2017-02-10 09:10:36 -08:00
joeduffy 0b299f0ae5 Update ec2instance so that it compiles/verifies/evals 2017-02-10 09:10:13 -08:00
joeduffy 6b60852c76 Generate Golang Protobuf/gRPC code
This change moves the RPC definitions to the pkg/murpc package,
underneath the proto folder.  This is to ensure that the resulting
Protobufs get a good package name "murpc" that is unique within the
overall toolchain.  It also includes a `generate.sh` script that
can be used to manually regenerate client/server code.  Finally,
we are actually checking in the generated files underneath pkg/murpc.
2017-02-10 09:08:06 -08:00
joeduffy 20452a99e1 Add Protobuf definitions for resource providers 2017-02-10 08:55:26 -08:00
joeduffy 6e472f8ab4 Colorize Mu output
This change adds colorization to the core Mu tool's output, similar
to what we added to MuJS in
cf6bbd460d.
2017-02-09 17:26:49 -08:00
joeduffy 432b9666fe Add an install script for the AWS library
Eventually this won't be required, but for now, it will simplify
bringing up our first end-to-end working example.
2017-02-09 16:36:53 -08:00
joeduffy c821634761 Restructure the examples
This restructures the examples directory a bit, into three buckets:

* basic/: simplistic examples, like hello world and whatnot.

* conversions/: actual conversions from existing samples (with the source cited).

* scenarios/: more complex examples that demonstrate various features of the system.
2017-02-09 16:07:45 -08:00
joeduffy c333bf6f01 Tag an object moniker TODO with marapongo/mu#76 2017-02-09 16:02:45 -08:00
joeduffy 79f8b1bef7 Implement a DOT graph converter
This change adds a --dot option to the eval command, which will simply
output the MuGL graph using the DOT language.  This allows you to use
tools like Graphviz to inspect the resulting graph, including using the
`dot` command to generate images (like PNGs and whatnot).

For example, the simple MuGL program:

    class C extends mu.Resource {...}
    class B extends mu.Resource {...}
    class A extends mu.Resource {
        private b: B;
        private c: C;
        constructor() {
            this.b = new B();
            this.c = new C();
        }
    }
    let a = new A();

Results in the following DOT file, from `mu eval --dot`:

    strict digraph {
        Resource0 [label="A"];
        Resource0 -> {Resource1 Resource2}
        Resource1 [label="B"];
        Resource2 [label="C"];
    }

Eventually the auto-generated ResourceN identifiers will go away in
favor of using true object monikers (marapongo/mu#76).
2017-02-09 15:56:15 -08:00
joeduffy c26ec0aa65 Parent the predefined Resource class to the mu/resource module 2017-02-09 15:06:02 -08:00
joeduffy c0b0a87b07 Use tokens when printing initialized modules/classes 2017-02-09 15:04:26 -08:00
joeduffy c2897d5b70 Fix HasBaseName's logic 2017-02-09 15:01:23 -08:00
joeduffy 1b2ec4eebd Add some handy logging to graph generation 2017-02-09 15:01:08 -08:00
joeduffy 9fb8819375 Fix a possible nil deref in verbose logging 2017-02-09 14:52:33 -08:00
joeduffy e14ca5f4ff Manually print the stack-trace when --logtostderr is enabled
Glog doesn't actually print out the stack traces for all goroutines,
when --logtostderr is enabled, the same way it normally does.  This
makes debugging more complex in some cases.  So, we'll manually do it.
2017-02-09 14:50:41 -08:00
joeduffy b241ea3795 Fix a few messages (print the token value, not pointer address) 2017-02-09 14:35:45 -08:00
joeduffy eb7bfcf355 Implement new expression evaluation 2017-02-09 14:32:44 -08:00
joeduffy e8f54f3f4d Add a minimal MuJS blueprint example 2017-02-09 13:36:18 -08:00
joeduffy 8485929192 Transform interface heritage clauses
Turns out we hadn't been transforming interface heritage clauses --
extends and implements -- like we were classes.  This change fixes
that.  As a result, we're down to 14 verification errors for AWS.
2017-02-09 13:27:08 -08:00
joeduffy 3eb72b62d5 Introduce an <error> type
This change renames the old Error type to Exception -- more consistent
with our AST, etc. nodes anyway -- and introduces a new Error type ("<error>")
to use when something during typechecking or binding fails.

The old way led to errors like:

    error: MU504: tags.ts:32:18: Symbol 'Tag:push' not found
    error: MU522: tags.ts:32:8: Cannot invoke a non-function; 'any' is not a function

This is because of cascading errors during type-checking; the symbol not found
error means we cannot produce the right type for the function invoke that
consumes it.  But the 'any' part is weird.  Instead, this new change produces:

    error: MU504: tags.ts:32:18: Symbol 'Tag:push' not found
    error: MU522: tags.ts:32:8: Cannot invoke a non-function; '<error>' is not a function

It's slightly better.  And furthermore, it gives us a leg to stand on someday
should we decide to get smarter about detecting cascades and avoiding issuing
the secondary error messages (we can just check for the Error type).
2017-02-09 12:58:34 -08:00
joeduffy 42bdcb7bca Fix an inner break bug
We need to break out of two levels of loops, now that we've added
the outer loop around the possible filename candidates.
2017-02-09 12:53:09 -08:00
joeduffy 3a27a44d2c Strip .js, .d.ts, and .ts module name suffixes 2017-02-09 12:43:32 -08:00
joeduffy 6ad42d9063 Probe for MuPackages in MuJS dependency resolution
This change also accepts MuPackages during MuJS dependency resolution.
The old logic wasn't quite right, because it would skip over MuPackage
files, and keep probing upwards, possibly binding to the wrong, pre-
compilation, Mufile.  Note that we must still probe for both Mupackages
and Mufiles, because of intra-package dependencies.

After this change, the AWS MuPackage is down to 28 verification errors.
2017-02-09 12:35:53 -08:00
joeduffy a91f3e6050 Fix more phasing issues
This change fixes a few more phasing issues in the compiler.  Namely,
it now splits all passes into three distinct phases:

1. Declarations: simply populating names.

2. Definitions: chasing down any references to other names from those
   declared entities.  For instance, base classes, other modules, etc.

3. Bodies: fully type-checking everything else, which will depend
   upon both declarations and definitions being fully present.
2017-02-09 12:24:02 -08:00
joeduffy 9bcfbe859f Dealias symbols when producing tokens 2017-02-09 11:32:33 -08:00
joeduffy 330a6c3d25 Probe for Mupacks, not Mufiles, for dependencies 2017-02-09 11:23:27 -08:00
joeduffy a3e18fb79a Add a basic Mu standard library install script 2017-02-09 11:18:08 -08:00
joeduffy e72cf059fb Fix up dependency probing
This changes a few things with dependency probing:

1) Probe for Mupack files, not Mufiles.

2) Substitute defaults in the PackageURL before probing.

3) Trace the full search paths when an import fails to resolve.
   This will help diagnose dependency resolution issues.
2017-02-09 11:01:02 -08:00
joeduffy be7dcec123 Support sugared "*" semvers
This adds support for sugared "*" semvers, which is a shortcut for
">=0.0.0" (in other words, any version matches).  This is a minor part
of marapongo/mu#18.  I'm just doing it now as a convenience for dev
scenarios, as we start to do real packages and dependencies between them.
2017-02-09 10:48:18 -08:00
joeduffy 37f262e046 Prepare the Mu standard library package
This change:

* Renames the Mu standard library NPM package from "mu" to "@mu/mu".
  This reflects the convention that MuPackages published on NPM will,
  at least initially, be published under the "@mu" scope.  This
  indicates that a package is intended to be consumed by Mu programs.

* Adds an NPM peerDependency on the Mu package from the AWS package.

* Adds a Mu dependency on the Mu package from the AWS MuPackage.
2017-02-09 09:43:18 -08:00
joeduffy 1069372cca Save TypeScript definition files
To prepare a MuPackage for consumption by another MuPackage, we need
to save the definition files output by the TypeScript compiler.  In
theory, we could regenerate these definitions from the MuPackage itself;
in fact, when we tackle cross-language, this will be necessary.  For
now, however, it's much simpler to simply save the definition outputs
alongside the Mupack.json package metadata.

Note that we do not save "code" outputs.  The MuIL format encodes all
computations and so the only thing we need for dependent packages is
the header files to compile against; all "link" and runtime dependencies
are satisfied by the MuIL format and Mu toolchain.
2017-02-09 09:07:10 -08:00
joeduffy aaefbae956 Eliminate json.ts from the Mu standard library
This is a leftover bit of code from a long time ago, and is no longer needed.
2017-02-09 08:44:39 -08:00
joeduffy 26c16474c2 Use tsconfig.json's outDir by default
There are a variety of ways to specify a MuJS output location, including
the command line --out (-o for short) flag.  If that isn't present, we simply
dump the Mupack.json file in the current working directory.  However, in order
to prepare Mupackage files for packaging, distribution, and reuse, we actually
want to store the Mupack.json file alongside all the other package assets (like
TypeScript header files).  So it makes sense to recognize the outDir, if present,
in the tsconfig.json file, and use it as the default if not otherwise specified.
2017-02-09 08:42:49 -08:00
joeduffy 2f968b778c Permit any for object literals
This change permits object literals with the type of `any`; although
they will typically get coerced to record/interface types prior to use,
there is no reason to ban `any`.  In fact, it is the idiomatic way of
encoding "objects as bags of properties" that is common to dynamic
languages like JavaScript, Python, etc.
2017-02-08 17:03:38 -08:00
joeduffy 9de4b7ce5d Fully qualify more tokens
This changes transformIdentifierExpression to call through to the
general purpose function that understands how to transform any Symbol
reference into a fully qualified token suitable for serialization.
2017-02-08 16:49:32 -08:00
joeduffy 75eb10203b Transform null and undefined literals
This change recognizes identifier expressions that mention the null and
undefined constants, transforming them into null literals.  Note that
marapongo/mu#70 tracks mimicking the subtle differences between
undefined and null in ECMAScript.
2017-02-08 16:33:53 -08:00
joeduffy 7f094a3054 Chase exports
This change adds support for loading from export locations.  All we
need to do is keep chasing the referent pointer until we bottom out
on an actual method, property, etc.
2017-02-08 16:19:25 -08:00
joeduffy 914e88672c Omit object expression for module loads
In the event that we're loading a property straight from a module,
we needn't actually load the module at all; instead, we refer to it
using a fully qualified token.
2017-02-08 16:12:18 -08:00
joeduffy 840f0bd05d Transform cross-module references into correct tokens
In many cases, property access expressions interact with types.  For
example, the expression `o.j.bar()` likely accesses variable `o`, then
its property `j`, then `j`'s method `bar`.  In other cases, however,
property access elements are actually modules.  For example, in:

    import * as o from "o";
    o.j.bar();

This change recognizes this situation and emits code correctly.
2017-02-08 16:07:19 -08:00
joeduffy 69b23ca2ea Implement structured token binding
This change fixes a whole host of issues with our current token binding
logic.  There are two primary aspects of this change:

First, the prior token syntax was ambiguous, due to our choice of
delimiter characters.  For instance, "/" could be used both as a module
member delimiter, in addition to being a valid character for sub-modules.
The result is that we could not look at a token and know for certain
which kind it is.  There was also some annoyance with "." being the
delimiter for class members in addition to being the leading character
for special names like ".this", ".super", and ".ctor".  Now, we just use
":" as the delimiter character for everything.  The result is unambiguous.

Second, the simplistic token table lookup really doesn't work.  This is
for three reasons: 1) decorated types like arrays, maps, pointers, and
functions shouldn't need token lookup in the classical sense; 2) largely
because of decorated naming, the mapping of token pieces to symbolic
information isn't straightforward and requires parsing; 3) default modules
need to be expanded and the old method only worked for simple cases and,
in particular, would not work when combined with decorated names.
2017-02-08 14:10:16 -08:00
joeduffy f9c02a12a3 Improve some token-related assertion messages 2017-02-08 10:12:09 -07:00
joeduffy 6e554603b9 Quality property access type tokens 2017-02-08 10:04:36 -07:00
joeduffy 5fb638a9f9 Add some quotes to a few error messages 2017-02-08 09:57:54 -07:00
joeduffy 31ff4e96a6 Add missing ClassMemberToken case 2017-02-08 09:56:10 -07:00
joeduffy 93c6c936c3 Permit nil typemap entries
Previously we asserted that typemap entries are never nil.  It turns
out we represent "void" as the absence of a type in MuIL, and so we need
to permit these for constructors, etc.
2017-02-08 09:53:29 -07:00
joeduffy 130838b1b1 Walk arguments in calls and function invokes 2017-02-08 09:53:00 -07:00
joeduffy 9b773b4e95 Transform super() calls
This change recognizes the special case of a `super` variable load
in the position of a function call.  Left on its own, this yields
unverifiable MuIL, because we attempt to invoke a non-function.
2017-02-08 09:39:41 -07:00
joeduffy 3396163b93 Rename Mu.out.json baselines to Mupack.json
This matches the default file name from the MuJS CLI, which makes
rebaselining ever-so-slightly more convenient.
2017-02-08 09:02:31 -07:00
joeduffy 4b8ac3f4bc Emit fully resolved tokens for intra-module types
This change fixes the type token emission logic in MuJS to emit fully
resolved tokens for intra-module type references.  The prior logic emitted
simple identifiers when type references were contained within a single file.
This hearkens back to the days where we used simple names, coupled with a
lexical symbol table, to resolve such things.

This brings the AWS MuPack verification error count to 57 from 84.
2017-02-08 08:56:39 -07:00