Coder Social home page Coder Social logo

spitsh's Introduction

👻 Spook in the Shell 👻 (Spit-sh) Build Status

Spook in the Shell (Spit or Spit-sh) is a language/compiler that outputs shell scripts. It compiles a strongly typed Perl 6 like language called "Spook" into /bin/sh compatible scripts. It's main purpose is devops/infrastructure related tasks. Current features include:

  • Compile time type checking
  • Basic libraries/modules
  • Test module for outputting TAP
  • Useful builtin classes and functions
  • Running and testing scripts in Docker
  • Logging to standard output

Everything about the language and compiler is still experimental. I am thinking about pivoting a bit into compiling golang to create standalone binaries instead of shell scripts. 🤔

Example

To get an idea of what Spit is consider the following basic program:

.install unless Pkg<nc>; # install nc unless it's already there
ok Cmd<nc>,"nc command exists now"; # test the nc command is there

You can compile this for CentOS from the command line like:

spit eval --os=centos  '.install unless Pkg<nc>; ok Cmd<nc>,"nc command exists now"'

Which ouputs the following shell at the time of writing:

BEGIN(){
  e(){ printf %s "$1"; }
  exec 4>/dev/null
  installed(){ yum list installed "$1" >&4 2>&4; }
  install(){ yum install -y $1 >&4 2>&4; }
  exists(){ command -v "$1" >&4; }
  exec 3>&1
  say(){ printf '%s\n' "$1" >&3; }
  note(){ printf '%s\n' "$1" >&2; }
  die(){ note "$1" && kill "-TERM" $$ >&4; }
  ok(){ test "$1" && say "✔ - $2" || die "✘ - $2"; }
}
MAIN(){
  if ! installed nc; then
    install nc
  fi
  ok "$(exists nc && e 1)" 'nc command exists now'
}
BEGIN && MAIN

If you have docker installed you can test this with:

spit eval --in-docker=centos '.install unless Pkg<nc>; ok Cmd<nc>,"nc command exists now"'
✔ - nc command exists now

Unfortunately on Debian the package is named 'netcat'. Let's deal with that:

# install-nc.sp
constant Pkg $nc = on {
    Debian { 'netcat' }
    Any    { 'nc' } # the default
};

.install unless $nc;
ok Cmd<nc>,"nc command exists now";

And now it should work on both the RHEL and Debian families of Linux distributions.

spit  compile install-nc.sp --in-docker=debian:latest
✔ - nc command exists now

Install

Spit is written in Perl 6 and requires rakudo and something to install Perl 6 ecosystem modules with like zef.

zef install Spit

and run

spit eval 'say "hello world"'

To check it's working.

Documentation

The documentation is pretty useless at the moment because the tooling has fallen far behind the language. What exists is under: doc/.

Project Layout

  • The Perl 6 Spit compiler module is in lib
  • The actual Spit source code is under resources/src
  • The core spit modules are under resouces/core-lib
  • The spec tests are in spec.

spitsh's People

Contributors

alexdaniel avatar jnthn avatar lizmat avatar llfourn avatar samcv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spitsh's Issues

Topic not set in if on or junction

if Cmd<echo> || Cmd<printf> {
    .say;
}
ERROR while compiling tmp/bug.sp: Scalar variable '_' hasn't been declared.
tmp/bug.sp:2
if Cmd<echo> || Cmd<printf> {
    ➧.say;
}

Likely bug with anon state var

Haven't run the code and just spotted this while reviewing some ecosystem code.

The {$++}" on this line needs to be changed to $($++)" or to " ~ $++:

name => "eval_{$++}",

With original version, the state var is in its own block, which gets cloned when the outer block is entered, so the var ends up always being set to 1.

m: for ^3 { say "and {++$}"; }
rakudo-moar e9351cbaa: OUTPUT: «and 1␤and 1␤and 1␤»

m: for ^3 { say "and $(++$)"; }
rakudo-moar e9351cbaa: OUTPUT: «and 1␤and 2␤and 3␤»
m: for ^3 { say "and " ~ ++$; }
rakudo-moar e9351cbaa: OUTPUT: «and 1␤and 2␤and 3␤»

