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

[HSE] A02 Daniil Shindov #1516

Open
wants to merge 59 commits into
base: A02-straight-line-x86
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
01362bf
Revert "Prepared assignment"
dboulytchev Feb 24, 2021
5e6e7cc
Makefile
dboulytchev Mar 2, 2021
2c276c3
Merge branch 'A01-straight-line-int-sm' of github.com:danyaberezun/co…
dboulytchev Mar 2, 2021
6d98fc3
Revert "Makefile"
dboulytchev Mar 3, 2021
a6c5b1f
update travis.yml: update docker archive
danyaberezun Sep 15, 2021
975dd8e
add check.yml
danyaberezun Sep 16, 2021
99f7710
Update check.yml
danyaberezun Sep 16, 2021
49f9723
Update check.yml
danyaberezun Sep 16, 2021
bb3dc6c
Update check.yml
danyaberezun Sep 16, 2021
13df55c
Update check.yml
danyaberezun Sep 16, 2021
d01c6f3
fix secu
danyaberezun Sep 16, 2021
b7f94a7
Update check.yml
danyaberezun Sep 16, 2021
3189743
Update postaction.yml
danyaberezun Sep 16, 2021
7818d31
Update check.yml
danyaberezun Sep 16, 2021
2e41e78
Update check.yml
danyaberezun Sep 16, 2021
81bfb82
Update postaction.yml
danyaberezun Sep 16, 2021
b4195c0
Update check.yml
danyaberezun Sep 16, 2021
a86da05
Update postaction.yml
danyaberezun Sep 16, 2021
e8d8e5a
rm extra
danyaberezun Sep 16, 2021
6adea44
Update check.yml
danyaberezun Sep 16, 2021
2bf9fc4
Update check.yml
danyaberezun Sep 16, 2021
eb1aac9
add synchronize
Oct 11, 2021
942d490
Update check.yml
danyaberezun Feb 11, 2022
be2f297
Update check.yml
danyaberezun Sep 27, 2022
05d2bd5
update readme
danyaberezun Jan 31, 2023
18581f3
comment check of SM
danyaberezun Jan 31, 2023
e51964a
update deadline
danyaberezun Jan 31, 2023
d222592
add .gitattributes
danyaberezun Jan 31, 2023
3b4a7bf
update README.md
danyaberezun Jan 31, 2023
b04f011
add pdfs
danyaberezun Jan 31, 2023
c1dade3
upd lfs
danyaberezun Jan 31, 2023
aa46d16
add pdfs
danyaberezun Jan 31, 2023
2fe02a4
fix check.yml
danyaberezun Feb 2, 2023
2ea5e3f
fix check.yml
danyaberezun Feb 2, 2023
48120c4
restore -s mode check
danyaberezun Feb 2, 2023
b3d9f79
add gitignore
danyaberezun Feb 2, 2023
f8d2218
Switched off SM regression; set up the deadline to 07.03.2023
dboulytchev Feb 21, 2023
e1b17a4
Switched off SM regression; set up the deadline to 07.03.2023
dboulytchev Feb 21, 2023
ccdf22a
disable deadline check
danyaberezun Feb 28, 2023
3895208
uncomment SM regression tests
danyaberezun Feb 28, 2023
42861f6
Assignment
dboulytchev Mar 1, 2023
d865b34
Assignment
dboulytchev Mar 1, 2023
035b845
Fixed README
dboulytchev Mar 4, 2023
45880f0
move all lectures to main
danyaberezun Apr 6, 2023
97f367d
move all lectures to main
danyaberezun Apr 6, 2023
f7d02e9
Set the deadline
dboulytchev Oct 9, 2023
70558de
Update check.yml
danyaberezun Feb 9, 2024
f417f3b
Update check.yml
danyaberezun Feb 9, 2024
3bf024b
Update check.yml
danyaberezun Feb 9, 2024
cb36dfd
update workflow
danyaberezun Feb 26, 2024
a996a11
rm outdated file
danyaberezun Feb 26, 2024
5264dad
Revert "rm outdated file"
danyaberezun Feb 27, 2024
daa8b80
update workflow: add university check; move deadline check to main wo…
danyaberezun Feb 27, 2024
d5de43b
rm outdated file
danyaberezun Feb 27, 2024
8d24383
Update check.yml
danyaberezun Sep 13, 2024
f9ac792
Added universities
dboulytchev Oct 28, 2024
c96c6bf
done A01
deker104 Nov 2, 2024
fb97fd0
Merge branch 'A01-straight-line-int-sm' into A02-straight-line-x86
deker104 Nov 9, 2024
e2fa92e
done AO2
deker104 Nov 9, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: |
prName="${{ github.event.pull_request.title }}"
university=`echo $prName | awk '{ sub(/.*\[/, ""); sub(/\].*/, ""); print }'`
universities=("SPBGU" "NUP" "CUB")
universities=("SPBGU" "NUP" "CUB" "HSE" "ITMO")
if [[ ! $(echo ${universities[@]} | grep -F -w $university) ]];
then
echo "FIASCO: Wrong university name or format in pull request title: $university "
Expand Down
26 changes: 22 additions & 4 deletions src/Expr.lama
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-- Expression evaluator

import List;
import State;


-- The evaluator itself: takes a state and an expression,
-- returns integer value
--
Expand All @@ -12,7 +10,27 @@ import State;
-- expr = Var (string) |
-- Const (int) |
-- Binop (string, expr, expr)

