Skip to content

Commit

Permalink
there you go
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-le committed Aug 10, 2024
1 parent 82b5f36 commit 7bf3016
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile.impls
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ wasm_MODE = wasmtime
# Implementation specific settings
#

IMPLS = ada ada.2 awk bash basic bbc-basic c c.2 chuck clojure coffee common-lisp cpp crystal cs d dart \
IMPLS = ada ada.2 awk bash basic bbc-basic c c.2 cc chuck clojure coffee common-lisp cpp crystal cs d dart \
elisp elixir elm erlang es6 factor fantom fennel forth fsharp go groovy gnu-smalltalk \
guile haskell haxe hy io janet java java-truffle js jq julia kotlin latex3 livescript logo lua make mal \
matlab miniMAL nasm nim objc objpascal ocaml perl perl6 php picolisp pike plpgsql \
Expand Down Expand Up @@ -112,6 +112,7 @@ basic_STEP_TO_PROG = $(basic_STEP_TO_PROG_$(basic_MODE))
bbc-basic_STEP_TO_PROG = impls/bbc-basic/$($(1)).bas
c_STEP_TO_PROG = impls/c/$($(1))
c.2_STEP_TO_PROG = impls/c.2/$($(1))
cc_STEP_TO_PROG = impls/cc/$($(1))
chuck_STEP_TO_PROG = impls/chuck/$($(1)).ck
clojure_STEP_TO_PROG = $(clojure_STEP_TO_PROG_$(clojure_MODE))
coffee_STEP_TO_PROG = impls/coffee/$($(1)).coffee
Expand Down
39 changes: 39 additions & 0 deletions impls/cc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
LD=$(CXX)
DEBUG=-ggdb
CXXFLAGS=-O3 -Wall $(DEBUG) $(INCPATHS) -std=c++11
LDFLAGS=-O3 $(DEBUG) $(LIBPATHS) -L. -lreadline -lhistory

LIBSOURCES=Core.cpp Environment.cpp Reader.cpp ReadLine.cpp String.cpp \
Types.cpp Validation.cpp
LIBOBJS=$(LIBSOURCES:%.cpp=%.o)

MAINS=$(wildcard step*.cc)
TARGETS=$(MAINS:%.cc=%)

.PHONY: all clean

.SUFFIXES: .cc .o

all: $(TARGETS)

dist: mal

mal: stepA_mal
cp $< $@

.deps: *.cc *.h
$(CXX) $(CXXFLAGS) -MM *.cc > .deps

$(TARGETS): %: %.o #libmal.a
$(LD) $^ -o $@ $(LDFLAGS)

libmal.a: $(LIBOBJS)
$(AR) rcs $@ $^

.cc.o:
$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
rm -rf *.o $(TARGETS) libmal.a .deps mal

-include .deps
2 changes: 2 additions & 0 deletions impls/cc/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec $(dirname $0)/${STEP:-stepA_mal} "${@}"
40 changes: 40 additions & 0 deletions impls/cc/step0_repl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <string>

std::string read(std::string input)
{
return input;
}

std::string eval(std::string input)
{
return input;
}

std::string print(std::string input)
{
return input;
}

std::string rep(std::string input)
{
auto read_result = read(input);
auto eval_result = eval(read_result);
auto print_result = print(eval_result);
return print_result;
}

int main(int argc, char *argv[])
{
std::string input;

while (!std::cin.eof())
{
std::cout << "user> ";
std::getline(std::cin, input);
auto rep_result = rep(input);
std::cout << rep_result << std::endl;
}

return 0;
}

0 comments on commit 7bf3016

Please sign in to comment.