.parse-names won't exist in 6.e language

The parse-names is now named uniparse, as of Rakudo version 2017.12-10-ge5c38ad

The original parse-names will continue to work for some time. It will issue a deprecation warning when 6.d language will be released (around first half of 2018) and will be removed entirely in 6.e language.

More info: Raku/doc@bff42f80b1

sub 'if' hasn't been declared

$spit eval 'if Foo { }'
ERROR while compiling eval: Sub 'if' hasn't been declared.
eval:0
➧if Foo { }

(Foo is a non existant symbol). When doing this in rakudo you get:

$ perl6 -e 'if Foo { }'
===SORRY!===
Function 'Foo' needs parens to avoid gobbling block (or perhaps it's a class that's not declared or available in this scope?)
at -e:1
------> if Foo { }⏏<EOL>
Missing block (apparently claimed by 'Foo')
at -e:1
------> if Foo { }⏏<EOL>

trailing comma in routine signature causes parse error

ERROR while compiling file<lib/Rakudo.sp>: Couldn't find closing ‘)’ to finish parameter list.
file<lib/Rakudo.sp>:12
    }

    static method build(
        :$checkout = $:checkout,
        :$prefix = $:prefix,
        :$build-dir = $:build-dir )↩,
    ) {
        Rakudo.install-deps;

Unbitrotting/possible takeover?

Hello,

I came across this project while browsing former conference talks on Perl6/Raku and it really made me interested.

Unfortunately, as suspected, it's kind of in a sleeping state. I think it would be a huge loss of the whole Raku community to let these great projects be lost for good so let me ask: are contributions welcome, or alternatively, are you open to donate the project altogether? I'm willing to start with necessary maintenance work and I also have plans for using this tool so probably I could pick it up the hard way.

I hope we can revive it directly, without starting with a fork - however, if this issue doesn't have a resolution, even a fork might be better than losing all the value.

Exceptions on installation

This is at least since 2020.06 release. The testing goes ok and then:

➜  ~ zef install Spit
===> Searching for: Spit
===> Searching for missing dependencies: DispatchMap, JSON::Tiny
===> Testing: DispatchMap:ver<0.2.3>
===> Testing [OK] for DispatchMap:ver<0.2.3>
===> Testing: JSON::Tiny:ver<1.0>
===> Testing [OK] for JSON::Tiny:ver<1.0>
===> Testing: Spit:ver<0.0.31>
[Spit] precompiling SETTING
===> Testing [OK] for Spit:ver<0.0.31>
===> Installing: DispatchMap:ver<0.2.3>
===> Installing: JSON::Tiny:ver<1.0>
===> Installing: Spit:ver<0.0.31>
===> Install [FAIL] for Spit:ver<0.0.31>: precompiling SETTING
===SORRY!=== Error while compiling /home/koto/site#sources/439BF46620E5A9ABA6750AED8F3C39E466FF18DE (Spit::PRECOMP::SETTING)
An exception occurred while evaluating a constant
at /home/koto/site#sources/439BF46620E5A9ABA6750AED8F3C39E466FF18DE (Spit::PRECOMP::SETTING):7
Exception details:
  ===SORRY!=== Error while compiling
  Not enough positional arguments; needed at least 2
  at :

precompiling SETTING
===SORRY!=== Error while compiling /home/koto/site#sources/439BF46620E5A9ABA6750AED8F3C39E466FF18DE (Spit::PRECOMP::SETTING)
An exception occurred while evaluating a constant
at /home/koto/site#sources/439BF46620E5A9ABA6750AED8F3C39E466FF18DE (Spit::PRECOMP::SETTING):7
Exception details:
  ===SORRY!=== Error while compiling
  Not enough positional arguments; needed at least 2
  at :

➜  ~ raku --version
This is Rakudo version 2020.06 built on MoarVM version 2020.06
implementing Raku 6.d.
'⏎                                                                                                                                                             ➜  ~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.