// Copyright 2024 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // https://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #ifdef WASM #define WASM_EXPORT(name) __attribute__((export_name(name))) void * alloc(int size); #else #define WASM_EXPORT(name) #endif #define BUFFER(name, type, size) type name[size]; \ WASM_EXPORT("_get_"#name) type* get_##name() {return name;} \ WASM_EXPORT("_len_"#name"__"#type) int get_##name##_len() {return (size);} #define DYNAMIC_BUFFER(name, type) type * name = NULL; int name##_len = 0; \ WASM_EXPORT("_get_"#name) type* get_##name() {return name;} \ WASM_EXPORT("_len_"#name"__"#type) int get_##name##_len() {return (name##_len);} \ void name##_alloc(int size) {name = (type*)alloc(size*sizeof(type)); name##_len = size;} enum { TAPE_LENGTH = 16, // must be 2 ** N PAIR_LENGTH = TAPE_LENGTH * 2 };