Commit Graph

53 Commits

Author SHA1 Message Date
3563378db7 Allow dead code in span.rs
There's some API design that I'm happy with so far but gives us some
unused code. I don't want to get rid of it so we'll just allow it for
now.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 16:00:37 -08:00
7414c7df70 WIP: Implement peg parser using pest
PEG parser using pest is implemented. It was able to run the three
examples that we currently have so hopefully there aren't any huge
issues. There's a few warnings remaining that I will squash soon. Token,
parser, and token modules have been removed.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 15:58:10 -08:00
f4699e5e21 WIP: Re-implement parser in pest
Parser implementation is kind of iffy. Let's try to re-implement it
using pest.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 14:50:09 -08:00
abd7f7960a Fix T and F builtins to be values, not functions
* T and F were builtins that were created as functions. They have been
  changed to just be global values instead, so you don't need to suffix
  them with ! to get the creamy value inside.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 11:38:43 -08:00
1f642b9739 Change if function stack ordering, add some basic math ops to Int, add factorial example
* `if` function stack ordering is changed to use condition, if-false,
  if-true (bottom to top). This is so we can pass a value on top of the
  stack directly to a new `if` in a condition, so we don't have to store
  a new value in a new variable.
* Add __splat__ and __minus__ functions to Int
* Add * and - builtins, which call the __splat__ and __minus__ functions
  of the top stack item, respectively.
* Add factorial example because now factorials are possible with this
  skeleton implementation, albeit a little hacky with the recursion.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 11:10:14 -08:00
a8cf2898e1 Add stack printing debug builtin
This function will print the stack without modifying it.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 10:08:42 -08:00
7eb4fa4ef6 Update error message, add Int.__eq__
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-04 19:03:04 -08:00
3b034052e5 Move to VTableBuilder for IntObj VTable, add __splat__ impl
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-04 18:43:55 -08:00
9e5b1b3176 Add VTableBuilder
Experimenting with using a builder instead of a macro for making vtables.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-04 18:40:52 -08:00
cb9e09064a Implement __bool__, add if builtin, vtable imporvements
* `if` builtin is the big one here - branching! Yay!
* The `if` builtin requires __bool__ to be implemented for things. This
  is added for all builtin objects.
* Vtables have slightly better ergonomics.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-04 17:29:41 -08:00
5ec955d544 Add note of defeat re: includes to compile
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-26 17:04:04 -08:00
ec8793a494 Remove Obj::into_gc() and have Obj ctors return a Gc instead
Since we're nightly and using coerce_unsized, we can just coerce a
Gc<T: Obj> into a Gc<dyn Obj> for free.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-25 17:36:07 -08:00
427d354857 Change BoolObj::new to return a Gc pointer, add T and F builtins
Since we're able to coerce objects easily, we're changing bools to be
interned behind the scenes.

T and F builtin functions are added because that's probably the easiest
way to implement true and false constants without making new
lexer/parsing rules.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-25 16:47:19 -08:00
fa0203b441 Add "nightly" feature to gc library, add unsize+coerce_unsized features
We're nightly, babey!!!

This is so we can coerce Gc<T> pointers to Gc<dyn Obj>

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-25 16:40:59 -08:00
d2f041798c Add bool builtin
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 19:43:30 -08:00
7b9539b5e8 Add TODO.md to .gitignore
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 18:43:54 -08:00
5cef5b1d43 Break out obj module into individual files by type
object.rs was getting a little big and the implementations are only
going to get bigger.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 18:35:41 -08:00
95fc8a85df Rename mod object->obj
Also, object.rs got moved to a new directory in preparation for
splitting members out into their own files

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 18:10:21 -08:00
9d5e5f14ca Get rid of file-wide allow(dead_code) in object
Also, squash most of the warnings that came up as a result of this.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 18:03:01 -08:00
44e2442b9c quote.0 -> quote.index()
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 17:55:31 -08:00
ea01f8e191 Remove Rc wrapping of BuiltinFnPtr in BuiltinFn wrapper
I'm trying to remember why this was added in the first place - I think
to simplifly cloning? It's not important now though.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-24 17:53:29 -08:00
070e497e1f Objs replace Values
* Obj is now a trait instead of a struct
* Value enum is gone, replaced with individual structs that implement
  Obj
