Skip to content

Commit

Permalink
Fix bug in base96_single
Browse files Browse the repository at this point in the history
Update requirements.txt
Update create_list to use a NumericLiteral
  • Loading branch information
Blue committed Nov 10, 2018
1 parent 24b2036 commit 42a9258
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions node/base96_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from nodes import Node


class Base96Single(Node):
char = "w"
args = 0
Expand All @@ -14,6 +15,7 @@ def __init__(self, value):
@Node.test_func([], [0], " ")
@Node.test_func([], [1], "!")
@Node.test_func([], [-32], "\x00")
@Node.test_func([], [4815162342], bytearray(b"\x91\xf8\x86\x98\x06"))
def func(self):
"""Return ord(const_arg)-32"""
return self.value
Expand All @@ -36,6 +38,7 @@ def accepts(cls, code, accept=False):
value |= (new & 0x7F)
value <<= 7
new = code[0]
code = code[1:]
value |= new
value -= 32
return code, cls(value)
2 changes: 1 addition & 1 deletion node/create_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class List(Node):
default_arg = 2
contents = []

def __init__(self, size: Node.Base10Single):
def __init__(self, size: Node.NumericLiteral):
self.args = size

def prepare(self, stack):
Expand Down
5 changes: 3 additions & 2 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def __call__(self, args):

def choose_function(self, args):
funcs = {}
for cur_func in self.get_functions(self):
all_funcs = self.get_functions(self)
for cur_func in all_funcs:
arg_types_dict = cur_func.__annotations__
has_star_args = cur_func.__code__.co_flags & 4
func_arg_names = cur_func.__code__.co_varnames[1:cur_func.__code__.co_argcount+has_star_args]
Expand Down Expand Up @@ -113,7 +114,7 @@ def choose_function(self, args):
try:
func = funcs[max(funcs.keys())]
except ValueError:
sys.stderr.write("No valid func for node %r, args: %r. Trying with Map.\n"%(self.__class__.__name__, args))
sys.stderr.write("No valid func for node %r, args: %r (All: %r). Trying with Map.\n"%(self.__class__.__name__, args, all_funcs))
return nodes["map"](self).choose_function(args)
return func

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flask
python-dateutil
pyephem
flask-cache
flask-caching
17 changes: 11 additions & 6 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from subprocess import Popen, PIPE, STDOUT, TimeoutExpired

from flask import Flask, request, redirect, render_template, send_from_directory
from flask_cache import Cache
from flask_caching import Cache

import explainer
import lang_ast
Expand Down Expand Up @@ -221,14 +221,16 @@ def get_docs():
pass
for test in func.tests[::-1]:
try:
#print(node, test, end=" ")
inp = literal_gen.stack_literal(test[0])
#print(test)
if isinstance(test[-1], bytearray):
cmd = nodes.nodes[node].char + test[-1]
else:
cmd = nodes.nodes[node].char+bytearray(test[-1].encode("ascii"))
lang_ast.test_code(inp+cmd, test[1])
try:
lang_ast.test_code(inp+cmd, test[1])
except AssertionError:
print(func)
raise
except NotImplementedError:
func_doc["input"] = "Literal Undefined\n"
func_doc["output"] = str(test[1])+"\n"
Expand All @@ -240,8 +242,11 @@ def get_docs():
cmd = "." + chr(cmd[0] & 0x7F) + cmd[1:].decode("ascii")
elif cmd[:1] == b"~":
cmd = "~." + chr(cmd[1] & 0x7F)
func_doc["input"] += (inp.decode("ascii")+cmd+"\n")
func_doc["output"] += (str(test[1])+"\n")
try:
func_doc["input"] += (inp.decode("ascii")+cmd+"\n")
func_doc["output"] += (str(test[1])+"\n")
except TypeError:
pass
func_doc["input"] = func_doc["input"][:-1]
func_doc["output"] = func_doc["output"][:-1]
func_doc["output"] = func_doc["output"].replace("<", "&lt;")
Expand Down

0 comments on commit 42a9258

Please sign in to comment.