Commit graph

140 commits

Author SHA1 Message Date
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
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
9bcfbe859f Dealias symbols when producing tokens 2017-02-09 11:32:33 -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
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
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
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
6e554603b9 Quality property access type tokens 2017-02-08 10:04:36 -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
joeduffy
c76201d751 Add a newline to the end of serialized MuJS MuPackages 2017-02-08 08:55:26 -07:00
joeduffy
4b56cc61f2 Fix the -o alias so it correctly maps to --out 2017-02-08 08:24:38 -07:00
joeduffy
ca313f10d5 Emit proper TypeToken AST nodes 2017-02-03 21:03:34 -08:00
joeduffy
4cb66fc520 Implement extends/implements heritage clauses 2017-02-03 20:57:35 -08:00
joeduffy
8254a7977c Fix a lint error that crept in: missing semicolon 2017-02-03 20:20:43 -08:00
joeduffy
c3f4f0ad0d Propagate source location for this and super 2017-02-03 20:20:22 -08:00
joeduffy
a1c94275e0 Restructure format/output selection a bit
This change restructures how MuJS selects the format and output a
bit, so that simply running `mujs -f yaml` will output a default
`Mupack.yaml` in the current directory.
2017-02-03 14:56:36 -08:00
joeduffy
21aa240eca Save MuJS output to Mupack.json by default
This change stops printing the AST to output after compilation.  It's
a little confusing and, especially as Mu test programs are getting larger,
staring at 1,000s of lines of JSON whiz by is losing it's fun.

By default, the compiler saves output into Mupack.json.  This can be
overridden with the --out switch (-o for short).  Both JSON and YAML files
are supported (as are unrecognized extensions, which get JSON by default).
Another switch --format (-f for short) is supported to explicitly specify
the output format.  A special -out of "-" means "print to stdoutput", so
for instance, running `mujs -o=- -f=yaml` will print YAML to the console.
2017-02-03 12:41:10 -08:00
joeduffy
7854e0d393 Merge branch 'master' of github.com:marapongo/mu 2017-02-03 12:09:56 -08:00
joeduffy
6e0d17c47c Don't attempt to transform if there were errors
This change doesn't attempt to transform the resulting AST if there
were any compiler errors.  The old code erroneously proceeded in cases
where errors occurred but an AST was actually produced, leading to
possible assertions and other unexpected conditions.
2017-02-03 12:08:41 -08:00
Luke Hoban
464bd4fe28 Simple EC2 instance example 2017-02-02 22:03:12 -08:00
joeduffy
cf6bbd460d Colorize MuJS errors/warnings
I've had a few times where I missed errors/warnings whizzing by alongside
other spew.  Although this was probably technically a "waste" of 10 minutes,
it actually would have saved me at least 10 in the past.  So, there you go.
2017-02-02 16:47:45 -08:00
joeduffy
5492ccba7c Add map tests
This adds map tests for ES6-style maps encoded in MuPack/MuIL.

It also fixes one simple bug, where we should not populate the
compiler options with TypeScript defaults *unless* they are (a)
missing from the arguments and (b) not discovered from a tsconfig
file.  Otherwise, we will rewrite overrides with the defaults.
2017-02-02 14:57:37 -08:00
joeduffy
f84d9341dd Add a clean target
This change just adds a clean target to the MuJS compiler's package
file.  If you rename tests, the old files stick around inside of bin/,
possibly causing superfluous test failures.  A clean does the trick.
2017-02-02 14:30:28 -08:00
joeduffy
69465b55a9 Generate correct array type tokens
This change adds support for generating array type tokens from MuJS.
Previously, we'd try to load up the Array type's associate MuPackage,
which is TypeScript's standard library; and then we'd error out
because, of course, it doesn't have one.  Now we recognize references
to it (and ES6-style Map<K, V>) to generate the correct tokens.

This includes a bunch of new array tests.
2017-02-02 14:28:05 -08:00
joeduffy
e1f3c5ce0e Rebaseline some tests after fixing tslint errors 2017-02-02 12:29:36 -08:00
joeduffy
6a4e7fe37b Emit proper type tokens for object and array literals 2017-02-02 12:27:59 -08:00
joeduffy
6fe7d77bd7 Fix test globbing
To prevent shell expansion of the glob "**", we must quote the path.
This fixes a bug that @lukehoban ran into last night on Windows, where
globbing wasn't be expanded the same way; ironically, it seems to have
been expanded the way we actually wanted it to...but obviously we want
globbing to work well on *NIX filesystems even moreso than Windows.