public fun evalExpr (st, expr) {
failure ("evalExpr not implemented\n")
case expr of
Var(name) -> st(name)
| Const(value) -> value
| Binop(op, lhs, rhs) -> getOp(op)(evalExpr(st, lhs), evalExpr(st, rhs))
esac
}
public fun getOp (op) {
case op of
"+" -> fun (x, y) {x + y}
| "-" -> fun (x, y) {x - y}
| "*" -> fun (x, y) {x * y}
| "/" -> fun (x, y) {x / y}
| "%" -> fun (x, y) {x % y}
| "==" -> fun (x, y) {x == y}
| "!=" -> fun (x, y) {x != y}
| "<" -> fun (x, y) {x < y}
| "<=" -> fun (x, y) {x <= y}
| ">" -> fun (x, y) {x > y}
| ">=" -> fun (x, y) {x >= y}
| "&&" -> fun (x, y) {x && y}
| "!!" -> fun (x, y) {x !! y}
esac
}
62 changes: 42 additions & 20 deletions src/SM.lama
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Stack machine.

import List;
import World;
import State;
Expand All @@ -10,40 +9,63 @@ import Fun;
-- Stack code printer. Takes a list of SM instructions, return its
-- string representation.
public fun showSMInsn (i) {
case i of
READ -> sprintf ("READ")
| WRITE -> sprintf ("WRITE")
| BINOP (s) -> sprintf ("BINOP %s", s)
| LD (x) -> sprintf ("LD %s", x)
| ST (x) -> sprintf ("ST %s", x)
| CONST (n) -> sprintf ("CONST %d", n)
esac
case i of
READ -> sprintf("READ")
| WRITE -> sprintf("WRITE")
| BINOP(s) -> sprintf("BINOP %s", s)
| LD(x) -> sprintf("LD %s", x)
| ST(x) -> sprintf("ST %s", x)
| CONST(n) -> sprintf("CONST %d", n)
esac
}

public fun showSM (prg) {
map (fun (i) {showSMInsn (i) ++ "\n"}, prg).stringcat
map(fun (i) {showSMInsn(i) ++ "\n"}, prg).stringcat
}

-- Stack machine interpreter. Takes an SM-configuration and a program,
-- returns a final configuration
fun eval (c, insns) {
failure ("SM eval not implemented\n")
-- printf("stack:");
-- iter(fun (x) {printf("%d ", x)}, c[0]);
-- printf("\n");
-- printf("output:");
-- iter(fun (x) {printf("%d ", x)}, c[2][1]);
-- printf("\n");
case [c, insns] of
[c, {}] -> c
| [[stack, state, world], READ: rest] -> (
var res = readWorld(world);

eval([res[0] : stack, state, res[1]], rest)
)
| [[value: stack, state, world], WRITE: rest] -> eval([stack, state, writeWorld(value, world)], rest)
| [[stack, state, world], CONST(value): rest] -> eval([value : stack, state, world], rest)
| [[stack, state, world], LD(name): rest] -> eval([state(name) : stack, state, world], rest)
| [[value: stack, state, world], ST(name): rest] -> eval([stack, state <- [name, value], world], rest)
| [[b: a: stack, state, world], BINOP(op): rest] -> eval([getOp(op)(a, b) : stack, state, world], rest)
esac
}

-- Runs a stack machine for a given input and a given program, returns an output
public fun evalSM (input, insns) {
eval ([{}, emptyState, createWorld (input)], insns)[2].getOutput
eval([{}, emptyState, createWorld(input)], insns)[2].getOutput
}

-- Compiles an expression into a stack machine code.
-- Takes an expression, returns a list of stack machine instructions
fun compileExpr (expr) {
failure ("compileExpr not implemented\n")
case expr of
Var(name) -> {LD(name)}
| Const(value) -> {CONST(value)}
| Binop(op, lhs, rhs) -> compileExpr(lhs) +++ compileExpr(rhs) +++ {BINOP(op)}
esac
}

-- Compiles a statement into a stack machine code.
-- Takes a statement, returns a list of stack machine
-- instructions.
public fun compileSM (stmt) {
failure ("compileSM not implemented\n")
}
case stmt of
Skip -> {}
| Seq(stmt, rest) -> compileSM(stmt) +++ compileSM(rest)
| Assn(name, expr) -> compileExpr(expr) +++ {ST(name)}
| Read(name) -> {READ, ST(name)}
| Write(expr) -> compileExpr(expr) +++ {WRITE}
esac
}
17 changes: 10 additions & 7 deletions src/Stmt.lama
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Statement evaluator.

import State;
import Expr;
import World;
Expand All @@ -15,12 +14,16 @@ import World;
-- Skip |
-- Read (string) |
-- Write (expr) |

fun eval (c, stmt) {
failure ("Stmt eval not implemented\n")
fun eval (c@[state, world], stmt) {
case stmt of
Skip -> c
| Seq(stmt, rest) -> eval(eval(c, stmt), rest)
| Assn(name, expr) -> [state <- [name, evalExpr(state, expr)], world]
| Read(name) -> (var res = readWorld(world); [state <- [name, res[0]], res[1]])
| Write(expr) -> [state, writeWorld(evalExpr(state, expr), world)]
esac
}

-- Evaluates a program with a given input and returns an output
public fun evalStmt (input, stmt) {
eval ([emptyState, createWorld (input)], stmt).snd.getOutput
}
eval([emptyState, createWorld(input)], stmt).snd.getOutput
}
Loading
Loading