Commit 80eae736 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Add starter code

parent 6c3e936b
No related merge requests found
Showing with 57 additions and 6 deletions
+57 -6
......@@ -18,6 +18,7 @@ If you want to try your `make.js` on a real project, I have included a [makefile
If you have a macOS or Linux machine, you should be able to download the CS 24 [starter code](https://gitlab.caltech.edu/cs24-19fa/project05/tree/67155769103e2c50dde1a9ec18f4eb5a849fdca8) and build the `subpython` executable:
```
# cd to the directory with the CS 24 code
$ cd project05
# Build the interactive subpython interpreter
$ node ../make.js ../tests/cs24-project05.js subpython
......@@ -26,9 +27,14 @@ $ node ../make.js ../tests/cs24-project05.js subpython
$ ./subpython -m 100000
CS24 Subpython [Fall 2019]
Using a memory size of 100000 bytes.
>>> 1 + 2
>>> x = 1
>>> y = 2
>>> x + y
3
# Remove all built files
$ node ../make.js ../tests/cs24-project05.js clean
# Run the tests (they fail on the starter code)
$ node ../make.js ../tests/cs24-project05.js test
```
......
const {execFile} = require('child_process')
const path = require('path')
const {promisify} = require('util')
// A version of child_process.execFile() that returns a Promise
const exec = promisify(execFile)
/**
* Creates a Promise representing running the given command.
* For example, runCommand(['clang', '-c', 'main.c']) runs `clang -c main.c`.
* The returned Promise resolves when the command finishes.
* If the command fails, the returned Promise rejects with the error.
* Also prints the output from the command.
*/
const runCommmand = ([command, ...args]) =>
exec(command, args)
.then(({stdout, stderr}) => {
process.stdout.write(stdout)
process.stderr.write(stderr)
})
const [recipesFile, ...targets] = process.argv.slice(2)
if (!recipesFile) throw new Error('Missing recipes file')
const recipes = require(path.resolve(recipesFile))
// Map of build targets to their recipes
const recipeMap = new Map()
// TODO: build `recipeMap` from `recipes`
// Map of build targets to Promises representing their build process.
// This allows you to reuse these Promises if multiple targets have the same dependencies.
const buildPromises = new Map()
/**
* Creates a Promise representing building the given target.
* Should use the Promise in `buildPromises` for this target if it exists,
* and store the new Promise in `buildPromises`.
*
* @param target the target file to build
* @return a Promise that resolves when `target` has been built
*/
function makeBuildPromise(target) {
// TODO
}
// TODO: use makeBuildPromise() to build all the requested targets
......@@ -11,6 +11,6 @@
},
"license": "MIT",
"devDependencies": {
"ava": "^3.8.1"
"ava": "^3.13.0"
}
}
const CC = 'clang'
const CFLAGS = ['-Wall', '-Wextra', '-Werror']
const LDFLAGS = ['-lreadline']
const CFLAGS = ['-Wall', '-Wextra', '-Werror', '-DNREADLINE']
const SUBPYTHON = 'subpython'
const OBJS = [
......@@ -77,7 +76,7 @@ module.exports = [
{
target: SUBPYTHON,
dependencies: OBJS,
command: [CC, ...CFLAGS, ...OBJS, '-o', SUBPYTHON, ...LDFLAGS]
command: [CC, ...CFLAGS, ...OBJS, '-o', SUBPYTHON]
},
...TESTS3.map(test => {
const dependency = `tests/${test}.py`
......@@ -125,6 +124,6 @@ module.exports = [
{
target: 'clean',
dependencies: [],
command: ['sh', '-c', `rm -f *.d *.o subpython tests/*.txt`]
command: ['sh', '-c', 'rm -f *.d *.o subpython tests/*.txt']
}
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment