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

Implement the load-all special form #159

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 26 additions & 1 deletion editor/special_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional, Type

from datamodel import Expression, Symbol, Pair, SingletonTrue, SingletonFalse, Nil, Undefined, Promise, NilType
from datamodel import Expression, Symbol, Pair, SingletonTrue, SingletonFalse, Nil, Undefined, Promise, NilType, String
from environment import global_attr
from environment import special_form
from evaluate_apply import Frame, evaluate, Callable, evaluate_all, Applicable
Expand Down Expand Up @@ -438,6 +438,31 @@ def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder,
raise LoadError(e)


@global_attr("load-all")
class LoadAll(Applicable):
def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder, eval_operands=True):
verify_exact_callable_length(self, 1, len(operands))
if eval_operands:
operands = evaluate_all(operands, frame, gui_holder.expression.children[1:])
if not isinstance(operands[0], String):
raise OperandDeduceError(f"Load expected a String, received {operands[0]}.")
if logger.fragile:
raise IrreversibleOperationError()
from os import listdir
from os.path import join
directory = operands[0].value
try:
targets = sorted(listdir(directory))
targets = [join(directory, target) for target in targets if target.endswith(".scm")]
exprs = [make_list([Symbol("load"), make_list([Symbol("quote"), Symbol(x[:-4])])]) for x in targets]
equiv = make_list([Symbol("begin-noexcept")] + exprs)
gui_holder.expression.set_entries([equiv])
gui_holder.apply()
return evaluate(equiv, frame, gui_holder.expression.children[0], True)
except Exception as e:
raise SchemeError(e)


@special_form("begin-noexcept")
class BeginNoExcept(Callable):
def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder):
Expand Down
7 changes: 7 additions & 0 deletions release
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"${3}"

curl \
--user "$1" \
-d '{"tag_name":"'${2}'", "name":"'${3}'"}' \
-H "Content-Type: application/json" \
-X POST 'https://api.github.com/repos/Cal-CS-61A-Staff/scheme_editor/releases'
6 changes: 0 additions & 6 deletions strip_annotations

This file was deleted.

8 changes: 8 additions & 0 deletions transpile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
mkdir -p ./compiled
cp -r ./editor ./compiled/editor
for file in editor/*.py
do
py-backwards -i "$file" -t 3.5 -o compiled/editor
done
zip -r editor.zip editor