Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

Embed Sinatra #85

Merged
merged 23 commits into from Jun 21, 2019
Merged

Embed Sinatra #85

merged 23 commits into from Jun 21, 2019

Conversation

lopopolo
Copy link
Member

This branch is an ongoing effort to get the following code to parse and return a Rack app:

require 'sinatra/base'

class MyApp < Sinatra::Base
  set :sessions, true
  set :foo, 'bar'

  get '/' do
    'Hello world!'
  end
end

This branch is a top-down approach to implementing core and the standard library in contrast to the bottom up approach I've been taking with Regexp.

The supplied main function in the ditty crate will return MrbError until the code parses and compiles. Address errors as they come up.

Some things I've had to do so far:

  • Import Ruby sources for standard library components from Ruby 2.6.3.
  • Modify Ruby standard library components for the mruby VM (e.g. Thread, Monitor, Mutex).
  • Patch gem sources to work around mruby limitations.

I anticipate needing to implement more of core and standard library in Rust.

@felipecsl
Copy link
Contributor

felipecsl commented May 29, 2019

solid
image

@lopopolo
Copy link
Member Author

uri depends on String#scan, which depends on Regexp#match.

Once I get a working Regexp matcher, I can implement scan in pure Ruby, using a string pointer. Here is the prototype:

https://github.com/lopopolo/ferrocarril/blob/37034d455d75d39eae4be5ffdd458de98713e42b/mruby-sys/vendor/mruby-c078758/mrblib/string.rb#L108-L116

This was referenced May 31, 2019
@lopopolo
Copy link
Member Author

lopopolo commented Jun 1, 2019

GH-89 and GH-92 were extracted from this PR and added Thread, Mutex, and Monitor implementations.

@lopopolo
Copy link
Member Author

As of 6368f9f, Sinatra is able to successfully load the mustermann gem. This requires a stub implementation of StringScanner. Implementing the required methods on StringScanner is tracked in GH-91.

@lopopolo
Copy link
Member Author

As of this most recent push, the ditty crate successfully initializes a Sinatra::Base Rack application and returns a 404 page.

Screen Shot 2019-06-13 at 3 16 08 AM

(Showing the 404 page is a bug, but expected given the amount of stubbing going on.)

@lopopolo
Copy link
Member Author

leak tests fail locally for me but seem to pass in CI. Will dig into this later.

@lopopolo
Copy link
Member Author

Got an echo server running that outputs a JSON response containing the Rack request.

http://localhost:8000/boom succeeds
http://localhost:8000/boom?foo=bar blows up

lopopolo added a commit that referenced this pull request Jun 14, 2019
This commit is in support of GH-85.

Add the following APIs:

- Regexp::escape
- Regexp::union
- Regexp#===
- Regexp#names
- Regexp#named_captures
- Regexp#options
- MatchData#length
- MatchData#named_captures
- String#scan
- String#-@

Added the constants Regexp::IGNORECASE, Regexp::EXTENDED, and
Regexp::MULTILINE.

Regexp#to_s and Regexp#inspect were erroneously implemented with the
same function. Regexp#to_s now supports roundtripping through
Regexp::compile.

Imported escape functionality from Rust regex crate.

Fix null pointer exception in String#=~ when Regexp does not match.

Reimplemented the following String APIs to work with Regexp patterns:

- String#split (TODO: does not handle blocks)
- String#sub
- String#gsub
- String#gsub!
This shouldn't be a 404. I think it has to do with the StringScanner stubs
which are used by Mustermann for route matching.
mruby does not support reraising $! in a rescue block.
Add an echo server that creates a Rack app with Sinatra::Base. The app
outputs a JSON serialized version of the Rack request.

Once support for IO and StringIO (GH-9) is implemented, Hubris will return
information about the request body.

Once digest is implemented Hubris will return a hash of body contents.

Once SecureRandom is implemented, Hubris will return a request UUID.
@lopopolo
Copy link
Member Author

It works!

Screen Shot 2019-06-21 at 3 36 09 PM

@lopopolo lopopolo merged commit 0cc4a8e into master Jun 21, 2019
@lopopolo lopopolo deleted the sinatra branch June 21, 2019 14:40
@lopopolo lopopolo changed the title [WIP] Embed Sinatra Embed Sinatra Jun 21, 2019
lopopolo added a commit to artichoke/artichoke that referenced this pull request Sep 1, 2019
This API and constant were added in artichoke/ferrocarril#85 to load Sinatra and
work around mruby not supporting expressions as default parameters in method argument
lists.

This patch belongs in nemesis instead of artichoke core.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants