Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CUB] Mikhail Rodionychev A08 #1405

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ocaml/opam:ubuntu-lts-ocaml-4.14

USER root
RUN dpkg --add-architecture i386 && \
apt-get update --fix-missing -y && \
apt-get install -y software-properties-common gcc-multilib make m4 && \
rm -rf /var/lib/apt/lists/*

USER opam
RUN opam init --disable-sandboxing -y && \
opam pin add -y ostap 0.5 && \
opam pin add -y Lama https://github.com/JetBrains-Research/Lama.git\#1.20
84 changes: 57 additions & 27 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,74 @@
name: Regression

on: # [push]
on:
pull_request:
# pull_request_target:
types: [synchronize, opened, reopened, edited]

jobs:
job1:
runs-on: ubuntu-latest
# Map a step output to a job output
steps:
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- uses: actions/checkout@v2
with:
ref: refs/pull/${{ github.event.pull_request.number }}/head
- id: step1
- name: Check pull request's name
run: |
prName="${{ github.event.pull_request.title }}"
university=`echo $prName | awk '{ sub(/.*\[/, ""); sub(/\].*/, ""); print }'`
universities=("SPBGU" "NUP" "CUB")
if [[ ! $(echo ${universities[@]} | grep -F -w $university) ]];
then
echo "FIASCO: Wrong university name or format in pull request title: $university "
exit 1
fi
echo "your university $university "
echo $university > university.txt
- name: Check branches compatibility
run: |
login=${{ github.event.pull_request.user.login }}
echo "$login"
if [ "${{ github.base_ref }}" != "${{ github.head_ref }}" ]; then
echo "FIASCO: base and head branches differs"
exit 1
fi
wget -c --retry-connrefused --tries=0 -q --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet -c --retry-connrefused --tries=0 --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1grnb60AaZBCwhBqETeKOGh3tW7ggEWDJ' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1grnb60AaZBCwhBqETeKOGh3tW7ggEWDJ" -O cw-20201.tar.gz && rm -rf /tmp/cookies.txt
rm -rf /tmp/cookies.txt
docker load < cw-20201.tar.gz
docker run -d -it --name cw-2021 -v $(pwd):/usr/share/compiler-workout berezun/cw-2021
docker exec -t cw-2021 sh test.sh
echo "All checks have successfully passed"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker cache
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./.github/workflows/Dockerfile
tags: berezun/lama-image:latest
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Store Docker cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Run tests
run: |
docker run -d -it --name lama-testing-image berezun/lama-image
docker cp . lama-testing-image:/home/opam/lama
docker exec -u root -t lama-testing-image chown -R opam:opam /home/opam/lama
docker exec -u opam -w /home/opam/lama -t lama-testing-image sh -c 'eval $(opam config env) && make'
echo "Regression: All checks have successfully passed"
# - name: Check Deadline
# run: |
# deadline=2025-03-04T23:59
# if [[ $(date +'%Y-%m-%d') > $deadline ]];
# then
# echo "FIASCO: The deadline has expired"
# exit 1
# fi
- name: Prepare results
run: |
login=${{ github.event.pull_request.user.login }}
echo "$login" > gitid.txt
echo ${{ github.base_ref }} > base.txt
branch=${{ github.base_ref }}
Expand All @@ -41,19 +78,12 @@ jobs:
else
echo ${branch:1:2} > assignment_number.txt
fi
- name: Check Deadline
run: |
deadline=2023-12-30T23:59
if [[ $(date +'%Y-%m-%dT%H:%M') > $deadline ]];
then
echo "FIASCO: The deadline has expired"
echo $(date +'%Y-%m-%dT%H:%M')
exit 1
fi
- uses: actions/upload-artifact@v2
- name: Upload results
uses: actions/upload-artifact@v2
with:
name: share_info
path: |
gitid.txt
base.txt
assignment_number.txt
university.txt
103 changes: 102 additions & 1 deletion src/Expr.lama
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,109 @@ fun evalList (c, exprs) {
esac
}


fun addNamesVals(state, names, vals) {
foldl (fun (s, [name, value]) {s.addName(name, value)}, state, zip(names, vals))
}

fun addDefs(state, defs) {
foldl(fun (st, def) {
case def of
Fun(name, args, body) -> addFunction(st, name, args, body)
| Var (v) -> addNames(st, v)
esac
}, state, defs)
}