This also fies a couple missed lint errors in our tests that are
revealed as a result.
2017-02-02 11:33:30 -08:00
joeduffy
6065d2dc26 Update some READMEs from last night
This change updates the READMEs based on some difficulties we had
getting Kurt and Luke's enlistments up and running last night.
2017-02-02 11:09:33 -08:00
joeduffy
87506c37c2 Bind constructor types correctly
This change stops digging into the "new" expression and instead uses
the TypeScript-assigned type (based on its bound signature).  The result
is that expressions of the form

    import * as aws from "aws";
    let vm = new aws.ec2.VM(...);

now typecheck and emit fully resolved type tokens for the constructed types.
2017-02-01 23:20:53 -08:00
joeduffy
1481b993fa Only print the MuJS AST if no errors occurred 2017-02-01 22:37:29 -08:00
joeduffy
c8d6444fb6 Use os.EOL in place of "\n"s 2017-02-01 22:13:55 -08:00
joeduffy
b5a18d45ea Update nodets dependency to use published NPM module 2017-02-01 20:29:36 -08:00
joeduffy
1c6126c807 Eliminate Typings from postinstall script 2017-02-01 20:19:46 -08:00
joeduffy
3c28cebd26 Emit good tokens
This overhauls how MuJS creates and emits tokens, so that they are
properly fully qualified.  Before this change, we frequently emitted
"naked" identifier names that, though the compiler had already resolved
and bound them, looked to the MuIL toolchain as though they hadn't been.

This required rearranging the "symbols" (now "tokens") layer to look more
like the types in the MuIL toolchain.

More impactfully, however, it means we need to load MuIL packages from
dependencies as part of creating the fully resolved tokens.  This injects
I/O into places it didn't exist before, so a large part of this change is
simply playing the async/await whack-a-mole game.

This is one big step along the path of fixing marapongo/mu#46.  It
still isn't 100% because we need to emit array/property symbols correctly,
and also I suspect as we do more multi-module testing, a few other things
will crop up.  But we're almost there.
2017-01-30 13:00:53 -08:00
joeduffy
69b19332d6 Run parameter initializers in the right order 2017-01-30 09:48:50 -08:00
joeduffy
548bc86ef1 Add marapongo/mu#62 to lambda todos 2017-01-28 14:40:26 -08:00
joeduffy
34aefc8c72 Add instructions for building and testing MuJS 2017-01-26 13:39:33 -08:00
joeduffy
529381ce12 Emit tokens, not identifiers, in LoadLocationExpression nodes 2017-01-26 09:52:35 -08:00
joeduffy
281805311c Perform package and module evaluation
This change looks up the main module from a package, and that module's
entrypoint, when performing evaluation.  In any case, the arguments are
validated and bound to the resulting function's parameters.
2017-01-25 18:38:53 -08:00
joeduffy
5bdb535c54 Begin doing evaluation
This change checks in an enormously rudimentary interpreter.  There is
a lot left to do, as evidenced by the countless TODOs scattered throughout
pkg/compiler/eval/eval.go.  Nevertheless, the scaffolding and some important
pieces are included in this change.

In particular, to evaluate a package, we must locate its entrypoint and then,
using the results of binding, systematically walk the full AST.  As we do
so, we will assert that aspects of the AST match the expected shape,
including symbols and their types, and produce value objects for expressions.

An *unwind structure is used for returns, throws, breaks, and continues (both
labeled and unlabeled).  Each statement or expression visitation may optionally
return one and its presence indicates that control flow transfer is occurring.
The visitation logic then needs to propagate this; usually just by bailing out
of the current context immediately, but sometimes -- as is the case with
TryCatchBlock statements, for instance -- the unwind is manipulated in more
"interesting" ways.

An *Object structure is used for expressions yielding values.  This is a
"runtime object" in our system and is comprised of three things: 1) a Type
(essentially its v-table), 2) an optional data pointer (for tagged primitives),
and 3) an optional bag of properties (for complex object property values).
I am still on the fence about whether to unify the data representations.

The hokiest aspect of this change is the scoping and value management.  I am
trying to avoid needing to implement any sort of "garbage collection", which
means our bag-of-values approach will not work.  Instead, we will need to
arrange for scopes to be erected and discarded in the correct order during
evaluation.  I will probably tackle that next, along with fleshing out the
many missing statement and expression cases (...and tests, of course).
2017-01-25 10:13:06 -08:00
joeduffy
d56f640d5f Bind object initializers 2017-01-23 12:51:13 -08:00
joeduffy
a7ccc1b052 Add optional properties 2017-01-23 11:14:24 -08:00
joeduffy
7c5241978e Perform member lookup and binding 2017-01-22 09:45:58 -08:00