Skip to content

Commit

Permalink
Implement the load-all special form (#159)
Browse files Browse the repository at this point in the history
* Began working on automatic release generation.

* Implemented the load-all special form
  • Loading branch information
rahularya50 authored Oct 28, 2019
1 parent 3ecfcbd commit 2f097b9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
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

0 comments on commit 2f097b9

Please sign in to comment.