fun eval (c@[s, w], expr) {
failure ("evalExpr not implemented\n")
fun set(c@[s, w], name, value) {
[[s <- [name, value], w], value]
}

case expr of
Assn (l, r) ->
case evalList(c, {l, r}) of
[c, {l, r}] -> case l of
ElemRef (arr, ind) -> [c, arr[ind] := r]
| _ -> set(c, l, r)
esac
esac
| Set (name, expr) ->
case eval(c, expr) of
[c, value] -> set(c, name, value)
esac
| Seq (e1, e2) -> eval(eval(c, e1)[0], e2)
| Skip -> [c, T]
| If (cond, thn, els) ->
case eval(c, cond) of
[c, v] -> if v
then eval(c, thn)
else eval(c, els)
fi
esac
| While (cond, body) ->
case eval(c, cond) of
[c, v] -> if v != 0
then eval(c, Seq(body, expr))
else [c, T]
fi
esac
| DoWhile (body, cond) -> eval(eval(c, body)[0], While(cond, body))
| Var (vr) -> [c, lookup(s, vr)]
| Ref (vr) -> [c, vr]
| Const (int) -> [c, int]
| Binop (op, l, r) ->
case evalList(c, {l, r}) of
[c, w : v : _] -> [c, evalOp(op, w, v)]
esac
| Ignore (exp) -> [eval(c, exp)[0], T]
| Call (f, args) ->
case lookup(s, f) of
Fun (_, External) -> eval(c, Builtin(f, args))
| Fun(locs, body) ->
case evalList(c, args) of
[[st, w], vals] ->
case eval([addNamesVals(enterFunction(st), locs, vals), w], body) of
[[ss, w], v] -> [[leaveFunction(s, getGlobal(ss)), w], v]
esac
esac
esac
| Scope (d, e) ->
case enterScope(s) of
st -> case eval([addDefs(st, d), w], e) of
[[st, w], v] -> [[leaveScope(st), w], v]
esac
esac
| Array (elems) ->
case evalList(c, elems) of
[c, vals] -> [c, listArray(vals)]
esac
| Sexp (tag, elems) ->
case evalList(c, elems) of
[c, vals] -> [c, Sexp(tag, listArray(vals))]
esac
| Elem (arrExpr, indExpr) ->
case evalList(c, {arrExpr, indExpr}) of
[c, {arr, ind}] -> case arr of
Sexp (_, args) -> [c, args[ind]]
| _ -> [c, arr[ind]]
esac
esac
| ElemRef (arrExpr, indExpr) ->
case evalList(c, {arrExpr, indExpr}) of
[c, {arr, ind}] -> case arr of
Sexp (_, args) -> [c, ElemRef(args, ind)]
| _ -> [c, ElemRef(arr, ind)]
esac
esac
| Builtin (name, args) ->
case evalList(c, args) of
[[s, w], vals] -> case evalBuiltin(name, vals, w) of
[res, w] -> [[s, w], res]
esac
esac
| String (strng) -> [c, strng]
esac
}


Expand Down
15 changes: 14 additions & 1 deletion src/Parser.lama
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ fun distributeScope (expr, exprConstructor) {
| _ -> exprConstructor (expr)
esac
}


var ifExpr = memo $ eta syntax (
cE=exp kThen tE=scopeExpr { fun(a) { If(cE (Val), tE (a), assertVoid(a, Skip, loc))} } |
cE=exp kThen tE=scopeExpr kElse eE=scopeExpr { fun(a) { If(cE (Val), tE (a), eE (a))} } |
cE=exp kThen tE=scopeExpr kElif eE=ifExpr { fun(a) { If(cE (Val), tE (a), eE (a))} }
);

var primary = memo $ eta syntax (
-- array constant
Expand Down Expand Up @@ -147,7 +154,13 @@ var primary = memo $ eta syntax (
None -> {}
| Some (args) -> args
esac), loc)}} |
$(failure ("the rest of primary parsing in not implemented\n"))),
inbr[s("("), scopeExpr, s(")")] |
loc=pos kSkip {fun (a) {assertVoid(a, Skip, loc)}} |
loc=pos kIf ifE=ifExpr kFi {fun (a) {ifE (a)}} |
loc=pos kWhile cE=exp kDo bE=scopeExpr kOd {fun (a) {assertVoid(a, While(cE(Val), bE(Void)), loc)}} |
loc=pos kDo bE=scopeExpr kWhile cE=exp kOd {fun (a) {assertVoid(a, distributeScope(bE(Void), fun (expr) {DoWhile(expr, cE(Val)) }), loc)}} |
loc=pos kFor iE=scopeExpr s[","] cE=exp s[","] eE=exp kDo bE=scopeExpr kOd {fun (a) {assertVoid(a, distributeScope(iE(Void), fun (expr) {Seq(expr, While(cE(Val), Seq(bE(Void), eE(Void))))}), loc)}}
),
basic = memo $ eta (expr ({[Right, {[s (":="),
fun (l, loc, r) {
fun (a) {assertValue (a, Assn (l (Ref), r (Val)), loc)}
Expand Down
Loading
Loading