GithubHelp home page GithubHelp logo

sh1okoh / 9cc-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petitviolet/9cc-ruby

0.0 0.0 0.0 72 KB

A tiny language compiler written in Ruby

Shell 7.69% Ruby 86.92% Makefile 1.64% Dockerfile 3.76%

9cc-ruby's Introduction

A tiny language compiler written in Ruby

https://www.sigbus.info/compilerbook

What language looks like

See test.sh.

How to run

Docker image for this repository is available on petitviolet:9cc-ruby in docker hub.

# Run all test
$ make docker/test

# Run oneshot test. ARG: [expected program]
$ make docker/try ARG="3 'def add(i, j) { i + j }; add(1, 2)'"
$ make docker/try ARG="3 'def add(i, j) { i + j }; add(1, 2)' -v" # verbose option
$ make docker/try ARG="16 '1 + 2 + 3'"
docker run --rm -v $PWD:/9cc -w /9cc petitviolet/9cc-ruby:latest sh -c "./test.sh 16 '1 + 2 + 3'"
[2020-06-17 12:57:46.045 UTC]NG! 1 + 2 + 3 => 16 expected, but got 6
make: *** [docker/try] Error 1

$ make docker/try ARG="16 '1 + 2 + 3' -v"
docker run --rm -v $PWD:/9cc -w /9cc petitviolet/9cc-ruby:latest sh -c "./test.sh 16 '1 + 2 + 3' -v"
[Token::Num(value: 1),
 Token::Reserved(char: +),
 Token::Num(value: 2),
 Token::Reserved(char: +),
 Token::Num(value: 3),
 Token::Eof]
[[Node::Add(lhs: Node::Add(lhs: Node::Num(value: 1), rhs: Node::Num(value: 2)), rhs: Node::Num(value: 3))]]
==='-v'
.intel_syntax noprefix # headers
.global main
main:
  push r14 # prologue
  push r15
  push rbp
  mov rbp, rsp
  sub rsp, 0 # ^^^ prologue
  # statement: 1 + 2 + 3
  push 1
  push 2
  pop rdi
  pop rax
  add rax, rdi
  push rax
  push 3
  pop rdi
  pop rax
  add rax, rdi
  push rax
  # ^^^ statement: 1 + 2 + 3
  pop rax
  mov rsp, rbp # epilogue
  pop rbp
  pop r15
  pop r14
  ret # ^^^ epilogue
===
[2020-06-17 12:57:51.881 UTC]NG! 1 + 2 + 3 => 16 expected, but got 6
make: *** [docker/try] Error 1

9cc-ruby's People

Contributors

petitviolet avatar

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.