Commit Graph

16 Commits

Author SHA1 Message Date
692bb521ec Run rustfmt
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-20 16:21:50 -07:00
9169f5970e Add IntValue type alias for backend integer values
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-20 13:10:53 -07:00
1d6b2e35bc Fix bug where global names could only be used once in the root scope
Global names previously would only load once, and then not again because
of issues with how the root scope is compiled. This is fixed.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-19 16:57:40 -07:00
902da3f2f3 Add internal error handling to VM, plus function arity
* VM is able to handle basic runtime errors although there is no way to
  catch this in executing code currently
* If a function is called with the wrong number of arguments (arity) it
  will invoke a runtime error.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-13 14:07:22 -07:00
dd7cd04b39 Finish up function call implementation, it appears to be working
Functions are downcasted to a `Fun` trait, which will construct the
appropriate stack frame.

A few other things have been shifted around that affect internal APIs
while things are still under construction.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-07 15:48:24 -07:00
958a6caabb Update how scope rules work, and update implementation
* Currently, scopes are only allowed to look at their locals and the
  globals. Inner functions cannot refer to values in their parent
  functions. This will change eventually.
* Scope lookup is split between globals and locals. Locals are defined
  in a scope if they are explicitly assigned to.
    * i.e. `a = foo` will treat `a` as a local in the current scope if
      it appears anywhere in that scope. This does not extend to
      setattrs; `a.b = foo` will not trigger `a` into being a local var.
* `Package` objects are no longer returned from the compiler - instead,
  a user function is returned.
* Other various changes and renames

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-27 19:33:18 -07:00
4848a342f0 Add function compilation
Functions are compiled in the most naiive way right now. I want to fix
up how scope lookups are done before it becomes too much to update.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-26 18:31:23 -07:00
cb5689c513 Add vm:📦:Package, instruction disassembly
* Code is compiled into a vm:📦:Package which contains the
  executable code, the constants, and the local name mappings.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-18 15:45:54 -07:00
0d6f68216b Rename "Local" to "Name" when referring to variables during compilation
* Variables were previously named "Local"s because they described a
  local variable - however, this is kind of a misnomer because it
  handles globals as well. This has been changed pretty much everywhere
  when appropriate (hopefully).
* Renamed obj/names.rs to obj/reserved.rs, freeing up the "names" module
  for the new Names handle
* Renamed obj/locals.rs to obj/names.rs, see above

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-18 13:57:51 -07:00
534812f54d Add instruction dumper
A vector of instructions and constants can now be decompiled as text on
the terminal to give an idea of what the VM is doing.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-17 13:09:37 -07:00
e72cbe2b8c Base compilation of some kind of file to a list of instructions seems to work(!)
I'm able to compile some basic expressions into instructions using the
`not` binary. Big first step, now we need to introduce branches and
loops to the syntax.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-16 18:01:40 -07:00
61ac00ae39 Remove 'text' member from Compile struct, since we can return file positions instead
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-16 17:36:40 -07:00
099ee5ea0d Add local variable collection to compilation
* Upon entering a new body, the local scope variables are collected.
* VM instruction PushLocal now uses a `Local` value instead of a `Sym`
  value
* Compilation of a new AST body will implicitly create a new scope

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-16 17:27:33 -07:00
582b3a4b73 Add basic blocks and implementation of flattening thunks -> basic blocks
* Basic are a more linear way of representing code. Thunks beget basic
  blocks, which beget vectors of instructions.
* Basic blocks are also being flattened into a vector of instructions
  (hopefully, no tests done yet)
* OH yeah locals can be collected too (but currently are not being
  collected in the compiler, that should come soon)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-16 17:18:31 -07:00
372e58f620 Fold runtime/ crate into this source tree
While I like the idea of having a runtime completely decoupled from the
syntax and compiler, I don't think this is that big of a project for
that to be necessary or even useful yet.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-14 14:14:21 -07:00
8e2cbb10a4 General changes across the runtime crate in support of compile module
* Compile module is able to compile bytecode (or so it seems...)
* Runtime crate has had some new stuff added to it, mostly with objects
  and vtables. Still not 100% on the object method function call story,
  but I guess it'll be tackled when we get there.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-14 14:09:29 -07:00