Permalink
Browse files
Fix oheap encoding of osh.asdl.
I introduced a repeated Id field in AndOr(ids* ops, ...), to fix the
precedence of && and ||.
This case wasn't handled correctly by asdl/gen_cpp.py.
'asdl/run.sh osh-demo' now works again.
Loading branch information...
Showing
5 changed files
with
34 additions
and
4 deletions .
+7
−2
asdl/encode.py
+10
−2
asdl/gen_cpp.py
+13
−0
asdl/osh_demo.cc
+1
−0
asdl/run.sh
+3
−0
benchmarks/osh-runtime.sh
@@ -160,6 +160,11 @@ def EncodeArray(obj_list, item_desc, enc, out):
for item in obj_list:
enc.Int(item, array_chunk)
elif isinstance (item_desc, asdl.UserType):
# Assume Id for now
for item in obj_list:
enc.Int(item.enum_value, array_chunk)
elif isinstance (item_desc, asdl.StrType):
for item in obj_list:
ref = out.Write(enc.PaddedStr(item))
@@ -172,8 +177,8 @@ def EncodeArray(obj_list, item_desc, enc, out):
else :
# A simple value is either an int, enum, or pointer. (Later: Iter<Str>
# might be possible for locality.)
assert isinstance (item_desc, asdl.Sum) or isinstance (
item_desc, asdl.Product), item_desc
assert isinstance (item_desc, asdl.Sum) or \
isinstance ( item_desc, asdl.Product), item_desc
# This is like vector<T*>
# Later:
@@ -308,7 +308,7 @@ def VisitField(self, field, type_name, offset, depth):
body_line1 = ARRAY_OFFSET
inline_body = ' return Ref(base, %(offset)d ).Int(a);'
elif ctype.endswith(' _e' ):
elif ctype.endswith(' _e' ) or ctype in self .enum_types :
func_header = A_POINTER + ' {'
body_line1 = ARRAY_OFFSET
inline_body = (
@@ -406,7 +406,15 @@ def main(argv):
schema_path = argv[2 ]
with open (schema_path) as input_f:
module = asdl.parse(input_f)
type_lookup = asdl.ResolveTypes(module)
# TODO : gen_cpp.py should be a library and the application should add Id?
# Or we should enable ASDL metaprogramming, and let Id be a metaprogrammed
# simple sum type.
from core.id_kind import Id
app_types = {' id' : asdl.UserType(Id)}
type_lookup = asdl.ResolveTypes(module, app_types)
f = sys.stdout
@@ -85,6 +85,19 @@ void PrintCommand(const uint32_t* base, const command_t& e, int indent) {
printf (" \n " );
break ;
}
case command_e::AndOr: {
auto & e2 = static_cast <const AndOr&>(e);
printf (" Ops: " );
for (int i = 0 ; i < e2 .ops_size (base); ++i) {
printf (" %hhu " , e2 .ops (base, i));
}
printf (" \n " );
for (int i = 0 ; i < e2 .children_size (base); ++i) {
PrintCommand (base, e2 .children (base, i), indent+1 );
}
printf (" \n " );
break ;
}
case command_e::CommandList: {
auto & e2 = static_cast <const CommandList&>(e);
printf (" CommandList %d\n " , e2 .children_size (base));
@@ -152,6 +152,7 @@ osh-demo() {
local code=' echo hi; echo bye # comment'
local code=' declare -r -x foo' # for testing repeated array
local code=' echo x && echo y && echo z || die' # for && || chains
# local code='echo $(( 2 + 3 ))'
# local code='echo $(( -2 * -3 ))' # test negative integers
bin/osh -n --ast-format oheap -c " $code " > $data
@@ -133,6 +133,9 @@ runtime-task() {
cpython)
# NOTE: $task_arg unused.
# This configure script defeats --runtime-mem-dump, I think because of:
# exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# autoconf supports running configure from a different directory.
pushd $files_out_dir > /dev/null
Toggle all file notes
0 comments on commit
1c7cd4b