* All instances where a Value was used, a Gc<(dyn Obj + 'static)> takes
  its place. ObjPtr is shorthand for this.
* A __str__ method for objects is implemented for a couple builtin types
  as a proof-of-concept
* println and print builtin functions are implemented using this
  interface

There's still a lot to do, mostly with interned values. For example,
whenever a new string object is created, a new __str__ function object
is created each time, rather than reusing the first one that was
created. Stuff like that.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-18 14:39:06 -08:00
248dfd3630 Minor cleanup in main()
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-18 14:36:45 -08:00
c57c4f1ab3 Remove lazy_static dependency
I just learned about thread local storage, so we really don't
lazy_static for anything anymore - it was only being used for the lexer
regex.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-18 14:31:32 -08:00
aad0e8adc2 Add new base object stuff, gc dependency
I'm not writing my own GC, it's a huge pain in Rust. I'm using the gc
library instead.

Base object stuff implementation is here too. Hopefully going to start
using ObjPtr instead of Value next.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-17 19:54:19 -08:00
d06e1b82dd Remove max_arena_objects configuration
This isn't something we can't really control so out it goes, I guess.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-17 19:51:19 -08:00
5d30719fa2 Remove Obj and Arena
These weren't being used and they didn't have very good implementations.
Movin' on up

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-17 19:15:22 -08:00
953fe7cb2a Squash some more warnings from unused member in Machine
We're not using objects yet, so the object arena isn't being used.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:53:08 -08:00
280214c799 Remove Thunks for now.
Since we don't do any language-level indirection, thunks are probably
not necessary for now.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:51:55 -08:00
69431c4926 Add vm::builtins mod as a place for builtin functions to live
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:22:02 -08:00
4cf377ff1e Temporarily remove Value::ObjPtr because we aren't using those yet
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:21:28 -08:00
07ce1378cf Add tilde to allowed characters for words
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:19:40 -08:00
399ade6ba0 Fix parser test that was failing because of Span PartialCmp
Span was using the auto-implemented PartialCmp during testing, which was
interfering with the new "source" member, causing test failures.
PartialCmp of a Span during testing is now always true.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 19:16:26 -08:00
b3cf1c5681 Add call site discovery to call frames, and add call stack error messages
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 18:56:33 -08:00
dfac970cc7 Fix a bug with how line/col positions are calculated
Positions were being calculated by looking at the *first* character,
which would cause the same character to be visited twice. Now, if the
character is a null byte (\0), it won't advance the position at all.

The null byte should be a safe sentinel value to use because it
(hypothetically) shouldn't be showing up in a source file. This will
probably cause a hang if a file that starts with null bytes, but that's
a problem for future me.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 18:49:38 -08:00
1eb7eb73cb Remove RuntimeSpanError and just incorporate it into RuntimeError; add Span information to compiled instructions
* RuntimeSpanError was an extraneous solution to adding spans to the
  errors; so instead this behavior has been delegated to the
  RuntimeError itself.
* Usage of Inst has mostly been replaced with SpInst so if an error is
  encountered, we can spit out where it happened in the source code
  (hopefully with a stack trace).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 16:49:54 -08:00
67054b2c84 Update branching example to use new syntax
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 16:49:09 -08:00
9704e07c45 Add call stack error chain
This allows us to write out errors that follow the call stack and give
locations to where errors originated.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 15:25:58 -08:00
2752bdf6d3 Add source string to Span
This is the path to the location that this span is pointing to. This is
usually going to be a file path, but it can really be anything you want.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 14:40:09 -08:00
effa99e65d Add Stmt and incorporate meta statements
This helps split up expressions, meta calls (like includes) that can be
expanded into more expressions.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 14:14:50 -08:00
c3d667ec54 Add .vscode directory to gitignore
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 14:07:26 -08:00
ced903c0c1 Update hello world example to match new syntax
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 14:05:28 -08:00
cc1d55d826 Remove colon token, and update assign atom to use colon instead of equals
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 13:08:23 -08:00
c493ab69bb Add meta token
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-16 12:27:26 -08:00
88080c750b Rename bang->apply
! syntax item has been referred to as "bang" instead of "apply" in some
places, this is fixed

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-12 22:14:54 -08:00
90f27a4108 Add branching and more coherent method of function calls
We're turing-complete, babey!

* Call stack for functions now differentiates between native and quote
  calls
* Better API for builtin functions allowing for more control
* Example showing off branches

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-12 21:49:41 -08:00
c31be8142c Update hello world to use a function
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-12 19:43:29 -08:00
907c8ce1af Move src/syn/word.rs to src/scope.rs; add BuiltinFn
* crate::scope instead of crate::syn::word, which makes more sense
  because scopes are not really used in syntax at all
* Reference-counted BuiltinFn values are available for creation now

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-12 18:00:11 -08:00
1c669decc4 Finally have things printing to the screen
Nothing fancy yet. This commit adds a bunch of stuff (oops):

* compiling code
* VM with instructions
* remove eval.rs and just eval in the Machine struct itself
* squash most warnings now that we're using stuff here

And probably more. But that's all for now folks

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-12 17:35:48 -08:00
a190157eeb Minor cosmetic update to parser.rs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-01-09 18:04:32 -08:00