Skip to content

Commit

Permalink
Import: Assignment 1 - Shell
Browse files Browse the repository at this point in the history
  • Loading branch information
fubupc committed May 23, 2023
1 parent 20b40e0 commit 3435048
Show file tree
Hide file tree
Showing 89 changed files with 1,889 additions and 0 deletions.
154 changes: 154 additions & 0 deletions 1-shell/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# reftex files
*.rel

# cask packages
.cask/

# Flycheck
flycheck_*.el

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
*.bin
*.img

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Generated by Cargo
# will have compiled files and executables
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# General
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Submission files
*.tar.gz

# Assignment 1 specific
ttywrite/input
ttywrite/output
73 changes: 73 additions & 0 deletions 1-shell/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
ASSIGNMENT_NAME := assignment1
BASE_URL := https://cs140e.sergio.bz
SUBMISSION_SITE := $(BASE_URL)/assignments/submission/
SUBMIT_TAR := $(ASSIGNMENT_NAME).tar.gz

CS140E_REL_ROOT := ..
REPO_NAMES := 0-blinky 1-shell os
QUESTIONS_DIRS := $(shell find . -type d -name "questions")

.PHONY: all test check submission clean

all:
@echo "usage: make [target]"
@echo
@echo "available targets:"
@echo "test run tests for all targets"
@echo "check ensure every question is answered"
@echo "submission create submission tarball"
@echo "clean clean products from all targets"

test:
cd ttywrite && ./test.sh
cd stack-vec && cargo test
cd xmodem && cargo test

check:
@okay=true; \
for qdir in $(QUESTIONS_DIRS); do \
for file in "$${qdir}/"*; do \
if ! [ -s "$${file}" ]; then \
okay=false; \
echo "Question file '$${file}' is empty."; \
fi \
done \
done; \
if ! $$okay; then \
echo "Questions remain unanswered. Aborting."; \
exit 1; \
else \
echo "All questions appear to be answered."; \
fi

submission: $(SUBMIT_TAR)
@echo "Your submission file "$^" was successfully created."
@echo "Submit it at $(SUBMISSION_SITE)"

.FORCE:
$(SUBMIT_TAR): .FORCE
@rm -f $@
@cwd="$${PWD}"; \
for repo in $(REPO_NAMES); do \
repo_path="$${cwd}/$(CS140E_REL_ROOT)/$${repo}"; \
cd "$${repo_path}"; \
if ! [ -z "$$(git status --porcelain)" ]; then \
echo "There are uncommited changes in $${repo}! Aborting."; \
rm -f $@; \
exit 1; \
else \
git_files=$$(git ls-files) ; \
cd "$${repo_path}/.." ; \
for file in $$git_files; do \
tar -rf "$${cwd}/$@" "$${repo}/$${file}"; \
done \
fi \
done
@gzip -f $@
@mv $@.gz $@

clean:
rm -f $(SUBMIT_TAR)
cd ttywrite && cargo clean
cd stack-vec && cargo clean
cd xmodem && cargo clean
10 changes: 10 additions & 0 deletions 1-shell/ferris-wheel/compile-fail/modules-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// FIXME: Prevent this file from compiling! Diff budget: 1 line.

mod a {
pub fn f() { }
}

// Do not modify this function.
fn main() {
a::f();
}
10 changes: 10 additions & 0 deletions 1-shell/ferris-wheel/compile-fail/move.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// FIXME: Prevent this file from compiling! Diff budget: 1 line.
#[derive(Clone, Copy)]
struct MyType(usize);

// Note: do not modify this function.
fn main() {
let x = MyType(10);
let y = x;
let z = x;
}
10 changes: 10 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/borrow-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// FIXME: Make me compile! Diff budget: 1 line.

struct MyType(usize);

// Do not modify this function.
pub fn main() {
let x = MyType(1);
let y = &x;
let z = *y;
}
9 changes: 9 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// FIXME: Make me compile! Diff budget: 3 lines.

const VAR: i32 = add(34, 10);

fn add(a: i32, b: i32) -> i32 {
a + b
}

fn main() { }
14 changes: 14 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// FIXME: Make me compile! Diff budget: 1 line.
enum Duration {
MilliSeconds(u64),
Seconds(u32),
Minutes(u16)
}

pub fn main() {
println!("Duration: {:?}", Duration::MilliSeconds(1200));

let x = Duration::Minutes(10);
let y = x;
let z = x;
}
10 changes: 10 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/feature-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// FIXME: Make me compile! Diff budget: 2 lines.
// Do not modify this definition.
enum Duration {
MicroSeconds(u128),
MilliSeconds(u64),
Seconds(u32),
Minutes(u16)
}

fn main() { }
14 changes: 14 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/io-read-write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// FIXME: Make me compile! Diff budget: 2 lines.
use std::io;

struct ReadWrapper<T: io::Read> {
inner: T
}

impl io::Read for ReadWrapper<T> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
self.inner.read(buf)
}
}

fn main() { }
16 changes: 16 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/lifetimes-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// FIXME: Make me compile! Diff budget: 1 line.

struct StrWrapper<'a>(&'a str);

impl<'a> StrWrapper<'a> {
fn inner(&self) -> &str {
self.0
}
}

// Do not modify this function.
pub fn main() {
let string = "Hello!";
let wrapper = StrWrapper(&string);
let _: &'static str = wrapper.inner();
}
17 changes: 17 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/lifetimes-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// FIXME: Make me compile! Diff budget: 3 lines.

// Do not modify the inner type &'a T.
struct RefWrapper<T>(&'a T);

impl RefWrapper {
fn inner(&self) -> &T {
self.0
}
}

// Do not modify this function.
pub fn main() {
let x = 1;
let mut r = &x;
r = RefWrapper(r).inner();
}
9 changes: 9 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/lifetimes-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// FIXME: Make me compile! Diff budget: 2 lines.

// Do not modify the inner type &'a T.
struct RefWrapper<T>(&'a T);

// Do not modify the inner type &'b RefWrapper<'a, T>.
struct RefWrapperWrapper<T>(&'b RefWrapper<'a, T>);

pub fn main() { }
15 changes: 15 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/lifetimes-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// FIXME: Make me compile! Diff budget: 3 lines.

// Do not modify the inner type &'a T.
struct RefWrapper<T>(&'a T);

// Do not modify the inner type &'b RefWrapper<'a, T>.
struct RefWrapperWrapper<T>(&'b RefWrapper<'a, T>);

impl RefWrapperWrapper {
fn inner(&self) -> &'a T {
(self.0).0
}
}

pub fn main() { }
6 changes: 6 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/mutability-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// FIXME: Make me compile! Diff budget: 1 line.
fn make_1(v: &u32) {
*v = 1;
}

pub fn main() { }
6 changes: 6 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/mutability-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// FIXME: Make me compile! Diff budget: 1 line.

pub fn main() {
let x = 10;
*x = 20;
}
6 changes: 6 additions & 0 deletions 1-shell/ferris-wheel/compile-pass/mutability-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// FIXME: Make me compile! Diff budget: 1 line.

pub fn main() {
let x = 10;
x = 20;
}
Loading

0 comments on commit 3435048

Please sign in to comment.