From 2f097b97a25106a64000b8254891547f7f1551dd Mon Sep 17 00:00:00 2001 From: Rahul Arya Date: Mon, 28 Oct 2019 01:21:59 -0700 Subject: [PATCH] Implement the load-all special form (#159) * Began working on automatic release generation. * Implemented the load-all special form --- editor/special_forms.py | 27 ++++++++++++++++++++++++++- release | 7 +++++++ strip_annotations | 6 ------ transpile | 8 ++++++++ 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 release delete mode 100644 strip_annotations create mode 100644 transpile diff --git a/editor/special_forms.py b/editor/special_forms.py index 29d410d9..a4f0e384 100644 --- a/editor/special_forms.py +++ b/editor/special_forms.py @@ -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 @@ -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): diff --git a/release b/release new file mode 100644 index 00000000..38dbae21 --- /dev/null +++ b/release @@ -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' diff --git a/strip_annotations b/strip_annotations deleted file mode 100644 index e12d354c..00000000 --- a/strip_annotations +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -cp -r ./editor ./compiled -for file in editor/*.py -do - py-backwards -i "$file" -t 3.5 -o compiled -d -done \ No newline at end of file diff --git a/transpile b/transpile new file mode 100644 index 00000000..f023f28d --- /dev/null +++ b/transpile @@ -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 \ No newline at end of file