Commit Graph

13 Commits

Author SHA1 Message Date
16063d50f8 Add a couple of builtin functions, and the Vm::call() method
* Builtin functions print and println have been added
* If a global lookup fails, the VM will attempt to look up a builtin
* Vm::call(fun, args) allows interrupting the current execution state
  and starting a new function instead. It will return the value left on
  top of the stack.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-07 17:21:01 -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
0ca8dc64b2 Remove get_local function from Vm
It does not use the global/local dichotomy and it wasn't being used

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-10-06 15:41:13 -07:00
43c4a9c531 Remove vm::package module, add object attribute shortcut methods
* vm::package is no longer needed since the compiler now creates
  UserFunRef objects
* Reserved object attributes can be accessed using get_* methods, e.g.
  get_plus for ease of use.
* Add some implementations for operator instructions in the VM

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-28 16:48:30 -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
3976b2135a Functions are implemented and VM should be able to handle function calls
* VM Signals are used by running functions to dictate whether a function
  should return, or if it should call another function. These signals
  can be injected at any time allowing for user functions to inject
  themselves at runtime.
* obj::Method is gone since it's not being used yet.
* Obj impls must implement as_any(&self) -> &dyn Any now. This allows
  for UserFun and NativeFun to be explicitly cast (among other things,
  in the future).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-24 15:29:44 -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
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
ef38680fe5 Add Vm::frames(&self) function
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-14 16:37:16 -07:00
fdbb0a1307 Add some base VM implementations
Some instructions are currently implemented. Others are not. This is
mostly just a checkpoint so I can implement lexical name definitions.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-14 16:32:58 -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